-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.fixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.
Description
struct S;
impl S {
fn f<'a:'a>(_x:&'a i32) {}
}
fn main() {
let g1: &Fn(&i32) = &|x| S::f(x);
g1(&1);
let g2 = &|x| S::f(x);
g2(&1);
}
<anon>:9:9: 9:10 error: borrowed value does not live long enough
<anon>:9 g2(&1);
^
<anon>:8:27: 10:2 note: reference must be valid for the block suffix following statement 2 at 8:26...
<anon>: 8 let g2 = &|x| S::f(x);
<anon>: 9 g2(&1);
<anon>:10 }
<anon>:9:5: 9:12 note: ...but borrowed value is only valid for the statement at 9:4
<anon>:9 g2(&1);
^~~~~~~
<anon>:9:5: 9:12 help: consider using a `let` binding to increase its lifetime
<anon>:9 g2(&1);
^~~~~~~
error: aborting due to previous error
Lifetime inference is doing something weird with the second closure.
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.fixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.