Skip to content

Commit

Permalink
Suggest fixing typos and let bindings at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
uellenberg committed Nov 2, 2024
1 parent 7c7bb7d commit 42cc20c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 6 additions & 3 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,13 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {

// 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);
if !self.r.add_typo_suggestion(err, suggestion, ident_span) {
fallback = !self.let_binding_suggestion(err, ident_span);
}
self.r.add_typo_suggestion(err, suggestion, ident_span);
}

if self.let_binding_suggestion(err, ident_span) {
fallback = false;
}

fallback
}

Expand Down
11 changes: 10 additions & 1 deletion tests/ui/error-festival.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ error[E0425]: cannot find value `y` in this scope
--> $DIR/error-festival.rs:14:5
|
LL | y = 2;
| ^ help: a local variable with a similar name exists: `x`
| ^
|
help: a local variable with a similar name exists
|
LL | x = 2;
| ~
help: you might have meant to introduce a new binding
|
LL | let y = 2;
| +++

error[E0603]: constant `FOO` is private
--> $DIR/error-festival.rs:22:10
Expand Down

0 comments on commit 42cc20c

Please sign in to comment.