Skip to content
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

Multiple errors on single typo in match pattern #52717

Closed
estebank opened this issue Jul 25, 2018 · 3 comments
Closed

Multiple errors on single typo in match pattern #52717

estebank opened this issue Jul 25, 2018 · 3 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@estebank
Copy link
Contributor

With a single typo in a match arm, we generate three separate errors:

error[E0425]: cannot find value `func` in this scope
   --> 
    |
125 |       Target::Match { ref attr, ref fung} => func.apply(&value, &attr.value)?,
    |                                              ^^^^ did you mean `fung`?

error[E0026]: variant `internal::Target::Match` does not have a field named `fung`
   -->
    |
125 |       Target::Match { ref attr, ref fung} => func.apply(&value, &attr.value)?,
    |                                 ^^^^^^^^ variant `internal::Target::Match` does not have this field

error[E0027]: pattern does not mention field `func`
   -->
    |
125 |       Target::Match { ref attr, ref fung} => func.apply(&value, &attr.value)?,
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `func`

We should collect all these errors into a single diagnostic:

error[E0026]: variant `internal::Target::Match` does not have a field named `fung`
   -->
    |
125 |       Target::Match { ref attr, ref fung} => func.apply(&value, &attr.value)?,
    |                                 ^^^^^^^^
    |                                 |
    |                                 variant `internal::Target::Match` does not have this field
    |                                 help: did you mean: `func`
@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Jul 25, 2018
@PramodBisht
Copy link
Contributor

@estebank could you share sample code to exactly reproduce above diagnostic?

@estebank
Copy link
Contributor Author

estebank commented Oct 7, 2018

enum A {
  A {
    foo: usize,
  }
}

fn main() {
  let x = A::A { foo: 3 };
  match x {
    A::A { fob } => { println!("{}", fob); }
  }
}

PramodBisht added a commit to PramodBisht/rust that referenced this issue Oct 19, 2018
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
@PramodBisht
Copy link
Contributor

I will raise another PR to address the case where we are unnecessarily throwing E0425.

@PramodBisht PramodBisht self-assigned this Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

2 participants