|
| 1 | +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +// Issue #21633: reject duplicate loop labels in function bodies. |
| 12 | +// This is testing interaction between lifetime-params and labels. |
| 13 | + |
| 14 | +fn main() { |
| 15 | + fn foo<'a>() { //~ NOTE shadowed lifetime `'a` declared here |
| 16 | + 'a: loop { break 'a; } //~ ERROR label name `'a` shadows a lifetime name that is already in scope |
| 17 | + } |
| 18 | + |
| 19 | + struct Struct<'b, 'c> { _f: &'b i8, _g: &'c i8 } |
| 20 | + enum Enum<'d, 'e> { A(&'d i8), B(&'e i8) } |
| 21 | + |
| 22 | + impl<'d, 'e> Struct<'d, 'e> { |
| 23 | + fn meth_okay() { |
| 24 | + 'a: loop { break 'a; } |
| 25 | + 'b: loop { break 'b; } |
| 26 | + 'c: loop { break 'c; } |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + impl <'d, 'e> Enum<'d, 'e> { |
| 31 | + fn meth_okay() { |
| 32 | + 'a: loop { break 'a; } |
| 33 | + 'b: loop { break 'b; } |
| 34 | + 'c: loop { break 'c; } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + impl<'bad, 'c> Struct<'bad, 'c> { //~ NOTE shadowed lifetime `'bad` declared here |
| 39 | + fn meth_bad(&self) { |
| 40 | + 'bad: loop { break 'bad; } |
| 41 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + impl<'b, 'bad> Struct<'b, 'bad> { //~ NOTE shadowed lifetime `'bad` declared here |
| 46 | + fn meth_bad2(&self) { |
| 47 | + 'bad: loop { break 'bad; } |
| 48 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + impl<'b, 'c> Struct<'b, 'c> { |
| 53 | + fn meth_bad3<'bad>(x: &'bad i8) { //~ NOTE shadowed lifetime `'bad` declared here |
| 54 | + 'bad: loop { break 'bad; } |
| 55 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 56 | + } |
| 57 | + |
| 58 | + fn meth_bad4<'a,'bad>(x: &'a i8, y: &'bad i8) { //~ NOTE shadowed lifetime `'bad` declared here |
| 59 | + 'bad: loop { break 'bad; } |
| 60 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + impl <'bad, 'e> Enum<'bad, 'e> { //~ NOTE shadowed lifetime `'bad` declared here |
| 65 | + fn meth_bad(&self) { |
| 66 | + 'bad: loop { break 'bad; } |
| 67 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 68 | + } |
| 69 | + } |
| 70 | + impl <'d, 'bad> Enum<'d, 'bad> { //~ NOTE shadowed lifetime `'bad` declared here |
| 71 | + fn meth_bad2(&self) { |
| 72 | + 'bad: loop { break 'bad; } |
| 73 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 74 | + } |
| 75 | + } |
| 76 | + impl <'d, 'e> Enum<'d, 'e> { |
| 77 | + fn meth_bad3<'bad>(x: &'bad i8) { //~ NOTE shadowed lifetime `'bad` declared here |
| 78 | + 'bad: loop { break 'bad; } |
| 79 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 80 | + } |
| 81 | + |
| 82 | + fn meth_bad4<'a,'bad>(x: &'bad i8) { //~ NOTE shadowed lifetime `'bad` declared here |
| 83 | + 'bad: loop { break 'bad; } |
| 84 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + trait HasDefaultMethod1<'bad> { //~ NOTE shadowed lifetime `'bad` declared here |
| 89 | + fn meth_okay() { |
| 90 | + 'c: loop { break 'c; } |
| 91 | + } |
| 92 | + fn meth_bad(&self) { |
| 93 | + 'bad: loop { break 'bad; } |
| 94 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 95 | + } |
| 96 | + } |
| 97 | + trait HasDefaultMethod2<'a,'bad> { //~ NOTE shadowed lifetime `'bad` declared here |
| 98 | + fn meth_bad(&self) { |
| 99 | + 'bad: loop { break 'bad; } |
| 100 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 101 | + } |
| 102 | + } |
| 103 | + trait HasDefaultMethod3<'a,'b> { |
| 104 | + fn meth_bad<'bad>(&self) { //~ NOTE shadowed lifetime `'bad` declared here |
| 105 | + 'bad: loop { break 'bad; } |
| 106 | + //~^ ERROR label name `'bad` shadows a lifetime name that is already in scope |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments