]> git.proxmox.com Git - rustc.git/blob - tests/ui/mir/field-projection-mutating-context2.rs
New upstream version 1.69.0+dfsg1
[rustc.git] / tests / ui / mir / field-projection-mutating-context2.rs
1 use std::sync::Mutex;
2
3 static GLOBAL: Mutex<&'static str> = Mutex::new("global str");
4
5 struct Foo<T>(T); // `T` is covariant.
6
7 fn foo<'a>(mut x: Foo<fn(&'a str)>, string: &'a str) {
8 let Foo(ref mut y): Foo<fn(&'static str)> = x;
9 //~^ ERROR lifetime may not live long enough
10 *y = |s| *GLOBAL.lock().unwrap() = s;
11 (x.0)(&string);
12 }
13
14 fn main() {
15 foo(Foo(|_| ()), &String::from("i am shortlived"));
16 println!("{}", GLOBAL.lock().unwrap());
17 }