Closed
Description
I've ran into a borrowing issue using try_borrow() in an if let statement.
The problem occurs when it's the last expression of the scope and is resolved by making it a statement.
I'm not sure if this is a bug or limitation in the borrow checker, but either way the error message is confusing.
fn does_not_compile() {
let container = RefCell::new(0);
if let Ok(_) = container.try_borrow() { }
}
fn compiles() {
let container = RefCell::new(0);
if let Ok(_) = container.try_borrow() { };
}
rustc 1.16.0 (30cf806 2017-03-10)
error:container
does not live long enough
--> :6:1
|
5 | if let Ok(_) = container.try_borrow() { }
| --------- borrow occurs here
6 | }
| ^container
dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are createderror: aborting due to previous error
Metadata
Metadata
Assignees
Labels
No labels