Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions compiler/rustc_resolve/src/diagnostics/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,9 +1928,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ident,
is_expected,
);
if !self.add_typo_suggestion(err, suggestion, ident.span) {
self.detect_derive_attribute(err, ident, parent_scope, sugg_span);
}
self.add_typo_suggestion(err, suggestion, ident.span);
self.detect_derive_attribute(err, ident, parent_scope, sugg_span);

let import_suggestions =
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
Expand Down Expand Up @@ -2211,11 +2210,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
err: &mut Diag<'_>,
suggestion: Option<TypoSuggestion>,
span: Span,
) -> bool {
) {
let suggestion = match suggestion {
None => return false,
None => return,
// We shouldn't suggest underscore.
Some(suggestion) if suggestion.candidate == kw::Underscore => return false,
Some(suggestion) if suggestion.candidate == kw::Underscore => return,
Some(suggestion) => suggestion,
};

Expand All @@ -2241,7 +2240,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// |
// LL | const Y: X = Y("ö");
// | ^
return false;
return;
}
let span = self.tcx.sess.source_map().guess_head_span(def_span);
let candidate_descr = suggestion.res.descr();
Expand Down Expand Up @@ -2271,7 +2270,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
"the leading underscore in `{candidate}` marks it as unused, consider renaming it to `{snippet}`"
);
if !did_label_def_span {
err.span_label(span, format!("`{candidate}` defined here"));
err.span_note(span, format!("`{candidate}` defined here"));
}
(span, msg, snippet)
} else {
Expand All @@ -2288,7 +2287,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
(span, msg, suggestion.candidate.to_ident_string())
};
err.span_suggestion_verbose(span, msg, sugg, Applicability::MaybeIncorrect);
true
}

fn decl_description(&self, b: Decl<'_>, ident: Ident, scope: Scope<'_>) -> String {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,14 +1219,14 @@ pub(crate) struct CannotFindBuiltinMacroWithName {

#[derive(Subdiagnostic)]
pub(crate) enum DefinedHere {
#[label("similarly named {$candidate_descr} `{$candidate}` defined here")]
#[note("similarly named {$candidate_descr} `{$candidate}` defined here")]
SimilarlyNamed {
#[primary_span]
span: Span,
candidate_descr: &'static str,
candidate: Symbol,
},
#[label("{$candidate_descr} `{$candidate}` defined here")]
#[note("{$candidate_descr} `{$candidate}` defined here")]
SingleItem {
#[primary_span]
span: Span,
Expand Down
37 changes: 18 additions & 19 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,31 +1319,30 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {

let typo_sugg =
self.lookup_typo_candidate(path, following_seg, source.namespace(), is_expected);
let mut fallback = false;
let mut fallback = true;
let typo_sugg = typo_sugg
.to_opt_suggestion()
.filter(|sugg| !suggested_candidates.contains(sugg.candidate.as_str()));
if !self.r.add_typo_suggestion(err, typo_sugg, ident_span) {
fallback = true;
match self.diag_metadata.current_let_binding {
Some((pat_sp, Some(ty_sp), None))
if ty_sp.contains(base_error.span) && base_error.could_be_expr =>
{
err.span_suggestion_verbose(
pat_sp.between(ty_sp),
"use `=` if you meant to assign",
" = ",
Applicability::MaybeIncorrect,
);
}
_ => {}
}
self.r.add_typo_suggestion(err, typo_sugg, ident_span);

// If the trait has a single item (which wasn't matched by the algorithm), suggest it
let suggestion = self.get_single_associated_item(path, &source, is_expected);
self.r.add_typo_suggestion(err, suggestion, ident_span);
match self.diag_metadata.current_let_binding {
Some((pat_sp, Some(ty_sp), None))
if ty_sp.contains(base_error.span) && base_error.could_be_expr =>
{
err.span_suggestion_verbose(
pat_sp.between(ty_sp),
"use `=` if you meant to assign",
" = ",
Applicability::MaybeIncorrect,
);
}
_ => {}
}

// If the trait has a single item (which wasn't matched by the algorithm), suggest it
let suggestion = self.get_single_associated_item(path, &source, is_expected);
self.r.add_typo_suggestion(err, suggestion, ident_span);

if self.let_binding_suggestion(err, ident_span) {
fallback = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ help: a built-in attribute with a similar name exists
LL - #[lint("this is an example message", code = E0123)]
LL + #[link("this is an example message", code = E0123)]
|
help: the derive macros `Lift` and `Lift_Generic` accept the similarly named `lift` attribute
|
LL - #[lint("this is an example message", code = E0123)]
LL + #[lift("this is an example message", code = E0123)]
|

error: cannot find attribute `multipart_suggestion` in this scope
--> $DIR/diagnostic-derive-inline.rs:565:3
Expand Down
14 changes: 8 additions & 6 deletions tests/ui/argument-suggestions/disjoint-spans-issue-151607.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
error[E0425]: cannot find type `E` in this scope
--> $DIR/disjoint-spans-issue-151607.rs:8:24
|
LL | struct B;
| --------- similarly named struct `B` defined here
...
LL | fn foo(g: F, y: F, e: &E) {
| ^
| ^ not found in this scope
|
note: similarly named struct `B` defined here
--> $DIR/disjoint-spans-issue-151607.rs:5:1
|
LL | struct B;
| ^^^^^^^^^
help: a struct with a similar name exists
|
LL - fn foo(g: F, y: F, e: &E) {
Expand All @@ -21,7 +23,7 @@ error[E0425]: cannot find value `E` in this scope
--> $DIR/disjoint-spans-issue-151607.rs:10:18
|
LL | foo(B, g, D, E, F, G)
| ^
| ^ not found in this scope
|
help: a local variable with a similar name exists
|
Expand All @@ -43,7 +45,7 @@ error[E0425]: cannot find value `G` in this scope
--> $DIR/disjoint-spans-issue-151607.rs:10:24
|
LL | foo(B, g, D, E, F, G)
| ^
| ^ not found in this scope
|
help: a local variable with a similar name exists
|
Expand Down
20 changes: 12 additions & 8 deletions tests/ui/argument-suggestions/issue-109831.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
error[E0425]: cannot find type `C` in this scope
--> $DIR/issue-109831.rs:4:24
|
LL | struct A;
| --------- similarly named struct `A` defined here
...
LL | fn f(b1: B, b2: B, a2: C) {}
| ^
| ^ not found in this scope
|
note: similarly named struct `A` defined here
--> $DIR/issue-109831.rs:1:1
|
LL | struct A;
| ^^^^^^^^^
help: a struct with a similar name exists
|
LL - fn f(b1: B, b2: B, a2: C) {}
Expand All @@ -20,12 +22,14 @@ LL | fn f<C>(b1: B, b2: B, a2: C) {}
error[E0425]: cannot find value `C` in this scope
--> $DIR/issue-109831.rs:7:16
|
LL | struct A;
| --------- similarly named unit struct `A` defined here
...
LL | f(A, A, B, C);
| ^
| ^ not found in this scope
|
note: similarly named unit struct `A` defined here
--> $DIR/issue-109831.rs:1:1
|
LL | struct A;
| ^^^^^^^^^
help: a unit struct with a similar name exists
|
LL - f(A, A, B, C);
Expand Down
16 changes: 10 additions & 6 deletions tests/ui/associated-item/issue-87638.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
error[E0576]: cannot find associated type `Output` in trait `Trait`
--> $DIR/issue-87638.rs:17:26
|
LL | type Target;
| ------------ associated type `Target` defined here
...
LL | let _: <S as Trait>::Output;
| ^^^^^^ not found in `Trait`
|
note: associated type `Target` defined here
--> $DIR/issue-87638.rs:6:5
|
LL | type Target;
| ^^^^^^^^^^^^
help: maybe you meant this associated type
|
LL - let _: <S as Trait>::Output;
Expand All @@ -16,12 +18,14 @@ LL + let _: <S as Trait>::Target;
error[E0576]: cannot find method or associated constant `BAR` in trait `Trait`
--> $DIR/issue-87638.rs:20:27
|
LL | const FOO: usize;
| ----------------- associated constant `FOO` defined here
...
LL | let _ = <S as Trait>::BAR;
| ^^^ not found in `Trait`
|
note: associated constant `FOO` defined here
--> $DIR/issue-87638.rs:4:5
|
LL | const FOO: usize;
| ^^^^^^^^^^^^^^^^^
help: maybe you meant this associated constant
|
LL - let _ = <S as Trait>::BAR;
Expand Down
8 changes: 5 additions & 3 deletions tests/ui/associated-types/issue-19883.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
error[E0576]: cannot find associated type `Dst` in trait `From`
--> $DIR/issue-19883.rs:9:30
|
LL | type Output;
| ------------ associated type `Output` defined here
...
LL | <Dst as From<Self>>::Dst
| ^^^ not found in `From`
|
note: associated type `Output` defined here
--> $DIR/issue-19883.rs:2:5
|
LL | type Output;
| ^^^^^^^^^^^^
help: maybe you meant this associated type
|
LL - <Dst as From<Self>>::Dst
Expand Down
7 changes: 5 additions & 2 deletions tests/ui/associated-types/issue-22037.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
error[E0576]: cannot find associated type `X` in trait `A`
--> $DIR/issue-22037.rs:3:33
|
LL | type Output;
| ------------ associated type `Output` defined here
LL | fn a(&self) -> <Self as A>::X;
| ^ not found in `A`
|
note: associated type `Output` defined here
--> $DIR/issue-22037.rs:2:5
|
LL | type Output;
| ^^^^^^^^^^^^
help: maybe you meant this associated type
|
LL - fn a(&self) -> <Self as A>::X;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/align-on-fields-143987.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0425]: cannot find type `usize8` in this scope
--> $DIR/align-on-fields-143987.rs:17:8
|
LL | x: usize8,
| ^^^^^^
| ^^^^^^ not found in this scope
|
help: a builtin type with a similar name exists
|
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/c-variadic/issue-86053-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ error[E0425]: cannot find type `F` in this scope
--> $DIR/issue-86053-1.rs:10:54
|
LL | self , _: ... , self , self , _: ... ) where F : FnOnce ( & 'a & 'b usize ) {
| ^
| ^ not found in this scope
|
note: similarly named trait `Fn` defined here
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
= note: similarly named trait `Fn` defined here
help: a trait with a similar name exists
|
LL | self , _: ... , self , self , _: ... ) where Fn : FnOnce ( & 'a & 'b usize ) {
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/closures/issue-78720.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ error[E0425]: cannot find type `F` in this scope
--> $DIR/issue-78720.rs:14:12
|
LL | _func: F,
| ^
| ^ not found in this scope
|
note: similarly named trait `Fn` defined here
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
= note: similarly named trait `Fn` defined here
help: a trait with a similar name exists
|
LL | _func: Fn,
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/closures/issue-90871.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ error[E0425]: cannot find type `n` in this scope
--> $DIR/issue-90871.rs:4:22
|
LL | type_ascribe!(2, n([u8; || 1]))
| ^
| ^ not found in this scope
|
note: similarly named trait `Fn` defined here
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
= note: similarly named trait `Fn` defined here
help: a trait with a similar name exists
|
LL | type_ascribe!(2, Fn([u8; || 1]))
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ LL | f1: extern "cmse-nonsecure-call" fn<U: Copy>(U, u32, u32, u32) -> u64,
error[E0425]: cannot find type `U` in this scope
--> $DIR/generics.rs:15:50
|
LL | struct Test<T: Copy> {
| - similarly named type parameter `T` defined here
LL | f1: extern "cmse-nonsecure-call" fn<U: Copy>(U, u32, u32, u32) -> u64,
| ^
| ^ not found in this scope
|
note: similarly named type parameter `T` defined here
--> $DIR/generics.rs:14:13
|
LL | struct Test<T: Copy> {
| ^
help: a type parameter with a similar name exists
|
LL - f1: extern "cmse-nonsecure-call" fn<U: Copy>(U, u32, u32, u32) -> u64,
Expand Down
20 changes: 12 additions & 8 deletions tests/ui/compiletest-self-test/ui-testing-optout.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ error[E0425]: cannot find type `B` in this scope
error[E0425]: cannot find type `D` in this scope
--> $DIR/ui-testing-optout.rs:7:10
|
4 | type A = B;
| ----------- similarly named type alias `A` defined here
...
7 | type C = D;
| ^
| ^ not found in this scope
|
note: similarly named type alias `A` defined here
--> $DIR/ui-testing-optout.rs:4:1
|
4 | type A = B;
| ^^^^^^^^^^^
help: a type alias with a similar name exists
|
7 - type C = D;
Expand All @@ -22,12 +24,14 @@ help: a type alias with a similar name exists
error[E0425]: cannot find type `F` in this scope
--> $DIR/ui-testing-optout.rs:92:10
|
4 | type A = B;
| ----------- similarly named type alias `A` defined here
...
92 | type E = F;
| ^
| ^ not found in this scope
|
note: similarly named type alias `A` defined here
--> $DIR/ui-testing-optout.rs:4:1
|
4 | type A = B;
| ^^^^^^^^^^^
help: a type alias with a similar name exists
|
92 - type E = F;
Expand Down
Loading
Loading