-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Region inference fails for closure parameter #17004
Comments
I'm not sure if this is still relevant with the closure changes or not. @nikomatsakis ? |
I updated the code to Rust 1.0 as well as i could. Seems to produce the same errors. (playpen link) enum Chain<'a:'b, 'b> {
Base(&'a i32),
Rec(&'a i32, &'b Chain<'a,'b>)
}
fn call_with_rec<'a, 'b, F>(c: Chain<'a, 'b>,
x: &'a i32,
f: F) where F: for<'c> Fn(Chain<'a, 'c>) {
f(Chain::Rec(x, &c))
}
fn main() {
let x = 0;
let y = 0;
call_with_rec(Chain::Base(&x), &y, |mut inner| {
loop {
match inner {
Chain::Base(&x) => {
println!("Base({})", x);
break;
},
Chain::Rec(&x, &p) => {
println!("Rec({})", x);
inner = p;
}
}
}
});
} |
The updated version now fails with 'cannot move out of borrowed content', which feels right. @bkoropoff if you're still seeing this in some form, please let me know, but closing until then. |
hmm. At this bug was originally filed, didn't we infer |
having said that, this attempt to update the code in the aforementioned manner also does not seem to replicate the bug anymore. Huzzah? use self::Chain::{Base, Rec};
#[derive(Copy, Clone)]
enum Chain<'a:'b, 'b> {
Base(&'a i32),
Rec(&'a i32, &'b Chain<'a,'b>)
}
fn call_with_rec<'a, 'b, F: for <'c> Fn(Chain<'a, 'c>)>(c: Chain<'a, 'b>,
x: &'a i32,
f: F) {
f(Rec(x, &c))
}
fn helper<'a, 'b>(mut inner: Chain<'a, 'b>) {
loop {
match inner {
Base(&x) => {
println!("Base({})", x);
break;
},
Rec(&x, &p) => {
println!("Rec({})", x);
inner = p;
}
}
}
}
fn main() {
let x = 0i32;
let y = 0i32;
call_with_rec(Base(&x), &y, helper);
call_with_rec(Base(&x), &y, |mut inner| {
loop {
match inner {
Base(&x) => {
println!("Base({})", x);
break;
},
Rec(&x, &p) => {
println!("Rec({})", x);
inner = p;
}
}
}
})
} |
Try caching macro calls more aggressively in Semantics
Test
Output
Workaround
The program compiles successfully if the closure is converted into a named function.
cc @nikomatsakis
I'm not sure if inference is intended to work in this scenario. It's not particularly serious since there's an easy workaround.
The text was updated successfully, but these errors were encountered: