Closed as not planned
Description
The borrow checker thinks that in the following code the variable v
lives at least as long as *opt = None;
which is certainly not correct and is also fixed when swapping the two conditions on lines 2 and 3 . To test, here's a link to the rust playground.
I tried this code:
fn f<'a>(opt : &'a mut Option<i32>, b : bool) -> Result<&'a mut Option<i32>, &'a mut i32> {
if let Some(v) = opt {
if b {
return Err(v);
}
}
*opt = None;
return Ok(opt)
}
I expected to see this happen: no compile error
Instead, this happened: compile error E0506
Meta
Bug also exists in beta and nightly
rustc --version --verbose
:
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7