diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index fdca6d0e17a1d..7cae74b59c7f9 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -191,7 +191,7 @@ rustc_queries! { /// Returns the inferred outlives predicates (e.g., for `struct /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`). - query inferred_outlives_of(_: DefId) -> &'tcx [ty::Predicate<'tcx>] {} + query inferred_outlives_of(_: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {} /// Maps from the `DefId` of a trait to the list of /// super-predicates. This is a subset of the full list of diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index 4696d4da58ec0..2734fce4ea55a 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -378,15 +378,21 @@ fn orphan_check_trait_ref<'tcx>( // Let Ti be the first such type. // - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti) // - fn uncover_fundamental_ty(ty: Ty<'_>) -> Vec<Ty<'_>> { - if fundamental_ty(ty) { - ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(ty)).collect() + fn uncover_fundamental_ty<'a>( + tcx: TyCtxt<'_>, + ty: Ty<'a>, + in_crate: InCrate, + ) -> Vec<Ty<'a>> { + if fundamental_ty(ty) && !ty_is_local(tcx, ty, in_crate) { + ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate)).collect() } else { vec![ty] } } - for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) { + for input_ty in + trait_ref.input_types().flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate)) + { debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty); if ty_is_local(tcx, input_ty, in_crate) { debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty); diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 4660e8025d48e..8807f3f8ed357 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1138,7 +1138,7 @@ pub struct CratePredicatesMap<'tcx> { /// For each struct with outlive bounds, maps to a vector of the /// predicate of its outlive bounds. If an item has no outlives /// bounds, it will have no entry. - pub predicates: FxHashMap<DefId, &'tcx [ty::Predicate<'tcx>]>, + pub predicates: FxHashMap<DefId, &'tcx [(ty::Predicate<'tcx>, Span)]>, } impl<'tcx> AsRef<Predicate<'tcx>> for Predicate<'tcx> { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 15adf7e4add73..6e8bc11162f66 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -106,8 +106,6 @@ pub fn abort_on_err<T>(result: Result<T, ErrorReported>, sess: &Session) -> T { pub trait Callbacks { /// Called before creating the compiler instance fn config(&mut self, _config: &mut interface::Config) {} - /// Called early during compilation to allow other drivers to easily register lints. - fn extra_lints(&mut self, _ls: &mut lint::LintStore) {} /// Called after parsing. Return value instructs the compiler whether to /// continue the compilation afterwards (defaults to `Compilation::Continue`) fn after_parsing(&mut self, _compiler: &interface::Compiler) -> Compilation { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index ad674911e6f33..7c19449f96b86 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1497,10 +1497,10 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN impl ExplicitOutlivesRequirements { fn lifetimes_outliving_lifetime<'tcx>( - inferred_outlives: &'tcx [ty::Predicate<'tcx>], + inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)], index: u32, ) -> Vec<ty::Region<'tcx>> { - inferred_outlives.iter().filter_map(|pred| { + inferred_outlives.iter().filter_map(|(pred, _)| { match pred { ty::Predicate::RegionOutlives(outlives) => { let outlives = outlives.skip_binder(); @@ -1517,10 +1517,10 @@ impl ExplicitOutlivesRequirements { } fn lifetimes_outliving_type<'tcx>( - inferred_outlives: &'tcx [ty::Predicate<'tcx>], + inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)], index: u32, ) -> Vec<ty::Region<'tcx>> { - inferred_outlives.iter().filter_map(|pred| { + inferred_outlives.iter().filter_map(|(pred, _)| { match pred { ty::Predicate::TypeOutlives(outlives) => { let outlives = outlives.skip_binder(); @@ -1539,7 +1539,7 @@ impl ExplicitOutlivesRequirements { &self, param: &'tcx hir::GenericParam, tcx: TyCtxt<'tcx>, - inferred_outlives: &'tcx [ty::Predicate<'tcx>], + inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)], ty_generics: &'tcx ty::Generics, ) -> Vec<ty::Region<'tcx>> { let index = ty_generics.param_def_id_to_index[ diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 0dc9f91ae00e1..08554c83ed5bf 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -197,6 +197,13 @@ impl<'tcx> SpecializedEncoder<Span> for EncodeContext<'tcx> { return TAG_INVALID_SPAN.encode(self) } + // HACK(eddyb) there's no way to indicate which crate a Span is coming + // from right now, so decoding would fail to find the SourceFile if + // it's not local to the crate the Span is found in. + if self.source_file_cache.is_imported() { + return TAG_INVALID_SPAN.encode(self) + } + TAG_VALID_SPAN.encode(self)?; span.lo.encode(self)?; @@ -379,6 +386,7 @@ impl<'tcx> EncodeContext<'tcx> { .filter(|source_file| { // No need to re-export imported source_files, as any downstream // crate will import them from their original source. + // FIXME(eddyb) the `Span` encoding should take that into account. !source_file.is_imported() }) .map(|source_file| { diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index f2aef2c12c7df..9ad63f28a8e16 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -578,7 +578,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) | hir::ItemKind::Trait(..) | - hir::ItemKind::Impl(..) => self.tcx.sess.source_map().def_span(item.span), + hir::ItemKind::Impl(..) => item.ident.span, _ => item.span, }; let participle = match item.kind { diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 136ab1f0444fa..9b254ab7ec1a2 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -316,22 +316,8 @@ impl<'a> PathSource<'a> { } } -struct LateResolutionVisitor<'a, 'b> { - r: &'b mut Resolver<'a>, - - /// The module that represents the current item scope. - parent_scope: ParentScope<'a>, - - /// The current set of local scopes for types and values. - /// FIXME #4948: Reuse ribs to avoid allocation. - ribs: PerNS<Vec<Rib<'a>>>, - - /// The current set of local scopes, for labels. - label_ribs: Vec<Rib<'a, NodeId>>, - - /// The trait that the current context can refer to. - current_trait_ref: Option<(Module<'a>, TraitRef)>, - +#[derive(Default)] +struct DiagnosticMetadata { /// The current trait's associated types' ident, used for diagnostic suggestions. current_trait_assoc_types: Vec<Ident>, @@ -350,6 +336,29 @@ struct LateResolutionVisitor<'a, 'b> { /// Only used for better errors on `fn(): fn()`. current_type_ascription: Vec<Span>, + + /// Only used for better errors on `let <pat>: <expr, not type>;`. + current_let_binding: Option<(Span, Option<Span>, Option<Span>)>, +} + +struct LateResolutionVisitor<'a, 'b> { + r: &'b mut Resolver<'a>, + + /// The module that represents the current item scope. + parent_scope: ParentScope<'a>, + + /// The current set of local scopes for types and values. + /// FIXME #4948: Reuse ribs to avoid allocation. + ribs: PerNS<Vec<Rib<'a>>>, + + /// The current set of local scopes, for labels. + label_ribs: Vec<Rib<'a, NodeId>>, + + /// The trait that the current context can refer to. + current_trait_ref: Option<(Module<'a>, TraitRef)>, + + /// Fields used to add information to diagnostic errors. + diagnostic_metadata: DiagnosticMetadata, } /// Walks the whole crate in DFS order, visiting each item, resolving names as it goes. @@ -373,7 +382,18 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { self.resolve_expr(expr, None); } fn visit_local(&mut self, local: &'tcx Local) { + let local_spans = match local.pat.kind { + // We check for this to avoid tuple struct fields. + PatKind::Wild => None, + _ => Some(( + local.pat.span, + local.ty.as_ref().map(|ty| ty.span), + local.init.as_ref().map(|init| init.span), + )), + }; + let original = replace(&mut self.diagnostic_metadata.current_let_binding, local_spans); self.resolve_local(local); + self.diagnostic_metadata.current_let_binding = original; } fn visit_ty(&mut self, ty: &'tcx Ty) { match ty.kind { @@ -415,7 +435,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { } } fn visit_fn(&mut self, fn_kind: FnKind<'tcx>, declaration: &'tcx FnDecl, sp: Span, _: NodeId) { - let previous_value = replace(&mut self.current_function, Some(sp)); + let previous_value = replace(&mut self.diagnostic_metadata.current_function, Some(sp)); debug!("(resolving function) entering function"); let rib_kind = match fn_kind { FnKind::ItemFn(..) => FnItemRibKind, @@ -441,7 +461,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { debug!("(resolving function) leaving function"); }) }); - self.current_function = previous_value; + self.diagnostic_metadata.current_function = previous_value; } fn visit_generics(&mut self, generics: &'tcx Generics) { @@ -475,7 +495,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { // (We however cannot ban `Self` for defaults on *all* generic // lists; e.g. trait generics can usefully refer to `Self`, // such as in the case of `trait Add<Rhs = Self>`.) - if self.current_self_item.is_some() { // (`Some` if + only if we are in ADT's generics.) + if self.diagnostic_metadata.current_self_item.is_some() { + // (`Some` if + only if we are in ADT's generics.) default_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err); } @@ -527,12 +548,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { }, label_ribs: Vec::new(), current_trait_ref: None, - current_trait_assoc_types: Vec::new(), - current_self_type: None, - current_self_item: None, - current_function: None, - unused_labels: Default::default(), - current_type_ascription: Vec::new(), + diagnostic_metadata: DiagnosticMetadata::default(), } } @@ -892,16 +908,22 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { fn with_current_self_type<T>(&mut self, self_type: &Ty, f: impl FnOnce(&mut Self) -> T) -> T { // Handle nested impls (inside fn bodies) - let previous_value = replace(&mut self.current_self_type, Some(self_type.clone())); + let previous_value = replace( + &mut self.diagnostic_metadata.current_self_type, + Some(self_type.clone()), + ); let result = f(self); - self.current_self_type = previous_value; + self.diagnostic_metadata.current_self_type = previous_value; result } fn with_current_self_item<T>(&mut self, self_item: &Item, f: impl FnOnce(&mut Self) -> T) -> T { - let previous_value = replace(&mut self.current_self_item, Some(self_item.id)); + let previous_value = replace( + &mut self.diagnostic_metadata.current_self_item, + Some(self_item.id), + ); let result = f(self); - self.current_self_item = previous_value; + self.diagnostic_metadata.current_self_item = previous_value; result } @@ -912,14 +934,14 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { f: impl FnOnce(&mut Self) -> T, ) -> T { let trait_assoc_types = replace( - &mut self.current_trait_assoc_types, + &mut self.diagnostic_metadata.current_trait_assoc_types, trait_items.iter().filter_map(|item| match &item.kind { TraitItemKind::Type(bounds, _) if bounds.len() == 0 => Some(item.ident), _ => None, }).collect(), ); let result = f(self); - self.current_trait_assoc_types = trait_assoc_types; + self.diagnostic_metadata.current_trait_assoc_types = trait_assoc_types; result } @@ -1746,7 +1768,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { fn with_resolved_label(&mut self, label: Option<Label>, id: NodeId, f: impl FnOnce(&mut Self)) { if let Some(label) = label { - self.unused_labels.insert(id, label.ident.span); + self.diagnostic_metadata.unused_labels.insert(id, label.ident.span); self.with_label_rib(NormalRibKind, |this| { let ident = label.ident.modern_and_legacy(); this.label_ribs.last_mut().unwrap().bindings.insert(ident, id); @@ -1850,7 +1872,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { Some(node_id) => { // Since this res is a label, it is never read. self.r.label_res_map.insert(expr.id, node_id); - self.unused_labels.remove(&node_id); + self.diagnostic_metadata.unused_labels.remove(&node_id); } } @@ -1912,9 +1934,9 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { } } ExprKind::Type(ref type_expr, _) => { - self.current_type_ascription.push(type_expr.span); + self.diagnostic_metadata.current_type_ascription.push(type_expr.span); visit::walk_expr(self, expr); - self.current_type_ascription.pop(); + self.diagnostic_metadata.current_type_ascription.pop(); } // `async |x| ...` gets desugared to `|x| future_from_generator(|| ...)`, so we need to // resolve the arguments within the proper scopes so that usages of them inside the @@ -2073,7 +2095,7 @@ impl<'a> Resolver<'a> { pub(crate) fn late_resolve_crate(&mut self, krate: &Crate) { let mut late_resolution_visitor = LateResolutionVisitor::new(self); visit::walk_crate(&mut late_resolution_visitor, krate); - for (id, span) in late_resolution_visitor.unused_labels.iter() { + for (id, span) in late_resolution_visitor.diagnostic_metadata.unused_labels.iter() { self.session.buffer_lint(lint::builtin::UNUSED_LABELS, *id, *span, "unused label"); } } diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 2721df4c68763..07f44e0742e34 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -72,10 +72,26 @@ impl<'a> LateResolutionVisitor<'a, '_> { let path_str = Segment::names_to_string(path); let item_str = path.last().unwrap().ident; let code = source.error_code(res.is_some()); - let (base_msg, fallback_label, base_span) = if let Some(res) = res { + let (base_msg, fallback_label, base_span, could_be_expr) = if let Some(res) = res { (format!("expected {}, found {} `{}`", expected, res.descr(), path_str), format!("not a {}", expected), - span) + span, + match res { + Res::Def(DefKind::Fn, _) => { + // Verify whether this is a fn call or an Fn used as a type. + self.r.session.source_map().span_to_snippet(span).map(|snippet| { + snippet.ends_with(')') + }).unwrap_or(false) + } + Res::Def(DefKind::Ctor(..), _) | + Res::Def(DefKind::Method, _) | + Res::Def(DefKind::Const, _) | + Res::Def(DefKind::AssocConst, _) | + Res::SelfCtor(_) | + Res::PrimTy(_) | + Res::Local(_) => true, + _ => false, + }) } else { let item_span = path.last().unwrap().ident.span; let (mod_prefix, mod_str) = if path.len() == 1 { @@ -94,7 +110,8 @@ impl<'a> LateResolutionVisitor<'a, '_> { }; (format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str), format!("not found in {}", mod_str), - item_span) + item_span, + false) }; let code = DiagnosticId::Error(code.into()); @@ -134,7 +151,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { "`self` value is a keyword only available in methods with a `self` parameter", ), }); - if let Some(span) = &self.current_function { + if let Some(span) = &self.diagnostic_metadata.current_function { err.span_label(*span, "this function doesn't have a `self` parameter"); } return (err, Vec::new()); @@ -257,6 +274,18 @@ impl<'a> LateResolutionVisitor<'a, '_> { if !levenshtein_worked { err.span_label(base_span, fallback_label); self.type_ascription_suggestion(&mut err, base_span); + match self.diagnostic_metadata.current_let_binding { + Some((pat_sp, Some(ty_sp), None)) + if ty_sp.contains(base_span) && could_be_expr => { + err.span_suggestion_short( + pat_sp.between(ty_sp), + "use `=` if you meant to assign", + " = ".to_string(), + Applicability::MaybeIncorrect, + ); + } + _ => {} + } } (err, candidates) } @@ -491,7 +520,9 @@ impl<'a> LateResolutionVisitor<'a, '_> { // Fields are generally expected in the same contexts as locals. if filter_fn(Res::Local(ast::DUMMY_NODE_ID)) { - if let Some(node_id) = self.current_self_type.as_ref().and_then(extract_node_id) { + if let Some(node_id) = self.diagnostic_metadata.current_self_type.as_ref() + .and_then(extract_node_id) + { // Look for a field with the same name in the current self_type. if let Some(resolution) = self.r.partial_res_map.get(&node_id) { match resolution.base_res() { @@ -510,7 +541,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { } } - for assoc_type_ident in &self.current_trait_assoc_types { + for assoc_type_ident in &self.diagnostic_metadata.current_trait_assoc_types { if *assoc_type_ident == ident { return Some(AssocSuggestion::AssocItem); } @@ -644,11 +675,9 @@ impl<'a> LateResolutionVisitor<'a, '_> { err: &mut DiagnosticBuilder<'_>, base_span: Span, ) { - debug!("type_ascription_suggetion {:?}", base_span); let cm = self.r.session.source_map(); let base_snippet = cm.span_to_snippet(base_span); - debug!("self.current_type_ascription {:?}", self.current_type_ascription); - if let Some(sp) = self.current_type_ascription.last() { + if let Some(sp) = self.diagnostic_metadata.current_type_ascription.last() { let mut sp = *sp; loop { // Try to find the `:`; bail on first non-':' / non-whitespace. diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 7a8a209a5350c..3d380a5f1826c 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -479,10 +479,12 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { let mut skip_add = false; if let ty::Opaque(defin_ty_def_id, _substs) = definition_ty.kind { - if def_id == defin_ty_def_id { - debug!("Skipping adding concrete definition for opaque type {:?} {:?}", - opaque_defn, defin_ty_def_id); - skip_add = true; + if let hir::OpaqueTyOrigin::TypeAlias = opaque_defn.origin { + if def_id == defin_ty_def_id { + debug!("Skipping adding concrete definition for opaque type {:?} {:?}", + opaque_defn, defin_ty_def_id); + skip_add = true; + } } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 00435d67184a3..d5fa0169d4ada 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1981,19 +1981,18 @@ fn predicates_defined_on( ); let inferred_outlives = tcx.inferred_outlives_of(def_id); if !inferred_outlives.is_empty() { - let span = tcx.def_span(def_id); debug!( "predicates_defined_on: inferred_outlives_of({:?}) = {:?}", def_id, inferred_outlives, ); - result.predicates = tcx.arena.alloc_from_iter( - result.predicates.iter().copied().chain( - // FIXME(eddyb) use better spans - maybe add `Span`s - // to `inferred_outlives_of` predicates as well? - inferred_outlives.iter().map(|&p| (p, span)), - ), - ); + if result.predicates.is_empty() { + result.predicates = inferred_outlives; + } else { + result.predicates = tcx.arena.alloc_from_iter( + result.predicates.iter().chain(inferred_outlives).copied(), + ); + } } debug!("predicates_defined_on({:?}) = {:?}", def_id, result); result diff --git a/src/librustc_typeck/outlives/explicit.rs b/src/librustc_typeck/outlives/explicit.rs index 83194144216ee..21e529f33cfd0 100644 --- a/src/librustc_typeck/outlives/explicit.rs +++ b/src/librustc_typeck/outlives/explicit.rs @@ -30,11 +30,17 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { let mut required_predicates = RequiredPredicates::default(); // process predicates and convert to `RequiredPredicates` entry, see below - for (pred, _) in predicates.predicates { - match pred { + for &(predicate, span) in predicates.predicates { + match predicate { ty::Predicate::TypeOutlives(predicate) => { let OutlivesPredicate(ref ty, ref reg) = predicate.skip_binder(); - insert_outlives_predicate(tcx, (*ty).into(), reg, &mut required_predicates) + insert_outlives_predicate( + tcx, + (*ty).into(), + reg, + span, + &mut required_predicates, + ) } ty::Predicate::RegionOutlives(predicate) => { @@ -43,6 +49,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { tcx, (*reg1).into(), reg2, + span, &mut required_predicates, ) } diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index 433d04ffa64ff..74048b8d20c82 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -4,6 +4,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::subst::{GenericArg, Subst, GenericArgKind}; use rustc::ty::{self, Ty, TyCtxt}; use rustc::util::nodemap::FxHashMap; +use syntax_pos::Span; use super::explicit::ExplicitPredicatesMap; use super::utils::*; @@ -79,9 +80,11 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> { // (struct/enum/union) there will be outlive // requirements for adt_def. let field_ty = self.tcx.type_of(field_def.did); + let field_span = self.tcx.def_span(field_def.did); insert_required_predicates_to_be_wf( self.tcx, field_ty, + field_span, self.global_inferred_outlives, &mut item_required_predicates, &mut self.explicit_map, @@ -118,6 +121,7 @@ impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> { fn insert_required_predicates_to_be_wf<'tcx>( tcx: TyCtxt<'tcx>, field_ty: Ty<'tcx>, + field_span: Span, global_inferred_outlives: &FxHashMap<DefId, RequiredPredicates<'tcx>>, required_predicates: &mut RequiredPredicates<'tcx>, explicit_map: &mut ExplicitPredicatesMap<'tcx>, @@ -130,7 +134,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( // We also want to calculate potential predicates for the T ty::Ref(region, rty, _) => { debug!("Ref"); - insert_outlives_predicate(tcx, rty.into(), region, required_predicates); + insert_outlives_predicate(tcx, rty.into(), region, field_span, required_predicates); } // For each Adt (struct/enum/union) type `Foo<'a, T>`, we @@ -158,7 +162,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( // 'a` holds for `Foo`. debug!("Adt"); if let Some(unsubstituted_predicates) = global_inferred_outlives.get(&def.did) { - for unsubstituted_predicate in unsubstituted_predicates { + for (unsubstituted_predicate, &span) in unsubstituted_predicates { // `unsubstituted_predicate` is `U: 'b` in the // example above. So apply the substitution to // get `T: 'a` (or `predicate`): @@ -167,6 +171,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( tcx, predicate.0, predicate.1, + span, required_predicates, ); } @@ -272,7 +277,7 @@ pub fn check_explicit_predicates<'tcx>( ); let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id); - for outlives_predicate in explicit_predicates.iter() { + for (outlives_predicate, &span) in explicit_predicates { debug!("outlives_predicate = {:?}", &outlives_predicate); // Careful: If we are inferring the effects of a `dyn Trait<..>` @@ -320,6 +325,6 @@ pub fn check_explicit_predicates<'tcx>( let predicate = outlives_predicate.subst(tcx, substs); debug!("predicate = {:?}", &predicate); - insert_outlives_predicate(tcx, predicate.0.into(), predicate.1, required_predicates); + insert_outlives_predicate(tcx, predicate.0.into(), predicate.1, span, required_predicates); } } diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index cdb83eb328ac2..6b861656d7e2d 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -5,6 +5,7 @@ use rustc::ty::query::Providers; use rustc::ty::subst::GenericArgKind; use rustc::ty::{self, CratePredicatesMap, TyCtxt}; use syntax::symbol::sym; +use syntax_pos::Span; mod explicit; mod implicit_infer; @@ -23,7 +24,7 @@ pub fn provide(providers: &mut Providers<'_>) { fn inferred_outlives_of( tcx: TyCtxt<'_>, item_def_id: DefId, -) -> &[ty::Predicate<'_>] { +) -> &[(ty::Predicate<'_>, Span)] { let id = tcx .hir() .as_local_hir_id(item_def_id) @@ -43,7 +44,7 @@ fn inferred_outlives_of( if tcx.has_attr(item_def_id, sym::rustc_outlives) { let mut pred: Vec<String> = predicates .iter() - .map(|out_pred| match out_pred { + .map(|(out_pred, _)| match out_pred { ty::Predicate::RegionOutlives(p) => p.to_string(), ty::Predicate::TypeOutlives(p) => p.to_string(), err => bug!("unexpected predicate {:?}", err), @@ -96,19 +97,19 @@ fn inferred_outlives_crate( let predicates = global_inferred_outlives .iter() .map(|(&def_id, set)| { - let predicates = tcx.arena.alloc_from_iter(set + let predicates = &*tcx.arena.alloc_from_iter(set .iter() .filter_map( - |ty::OutlivesPredicate(kind1, region2)| match kind1.unpack() { + |(ty::OutlivesPredicate(kind1, region2), &span)| match kind1.unpack() { GenericArgKind::Type(ty1) => { - Some(ty::Predicate::TypeOutlives(ty::Binder::bind( + Some((ty::Predicate::TypeOutlives(ty::Binder::bind( ty::OutlivesPredicate(ty1, region2) - ))) + )), span)) } GenericArgKind::Lifetime(region1) => { - Some(ty::Predicate::RegionOutlives( + Some((ty::Predicate::RegionOutlives( ty::Binder::bind(ty::OutlivesPredicate(region1, region2)) - )) + ), span)) } GenericArgKind::Const(_) => { // Generic consts don't impose any constraints. @@ -116,7 +117,7 @@ fn inferred_outlives_crate( } }, )); - (def_id, &*predicates) + (def_id, predicates) }).collect(); tcx.arena.alloc(ty::CratePredicatesMap { diff --git a/src/librustc_typeck/outlives/utils.rs b/src/librustc_typeck/outlives/utils.rs index d34605dc482a3..361116e96d0bf 100644 --- a/src/librustc_typeck/outlives/utils.rs +++ b/src/librustc_typeck/outlives/utils.rs @@ -2,12 +2,13 @@ use rustc::ty::outlives::Component; use rustc::ty::subst::{GenericArg, GenericArgKind}; use rustc::ty::{self, Region, RegionKind, Ty, TyCtxt}; use smallvec::smallvec; -use std::collections::BTreeSet; +use std::collections::BTreeMap; +use syntax_pos::Span; /// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred /// must be added to the struct header. pub type RequiredPredicates<'tcx> = - BTreeSet<ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>>; + BTreeMap<ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>, Span>; /// Given a requirement `T: 'a` or `'b: 'a`, deduce the /// outlives_component and add it to `required_predicates` @@ -15,6 +16,7 @@ pub fn insert_outlives_predicate<'tcx>( tcx: TyCtxt<'tcx>, kind: GenericArg<'tcx>, outlived_region: Region<'tcx>, + span: Span, required_predicates: &mut RequiredPredicates<'tcx>, ) { // If the `'a` region is bound within the field type itself, we @@ -53,6 +55,7 @@ pub fn insert_outlives_predicate<'tcx>( tcx, r.into(), outlived_region, + span, required_predicates, ); } @@ -73,7 +76,8 @@ pub fn insert_outlives_predicate<'tcx>( // where clause that `U: 'a`. let ty: Ty<'tcx> = param_ty.to_ty(tcx); required_predicates - .insert(ty::OutlivesPredicate(ty.into(), outlived_region)); + .entry(ty::OutlivesPredicate(ty.into(), outlived_region)) + .or_insert(span); } Component::Projection(proj_ty) => { @@ -88,7 +92,8 @@ pub fn insert_outlives_predicate<'tcx>( // Here we want to add an explicit `where <T as Iterator>::Item: 'a`. let ty: Ty<'tcx> = tcx.mk_projection(proj_ty.item_def_id, proj_ty.substs); required_predicates - .insert(ty::OutlivesPredicate(ty.into(), outlived_region)); + .entry(ty::OutlivesPredicate(ty.into(), outlived_region)) + .or_insert(span); } Component::EscapingProjection(_) => { @@ -117,7 +122,8 @@ pub fn insert_outlives_predicate<'tcx>( if !is_free_region(tcx, r) { return; } - required_predicates.insert(ty::OutlivesPredicate(kind, outlived_region)); + required_predicates.entry(ty::OutlivesPredicate(kind, outlived_region)) + .or_insert(span); } GenericArgKind::Const(_) => { diff --git a/src/libsyntax/parse/parser/stmt.rs b/src/libsyntax/parse/parser/stmt.rs index d54d9c4b8e9fa..ea7e4c05ea1ae 100644 --- a/src/libsyntax/parse/parser/stmt.rs +++ b/src/libsyntax/parse/parser/stmt.rs @@ -239,7 +239,7 @@ impl<'a> Parser<'a> { err.span_suggestion_short( colon_sp, "use `=` if you meant to assign", - "=".to_string(), + " =".to_string(), Applicability::MachineApplicable ); err.emit(); diff --git a/src/test/ui-fulldeps/lint-plugin-cmdline-allow.stderr b/src/test/ui-fulldeps/lint-plugin-cmdline-allow.stderr index c6d198dc458a6..5ab3dfb24496f 100644 --- a/src/test/ui-fulldeps/lint-plugin-cmdline-allow.stderr +++ b/src/test/ui-fulldeps/lint-plugin-cmdline-allow.stderr @@ -7,10 +7,10 @@ LL | #![plugin(lint_plugin_test)] = note: `#[warn(deprecated)]` on by default warning: function is never used: `lintme` - --> $DIR/lint-plugin-cmdline-allow.rs:10:1 + --> $DIR/lint-plugin-cmdline-allow.rs:10:4 | LL | fn lintme() { } - | ^^^^^^^^^^^ + | ^^^^^^ | note: lint level defined here --> $DIR/lint-plugin-cmdline-allow.rs:7:9 diff --git a/src/test/ui-fulldeps/lint-tool-cmdline-allow.stderr b/src/test/ui-fulldeps/lint-tool-cmdline-allow.stderr index 239732521d59e..3a9fd7c2867f2 100644 --- a/src/test/ui-fulldeps/lint-tool-cmdline-allow.stderr +++ b/src/test/ui-fulldeps/lint-tool-cmdline-allow.stderr @@ -19,10 +19,10 @@ LL | fn lintme() {} = note: `#[warn(clippy::test_lint)]` on by default warning: function is never used: `lintme` - --> $DIR/lint-tool-cmdline-allow.rs:10:1 + --> $DIR/lint-tool-cmdline-allow.rs:10:4 | LL | fn lintme() {} - | ^^^^^^^^^^^ + | ^^^^^^ | note: lint level defined here --> $DIR/lint-tool-cmdline-allow.rs:7:9 diff --git a/src/test/ui/coherence/impl-foreign-for-locally-defined-fundamental.rs b/src/test/ui/coherence/impl-foreign-for-locally-defined-fundamental.rs new file mode 100644 index 0000000000000..d461b5abd60ff --- /dev/null +++ b/src/test/ui/coherence/impl-foreign-for-locally-defined-fundamental.rs @@ -0,0 +1,16 @@ +#![feature(fundamental)] +#![feature(re_rebalance_coherence)] + +// compile-flags:--crate-name=test +// aux-build:coherence_lib.rs +// check-pass + +extern crate coherence_lib as lib; +use lib::*; + +#[fundamental] +struct Local; + +impl Remote for Local {} + +fn main() {} diff --git a/src/test/ui/coherence/impl-foreign-for-locally-defined-fundamental[foreign].rs b/src/test/ui/coherence/impl-foreign-for-locally-defined-fundamental[foreign].rs new file mode 100644 index 0000000000000..0a3d9e2e0e89c --- /dev/null +++ b/src/test/ui/coherence/impl-foreign-for-locally-defined-fundamental[foreign].rs @@ -0,0 +1,16 @@ +#![feature(fundamental)] +#![feature(re_rebalance_coherence)] + +// compile-flags:--crate-name=test +// aux-build:coherence_lib.rs +// check-pass + +extern crate coherence_lib as lib; +use lib::*; + +#[fundamental] +struct MyBox<T>(T); + +impl<T> Remote for MyBox<T> {} + +fn main() {} diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs new file mode 100644 index 0000000000000..2b4f5e0975ac3 --- /dev/null +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs @@ -0,0 +1,7 @@ +// Test that an `impl Trait` type that expands to itself is an error. + +fn test() -> impl Sized { //~ ERROR E0720 + test() +} + +fn main() {} diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-direct.stderr b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.stderr new file mode 100644 index 0000000000000..1b5dbd814a481 --- /dev/null +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.stderr @@ -0,0 +1,11 @@ +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-direct.rs:3:14 + | +LL | fn test() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: type resolves to itself + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0720`. diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type.rs b/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.rs similarity index 100% rename from src/test/ui/impl-trait/recursive-impl-trait-type.rs rename to src/test/ui/impl-trait/recursive-impl-trait-type-indirect.rs diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type.stderr b/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr similarity index 76% rename from src/test/ui/impl-trait/recursive-impl-trait-type.stderr rename to src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr index 324607117dc50..b7ba0d6ab177c 100644 --- a/src/test/ui/impl-trait/recursive-impl-trait-type.stderr +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr @@ -1,5 +1,5 @@ error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:6:22 + --> $DIR/recursive-impl-trait-type-indirect.rs:6:22 | LL | fn option(i: i32) -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -7,7 +7,7 @@ LL | fn option(i: i32) -> impl Sized { = note: expanded type is `std::option::Option<(impl Sized, i32)>` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:14:15 + --> $DIR/recursive-impl-trait-type-indirect.rs:14:15 | LL | fn tuple() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -15,7 +15,7 @@ LL | fn tuple() -> impl Sized { = note: expanded type is `(impl Sized,)` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:18:15 + --> $DIR/recursive-impl-trait-type-indirect.rs:18:15 | LL | fn array() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -23,7 +23,7 @@ LL | fn array() -> impl Sized { = note: expanded type is `[impl Sized; 1]` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:22:13 + --> $DIR/recursive-impl-trait-type-indirect.rs:22:13 | LL | fn ptr() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -31,7 +31,7 @@ LL | fn ptr() -> impl Sized { = note: expanded type is `*const impl Sized` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:26:16 + --> $DIR/recursive-impl-trait-type-indirect.rs:26:16 | LL | fn fn_ptr() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -39,47 +39,47 @@ LL | fn fn_ptr() -> impl Sized { = note: expanded type is `fn() -> impl Sized` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:30:25 + --> $DIR/recursive-impl-trait-type-indirect.rs:30:25 | LL | fn closure_capture() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type | - = note: expanded type is `[closure@$DIR/recursive-impl-trait-type.rs:32:5: 32:19 x:impl Sized]` + = note: expanded type is `[closure@$DIR/recursive-impl-trait-type-indirect.rs:32:5: 32:19 x:impl Sized]` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:35:29 + --> $DIR/recursive-impl-trait-type-indirect.rs:35:29 | LL | fn closure_ref_capture() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type | - = note: expanded type is `[closure@$DIR/recursive-impl-trait-type.rs:37:5: 37:20 x:impl Sized]` + = note: expanded type is `[closure@$DIR/recursive-impl-trait-type-indirect.rs:37:5: 37:20 x:impl Sized]` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:40:21 + --> $DIR/recursive-impl-trait-type-indirect.rs:40:21 | LL | fn closure_sig() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type | - = note: expanded type is `[closure@$DIR/recursive-impl-trait-type.rs:41:5: 41:21]` + = note: expanded type is `[closure@$DIR/recursive-impl-trait-type-indirect.rs:41:5: 41:21]` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:44:23 + --> $DIR/recursive-impl-trait-type-indirect.rs:44:23 | LL | fn generator_sig() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type | - = note: expanded type is `[closure@$DIR/recursive-impl-trait-type.rs:45:5: 45:23]` + = note: expanded type is `[closure@$DIR/recursive-impl-trait-type-indirect.rs:45:5: 45:23]` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:48:27 + --> $DIR/recursive-impl-trait-type-indirect.rs:48:27 | LL | fn generator_capture() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type | - = note: expanded type is `[generator@$DIR/recursive-impl-trait-type.rs:50:5: 50:26 x:impl Sized {()}]` + = note: expanded type is `[generator@$DIR/recursive-impl-trait-type-indirect.rs:50:5: 50:26 x:impl Sized {()}]` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:53:26 + --> $DIR/recursive-impl-trait-type-indirect.rs:53:26 | LL | fn substs_change<T>() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -87,15 +87,15 @@ LL | fn substs_change<T>() -> impl Sized { = note: expanded type is `(impl Sized,)` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:57:24 + --> $DIR/recursive-impl-trait-type-indirect.rs:57:24 | LL | fn generator_hold() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type | - = note: expanded type is `[generator@$DIR/recursive-impl-trait-type.rs:58:5: 62:6 {impl Sized, ()}]` + = note: expanded type is `[generator@$DIR/recursive-impl-trait-type-indirect.rs:58:5: 62:6 {impl Sized, ()}]` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:69:26 + --> $DIR/recursive-impl-trait-type-indirect.rs:69:26 | LL | fn mutual_recursion() -> impl Sync { | ^^^^^^^^^ expands to a recursive type @@ -103,7 +103,7 @@ LL | fn mutual_recursion() -> impl Sync { = note: type resolves to itself error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:73:28 + --> $DIR/recursive-impl-trait-type-indirect.rs:73:28 | LL | fn mutual_recursion_b() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.rs b/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.rs similarity index 100% rename from src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.rs rename to src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.rs diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.stderr b/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.stderr similarity index 77% rename from src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.stderr rename to src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.stderr index 7572c6c1bf057..73c12f6137d24 100644 --- a/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.stderr +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.stderr @@ -1,5 +1,5 @@ error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type--through-non-recursize.rs:7:22 + --> $DIR/recursive-impl-trait-type-through-non-recursive.rs:7:22 | LL | fn recursive_id() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -7,7 +7,7 @@ LL | fn recursive_id() -> impl Sized { = note: type resolves to itself error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type--through-non-recursize.rs:11:23 + --> $DIR/recursive-impl-trait-type-through-non-recursive.rs:11:23 | LL | fn recursive_id2() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -15,7 +15,7 @@ LL | fn recursive_id2() -> impl Sized { = note: type resolves to itself error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type--through-non-recursize.rs:17:24 + --> $DIR/recursive-impl-trait-type-through-non-recursive.rs:17:24 | LL | fn recursive_wrap() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type @@ -23,7 +23,7 @@ LL | fn recursive_wrap() -> impl Sized { = note: expanded type is `((impl Sized,),)` error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type--through-non-recursize.rs:21:25 + --> $DIR/recursive-impl-trait-type-through-non-recursive.rs:21:25 | LL | fn recursive_wrap2() -> impl Sized { | ^^^^^^^^^^ expands to a recursive type diff --git a/src/test/ui/dead-code-alias-in-pat.rs b/src/test/ui/lint/dead-code/alias-in-pat.rs similarity index 100% rename from src/test/ui/dead-code-alias-in-pat.rs rename to src/test/ui/lint/dead-code/alias-in-pat.rs diff --git a/src/test/ui/lint-dead-code-associated-type.rs b/src/test/ui/lint/dead-code/associated-type.rs similarity index 100% rename from src/test/ui/lint-dead-code-associated-type.rs rename to src/test/ui/lint/dead-code/associated-type.rs diff --git a/src/test/ui/fail-no-dead-code.rs b/src/test/ui/lint/dead-code/basic.rs similarity index 100% rename from src/test/ui/fail-no-dead-code.rs rename to src/test/ui/lint/dead-code/basic.rs diff --git a/src/test/ui/fail-no-dead-code.stderr b/src/test/ui/lint/dead-code/basic.stderr similarity index 68% rename from src/test/ui/fail-no-dead-code.stderr rename to src/test/ui/lint/dead-code/basic.stderr index 8babcffaa8dd7..194398e5a07a5 100644 --- a/src/test/ui/fail-no-dead-code.stderr +++ b/src/test/ui/lint/dead-code/basic.stderr @@ -1,11 +1,11 @@ error: function is never used: `foo` - --> $DIR/fail-no-dead-code.rs:4:1 + --> $DIR/basic.rs:4:4 | LL | fn foo() { - | ^^^^^^^^ + | ^^^ | note: lint level defined here - --> $DIR/fail-no-dead-code.rs:1:9 + --> $DIR/basic.rs:1:9 | LL | #![deny(dead_code)] | ^^^^^^^^^ diff --git a/src/test/ui/dead-code-closure-bang.rs b/src/test/ui/lint/dead-code/closure-bang.rs similarity index 100% rename from src/test/ui/dead-code-closure-bang.rs rename to src/test/ui/lint/dead-code/closure-bang.rs diff --git a/src/test/ui/lint/lint-dead-code-const-and-self.rs b/src/test/ui/lint/dead-code/const-and-self.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-const-and-self.rs rename to src/test/ui/lint/dead-code/const-and-self.rs diff --git a/src/test/ui/lint/lint-dead-code-empty-unused-enum.rs b/src/test/ui/lint/dead-code/empty-unused-enum.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-empty-unused-enum.rs rename to src/test/ui/lint/dead-code/empty-unused-enum.rs diff --git a/src/test/ui/lint/lint-dead-code-empty-unused-enum.stderr b/src/test/ui/lint/dead-code/empty-unused-enum.stderr similarity index 67% rename from src/test/ui/lint/lint-dead-code-empty-unused-enum.stderr rename to src/test/ui/lint/dead-code/empty-unused-enum.stderr index 4e3bebfc48bde..44b0a8f613e27 100644 --- a/src/test/ui/lint/lint-dead-code-empty-unused-enum.stderr +++ b/src/test/ui/lint/dead-code/empty-unused-enum.stderr @@ -1,11 +1,11 @@ error: enum is never used: `E` - --> $DIR/lint-dead-code-empty-unused-enum.rs:3:1 + --> $DIR/empty-unused-enum.rs:3:6 | LL | enum E {} - | ^^^^^^ + | ^ | note: lint level defined here - --> $DIR/lint-dead-code-empty-unused-enum.rs:1:9 + --> $DIR/empty-unused-enum.rs:1:9 | LL | #![deny(unused)] | ^^^^^^ diff --git a/src/test/ui/lint/lint-dead-code-empty-unused-enum-pub.rs b/src/test/ui/lint/dead-code/empty-unused-public-enum.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-empty-unused-enum-pub.rs rename to src/test/ui/lint/dead-code/empty-unused-public-enum.rs diff --git a/src/test/ui/lint-dead-code-variant.rs b/src/test/ui/lint/dead-code/enum-variants.rs similarity index 100% rename from src/test/ui/lint-dead-code-variant.rs rename to src/test/ui/lint/dead-code/enum-variants.rs diff --git a/src/test/ui/lint/lint-dead-code-impl-trait.rs b/src/test/ui/lint/dead-code/impl-trait.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-impl-trait.rs rename to src/test/ui/lint/dead-code/impl-trait.rs diff --git a/src/test/ui/lint/lint-dead-code-impl-trait.stderr b/src/test/ui/lint/dead-code/impl-trait.stderr similarity index 71% rename from src/test/ui/lint/lint-dead-code-impl-trait.stderr rename to src/test/ui/lint/dead-code/impl-trait.stderr index 61d0954bf3146..f2a78cc65e26e 100644 --- a/src/test/ui/lint/lint-dead-code-impl-trait.stderr +++ b/src/test/ui/lint/dead-code/impl-trait.stderr @@ -1,11 +1,11 @@ error: type alias is never used: `Unused` - --> $DIR/lint-dead-code-impl-trait.rs:12:1 + --> $DIR/impl-trait.rs:12:1 | LL | type Unused = (); | ^^^^^^^^^^^^^^^^^ | note: lint level defined here - --> $DIR/lint-dead-code-impl-trait.rs:1:9 + --> $DIR/impl-trait.rs:1:9 | LL | #![deny(dead_code)] | ^^^^^^^^^ diff --git a/src/test/ui/dead-code-leading-underscore.rs b/src/test/ui/lint/dead-code/leading-underscore.rs similarity index 100% rename from src/test/ui/dead-code-leading-underscore.rs rename to src/test/ui/lint/dead-code/leading-underscore.rs diff --git a/src/test/ui/lint/lint-dead-code-1.rs b/src/test/ui/lint/dead-code/lint-dead-code-1.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-1.rs rename to src/test/ui/lint/dead-code/lint-dead-code-1.rs diff --git a/src/test/ui/lint/lint-dead-code-1.stderr b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr similarity index 73% rename from src/test/ui/lint/lint-dead-code-1.stderr rename to src/test/ui/lint/dead-code/lint-dead-code-1.stderr index be96c697d9944..bac46a2e843cd 100644 --- a/src/test/ui/lint/lint-dead-code-1.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-1.stderr @@ -1,8 +1,8 @@ error: struct is never constructed: `Bar` - --> $DIR/lint-dead-code-1.rs:12:5 + --> $DIR/lint-dead-code-1.rs:12:16 | LL | pub struct Bar; - | ^^^^^^^^^^^^^^^ + | ^^^ | note: lint level defined here --> $DIR/lint-dead-code-1.rs:5:9 @@ -23,16 +23,16 @@ LL | const priv_const: isize = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct is never constructed: `PrivStruct` - --> $DIR/lint-dead-code-1.rs:35:1 + --> $DIR/lint-dead-code-1.rs:35:8 | LL | struct PrivStruct; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ error: enum is never used: `priv_enum` - --> $DIR/lint-dead-code-1.rs:64:1 + --> $DIR/lint-dead-code-1.rs:64:6 | LL | enum priv_enum { foo2, bar2 } - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^ error: variant is never constructed: `bar3` --> $DIR/lint-dead-code-1.rs:67:5 @@ -41,28 +41,28 @@ LL | bar3 | ^^^^ error: function is never used: `priv_fn` - --> $DIR/lint-dead-code-1.rs:88:1 + --> $DIR/lint-dead-code-1.rs:88:4 | LL | fn priv_fn() { - | ^^^^^^^^^^^^ + | ^^^^^^^ error: function is never used: `foo` - --> $DIR/lint-dead-code-1.rs:93:1 + --> $DIR/lint-dead-code-1.rs:93:4 | LL | fn foo() { - | ^^^^^^^^ + | ^^^ error: function is never used: `bar` - --> $DIR/lint-dead-code-1.rs:98:1 + --> $DIR/lint-dead-code-1.rs:98:4 | LL | fn bar() { - | ^^^^^^^^ + | ^^^ error: function is never used: `baz` - --> $DIR/lint-dead-code-1.rs:102:1 + --> $DIR/lint-dead-code-1.rs:102:4 | LL | fn baz() -> impl Copy { - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 10 previous errors diff --git a/src/test/ui/lint/lint-dead-code-2.rs b/src/test/ui/lint/dead-code/lint-dead-code-2.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-2.rs rename to src/test/ui/lint/dead-code/lint-dead-code-2.rs diff --git a/src/test/ui/lint/lint-dead-code-2.stderr b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr similarity index 69% rename from src/test/ui/lint/lint-dead-code-2.stderr rename to src/test/ui/lint/dead-code/lint-dead-code-2.stderr index 1226f9823ac54..a578a76d9a075 100644 --- a/src/test/ui/lint/lint-dead-code-2.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-2.stderr @@ -1,8 +1,8 @@ error: function is never used: `dead_fn` - --> $DIR/lint-dead-code-2.rs:22:1 + --> $DIR/lint-dead-code-2.rs:22:4 | LL | fn dead_fn() {} - | ^^^^^^^^^^^^ + | ^^^^^^^ | note: lint level defined here --> $DIR/lint-dead-code-2.rs:2:9 @@ -11,16 +11,16 @@ LL | #![deny(dead_code)] | ^^^^^^^^^ error: function is never used: `dead_fn2` - --> $DIR/lint-dead-code-2.rs:25:1 + --> $DIR/lint-dead-code-2.rs:25:4 | LL | fn dead_fn2() {} - | ^^^^^^^^^^^^^ + | ^^^^^^^^ error: function is never used: `main` - --> $DIR/lint-dead-code-2.rs:38:1 + --> $DIR/lint-dead-code-2.rs:38:4 | LL | fn main() { - | ^^^^^^^^^ + | ^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/lint-dead-code-3.rs b/src/test/ui/lint/dead-code/lint-dead-code-3.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-3.rs rename to src/test/ui/lint/dead-code/lint-dead-code-3.rs diff --git a/src/test/ui/lint/lint-dead-code-3.stderr b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr similarity index 80% rename from src/test/ui/lint/lint-dead-code-3.stderr rename to src/test/ui/lint/dead-code/lint-dead-code-3.stderr index 2408da0af89ea..569196fffdd50 100644 --- a/src/test/ui/lint/lint-dead-code-3.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-3.stderr @@ -1,8 +1,8 @@ error: struct is never constructed: `Foo` - --> $DIR/lint-dead-code-3.rs:13:1 + --> $DIR/lint-dead-code-3.rs:13:8 | LL | struct Foo; - | ^^^^^^^^^^^ + | ^^^ | note: lint level defined here --> $DIR/lint-dead-code-3.rs:3:9 @@ -17,16 +17,16 @@ LL | fn foo(&self) { | ^^^^^^^^^^^^^ error: function is never used: `bar` - --> $DIR/lint-dead-code-3.rs:20:1 + --> $DIR/lint-dead-code-3.rs:20:4 | LL | fn bar() { - | ^^^^^^^^ + | ^^^ error: enum is never used: `c_void` - --> $DIR/lint-dead-code-3.rs:59:1 + --> $DIR/lint-dead-code-3.rs:59:6 | LL | enum c_void {} - | ^^^^^^^^^^^ + | ^^^^^^ error: foreign function is never used: `free` --> $DIR/lint-dead-code-3.rs:61:5 diff --git a/src/test/ui/lint/lint-dead-code-4.rs b/src/test/ui/lint/dead-code/lint-dead-code-4.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-4.rs rename to src/test/ui/lint/dead-code/lint-dead-code-4.rs diff --git a/src/test/ui/lint/lint-dead-code-4.stderr b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr similarity index 96% rename from src/test/ui/lint/lint-dead-code-4.stderr rename to src/test/ui/lint/dead-code/lint-dead-code-4.stderr index b7ceee99998d7..8eaf789f8f793 100644 --- a/src/test/ui/lint/lint-dead-code-4.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-4.stderr @@ -27,10 +27,10 @@ LL | | }, | |_____^ error: enum is never used: `ABC` - --> $DIR/lint-dead-code-4.rs:24:1 + --> $DIR/lint-dead-code-4.rs:24:6 | LL | enum ABC { - | ^^^^^^^^ + | ^^^ error: variant is never constructed: `I` --> $DIR/lint-dead-code-4.rs:36:5 diff --git a/src/test/ui/lint/lint-dead-code-5.rs b/src/test/ui/lint/dead-code/lint-dead-code-5.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-5.rs rename to src/test/ui/lint/dead-code/lint-dead-code-5.rs diff --git a/src/test/ui/lint/lint-dead-code-5.stderr b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr similarity index 92% rename from src/test/ui/lint/lint-dead-code-5.stderr rename to src/test/ui/lint/dead-code/lint-dead-code-5.stderr index 740cfde2c069f..9670d8e7a32e3 100644 --- a/src/test/ui/lint/lint-dead-code-5.stderr +++ b/src/test/ui/lint/dead-code/lint-dead-code-5.stderr @@ -23,10 +23,10 @@ LL | Variant6(isize), | ^^^^^^^^^^^^^^^ error: enum is never used: `Enum3` - --> $DIR/lint-dead-code-5.rs:18:1 + --> $DIR/lint-dead-code-5.rs:18:6 | LL | enum Enum3 { - | ^^^^^^^^^^ + | ^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/lint/dead-code/newline-span.rs b/src/test/ui/lint/dead-code/newline-span.rs new file mode 100644 index 0000000000000..a4342056419d7 --- /dev/null +++ b/src/test/ui/lint/dead-code/newline-span.rs @@ -0,0 +1,19 @@ +#![deny(dead_code)] + +fn unused() { //~ error: function is never used: + println!("blah"); +} + +fn unused2(var: i32) { //~ error: function is never used: + println!("foo {}", var); +} + +fn unused3( //~ error: function is never used: + var: i32, +) { + println!("bar {}", var); +} + +fn main() { + println!("Hello world!"); +} diff --git a/src/test/ui/lint/dead-code/newline-span.stderr b/src/test/ui/lint/dead-code/newline-span.stderr new file mode 100644 index 0000000000000..c5d0d60506744 --- /dev/null +++ b/src/test/ui/lint/dead-code/newline-span.stderr @@ -0,0 +1,26 @@ +error: function is never used: `unused` + --> $DIR/newline-span.rs:3:4 + | +LL | fn unused() { + | ^^^^^^ + | +note: lint level defined here + --> $DIR/newline-span.rs:1:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: function is never used: `unused2` + --> $DIR/newline-span.rs:7:4 + | +LL | fn unused2(var: i32) { + | ^^^^^^^ + +error: function is never used: `unused3` + --> $DIR/newline-span.rs:11:4 + | +LL | fn unused3( + | ^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/dead-code-tuple-struct-field.rs b/src/test/ui/lint/dead-code/tuple-struct-field.rs similarity index 100% rename from src/test/ui/dead-code-tuple-struct-field.rs rename to src/test/ui/lint/dead-code/tuple-struct-field.rs diff --git a/src/test/ui/lint/lint-dead-code-type-alias.rs b/src/test/ui/lint/dead-code/type-alias.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-type-alias.rs rename to src/test/ui/lint/dead-code/type-alias.rs diff --git a/src/test/ui/lint/lint-dead-code-type-alias.stderr b/src/test/ui/lint/dead-code/type-alias.stderr similarity index 71% rename from src/test/ui/lint/lint-dead-code-type-alias.stderr rename to src/test/ui/lint/dead-code/type-alias.stderr index 4198ddfb6cb03..82df23bd9448b 100644 --- a/src/test/ui/lint/lint-dead-code-type-alias.stderr +++ b/src/test/ui/lint/dead-code/type-alias.stderr @@ -1,11 +1,11 @@ error: type alias is never used: `Unused` - --> $DIR/lint-dead-code-type-alias.rs:4:1 + --> $DIR/type-alias.rs:4:1 | LL | type Unused = u8; | ^^^^^^^^^^^^^^^^^ | note: lint level defined here - --> $DIR/lint-dead-code-type-alias.rs:1:9 + --> $DIR/type-alias.rs:1:9 | LL | #![deny(dead_code)] | ^^^^^^^^^ diff --git a/src/test/ui/lint/lint-dead-code-unused-enum.rs b/src/test/ui/lint/dead-code/unused-enum.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-unused-enum.rs rename to src/test/ui/lint/dead-code/unused-enum.rs diff --git a/src/test/ui/lint/lint-dead-code-unused-enum.stderr b/src/test/ui/lint/dead-code/unused-enum.stderr similarity index 61% rename from src/test/ui/lint/lint-dead-code-unused-enum.stderr rename to src/test/ui/lint/dead-code/unused-enum.stderr index ea711e7b05ee6..142c2ccb99b05 100644 --- a/src/test/ui/lint/lint-dead-code-unused-enum.stderr +++ b/src/test/ui/lint/dead-code/unused-enum.stderr @@ -1,27 +1,27 @@ error: struct is never constructed: `F` - --> $DIR/lint-dead-code-unused-enum.rs:3:1 + --> $DIR/unused-enum.rs:3:8 | LL | struct F; - | ^^^^^^^^^ + | ^ | note: lint level defined here - --> $DIR/lint-dead-code-unused-enum.rs:1:9 + --> $DIR/unused-enum.rs:1:9 | LL | #![deny(unused)] | ^^^^^^ = note: `#[deny(dead_code)]` implied by `#[deny(unused)]` error: struct is never constructed: `B` - --> $DIR/lint-dead-code-unused-enum.rs:4:1 + --> $DIR/unused-enum.rs:4:8 | LL | struct B; - | ^^^^^^^^^ + | ^ error: enum is never used: `E` - --> $DIR/lint-dead-code-unused-enum.rs:6:1 + --> $DIR/unused-enum.rs:6:6 | LL | enum E { - | ^^^^^^ + | ^ error: aborting due to 3 previous errors diff --git a/src/test/ui/lint/lint-dead-code-unused-variant.rs b/src/test/ui/lint/dead-code/unused-struct-variant.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-unused-variant.rs rename to src/test/ui/lint/dead-code/unused-struct-variant.rs diff --git a/src/test/ui/lint/lint-dead-code-unused-variant.stderr b/src/test/ui/lint/dead-code/unused-struct-variant.stderr similarity index 73% rename from src/test/ui/lint/lint-dead-code-unused-variant.stderr rename to src/test/ui/lint/dead-code/unused-struct-variant.stderr index 919996ec30020..0037592e3de06 100644 --- a/src/test/ui/lint/lint-dead-code-unused-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-struct-variant.stderr @@ -1,11 +1,11 @@ error: variant is never constructed: `Bar` - --> $DIR/lint-dead-code-unused-variant.rs:8:5 + --> $DIR/unused-struct-variant.rs:8:5 | LL | Bar(B), | ^^^^^^ | note: lint level defined here - --> $DIR/lint-dead-code-unused-variant.rs:1:9 + --> $DIR/unused-struct-variant.rs:1:9 | LL | #![deny(unused)] | ^^^^^^ diff --git a/src/test/ui/lint/lint-dead-code-unused-variant-pub.rs b/src/test/ui/lint/dead-code/unused-variant-pub.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-unused-variant-pub.rs rename to src/test/ui/lint/dead-code/unused-variant-pub.rs diff --git a/src/test/ui/lint/lint-dead-code-variant.rs b/src/test/ui/lint/dead-code/unused-variant.rs similarity index 100% rename from src/test/ui/lint/lint-dead-code-variant.rs rename to src/test/ui/lint/dead-code/unused-variant.rs diff --git a/src/test/ui/lint/lint-dead-code-variant.stderr b/src/test/ui/lint/dead-code/unused-variant.stderr similarity index 72% rename from src/test/ui/lint/lint-dead-code-variant.stderr rename to src/test/ui/lint/dead-code/unused-variant.stderr index a79432dc68d6a..2167b9d910d94 100644 --- a/src/test/ui/lint/lint-dead-code-variant.stderr +++ b/src/test/ui/lint/dead-code/unused-variant.stderr @@ -1,11 +1,11 @@ error: variant is never constructed: `Variant1` - --> $DIR/lint-dead-code-variant.rs:5:5 + --> $DIR/unused-variant.rs:5:5 | LL | Variant1, | ^^^^^^^^ | note: lint level defined here - --> $DIR/lint-dead-code-variant.rs:1:9 + --> $DIR/unused-variant.rs:1:9 | LL | #![deny(dead_code)] | ^^^^^^^^^ diff --git a/src/test/ui/fail-no-dead-code-core.rs b/src/test/ui/lint/dead-code/with-core-crate.rs similarity index 100% rename from src/test/ui/fail-no-dead-code-core.rs rename to src/test/ui/lint/dead-code/with-core-crate.rs diff --git a/src/test/ui/fail-no-dead-code-core.stderr b/src/test/ui/lint/dead-code/with-core-crate.stderr similarity index 65% rename from src/test/ui/fail-no-dead-code-core.stderr rename to src/test/ui/lint/dead-code/with-core-crate.stderr index 2540242f9f68b..0b6ab67d9bfa5 100644 --- a/src/test/ui/fail-no-dead-code-core.stderr +++ b/src/test/ui/lint/dead-code/with-core-crate.stderr @@ -1,11 +1,11 @@ error: function is never used: `foo` - --> $DIR/fail-no-dead-code-core.rs:7:1 + --> $DIR/with-core-crate.rs:7:4 | LL | fn foo() { - | ^^^^^^^^ + | ^^^ | note: lint level defined here - --> $DIR/fail-no-dead-code-core.rs:1:9 + --> $DIR/with-core-crate.rs:1:9 | LL | #![deny(dead_code)] | ^^^^^^^^^ diff --git a/src/test/ui/dead-code-impl.rs b/src/test/ui/lint/dead-code/with-impl.rs similarity index 100% rename from src/test/ui/dead-code-impl.rs rename to src/test/ui/lint/dead-code/with-impl.rs diff --git a/src/test/ui/path-lookahead.rs b/src/test/ui/path-lookahead.rs index fd7509a623e31..86bcb08de404e 100644 --- a/src/test/ui/path-lookahead.rs +++ b/src/test/ui/path-lookahead.rs @@ -1,14 +1,14 @@ // run-pass - -#![warn(unused)] +#![allow(dead_code)] +#![warn(unused_parens)] // Parser test for #37765 -fn with_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `with_parens` +fn with_parens<T: ToString>(arg: T) -> String { return (<T as ToString>::to_string(&arg)); //~WARN unnecessary parentheses around `return` value } -fn no_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `no_parens` +fn no_parens<T: ToString>(arg: T) -> String { return <T as ToString>::to_string(&arg); } diff --git a/src/test/ui/path-lookahead.stderr b/src/test/ui/path-lookahead.stderr index 197848e428a25..caf9e8303ea37 100644 --- a/src/test/ui/path-lookahead.stderr +++ b/src/test/ui/path-lookahead.stderr @@ -7,26 +7,6 @@ LL | return (<T as ToString>::to_string(&arg)); note: lint level defined here --> $DIR/path-lookahead.rs:3:9 | -LL | #![warn(unused)] - | ^^^^^^ - = note: `#[warn(unused_parens)]` implied by `#[warn(unused)]` - -warning: function is never used: `with_parens` - --> $DIR/path-lookahead.rs:7:1 - | -LL | fn with_parens<T: ToString>(arg: T) -> String { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: lint level defined here - --> $DIR/path-lookahead.rs:3:9 - | -LL | #![warn(unused)] - | ^^^^^^ - = note: `#[warn(dead_code)]` implied by `#[warn(unused)]` - -warning: function is never used: `no_parens` - --> $DIR/path-lookahead.rs:11:1 - | -LL | fn no_parens<T: ToString>(arg: T) -> String { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![warn(unused_parens)] + | ^^^^^^^^^^^^^ diff --git a/src/test/ui/privacy/privacy-ns2.rs b/src/test/ui/privacy/privacy-ns2.rs index c4e400f5adbd9..61fcebd787e51 100644 --- a/src/test/ui/privacy/privacy-ns2.rs +++ b/src/test/ui/privacy/privacy-ns2.rs @@ -39,6 +39,7 @@ fn test_single2() { use foo2::Bar; let _x : Box<Bar>; //~ ERROR expected type, found function `Bar` + let _x : Bar(); //~ ERROR expected type, found function `Bar` } fn test_list2() { diff --git a/src/test/ui/privacy/privacy-ns2.stderr b/src/test/ui/privacy/privacy-ns2.stderr index f0d5da6868596..e62ad81781197 100644 --- a/src/test/ui/privacy/privacy-ns2.stderr +++ b/src/test/ui/privacy/privacy-ns2.stderr @@ -48,7 +48,25 @@ LL | use foo3::Bar; | error[E0573]: expected type, found function `Bar` - --> $DIR/privacy-ns2.rs:47:17 + --> $DIR/privacy-ns2.rs:42:14 + | +LL | let _x : Bar(); + | ^^^^^ not a type +help: use `=` if you meant to assign + | +LL | let _x = Bar(); + | ^ +help: possible better candidates are found in other modules, you can import them into scope + | +LL | use foo1::Bar; + | +LL | use foo2::Bar; + | +LL | use foo3::Bar; + | + +error[E0573]: expected type, found function `Bar` + --> $DIR/privacy-ns2.rs:48:17 | LL | let _x: Box<Bar>; | ^^^ @@ -67,24 +85,24 @@ LL | use foo3::Bar; | error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:60:15 + --> $DIR/privacy-ns2.rs:61:15 | LL | use foo3::Bar; | ^^^ error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:64:15 + --> $DIR/privacy-ns2.rs:65:15 | LL | use foo3::Bar; | ^^^ error[E0603]: trait `Bar` is private - --> $DIR/privacy-ns2.rs:71:16 + --> $DIR/privacy-ns2.rs:72:16 | LL | use foo3::{Bar,Baz}; | ^^^ -error: aborting due to 7 previous errors +error: aborting due to 8 previous errors Some errors have detailed explanations: E0423, E0573, E0603. For more information about an error, try `rustc --explain E0423`. diff --git a/src/test/ui/span/macro-span-replacement.stderr b/src/test/ui/span/macro-span-replacement.stderr index 8b65e798b6ef5..439aedb4da4d2 100644 --- a/src/test/ui/span/macro-span-replacement.stderr +++ b/src/test/ui/span/macro-span-replacement.stderr @@ -1,11 +1,8 @@ warning: struct is never constructed: `S` - --> $DIR/macro-span-replacement.rs:7:14 + --> $DIR/macro-span-replacement.rs:7:12 | LL | $b $a; - | ^ -... -LL | m!(S struct); - | ------------- in this macro invocation + | ^^ | note: lint level defined here --> $DIR/macro-span-replacement.rs:3:9 diff --git a/src/test/ui/span/unused-warning-point-at-signature.rs b/src/test/ui/span/unused-warning-point-at-identifier.rs similarity index 84% rename from src/test/ui/span/unused-warning-point-at-signature.rs rename to src/test/ui/span/unused-warning-point-at-identifier.rs index 3af272a012eb2..d4d5bc1cbc8f1 100644 --- a/src/test/ui/span/unused-warning-point-at-signature.rs +++ b/src/test/ui/span/unused-warning-point-at-identifier.rs @@ -20,8 +20,8 @@ fn func() -> usize { //~ WARN function is never used 3 } -fn //~ WARN function is never used -func_complete_span() +fn +func_complete_span() //~ WARN function is never used -> usize { 3 diff --git a/src/test/ui/span/unused-warning-point-at-signature.stderr b/src/test/ui/span/unused-warning-point-at-identifier.stderr similarity index 52% rename from src/test/ui/span/unused-warning-point-at-signature.stderr rename to src/test/ui/span/unused-warning-point-at-identifier.stderr index 83e2ec1987b47..a4715d4adeb88 100644 --- a/src/test/ui/span/unused-warning-point-at-signature.stderr +++ b/src/test/ui/span/unused-warning-point-at-identifier.stderr @@ -1,36 +1,31 @@ warning: enum is never used: `Enum` - --> $DIR/unused-warning-point-at-signature.rs:5:1 + --> $DIR/unused-warning-point-at-identifier.rs:5:6 | LL | enum Enum { - | ^^^^^^^^^ + | ^^^^ | note: lint level defined here - --> $DIR/unused-warning-point-at-signature.rs:3:9 + --> $DIR/unused-warning-point-at-identifier.rs:3:9 | LL | #![warn(unused)] | ^^^^^^ = note: `#[warn(dead_code)]` implied by `#[warn(unused)]` warning: struct is never constructed: `Struct` - --> $DIR/unused-warning-point-at-signature.rs:12:1 + --> $DIR/unused-warning-point-at-identifier.rs:12:8 | LL | struct Struct { - | ^^^^^^^^^^^^^ + | ^^^^^^ warning: function is never used: `func` - --> $DIR/unused-warning-point-at-signature.rs:19:1 + --> $DIR/unused-warning-point-at-identifier.rs:19:4 | LL | fn func() -> usize { - | ^^^^^^^^^^^^^^^^^^ + | ^^^^ warning: function is never used: `func_complete_span` - --> $DIR/unused-warning-point-at-signature.rs:23:1 + --> $DIR/unused-warning-point-at-identifier.rs:24:1 | -LL | / fn -LL | | func_complete_span() -LL | | -> usize -LL | | { -LL | | 3 -LL | | } - | |_^ +LL | func_complete_span() + | ^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/suggestions/let-binding-init-expr-as-ty.rs b/src/test/ui/suggestions/let-binding-init-expr-as-ty.rs new file mode 100644 index 0000000000000..beea951a18a29 --- /dev/null +++ b/src/test/ui/suggestions/let-binding-init-expr-as-ty.rs @@ -0,0 +1,12 @@ +pub fn foo(num: i32) -> i32 { + let foo: i32::from_be(num); + //~^ ERROR expected type, found local variable `num` + //~| ERROR parenthesized type parameters may only be used with a `Fn` trait + //~| ERROR ambiguous associated type + //~| WARNING this was previously accepted by the compiler but is being phased out + foo +} + +fn main() { + let _ = foo(42); +} diff --git a/src/test/ui/suggestions/let-binding-init-expr-as-ty.stderr b/src/test/ui/suggestions/let-binding-init-expr-as-ty.stderr new file mode 100644 index 0000000000000..a7c784fe82788 --- /dev/null +++ b/src/test/ui/suggestions/let-binding-init-expr-as-ty.stderr @@ -0,0 +1,28 @@ +error[E0573]: expected type, found local variable `num` + --> $DIR/let-binding-init-expr-as-ty.rs:2:27 + | +LL | let foo: i32::from_be(num); + | -- ^^^ not a type + | | + | help: use `=` if you meant to assign + +error: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/let-binding-init-expr-as-ty.rs:2:19 + | +LL | let foo: i32::from_be(num); + | ^^^^^^^^^^^^ + | + = note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238> + +error[E0223]: ambiguous associated type + --> $DIR/let-binding-init-expr-as-ty.rs:2:14 + | +LL | let foo: i32::from_be(num); + | ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<i32 as Trait>::from_be` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0223, E0573. +For more information about an error, try `rustc --explain E0223`. diff --git a/src/test/ui/test-attrs/test-warns-dead-code.stderr b/src/test/ui/test-attrs/test-warns-dead-code.stderr index 62e99225dd902..cb118cdb4103c 100644 --- a/src/test/ui/test-attrs/test-warns-dead-code.stderr +++ b/src/test/ui/test-attrs/test-warns-dead-code.stderr @@ -1,8 +1,8 @@ error: function is never used: `dead` - --> $DIR/test-warns-dead-code.rs:5:1 + --> $DIR/test-warns-dead-code.rs:5:4 | LL | fn dead() {} - | ^^^^^^^^^ + | ^^^^ | note: lint level defined here --> $DIR/test-warns-dead-code.rs:3:9 diff --git a/src/test/ui/thread-local-not-in-prelude.rs b/src/test/ui/thread-local-not-in-prelude.rs index 039749826256f..e5ed09c600bf9 100644 --- a/src/test/ui/thread-local-not-in-prelude.rs +++ b/src/test/ui/thread-local-not-in-prelude.rs @@ -1,5 +1,4 @@ // run-pass - #![no_std] extern crate std; diff --git a/src/test/ui/dead-code-ret.rs b/src/test/ui/unreachable-code-ret.rs similarity index 100% rename from src/test/ui/dead-code-ret.rs rename to src/test/ui/unreachable-code-ret.rs diff --git a/src/test/ui/dead-code-ret.stderr b/src/test/ui/unreachable-code-ret.stderr similarity index 86% rename from src/test/ui/dead-code-ret.stderr rename to src/test/ui/unreachable-code-ret.stderr index 83841131599b2..c22342ce7218d 100644 --- a/src/test/ui/dead-code-ret.stderr +++ b/src/test/ui/unreachable-code-ret.stderr @@ -1,5 +1,5 @@ error: unreachable statement - --> $DIR/dead-code-ret.rs:7:5 + --> $DIR/unreachable-code-ret.rs:7:5 | LL | return; | ------ any code following this expression is unreachable @@ -7,7 +7,7 @@ LL | println!("Paul is dead"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here - --> $DIR/dead-code-ret.rs:3:9 + --> $DIR/unreachable-code-ret.rs:3:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^