diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 9502be728de06..de92204a7c2f0 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -942,17 +942,6 @@ impl<'a> Resolver<'a> { Some(suggestion) if suggestion.candidate == kw::Underscore => return false, Some(suggestion) => suggestion, }; - let msg = format!( - "{} {} with a similar name exists", - suggestion.res.article(), - suggestion.res.descr() - ); - err.span_suggestion( - span, - &msg, - suggestion.candidate.to_string(), - Applicability::MaybeIncorrect, - ); let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate { LOCAL_CRATE => self.opt_span(def_id), _ => Some( @@ -961,9 +950,30 @@ impl<'a> Resolver<'a> { .guess_head_span(self.cstore().get_span_untracked(def_id, self.session)), ), }); - if let Some(span) = def_span { + if let Some(def_span) = def_span { + if span.overlaps(def_span) { + // Don't suggest typo suggestion for itself like in the followoing: + // error[E0423]: expected function, tuple struct or tuple variant, found struct `X` + // --> $DIR/issue-64792-bad-unicode-ctor.rs:3:14 + // | + // LL | struct X {} + // | ----------- `X` defined here + // LL | + // LL | const Y: X = X("ö"); + // | -------------^^^^^^- similarly named constant `Y` defined here + // | + // help: use struct literal syntax instead + // | + // LL | const Y: X = X {}; + // | ^^^^ + // help: a constant with a similar name exists + // | + // LL | const Y: X = Y("ö"); + // | ^ + return false; + } err.span_label( - self.session.source_map().guess_head_span(span), + self.session.source_map().guess_head_span(def_span), &format!( "similarly named {} `{}` defined here", suggestion.res.descr(), @@ -971,6 +981,17 @@ impl<'a> Resolver<'a> { ), ); } + let msg = format!( + "{} {} with a similar name exists", + suggestion.res.article(), + suggestion.res.descr() + ); + err.span_suggestion( + span, + &msg, + suggestion.candidate.to_string(), + Applicability::MaybeIncorrect, + ); true } diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index ec6dbb070dfa8..dcab0858a75ae 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -12,7 +12,7 @@ use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder} use rustc_hir as hir; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::PrimTy; use rustc_session::config::nightly_options; use rustc_span::hygiene::MacroKind; @@ -88,6 +88,18 @@ fn import_candidate_to_enum_paths(suggestion: &ImportSuggestion) -> (String, Str } impl<'a> LateResolutionVisitor<'a, '_, '_> { + fn def_span(&self, def_id: DefId) -> Option { + match def_id.krate { + LOCAL_CRATE => self.r.opt_span(def_id), + _ => Some( + self.r + .session + .source_map() + .guess_head_span(self.r.cstore().get_span_untracked(def_id, self.r.session)), + ), + } + } + /// Handles error reporting for `smart_resolve_path_fragment` function. /// Creates base error and amends it with one short label and possibly some longer helps/notes. pub(crate) fn smart_resolve_report_errors( @@ -339,8 +351,6 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { // Try Levenshtein algorithm. let typo_sugg = self.lookup_typo_candidate(path, ns, is_expected, span); - let levenshtein_worked = self.r.add_typo_suggestion(&mut err, typo_sugg, ident_span); - // Try context-dependent help if relaxed lookup didn't work. if let Some(res) = res { if self.smart_resolve_context_dependent_help( @@ -351,14 +361,18 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { &path_str, &fallback_label, ) { + // We do this to avoid losing a secondary span when we override the main error span. + self.r.add_typo_suggestion(&mut err, typo_sugg, ident_span); return (err, candidates); } } - // Fallback label. - if !levenshtein_worked { + if !self.type_ascription_suggestion(&mut err, base_span) + && !self.r.add_typo_suggestion(&mut err, typo_sugg, ident_span) + { + // Fallback label. 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( @@ -518,6 +532,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { }), ) if followed_by_brace => { if let Some(sp) = closing_brace { + err.span_label(span, fallback_label); err.multipart_suggestion( "surround the struct literal with parentheses", vec![ @@ -550,7 +565,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { } _ => span, }; - if let Some(span) = self.r.opt_span(def_id) { + if let Some(span) = self.def_span(def_id) { err.span_label(span, &format!("`{}` defined here", path_str)); } let (tail, descr, applicability) = match source { @@ -581,12 +596,15 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { applicability, ); } - _ => {} + _ => { + err.span_label(span, fallback_label); + } } }; match (res, source) { (Res::Def(DefKind::Macro(MacroKind::Bang), _), _) => { + err.span_label(span, fallback_label); err.span_suggestion_verbose( span.shrink_to_hi(), "use `!` to invoke the macro", @@ -602,7 +620,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { if nightly_options::is_nightly_build() { let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \ `type` alias"; - if let Some(span) = self.r.opt_span(def_id) { + if let Some(span) = self.def_span(def_id) { err.span_help(span, msg); } else { err.help(msg); @@ -680,7 +698,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { bad_struct_syntax_suggestion(def_id); } (Res::Def(DefKind::Ctor(_, CtorKind::Fn), def_id), _) if ns == ValueNS => { - if let Some(span) = self.r.opt_span(def_id) { + if let Some(span) = self.def_span(def_id) { err.span_label(span, &format!("`{}` defined here", path_str)); } err.span_label(span, format!("did you mean `{}( /* fields */ )`?", path_str)); @@ -869,7 +887,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { start.to(sm.next_point(start)) } - fn type_ascription_suggestion(&self, err: &mut DiagnosticBuilder<'_>, base_span: Span) { + fn type_ascription_suggestion(&self, err: &mut DiagnosticBuilder<'_>, base_span: Span) -> bool { let sm = self.r.session.source_map(); let base_snippet = sm.span_to_snippet(base_span); if let Some(&sp) = self.diagnostic_metadata.current_type_ascription.last() { @@ -939,9 +957,11 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { "expecting a type here because of type ascription", ); } + return show_label; } } } + false } fn find_module(&mut self, def_id: DefId) -> Option<(Module<'a>, ImportSuggestion)> { diff --git a/src/test/ui/const-generics/struct-with-invalid-const-param.stderr b/src/test/ui/const-generics/struct-with-invalid-const-param.stderr index a968b26bc2611..47617c7849f4a 100644 --- a/src/test/ui/const-generics/struct-with-invalid-const-param.stderr +++ b/src/test/ui/const-generics/struct-with-invalid-const-param.stderr @@ -2,10 +2,7 @@ error[E0573]: expected type, found const parameter `C` --> $DIR/struct-with-invalid-const-param.rs:4:23 | LL | struct S(C); - | ----------------------^-- - | | | - | | help: a struct with a similar name exists: `S` - | similarly named struct `S` defined here + | ^ not a type warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/struct-with-invalid-const-param.rs:1:12 diff --git a/src/test/ui/empty/empty-struct-braces-expr.stderr b/src/test/ui/empty/empty-struct-braces-expr.stderr index c0ba9716fb001..6292ed446978d 100644 --- a/src/test/ui/empty/empty-struct-braces-expr.stderr +++ b/src/test/ui/empty/empty-struct-braces-expr.stderr @@ -12,14 +12,14 @@ LL | let e1 = Empty1; LL | pub struct XEmpty2; | ------------------- similarly named unit struct `XEmpty2` defined here | -help: a unit struct with a similar name exists - | -LL | let e1 = XEmpty2; - | ^^^^^^^ help: use struct literal syntax instead | LL | let e1 = Empty1 {}; | ^^^^^^^^^ +help: a unit struct with a similar name exists + | +LL | let e1 = XEmpty2; + | ^^^^^^^ error[E0423]: expected function, tuple struct or tuple variant, found struct `Empty1` --> $DIR/empty-struct-braces-expr.rs:16:14 @@ -29,15 +29,20 @@ LL | struct Empty1 {} ... LL | let e1 = Empty1(); | ^^^^^^^^ + | + ::: $DIR/auxiliary/empty-struct.rs:2:1 | -help: a unit struct with a similar name exists +LL | pub struct XEmpty2; + | ------------------- similarly named unit struct `XEmpty2` defined here | -LL | let e1 = XEmpty2(); - | ^^^^^^^ help: use struct literal syntax instead | LL | let e1 = Empty1 {}; | ^^^^^^^^^ +help: a unit struct with a similar name exists + | +LL | let e1 = XEmpty2(); + | ^^^^^^^ error[E0423]: expected value, found struct variant `E::Empty3` --> $DIR/empty-struct-braces-expr.rs:18:14 @@ -63,34 +68,43 @@ error[E0423]: expected value, found struct `XEmpty1` LL | let xe1 = XEmpty1; | ^^^^^^^ | - ::: $DIR/auxiliary/empty-struct.rs:2:1 + ::: $DIR/auxiliary/empty-struct.rs:1:1 | +LL | pub struct XEmpty1 {} + | ------------------ `XEmpty1` defined here LL | pub struct XEmpty2; | ------------------- similarly named unit struct `XEmpty2` defined here | -help: a unit struct with a similar name exists - | -LL | let xe1 = XEmpty2; - | ^^^^^^^ help: use struct literal syntax instead | LL | let xe1 = XEmpty1 {}; | ^^^^^^^^^^ +help: a unit struct with a similar name exists + | +LL | let xe1 = XEmpty2; + | ^^^^^^^ error[E0423]: expected function, tuple struct or tuple variant, found struct `XEmpty1` --> $DIR/empty-struct-braces-expr.rs:23:15 | LL | let xe1 = XEmpty1(); | ^^^^^^^^^ + | + ::: $DIR/auxiliary/empty-struct.rs:1:1 | -help: a unit struct with a similar name exists +LL | pub struct XEmpty1 {} + | ------------------ `XEmpty1` defined here +LL | pub struct XEmpty2; + | ------------------- similarly named unit struct `XEmpty2` defined here | -LL | let xe1 = XEmpty2(); - | ^^^^^^^ help: use struct literal syntax instead | LL | let xe1 = XEmpty1 {}; | ^^^^^^^^^^ +help: a unit struct with a similar name exists + | +LL | let xe1 = XEmpty2(); + | ^^^^^^^ error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope --> $DIR/empty-struct-braces-expr.rs:25:19 diff --git a/src/test/ui/empty/empty-struct-braces-pat-1.stderr b/src/test/ui/empty/empty-struct-braces-pat-1.stderr index b027c82f7dd37..3570012fc3752 100644 --- a/src/test/ui/empty/empty-struct-braces-pat-1.stderr +++ b/src/test/ui/empty/empty-struct-braces-pat-1.stderr @@ -13,19 +13,21 @@ error[E0532]: expected unit struct, unit variant or constant, found struct varia LL | XE::XEmpty3 => () | ^^^^^^^^^^^ | - ::: $DIR/auxiliary/empty-struct.rs:7:5 + ::: $DIR/auxiliary/empty-struct.rs:6:5 | +LL | XEmpty3 {}, + | ------- `XE::XEmpty3` defined here LL | XEmpty4, | ------- similarly named unit variant `XEmpty4` defined here | -help: a unit variant with a similar name exists - | -LL | XE::XEmpty4 => () - | ^^^^^^^ help: use struct pattern syntax instead | LL | XE::XEmpty3 { /* fields */ } => () | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: a unit variant with a similar name exists + | +LL | XE::XEmpty4 => () + | ^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/empty/empty-struct-braces-pat-2.stderr b/src/test/ui/empty/empty-struct-braces-pat-2.stderr index a53b88db7d1ed..3bd3f6a9644a1 100644 --- a/src/test/ui/empty/empty-struct-braces-pat-2.stderr +++ b/src/test/ui/empty/empty-struct-braces-pat-2.stderr @@ -6,30 +6,43 @@ LL | struct Empty1 {} ... LL | Empty1() => () | ^^^^^^^^ + | + ::: $DIR/auxiliary/empty-struct.rs:3:1 | -help: a tuple struct with a similar name exists +LL | pub struct XEmpty6(); + | --------------------- similarly named tuple struct `XEmpty6` defined here | -LL | XEmpty6() => () - | ^^^^^^^ help: use struct pattern syntax instead | LL | Empty1 {} => () | ^^^^^^^^^ +help: a tuple struct with a similar name exists + | +LL | XEmpty6() => () + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found struct `XEmpty1` --> $DIR/empty-struct-braces-pat-2.rs:18:9 | LL | XEmpty1() => () | ^^^^^^^^^ + | + ::: $DIR/auxiliary/empty-struct.rs:1:1 | -help: a tuple struct with a similar name exists +LL | pub struct XEmpty1 {} + | ------------------ `XEmpty1` defined here +LL | pub struct XEmpty2; +LL | pub struct XEmpty6(); + | --------------------- similarly named tuple struct `XEmpty6` defined here | -LL | XEmpty6() => () - | ^^^^^^^ help: use struct pattern syntax instead | LL | XEmpty1 {} => () | ^^^^^^^^^^ +help: a tuple struct with a similar name exists + | +LL | XEmpty6() => () + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found struct `Empty1` --> $DIR/empty-struct-braces-pat-2.rs:21:9 @@ -39,30 +52,43 @@ LL | struct Empty1 {} ... LL | Empty1(..) => () | ^^^^^^^^^^ + | + ::: $DIR/auxiliary/empty-struct.rs:3:1 | -help: a tuple struct with a similar name exists +LL | pub struct XEmpty6(); + | --------------------- similarly named tuple struct `XEmpty6` defined here | -LL | XEmpty6(..) => () - | ^^^^^^^ help: use struct pattern syntax instead | LL | Empty1 {} => () | ^^^^^^^^^ +help: a tuple struct with a similar name exists + | +LL | XEmpty6(..) => () + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found struct `XEmpty1` --> $DIR/empty-struct-braces-pat-2.rs:24:9 | LL | XEmpty1(..) => () | ^^^^^^^^^^^ + | + ::: $DIR/auxiliary/empty-struct.rs:1:1 | -help: a tuple struct with a similar name exists +LL | pub struct XEmpty1 {} + | ------------------ `XEmpty1` defined here +LL | pub struct XEmpty2; +LL | pub struct XEmpty6(); + | --------------------- similarly named tuple struct `XEmpty6` defined here | -LL | XEmpty6(..) => () - | ^^^^^^^ help: use struct pattern syntax instead | LL | XEmpty1 {} => () | ^^^^^^^^^^ +help: a tuple struct with a similar name exists + | +LL | XEmpty6(..) => () + | ^^^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/empty/empty-struct-braces-pat-3.stderr b/src/test/ui/empty/empty-struct-braces-pat-3.stderr index 93ace3eccef91..aac872ba0ecca 100644 --- a/src/test/ui/empty/empty-struct-braces-pat-3.stderr +++ b/src/test/ui/empty/empty-struct-braces-pat-3.stderr @@ -12,15 +12,23 @@ error[E0532]: expected tuple struct or tuple variant, found struct variant `XE:: | LL | XE::XEmpty3() => () | ^^^^^^^^^^^^^ + | + ::: $DIR/auxiliary/empty-struct.rs:6:5 | -help: a tuple variant with a similar name exists +LL | XEmpty3 {}, + | ------- `XE::XEmpty3` defined here +LL | XEmpty4, +LL | XEmpty5(), + | --------- similarly named tuple variant `XEmpty5` defined here | -LL | XE::XEmpty5() => () - | ^^^^^^^ help: use struct pattern syntax instead | LL | XE::XEmpty3 { /* fields */ } => () | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: a tuple variant with a similar name exists + | +LL | XE::XEmpty5() => () + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found struct variant `E::Empty3` --> $DIR/empty-struct-braces-pat-3.rs:25:9 @@ -36,15 +44,23 @@ error[E0532]: expected tuple struct or tuple variant, found struct variant `XE:: | LL | XE::XEmpty3(..) => () | ^^^^^^^^^^^^^^^ + | + ::: $DIR/auxiliary/empty-struct.rs:6:5 | -help: a tuple variant with a similar name exists +LL | XEmpty3 {}, + | ------- `XE::XEmpty3` defined here +LL | XEmpty4, +LL | XEmpty5(), + | --------- similarly named tuple variant `XEmpty5` defined here | -LL | XE::XEmpty5(..) => () - | ^^^^^^^ help: use struct pattern syntax instead | LL | XE::XEmpty3 { /* fields */ } => () | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: a tuple variant with a similar name exists + | +LL | XE::XEmpty5(..) => () + | ^^^^^^^ error: aborting due to 4 previous errors diff --git a/src/test/ui/empty/empty-struct-tuple-pat.stderr b/src/test/ui/empty/empty-struct-tuple-pat.stderr index 9388ed2665710..7b21d31635cf1 100644 --- a/src/test/ui/empty/empty-struct-tuple-pat.stderr +++ b/src/test/ui/empty/empty-struct-tuple-pat.stderr @@ -38,6 +38,8 @@ LL | XE::XEmpty5 => (), | LL | XEmpty4, | ------- similarly named unit variant `XEmpty4` defined here +LL | XEmpty5(), + | --------- `XE::XEmpty5` defined here error: aborting due to 4 previous errors diff --git a/src/test/ui/error-codes/E0423.stderr b/src/test/ui/error-codes/E0423.stderr index 077367de9d847..a9aecb520b228 100644 --- a/src/test/ui/error-codes/E0423.stderr +++ b/src/test/ui/error-codes/E0423.stderr @@ -34,21 +34,24 @@ LL | struct Foo { a: bool }; LL | LL | let f = Foo(); | ^^^^^ +... +LL | fn foo() { + | -------- similarly named function `foo` defined here | -help: a function with a similar name exists - | -LL | let f = foo(); - | ^^^ help: use struct literal syntax instead | LL | let f = Foo { a: val }; | ^^^^^^^^^^^^^^ +help: a function with a similar name exists + | +LL | let f = foo(); + | ^^^ error[E0423]: expected value, found struct `T` --> $DIR/E0423.rs:14:8 | LL | if T {} == T {} { println!("Ok"); } - | ^ + | ^ not a value | help: surround the struct literal with parentheses | diff --git a/src/test/ui/hygiene/rustc-macro-transparency.stderr b/src/test/ui/hygiene/rustc-macro-transparency.stderr index 024ce8207601e..94256b2eb79ab 100644 --- a/src/test/ui/hygiene/rustc-macro-transparency.stderr +++ b/src/test/ui/hygiene/rustc-macro-transparency.stderr @@ -8,7 +8,7 @@ error[E0423]: expected value, found macro `semitransparent` --> $DIR/rustc-macro-transparency.rs:29:5 | LL | semitransparent; - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ not a value | help: use `!` to invoke the macro | @@ -19,7 +19,7 @@ error[E0423]: expected value, found macro `opaque` --> $DIR/rustc-macro-transparency.rs:30:5 | LL | opaque; - | ^^^^^^ + | ^^^^^^ not a value | help: use `!` to invoke the macro | diff --git a/src/test/ui/issues/issue-31845.stderr b/src/test/ui/issues/issue-31845.stderr index fe51fa0699fb4..56281938559d0 100644 --- a/src/test/ui/issues/issue-31845.stderr +++ b/src/test/ui/issues/issue-31845.stderr @@ -1,10 +1,8 @@ error[E0425]: cannot find function `g` in this scope --> $DIR/issue-31845.rs:7:12 | -LL | fn h() { - | ------ similarly named function `h` defined here LL | g(); - | ^ help: a function with a similar name exists: `h` + | ^ not found in this scope error: aborting due to previous error diff --git a/src/test/ui/issues/issue-64792-bad-unicode-ctor.stderr b/src/test/ui/issues/issue-64792-bad-unicode-ctor.stderr index 12053d8a1291c..c3dda704b0e93 100644 --- a/src/test/ui/issues/issue-64792-bad-unicode-ctor.stderr +++ b/src/test/ui/issues/issue-64792-bad-unicode-ctor.stderr @@ -5,16 +5,7 @@ LL | struct X {} | ----------- `X` defined here LL | LL | const Y: X = X("ö"); - | ^^^^^^ - | -help: a constant with a similar name exists - | -LL | const Y: X = Y("ö"); - | ^ -help: use struct literal syntax instead - | -LL | const Y: X = X {}; - | ^^^^ + | ^^^^^^ help: use struct literal syntax instead: `X {}` error: aborting due to previous error diff --git a/src/test/ui/namespace/namespace-mix.stderr b/src/test/ui/namespace/namespace-mix.stderr index 636789c9cc300..ded3173f45b2e 100644 --- a/src/test/ui/namespace/namespace-mix.stderr +++ b/src/test/ui/namespace/namespace-mix.stderr @@ -53,14 +53,14 @@ LL | TV(), LL | check(m7::V); | ^^^^^ | -help: a tuple variant with a similar name exists - | -LL | check(m7::TV); - | ^^ help: use struct literal syntax instead | LL | check(m7::V {}); | ^^^^^^^^ +help: a tuple variant with a similar name exists + | +LL | check(m7::TV); + | ^^ help: consider importing one of these items instead | LL | use m8::V; @@ -74,19 +74,21 @@ error[E0423]: expected value, found struct variant `xm7::V` LL | check(xm7::V); | ^^^^^^ | - ::: $DIR/auxiliary/namespace-mix.rs:7:9 + ::: $DIR/auxiliary/namespace-mix.rs:6:9 | +LL | V {}, + | - `xm7::V` defined here LL | TV(), | ---- similarly named tuple variant `TV` defined here | -help: a tuple variant with a similar name exists - | -LL | check(xm7::TV); - | ^^ help: use struct literal syntax instead | LL | check(xm7::V { /* fields */ }); | ^^^^^^^^^^^^^^^^^^^^^^^ +help: a tuple variant with a similar name exists + | +LL | check(xm7::TV); + | ^^ help: consider importing one of these items instead | LL | use m8::V; diff --git a/src/test/ui/privacy/legacy-ctor-visibility.stderr b/src/test/ui/privacy/legacy-ctor-visibility.stderr index 4f0d72de6f1a4..c8057d85ed1d0 100644 --- a/src/test/ui/privacy/legacy-ctor-visibility.stderr +++ b/src/test/ui/privacy/legacy-ctor-visibility.stderr @@ -1,10 +1,8 @@ error[E0423]: expected function, tuple struct or tuple variant, found struct `S` --> $DIR/legacy-ctor-visibility.rs:9:13 | -LL | fn f() { - | ------ similarly named function `f` defined here LL | S(10); - | ^ help: a function with a similar name exists: `f` + | ^ error: aborting due to previous error diff --git a/src/test/ui/proc-macro/attributes-on-modules-fail.stderr b/src/test/ui/proc-macro/attributes-on-modules-fail.stderr index b37f1bd393c6f..97b2f22e161ec 100644 --- a/src/test/ui/proc-macro/attributes-on-modules-fail.stderr +++ b/src/test/ui/proc-macro/attributes-on-modules-fail.stderr @@ -44,12 +44,8 @@ error[E0412]: cannot find type `Y` in this scope --> $DIR/attributes-on-modules-fail.rs:10:14 | LL | type A = Y; - | ---------^- similarly named type alias `A` defined here + | ^ not found in this scope | -help: a type alias with a similar name exists - | -LL | type A = A; - | ^ help: consider importing this struct | LL | use Y; @@ -59,12 +55,8 @@ error[E0412]: cannot find type `X` in this scope --> $DIR/attributes-on-modules-fail.rs:14:10 | LL | type A = X; - | ---------^- similarly named type alias `A` defined here - | -help: a type alias with a similar name exists + | ^ not found in this scope | -LL | type A = A; - | ^ help: consider importing this struct | LL | use m::X; diff --git a/src/test/ui/resolve/issue-19452.stderr b/src/test/ui/resolve/issue-19452.stderr index d1690d4eef7ef..6c519d7348025 100644 --- a/src/test/ui/resolve/issue-19452.stderr +++ b/src/test/ui/resolve/issue-19452.stderr @@ -12,6 +12,11 @@ error[E0423]: expected value, found struct variant `issue_19452_aux::Homura::Mad | LL | let homura = issue_19452_aux::Homura::Madoka; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `issue_19452_aux::Homura::Madoka { /* fields */ }` + | + ::: $DIR/auxiliary/issue-19452-aux.rs:2:5 + | +LL | Madoka { age: u32 } + | ------ `issue_19452_aux::Homura::Madoka` defined here error: aborting due to 2 previous errors diff --git a/src/test/ui/resolve/issue-39226.stderr b/src/test/ui/resolve/issue-39226.stderr index c9b9aeb45ba42..72d66b0f6a2a1 100644 --- a/src/test/ui/resolve/issue-39226.stderr +++ b/src/test/ui/resolve/issue-39226.stderr @@ -7,14 +7,14 @@ LL | struct Handle {} LL | handle: Handle | ^^^^^^ | -help: a local variable with a similar name exists - | -LL | handle: handle - | ^^^^^^ help: use struct literal syntax instead | LL | handle: Handle {} | ^^^^^^^^^ +help: a local variable with a similar name exists + | +LL | handle: handle + | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index 3904a00dde1dd..f1ed7aaa86779 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -16,16 +16,9 @@ LL | m::Z::Unit; error[E0423]: expected value, found enum `Z` --> $DIR/privacy-enum-ctor.rs:25:9 | -LL | fn f() { - | ------ similarly named function `f` defined here -... LL | Z; | ^ | -help: a function with a similar name exists - | -LL | f; - | ^ help: try using one of the enum's variants | LL | m::Z::Fn; @@ -55,10 +48,6 @@ LL | fn f() { LL | let _: E = m::E; | ^^^^ | -help: a function with a similar name exists - | -LL | let _: E = m::f; - | ^ help: try using one of the enum's variants | LL | let _: E = E::Fn; @@ -67,6 +56,10 @@ LL | let _: E = E::Struct; | ^^^^^^^^^ LL | let _: E = E::Unit; | ^^^^^^^ +help: a function with a similar name exists + | +LL | let _: E = m::f; + | ^ help: consider importing one of these items instead | LL | use std::f32::consts::E; diff --git a/src/test/ui/resolve/resolve-hint-macro.stderr b/src/test/ui/resolve/resolve-hint-macro.stderr index 361da4cc78e00..7d35ce7e65e58 100644 --- a/src/test/ui/resolve/resolve-hint-macro.stderr +++ b/src/test/ui/resolve/resolve-hint-macro.stderr @@ -2,7 +2,7 @@ error[E0423]: expected function, found macro `assert` --> $DIR/resolve-hint-macro.rs:2:5 | LL | assert(true); - | ^^^^^^ + | ^^^^^^ not a function | help: use `!` to invoke the macro | diff --git a/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr b/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr index 33080340cb67a..2d35159ec9a22 100644 --- a/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr +++ b/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr @@ -31,14 +31,14 @@ LL | pub const I: i32 = 1; LL | a::b.J | ^^^^ | -help: a constant with a similar name exists - | -LL | a::I.J - | ^ help: use the path separator to refer to an item | LL | a::b::J | +help: a constant with a similar name exists + | +LL | a::I.J + | ^ error[E0423]: expected value, found module `a` --> $DIR/suggest-path-instead-of-mod-dot-item.rs:37:5 @@ -68,14 +68,14 @@ LL | pub const I: i32 = 1; LL | a::b.f() | ^^^^ | -help: a constant with a similar name exists - | -LL | a::I.f() - | ^ help: use the path separator to refer to an item | LL | a::b::f() | ^^^^^^^ +help: a constant with a similar name exists + | +LL | a::I.f() + | ^ error[E0423]: expected value, found module `a::b` --> $DIR/suggest-path-instead-of-mod-dot-item.rs:50:5 diff --git a/src/test/ui/struct-literal-variant-in-if.stderr b/src/test/ui/struct-literal-variant-in-if.stderr index 4cd1169cc1bb8..a2252d4e4d282 100644 --- a/src/test/ui/struct-literal-variant-in-if.stderr +++ b/src/test/ui/struct-literal-variant-in-if.stderr @@ -46,7 +46,7 @@ error[E0423]: expected value, found struct variant `E::V` --> $DIR/struct-literal-variant-in-if.rs:10:13 | LL | if x == E::V { field } {} - | ^^^^ + | ^^^^ not a value | help: surround the struct literal with parentheses | diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr index 45309486db46f..9b2febb1393e1 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr @@ -9,14 +9,14 @@ LL | B { a: usize }, LL | let _: E = E::B; | ^^^^ | -help: a tuple variant with a similar name exists - | -LL | let _: E = E::A; - | ^ help: use struct literal syntax instead | LL | let _: E = E::B { a: val }; | ^^^^^^^^^^^^^^^ +help: a tuple variant with a similar name exists + | +LL | let _: E = E::A; + | ^ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:29:20 diff --git a/src/test/ui/try-block/try-block-in-edition2015.stderr b/src/test/ui/try-block/try-block-in-edition2015.stderr index fe870ab737cc8..78cdfb2cc7f04 100644 --- a/src/test/ui/try-block/try-block-in-edition2015.stderr +++ b/src/test/ui/try-block/try-block-in-edition2015.stderr @@ -11,7 +11,7 @@ error[E0574]: expected struct, variant or union type, found macro `try` --> $DIR/try-block-in-edition2015.rs:4:33 | LL | let try_result: Option<_> = try { - | ^^^ + | ^^^ not a struct, variant or union type | = note: if you want the `try` keyword, you need to be in the 2018 edition help: use `!` to invoke the macro diff --git a/src/test/ui/type/type-ascription-with-fn-call.stderr b/src/test/ui/type/type-ascription-with-fn-call.stderr index 5f74724b59e52..d78fd08fd6065 100644 --- a/src/test/ui/type/type-ascription-with-fn-call.stderr +++ b/src/test/ui/type/type-ascription-with-fn-call.stderr @@ -4,10 +4,7 @@ error[E0573]: expected type, found function `f` LL | f() : | - help: maybe you meant to write `;` here LL | f(); - | ^^^ - | | - | not a type - | expecting a type here because of type ascription + | ^^^ expecting a type here because of type ascription error: aborting due to previous error diff --git a/src/test/ui/ui-testing-optout.stderr b/src/test/ui/ui-testing-optout.stderr index f562bb74c1173..652c472c0bcfe 100644 --- a/src/test/ui/ui-testing-optout.stderr +++ b/src/test/ui/ui-testing-optout.stderr @@ -2,10 +2,7 @@ error[E0412]: cannot find type `B` in this scope --> $DIR/ui-testing-optout.rs:4:10 | 4 | type A = B; - | ---------^- - | | | - | | help: a type alias with a similar name exists: `A` - | similarly named type alias `A` defined here + | ^ not found in this scope error[E0412]: cannot find type `D` in this scope --> $DIR/ui-testing-optout.rs:7:10 diff --git a/src/test/ui/xcrate/xcrate-unit-struct.stderr b/src/test/ui/xcrate/xcrate-unit-struct.stderr index 813d5d4fdb12b..3dc8b90795c4d 100644 --- a/src/test/ui/xcrate/xcrate-unit-struct.stderr +++ b/src/test/ui/xcrate/xcrate-unit-struct.stderr @@ -3,6 +3,11 @@ error[E0423]: expected value, found struct `xcrate_unit_struct::StructWithFields | LL | let _ = xcrate_unit_struct::StructWithFields; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `xcrate_unit_struct::StructWithFields { foo: val }` + | + ::: $DIR/auxiliary/xcrate_unit_struct.rs:20:1 + | +LL | pub struct StructWithFields { + | --------------------------- `xcrate_unit_struct::StructWithFields` defined here error: aborting due to previous error