]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/guarantor-issue-46974.rs
Auto merge of #105145 - Ayush1325:sequential-remote-server, r=Mark-Simulacrum
[rust.git] / src / test / ui / nll / guarantor-issue-46974.rs
1 // Test that NLL analysis propagates lifetimes correctly through
2 // field accesses, Box accesses, etc.
3
4 fn foo(s: &mut (i32,)) -> i32 {
5     let t = &mut *s; // this borrow should last for the entire function
6     let x = &t.0;
7     *s = (2,); //~ ERROR cannot assign to `*s`
8     *x
9 }
10
11 fn bar(s: &Box<(i32,)>) -> &'static i32 {
12     // FIXME(#46983): error message should be better
13     &s.0 //~ ERROR lifetime may not live long enough
14 }
15
16 fn main() {
17     foo(&mut (0,));
18     bar(&Box::new((1,)));
19 }