-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language team
Description
play.rust-lang.org http://is.gd/FWYYn9
use std::rc::Rc;
use std::cell::RefCell;
fn foo(a: &mut u32) -> Option<()> {
if *a < 10 { *a += 1; Some(()) } else { None }
}
fn main() {
let a = Rc::new(RefCell::new(4));
while let Some(()) = foo(&mut *a.borrow_mut()) {
// Works:
// while let Some(()) = { let mut b = a.borrow_mut(); foo(&mut *b) } {
println!("{}", *a.borrow());
}
}
The RefMut
seems to outlive the while let
block, instead of just the right expression.
The same happens if you put it in a block, like this:
while let Some(()) = { foo(&mut *a.borrow_mut()) } {
Same problem with if let
.
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language team