]> git.proxmox.com Git - rustc.git/blob - src/test/ui/loops/loops-reject-lifetime-shadowing-label.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / test / ui / loops / loops-reject-lifetime-shadowing-label.rs
1 // check-pass
2 #![feature(label_break_value)]
3 #![allow(dead_code, unused_variables)]
4
5 // Issue #21633: reject duplicate loop labels and block labels in function bodies.
6 //
7 // Test rejection of lifetimes in *expressions* that shadow 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 'b: {
28 let b = Box::new(|x: &()| ()) as Box<dyn for <'b> Fn(&'b ())>;
29 //~^ WARN lifetime name `'b` shadows a label name that is already in scope
30 break 'b;
31 }
32 }
33
34 pub fn main() {
35 foo();
36 }