-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in while let
and if let
?
#30832
Comments
- Bumped to 0.19.0 - Added temporary fix for rust-lang/rust#30832
/cc @rust-lang/lang |
I blame match desugaring, as always ;) |
This is not a 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));
loop {
match foo(&mut *a.borrow_mut()) {
// works:
// match { let mut b = a.borrow_mut(); foo(&mut *b) } {
Some(()) => { println!("{}", *a.borrow()); }
None => break,
}
};
} I think this is an rvalue-lifetimes issue. (Furthermore, I think this is expected behavior, but @nikomatsakis is more expert on these matters than I...) |
On Tue, Jan 12, 2016 at 08:28:28AM -0800, Felix S Klock II wrote:
Another way to make the error go away is to change to |
@nikomatsakis Thanks for the tip! |
We got to have some centralized place to track all annoyances with temporary destruction order rather than leaving them laying around in issues. |
triage: still an issue, even with NLL |
I'm going to close in favor of #15023 which is maybe not a great issue for this but seems to fit the bill of "temporary lifetimes are sometimes not quite what one would want". |
play.rust-lang.org http://is.gd/FWYYn9
The
RefMut
seems to outlive thewhile 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
.The text was updated successfully, but these errors were encountered: