]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/guarantor-issue-46974.rs
Rollup merge of #60685 - dtolnay:spdx, r=nikomatsakis
[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 #![feature(nll)]
5
6 fn foo(s: &mut (i32,)) -> i32 {
7     let t = &mut *s; // this borrow should last for the entire function
8     let x = &t.0;
9     *s = (2,); //~ ERROR cannot assign to `*s`
10     *x
11 }
12
13 fn bar(s: &Box<(i32,)>) -> &'static i32 {
14     // FIXME(#46983): error message should be better
15     &s.0 //~ ERROR explicit lifetime required in the type of `s` [E0621]
16 }
17
18 fn main() {
19     foo(&mut (0,));
20     bar(&Box::new((1,)));
21 }