]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-54556-used-vs-unused-tails.rs
Auto merge of #103600 - compiler-errors:early-binder-nits, r=spastorino
[rust.git] / src / test / ui / nll / issue-54556-used-vs-unused-tails.rs
1 // This test case is exploring the space of how blocks with tail
2 // expressions and statements can be composed, trying to keep each
3 // case on one line so that we can compare them via a vertical scan
4 // with the human eye.
5
6 // Each comment on the right side of the line is summarizing the
7 // expected suggestion from the diagnostic for issue #54556.
8
9 fn main() {
10     {              let mut _t1 = D(Box::new("t1")); D(&_t1).end()    } ; // suggest `;`
11 //~^ ERROR does not live long enough
12
13     {            { let mut _t1 = D(Box::new("t1")); D(&_t1).end() }  } ; // suggest `;`
14 //~^ ERROR does not live long enough
15
16     {            { let mut _t1 = D(Box::new("t1")); D(&_t1).end() }; }   // suggest `;`
17 //~^ ERROR does not live long enough
18
19     let _ =      { let mut _t1 = D(Box::new("t1")); D(&_t1).end()    } ; // suggest `;`
20 //~^ ERROR does not live long enough
21
22     let _u =     { let mut _t1 = D(Box::new("t1")); D(&_t1).unit()   } ; // suggest `;`
23 //~^ ERROR does not live long enough
24
25     let _x =     { let mut _t1 = D(Box::new("t1")); D(&_t1).end()    } ; // `let x = ...; x`
26 //~^ ERROR does not live long enough
27     let _x =     { let mut _t1 = D(Box::new("t1")); let x = D(&_t1).end(); x } ; // no error
28
29     let mut _y;
30     _y =         { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } ; // `let x = ...; x`
31 //~^ ERROR does not live long enough
32     _y =         { let mut _t1 = D(Box::new("t1")); let x = D(&_t1).end(); x } ; // no error
33 }
34
35 fn f_param_ref(_t1: D<Box<&'static str>>) {         D(&_t1).unit()   }  // no error
36
37 fn f_local_ref() { let mut _t1 = D(Box::new("t1")); D(&_t1).unit()   }  // suggest `;`
38 //~^ ERROR does not live long enough
39
40 fn f() -> String { let mut _t1 = D(Box::new("t1")); D(&_t1).end()   }   // `let x = ...; x`
41 //~^ ERROR does not live long enough
42
43 #[derive(Debug)]
44 struct D<T: std::fmt::Debug>(T);
45
46 impl<T: std::fmt::Debug>  Drop for D<T> {
47     fn drop(&mut self) {
48         println!("dropping {:?})", self);
49     }
50 }
51
52 impl<T: std::fmt::Debug> D<T> {
53     fn next<U: std::fmt::Debug>(&self, _other: U) -> D<U> { D(_other) }
54     fn end(&self) -> String { format!("End({:?})", self.0) }
55     fn unit(&self) { }
56 }