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

Spurious incorrect "consider removing this semicolon" help when accessing nonexistent field #67971

Closed
jonas-schievink opened this issue Jan 7, 2020 · 0 comments · Fixed by #71894
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonas-schievink
Copy link
Contributor

struct S {}

fn f(ctx: &mut S) -> String {
    ctx.sleep = 0;
}
error[E0609]: no field `sleep` on type `&mut S`
 --> src/lib.rs:4:9
  |
4 |     ctx.sleep = 0;
  |         ^^^^^ unknown field

error[E0308]: mismatched types
 --> src/lib.rs:3:22
  |
3 | fn f(ctx: &mut S) -> String {
  |    -                 ^^^^^^ expected struct `std::string::String`, found `()`
  |    |
  |    implicitly returns `()` as its body has no tail or `return` expression
4 |     ctx.sleep = 0;
  |                  - help: consider removing this semicolon

Both of these errors are correct, but the second one should not suggest to remove the semicolon, since that won't fix anything here.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Jan 7, 2020
@bors bors closed this as completed in 67a7b7a May 5, 2020
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant