]> git.proxmox.com Git - rustc.git/blob - src/test/ui/loops/loops-reject-labels-shadowing-lifetimes.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / test / ui / loops / loops-reject-labels-shadowing-lifetimes.rs
1 // Issue #21633: reject duplicate loop labels in function bodies.
2 // This is testing interaction between lifetime-params and labels.
3
4 // check-pass
5
6 #![allow(dead_code, unused_variables)]
7
8 fn foo() {
9 fn foo<'a>() {
10 'a: loop { break 'a; }
11 //~^ WARN label name `'a` shadows a lifetime name that is already in scope
12 }
13
14 struct Struct<'b, 'c> { _f: &'b i8, _g: &'c i8 }
15 enum Enum<'d, 'e> { A(&'d i8), B(&'e i8) }
16
17 impl<'d, 'e> Struct<'d, 'e> {
18 fn meth_okay() {
19 'a: loop { break 'a; }
20 'b: loop { break 'b; }
21 'c: loop { break 'c; }
22 }
23 }
24
25 impl <'d, 'e> Enum<'d, 'e> {
26 fn meth_okay() {
27 'a: loop { break 'a; }
28 'b: loop { break 'b; }
29 'c: loop { break 'c; }
30 }
31 }
32
33 impl<'bad, 'c> Struct<'bad, 'c> {
34 fn meth_bad(&self) {
35 'bad: loop { break 'bad; }
36 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
37 }
38 }
39
40 impl<'b, 'bad> Struct<'b, 'bad> {
41 fn meth_bad2(&self) {
42 'bad: loop { break 'bad; }
43 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
44 }
45 }
46
47 impl<'b, 'c> Struct<'b, 'c> {
48 fn meth_bad3<'bad>(x: &'bad i8) {
49 'bad: loop { break 'bad; }
50 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
51 }
52
53 fn meth_bad4<'a,'bad>(x: &'a i8, y: &'bad i8) {
54 'bad: loop { break 'bad; }
55 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
56 }
57 }
58
59 impl <'bad, 'e> Enum<'bad, 'e> {
60 fn meth_bad(&self) {
61 'bad: loop { break 'bad; }
62 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
63 }
64 }
65 impl <'d, 'bad> Enum<'d, 'bad> {
66 fn meth_bad2(&self) {
67 'bad: loop { break 'bad; }
68 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
69 }
70 }
71 impl <'d, 'e> Enum<'d, 'e> {
72 fn meth_bad3<'bad>(x: &'bad i8) {
73 'bad: loop { break 'bad; }
74 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
75 }
76
77 fn meth_bad4<'a,'bad>(x: &'bad i8) {
78 'bad: loop { break 'bad; }
79 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
80 }
81 }
82
83 trait HasDefaultMethod1<'bad> {
84 fn meth_okay() {
85 'c: loop { break 'c; }
86 }
87 fn meth_bad(&self) {
88 'bad: loop { break 'bad; }
89 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
90 }
91 }
92 trait HasDefaultMethod2<'a,'bad> {
93 fn meth_bad(&self) {
94 'bad: loop { break 'bad; }
95 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
96 }
97 }
98 trait HasDefaultMethod3<'a,'b> {
99 fn meth_bad<'bad>(&self) {
100 'bad: loop { break 'bad; }
101 //~^ WARN label name `'bad` shadows a lifetime name that is already in scope
102 }
103 }
104 }
105
106
107 pub fn main() {
108 foo();
109 }