E0499 error shouldn't suggest adding a semicolon when there already is one · Issue #133941 · rust-lang/rust (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
Code
use std:📑: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