fn main() {
let s1 = String::from("11");
let sr = &s1;
// F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> T,
let _x = std::thread::scope(|s| {
// pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
// where
// F: FnOnce() -> T + Send + 'scope,
// T: Send + 'scope,
let xx = s.spawn(|| sr);
// ScopedJoinHandle<'scope, &String>
xx
});
}
was refused by
error: lifetime may not live long enough
--> src/main.rs:13:9
|
7 | let _x = std::thread::scope(|s| {
| -- return type of closure is ScopedJoinHandle<'2, &String>
| |
| has type `&'1 Scope<'1, '_>`
...
13 | xx
| ^^ returning this value requires that `'1` must outlive `'2`
but xx is ScopedJoinHandle<'scope, &String>, and it should be true that 'scope : 'scope