Closed
Description
The following code incorrectly fails to compile:
use std::thread::spawn;
mod foo {
struct Scope<'a>(&'a u8);
pub fn scope<'a, F, R>(f: F) -> R where F: FnOnce(&Scope<'a>) -> R {
panic!()
}
}
fn main() {
foo::scope(|scope| {
spawn(move || {
foo::scope(|s| {});
});
});
}
with error:
src/lib.rs:13:9: 13:14 error: the type `[closure@src/lib.rs:13:15: 15:10 scope:&foo::Scope<'_>]` does not fulfill the required lifetime [E0477]
src/lib.rs:13 spawn(move || {
^~~~~
note: type must outlive the static lifetime
However, if you change the name scope
in the closure within main
, it works fine:
fn main() {
foo::scope(|s| {
spawn(move || {
foo::scope(|s| {});
});
});
}