Open pigeonhands opened 1 year ago
Also happens in this thing I encountered yesterday. Same fix as above, use &_
.
fn main() {
let closure = |_v| {};
let a = vec!["".to_string(), "".to_string(), "".to_string()];
for b in a {
closure(&b);
}
}
It seems that closure type inference is causing "borrowed value does not live long enough" errors in places where it shouldent.
However changing the closure definition to
or moving the
a
definition and call into the same scope as theclosure
definition allows it to compile.I assume what is happening is when
closure
is called witha
,closure
is inferred to befn(&'1 i32)
, but thenb
is called so it is trying to callfn(&'1 i32)
with a&'2 i32
. But when it is defined as&_
, the compiler does not infer the lifetime and instead uses hrbt.Meta
rustc --version --verbose
: