Skip to content

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

Closed
@jonas-schievink

Description

@jonas-schievink
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions