Fixed: Multiple errors on single typo in match pattern#55156
Fixed: Multiple errors on single typo in match pattern#55156bors merged 1 commit intorust-lang:masterfrom
Conversation
efeb079 to
487d580
Compare
estebank
left a comment
There was a problem hiding this comment.
Couple of nitpicks, but lgtm
There was a problem hiding this comment.
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
There was a problem hiding this comment.
which IDE or tools I should use to detect this issues?
There was a problem hiding this comment.
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.
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.
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
E0026andE0027for same case.Example
Here above we can see that both
E0026andE0027are depictingsame thing.
So, to fix this issue, we are simply checking if for last element of
inexistent_fieldsis there any value lies inunmentioned_fieldsusing 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 inE0027we are giving extra hint onE0026r? @estebank