Skip to content

E0499 error shouldn't suggest adding a semicolon when there already is one #133941

@josephcsible

Description

Code

use std::marker::PhantomData;

struct Bar<'a>(PhantomData<&'a mut i32>);

impl<'a> Drop for Bar<'a> {
    fn drop(&mut self) {}
}

struct Foo();

impl Foo {
    fn f(&mut self) -> Option<Bar<'_>> {
        None
    }
    
    fn g(&mut self) {}
}

fn main() {
    let mut foo = Foo();
    while let Some(_) = foo.f() {
        foo.g();
    };
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0499]: cannot borrow `foo` as mutable more than once at a time
  --> src/main.rs:22:9
   |
21 |     while let Some(_) = foo.f() {
   |                         -------
   |                         |
   |                         first mutable borrow occurs here
   |                         a temporary with access to the first borrow is created here ...
22 |         foo.g();
   |         ^^^ second mutable borrow occurs here
23 |     };
   |     - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
   |
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
   |
23 |     };;
   |      +

For more information about this error, try `rustc --explain E0499`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Desired output

Not have the help section since there already is a semicolon

Rationale and extra context

No response

Other cases

Rust Version

Tested on the Rust Playground with both stable 1.83.0 and 1.85.0-nightly 2024-12-04 acabb52 (sorry for the lack of the exact command you wanted, but see rust-lang/rust-playground#1043)

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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