-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fixed: Multiple errors on single typo in match pattern #55156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
efeb079
to
487d580
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of nitpicks, but lgtm
| ^^^^^ | ||
| | | ||
| variant `MyOption::MySome` does not have this field | ||
| help: did you mean: `0` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unfortunate, but not a regression as we were already providing this suggestion/error. Ideally it should actually suggest MyOption::MySome(42)
... Not a blocker for this PR, but lets open a follow up ticket.
src/librustc_typeck/check/_match.rs
Outdated
Symbol::intern(field.to_string().as_str())) | ||
.collect::<Vec<Symbol>>(); | ||
let suggested_name = find_best_match_for_name(input.iter(), | ||
&ident.name.as_str(), None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which IDE or tools I should use to detect this issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, you can make your changes, run rustfmt
on the file and only take the changes for the code you changed :-/
That workflow is annoying enough that I just memorized the most relevant rules. Basically, if you have multiple lines
like(this,
right,
here);
you want them to be aligned to the (
, which is why there's a preference to
this_other(
indentation,
of,
multiple,
args,
);
as it is independent of function name length.
This comment has been minimized.
This comment has been minimized.
487d580
to
66c4e1f
Compare
This comment has been minimized.
This comment has been minimized.
Here we have fixed the case where we were throwing two diagnostic messages `E0026` and `E0027` for same case like this Example error[E0026]: variant `A::A` does not have a field named `fob` --> src/test/ui/issue-52717.rs:20:12 | 20 | A::A { fob } => { println!("{}", fob); } | ^^^ variant `A::A` does not have this field error[E0027]: pattern does not mention field `foo` --> src/test/ui/issue-52717.rs:20:5 | 20 | A::A { fob } => { println!("{}", fob); } | ^^^^^^^^^^^^ missing field `foo` error: aborting due to 2 previous errors Here above we can see that both `E0026` and `E0027` are depicting same thing. So, to fix this issue, we are simply checking element of `inexistent_fields` is there any value lies in `unmentioned_fields` using Levenshtein algorithm, if does then for that case we are simply deleting element from `unmentioned_fields`. More or less now instead of showing separate message in `E0027` we are giving extra hint on `E0026` Address: rust-lang#52717
66c4e1f
to
978dc3d
Compare
r? @estebank again |
fn main() { | ||
let x = A::A { foo: 3 }; | ||
match x { | ||
A::A { fob } => { println!("{}", fob); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's another case that we're not handling (but it's fine):
A::A { fob } => { println!("{}", foo); }
In the present case after applying the suggestion, the code will complain about the printed fob
, while in the quoted case we'll have two complains, one about fob
and another about the printed foo
.
It'll be interesting coming up with a solution for this as a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working toward that :)
@bors r+ |
📌 Commit 978dc3d has been approved by |
Fixed: Multiple errors on single typo in match pattern Here we have fixed the case where we were throwing two diagnostic messages `E0026` and `E0027` for same case. Example ``` error[E0026]: variant `A::A` does not have a field named `fob` --> src/test/ui/issue-52717.rs:20:12 | 20 | A::A { fob } => { println!("{}", fob); } | ^^^ variant `A::A` does not have this field error[E0027]: pattern does not mention field `foo` --> src/test/ui/issue-52717.rs:20:5 | 20 | A::A { fob } => { println!("{}", fob); } | ^^^^^^^^^^^^ missing field `foo` error: aborting due to 2 previous errors ``` Here above we can see that both `E0026` and `E0027` are depicting same thing. So, to fix this issue, we are simply checking if for last element of `inexistent_fields` is there any value lies in `unmentioned_fields` using levenshtein algorithm, if it does then for that case we are simply deleting element from `unmentioned_fields`. More or less, now instead of showing separate message in `E0027` we are giving extra hint on `E0026` r? @estebank
☀️ Test successful - status-appveyor, status-travis |
Rollup of 5 pull requests Successful merges: - #55156 (Fixed: Multiple errors on single typo in match pattern) - #55189 (update books for the next release) - #55193 (make asm diagnostic instruction optional) - #55203 (Write an initial version of the `program_clauses` callback) - #55213 (ignore target folders) Failed merges: r? @ghost
Here we have fixed the case where we were throwing two diagnostic messages
E0026
andE0027
for same case.Example
Here above we can see that both
E0026
andE0027
are depictingsame thing.
So, to fix this issue, we are simply checking if for last element of
inexistent_fields
is there any value lies inunmentioned_fields
using levenshtein algorithm, if it does then for that case we are simply deleting element fromunmentioned_fields
. More or less, now instead of showing separate message inE0027
we are giving extra hint onE0026
r? @estebank