Stop warning against unrelated labels.

This commit is contained in:
Camille GILLOT 2022-05-01 13:07:57 +02:00
parent 84e19930e3
commit be40b58895
14 changed files with 42 additions and 428 deletions

View File

@ -3151,7 +3151,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
diagnostics::signal_label_shadowing(self.r.session, orig_ident, label.ident)
}
if rib.kind.is_label_barrier() {
rib.bindings.insert(ident, id);
break;
}
}

View File

@ -52,7 +52,6 @@ pub fn main() {
let k: isize = {
'x: for _ in 0..1 {
//~^ WARNING shadows a label name that is already in scope
// ditto
loop_x!(break 'x);
i += 1;
@ -63,7 +62,6 @@ pub fn main() {
let l: isize = {
'x: for _ in 0..1 {
//~^ WARNING shadows a label name that is already in scope
// ditto
while_true!(break 'x);
i += 1;
@ -74,7 +72,6 @@ pub fn main() {
let n: isize = {
'x: for _ in 0..1 {
//~^ WARNING shadows a label name that is already in scope
// ditto
run_once!(continue 'x);
i += 1;

View File

@ -1,29 +0,0 @@
warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:54:9
|
LL | 'x: loop {
| -- first declared here
...
LL | 'x: for _ in 0..1 {
| ^^ label `'x` already in scope
warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:65:9
|
LL | 'x: loop {
| -- first declared here
...
LL | 'x: for _ in 0..1 {
| ^^ label `'x` already in scope
warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:76:9
|
LL | 'x: loop {
| -- first declared here
...
LL | 'x: for _ in 0..1 {
| ^^ label `'x` already in scope
warning: 3 warnings emitted

View File

@ -42,23 +42,17 @@ pub fn main() {
}
'x: loop {
//~^ WARNING shadows a label name that is already in scope
// ditto
loop_x!(break 'x);
panic!("break doesn't act hygienically inside infinite loop");
}
'x: while 1 + 1 == 2 {
//~^ WARNING shadows a label name that is already in scope
while_x!(break 'x);
panic!("break doesn't act hygienically inside infinite while loop");
}
'x: for _ in 0..1 {
//~^ WARNING shadows a label name that is already in scope
// ditto
run_once!(continue 'x);
panic!("continue doesn't act hygienically inside for loop");

View File

@ -1,29 +0,0 @@
warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels.rs:44:5
|
LL | 'x: for _ in 0..1 {
| -- first declared here
...
LL | 'x: loop {
| ^^ label `'x` already in scope
warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels.rs:52:5
|
LL | 'x: for _ in 0..1 {
| -- first declared here
...
LL | 'x: while 1 + 1 == 2 {
| ^^ label `'x` already in scope
warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels.rs:59:5
|
LL | 'x: for _ in 0..1 {
| -- first declared here
...
LL | 'x: for _ in 0..1 {
| ^^ label `'x` already in scope
warning: 3 warnings emitted

View File

@ -2,10 +2,7 @@ error[E0425]: cannot find value `while_loop` in this scope
--> $DIR/label_misspelled.rs:6:9
|
LL | 'while_loop: while true {
| -----------
| |
| a label with a similar name exists
| a label with a similar name exists
| ----------- a label with a similar name exists
LL |
LL | while_loop;
| ^^^^^^^^^^ not found in this scope
@ -14,10 +11,7 @@ error[E0425]: cannot find value `while_let` in this scope
--> $DIR/label_misspelled.rs:11:9
|
LL | 'while_let: while let Some(_) = Some(()) {
| ----------
| |
| a label with a similar name exists
| a label with a similar name exists
| ---------- a label with a similar name exists
LL |
LL | while_let;
| ^^^^^^^^^ not found in this scope
@ -26,10 +20,7 @@ error[E0425]: cannot find value `for_loop` in this scope
--> $DIR/label_misspelled.rs:16:9
|
LL | 'for_loop: for _ in 0..3 {
| ---------
| |
| a label with a similar name exists
| a label with a similar name exists
| --------- a label with a similar name exists
LL |
LL | for_loop;
| ^^^^^^^^ not found in this scope
@ -38,10 +29,7 @@ error[E0425]: cannot find value `LOOP` in this scope
--> $DIR/label_misspelled.rs:21:9
|
LL | 'LOOP: loop {
| -----
| |
| a label with a similar name exists
| a label with a similar name exists
| ----- a label with a similar name exists
LL |
LL | LOOP;
| ^^^^ not found in this scope
@ -50,81 +38,45 @@ error[E0425]: cannot find value `LOOP` in this scope
--> $DIR/label_misspelled.rs:28:15
|
LL | 'LOOP: loop {
| -----
| |
| a label with a similar name exists
| a label with a similar name exists
| ----- a label with a similar name exists
LL | break LOOP;
| ^^^^ not found in this scope
|
help: use the similarly named label
|
LL | break 'LOOP;
| ~~~~~
help: use the similarly named label
|
LL | break 'LOOP;
| ~~~~~
| ^^^^
| |
| not found in this scope
| help: use the similarly named label: `'LOOP`
error[E0425]: cannot find value `while_loop` in this scope
--> $DIR/label_misspelled.rs:32:15
|
LL | 'while_loop: while true {
| -----------
| |
| a label with a similar name exists
| a label with a similar name exists
| ----------- a label with a similar name exists
LL | break while_loop;
| ^^^^^^^^^^ not found in this scope
|
help: use the similarly named label
|
LL | break 'while_loop;
| ~~~~~~~~~~~
help: use the similarly named label
|
LL | break 'while_loop;
| ~~~~~~~~~~~
| ^^^^^^^^^^
| |
| not found in this scope
| help: use the similarly named label: `'while_loop`
error[E0425]: cannot find value `while_let` in this scope
--> $DIR/label_misspelled.rs:36:15
|
LL | 'while_let: while let Some(_) = Some(()) {
| ----------
| |
| a label with a similar name exists
| a label with a similar name exists
| ---------- a label with a similar name exists
LL | break while_let;
| ^^^^^^^^^ not found in this scope
|
help: use the similarly named label
|
LL | break 'while_let;
| ~~~~~~~~~~
help: use the similarly named label
|
LL | break 'while_let;
| ~~~~~~~~~~
| ^^^^^^^^^
| |
| not found in this scope
| help: use the similarly named label: `'while_let`
error[E0425]: cannot find value `for_loop` in this scope
--> $DIR/label_misspelled.rs:40:15
|
LL | 'for_loop: for _ in 0..3 {
| ---------
| |
| a label with a similar name exists
| a label with a similar name exists
| --------- a label with a similar name exists
LL | break for_loop;
| ^^^^^^^^ not found in this scope
|
help: use the similarly named label
|
LL | break 'for_loop;
| ~~~~~~~~~
help: use the similarly named label
|
LL | break 'for_loop;
| ~~~~~~~~~
| ^^^^^^^^
| |
| not found in this scope
| help: use the similarly named label: `'for_loop`
warning: unused label
--> $DIR/label_misspelled.rs:4:5

View File

@ -14,41 +14,23 @@ error[E0425]: cannot find value `b` in this scope
--> $DIR/label_misspelled_2.rs:8:15
|
LL | 'b: for _ in 0..1 {
| --
| |
| a label with a similar name exists
| a label with a similar name exists
| -- a label with a similar name exists
LL | break b;
| ^ not found in this scope
|
help: use the similarly named label
|
LL | break 'b;
| ~~
help: use the similarly named label
|
LL | break 'b;
| ~~
| ^
| |
| not found in this scope
| help: use the similarly named label: `'b`
error[E0425]: cannot find value `d` in this scope
--> $DIR/label_misspelled_2.rs:14:15
|
LL | d: for _ in 0..1 {
| -
| |
| a label with a similar name exists
| a label with a similar name exists
| - a label with a similar name exists
LL | break d;
| ^ not found in this scope
|
help: use the similarly named label
|
LL | break 'd;
| ~~
help: use the similarly named label
|
LL | break 'd;
| ~~
| ^
| |
| not found in this scope
| help: use the similarly named label: `'d`
error: aborting due to 4 previous errors

View File

@ -61,7 +61,6 @@ fn main() {
//~^ WARN unused label
'many_used_shadowed: for _ in 0..10 {
//~^ WARN label name `'many_used_shadowed` shadows a label name that is already in scope
//~| WARN label name `'many_used_shadowed` shadows a label name that is already in scope
if 1 % 2 == 0 {
break 'many_used_shadowed;
} else {

View File

@ -7,15 +7,6 @@ LL |
LL | 'many_used_shadowed: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^ label `'many_used_shadowed` already in scope
warning: label name `'many_used_shadowed` shadows a label name that is already in scope
--> $DIR/unused_labels.rs:62:9
|
LL | 'many_used_shadowed: for _ in 0..10 {
| ------------------- first declared here
LL |
LL | 'many_used_shadowed: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^ label `'many_used_shadowed` already in scope
warning: unused label
--> $DIR/unused_labels.rs:11:5
|
@ -59,16 +50,16 @@ LL | 'many_used_shadowed: for _ in 0..10 {
| ^^^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_labels.rs:73:5
--> $DIR/unused_labels.rs:72:5
|
LL | 'unused_loop_label: loop {
| ^^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_labels.rs:79:5
--> $DIR/unused_labels.rs:78:5
|
LL | 'unused_block_label: {
| ^^^^^^^^^^^^^^^^^^^
warning: 10 warnings emitted
warning: 9 warnings emitted

View File

@ -2,21 +2,12 @@ error[E0425]: cannot find value `LOOP` in this scope
--> $DIR/loop-break-value.rs:95:15
|
LL | 'LOOP: for _ in 0 .. 9 {
| -----
| |
| a label with a similar name exists
| a label with a similar name exists
| ----- a label with a similar name exists
LL | break LOOP;
| ^^^^ not found in this scope
|
help: use the similarly named label
|
LL | break 'LOOP;
| ~~~~~
help: use the similarly named label
|
LL | break 'LOOP;
| ~~~~~
| ^^^^
| |
| not found in this scope
| help: use the similarly named label: `'LOOP`
warning: denote infinite loops with `loop { ... }`
--> $DIR/loop-break-value.rs:26:5

View File

@ -1,36 +0,0 @@
// check-pass
#![feature(label_break_value)]
// Issue #21633: reject duplicate loop labels and block labels in function bodies.
//
// This is testing the generalization (to the whole function body)
// discussed here:
// https://internals.rust-lang.org/t/psa-rejecting-duplicate-loop-labels/1833
#[allow(unused_labels)]
pub fn foo() {
{ 'fl: for _ in 0..10 { break; } }
{ 'fl: loop { break; } } //~ WARN label name `'fl` shadows a label name that is already in scope
{ 'lf: loop { break; } }
{ 'lf: for _ in 0..10 { break; } } //~ WARN label name `'lf` shadows a label name that is already in scope
{ 'wl: while 2 > 1 { break; } }
{ 'wl: loop { break; } } //~ WARN label name `'wl` shadows a label name that is already in scope
{ 'lw: loop { break; } }
{ 'lw: while 2 > 1 { break; } } //~ WARN label name `'lw` shadows a label name that is already in scope
{ 'fw: for _ in 0..10 { break; } }
{ 'fw: while 2 > 1 { break; } } //~ WARN label name `'fw` shadows a label name that is already in scope
{ 'wf: while 2 > 1 { break; } }
{ 'wf: for _ in 0..10 { break; } } //~ WARN label name `'wf` shadows a label name that is already in scope
{ 'tl: while let Some(_) = None::<i32> { break; } }
{ 'tl: loop { break; } } //~ WARN label name `'tl` shadows a label name that is already in scope
{ 'lt: loop { break; } }
{ 'lt: while let Some(_) = None::<i32> { break; } }
//~^ WARN label name `'lt` shadows a label name that is already in scope
{ 'bl: {} }
{ 'bl: {} } //~ WARN label name `'bl` shadows a label name that is already in scope
}
pub fn main() {
foo();
}

View File

@ -1,74 +0,0 @@
warning: label name `'fl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:13:7
|
LL | { 'fl: for _ in 0..10 { break; } }
| --- first declared here
LL | { 'fl: loop { break; } }
| ^^^ label `'fl` already in scope
warning: label name `'lf` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:15:7
|
LL | { 'lf: loop { break; } }
| --- first declared here
LL | { 'lf: for _ in 0..10 { break; } }
| ^^^ label `'lf` already in scope
warning: label name `'wl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:17:7
|
LL | { 'wl: while 2 > 1 { break; } }
| --- first declared here
LL | { 'wl: loop { break; } }
| ^^^ label `'wl` already in scope
warning: label name `'lw` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:19:7
|
LL | { 'lw: loop { break; } }
| --- first declared here
LL | { 'lw: while 2 > 1 { break; } }
| ^^^ label `'lw` already in scope
warning: label name `'fw` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:21:7
|
LL | { 'fw: for _ in 0..10 { break; } }
| --- first declared here
LL | { 'fw: while 2 > 1 { break; } }
| ^^^ label `'fw` already in scope
warning: label name `'wf` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:23:7
|
LL | { 'wf: while 2 > 1 { break; } }
| --- first declared here
LL | { 'wf: for _ in 0..10 { break; } }
| ^^^ label `'wf` already in scope
warning: label name `'tl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:25:7
|
LL | { 'tl: while let Some(_) = None::<i32> { break; } }
| --- first declared here
LL | { 'tl: loop { break; } }
| ^^^ label `'tl` already in scope
warning: label name `'lt` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:27:7
|
LL | { 'lt: loop { break; } }
| --- first declared here
LL | { 'lt: while let Some(_) = None::<i32> { break; } }
| ^^^ label `'lt` already in scope
warning: label name `'bl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:30:7
|
LL | { 'bl: {} }
| --- first declared here
LL | { 'bl: {} }
| ^^^ label `'bl` already in scope
warning: 9 warnings emitted

View File

@ -1,49 +0,0 @@
// check-pass
#![feature(label_break_value)]
// Issue #21633: reject duplicate loop labels and block labels in function bodies.
#[allow(unused_labels)]
fn foo() {
'fl: for _ in 0..10 { break; }
'fl: loop { break; } //~ WARN label name `'fl` shadows a label name that is already in scope
'lf: loop { break; }
'lf: for _ in 0..10 { break; } //~ WARN label name `'lf` shadows a label name that is already in scope
'wl: while 2 > 1 { break; }
'wl: loop { break; } //~ WARN label name `'wl` shadows a label name that is already in scope
'lw: loop { break; }
'lw: while 2 > 1 { break; } //~ WARN label name `'lw` shadows a label name that is already in scope
'fw: for _ in 0..10 { break; }
'fw: while 2 > 1 { break; } //~ WARN label name `'fw` shadows a label name that is already in scope
'wf: while 2 > 1 { break; }
'wf: for _ in 0..10 { break; } //~ WARN label name `'wf` shadows a label name that is already in scope
'tl: while let Some(_) = None::<i32> { break; }
'tl: loop { break; } //~ WARN label name `'tl` shadows a label name that is already in scope
'lt: loop { break; }
'lt: while let Some(_) = None::<i32> { break; }
//~^ WARN label name `'lt` shadows a label name that is already in scope
'bl: {}
'bl: {} //~ WARN label name `'bl` shadows a label name that is already in scope
}
// Note however that it is okay for the same label to be reused in
// different methods of one impl, as illustrated here.
struct S;
impl S {
fn m1(&self) { 'okay: loop { break 'okay; } }
fn m2(&self) { 'okay: loop { break 'okay; } }
fn m3(&self) { 'okay: { break 'okay; } }
fn m4(&self) { 'okay: { break 'okay; } }
}
pub fn main() {
let s = S;
s.m1();
s.m2();
s.m3();
s.m4();
foo();
}

View File

@ -1,74 +0,0 @@
warning: label name `'fl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:9:5
|
LL | 'fl: for _ in 0..10 { break; }
| --- first declared here
LL | 'fl: loop { break; }
| ^^^ label `'fl` already in scope
warning: label name `'lf` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:12:5
|
LL | 'lf: loop { break; }
| --- first declared here
LL | 'lf: for _ in 0..10 { break; }
| ^^^ label `'lf` already in scope
warning: label name `'wl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:14:5
|
LL | 'wl: while 2 > 1 { break; }
| --- first declared here
LL | 'wl: loop { break; }
| ^^^ label `'wl` already in scope
warning: label name `'lw` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:16:5
|
LL | 'lw: loop { break; }
| --- first declared here
LL | 'lw: while 2 > 1 { break; }
| ^^^ label `'lw` already in scope
warning: label name `'fw` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:18:5
|
LL | 'fw: for _ in 0..10 { break; }
| --- first declared here
LL | 'fw: while 2 > 1 { break; }
| ^^^ label `'fw` already in scope
warning: label name `'wf` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:20:5
|
LL | 'wf: while 2 > 1 { break; }
| --- first declared here
LL | 'wf: for _ in 0..10 { break; }
| ^^^ label `'wf` already in scope
warning: label name `'tl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:22:5
|
LL | 'tl: while let Some(_) = None::<i32> { break; }
| --- first declared here
LL | 'tl: loop { break; }
| ^^^ label `'tl` already in scope
warning: label name `'lt` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:24:5
|
LL | 'lt: loop { break; }
| --- first declared here
LL | 'lt: while let Some(_) = None::<i32> { break; }
| ^^^ label `'lt` already in scope
warning: label name `'bl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:27:5
|
LL | 'bl: {}
| --- first declared here
LL | 'bl: {}
| ^^^ label `'bl` already in scope
warning: 9 warnings emitted