]> git.lizzy.rs Git - rust.git/blob - src/test/ui/loops/loops-reject-lifetime-shadowing-label.rs
Auto merge of #87150 - rusticstuff:simplify_wrapping_neg, r=m-ou-se
[rust.git] / src / test / ui / loops / loops-reject-lifetime-shadowing-label.rs
1 // check-pass
2
3 #![allow(dead_code, unused_variables)]
4
5 // Issue #21633:  reject duplicate loop labels in function bodies.
6 //
7 // Test rejection of lifetimes in *expressions* that shadow loop labels.
8
9 fn foo() {
10     // Reusing lifetime `'a` in function item is okay.
11     fn foo<'a>(x: &'a i8) -> i8 { *x }
12
13     // So is reusing `'a` in struct item
14     struct S1<'a> { x: &'a i8 } impl<'a> S1<'a> { fn m(&self) {} }
15     // and a method item
16     struct S2; impl S2 { fn m<'a>(&self) {} }
17
18     let z = 3_i8;
19
20     'a: loop {
21         let b = Box::new(|x: &i8| *x) as Box<dyn for <'a> Fn(&'a i8) -> i8>;
22         //~^ WARN lifetime name `'a` shadows a label name that is already in scope
23         assert_eq!((*b)(&z), z);
24         break 'a;
25     }
26 }
27
28
29 pub fn main() {
30     foo();
31 }