about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2021-01-20 17:50:21 -0800
committerEsteban Küber <esteban@kuber.com.ar>2021-01-21 21:41:46 -0800
commitc065234b341b285bb9a082d8303131a6a0207f0f (patch)
tree7ac11284bf4c56918a0d531d253813478a79e41d
parent8a13abba1d628ee17e1df93923665e6118221012 (diff)
downloadrust-c065234b341b285bb9a082d8303131a6a0207f0f.tar.gz
rust-c065234b341b285bb9a082d8303131a6a0207f0f.zip
Add more misspelled label tests
-rw-r--r--src/test/ui/label/label_misspelled.rs13
-rw-r--r--src/test/ui/label/label_misspelled.stderr113
-rw-r--r--src/test/ui/label/label_misspelled_2.rs18
-rw-r--r--src/test/ui/label/label_misspelled_2.stderr44
4 files changed, 173 insertions, 15 deletions
diff --git a/src/test/ui/label/label_misspelled.rs b/src/test/ui/label/label_misspelled.rs
index 17c709768d5..33619987fef 100644
--- a/src/test/ui/label/label_misspelled.rs
+++ b/src/test/ui/label/label_misspelled.rs
@@ -1,17 +1,23 @@
+#![warn(unused_labels)]
+
 fn main() {
     'while_loop: while true { //~ WARN denote infinite loops with
+        //~^ WARN unused label
         while_loop;
         //~^ ERROR cannot find value `while_loop` in this scope
     };
     'while_let: while let Some(_) = Some(()) {
+        //~^ WARN unused label
         while_let;
         //~^ ERROR cannot find value `while_let` in this scope
     }
     'for_loop: for _ in 0..3 {
+        //~^ WARN unused label
         for_loop;
         //~^ ERROR cannot find value `for_loop` in this scope
     };
     'LOOP: loop {
+        //~^ WARN unused label
         LOOP;
         //~^ ERROR cannot find value `LOOP` in this scope
     };
@@ -19,18 +25,22 @@ fn main() {
 
 fn foo() {
     'LOOP: loop {
+        //~^ WARN unused label
         break LOOP;
         //~^ ERROR cannot find value `LOOP` in this scope
     };
     'while_loop: while true { //~ WARN denote infinite loops with
+        //~^ WARN unused label
         break while_loop;
         //~^ ERROR cannot find value `while_loop` in this scope
     };
     'while_let: while let Some(_) = Some(()) {
+        //~^ WARN unused label
         break while_let;
         //~^ ERROR cannot find value `while_let` in this scope
     }
     'for_loop: for _ in 0..3 {
+        //~^ WARN unused label
         break for_loop;
         //~^ ERROR cannot find value `for_loop` in this scope
     };
@@ -39,14 +49,17 @@ fn foo() {
 fn bar() {
     let foo = ();
     'while_loop: while true { //~ WARN denote infinite loops with
+        //~^ WARN unused label
         break foo;
         //~^ ERROR `break` with value from a `while` loop
     };
     'while_let: while let Some(_) = Some(()) {
+        //~^ WARN unused label
         break foo;
         //~^ ERROR `break` with value from a `while` loop
     }
     'for_loop: for _ in 0..3 {
+        //~^ WARN unused label
         break foo;
         //~^ ERROR `break` with value from a `for` loop
     };
diff --git a/src/test/ui/label/label_misspelled.stderr b/src/test/ui/label/label_misspelled.stderr
index 3e99b0ff979..817eac8256f 100644
--- a/src/test/ui/label/label_misspelled.stderr
+++ b/src/test/ui/label/label_misspelled.stderr
@@ -1,40 +1,45 @@
 error[E0425]: cannot find value `while_loop` in this scope
-  --> $DIR/label_misspelled.rs:3:9
+  --> $DIR/label_misspelled.rs:6:9
    |
 LL |     'while_loop: while true {
    |     ----------- a label with a similar name exists
+LL |
 LL |         while_loop;
    |         ^^^^^^^^^^ not found in this scope
 
 error[E0425]: cannot find value `while_let` in this scope
-  --> $DIR/label_misspelled.rs:7:9
+  --> $DIR/label_misspelled.rs:11:9
    |
 LL |     'while_let: while let Some(_) = Some(()) {
    |     ---------- a label with a similar name exists
+LL |
 LL |         while_let;
    |         ^^^^^^^^^ not found in this scope
 
 error[E0425]: cannot find value `for_loop` in this scope
-  --> $DIR/label_misspelled.rs:11:9
+  --> $DIR/label_misspelled.rs:16:9
    |
 LL |     'for_loop: for _ in 0..3 {
    |     --------- a label with a similar name exists
+LL |
 LL |         for_loop;
    |         ^^^^^^^^ not found in this scope
 
 error[E0425]: cannot find value `LOOP` in this scope
-  --> $DIR/label_misspelled.rs:15:9
+  --> $DIR/label_misspelled.rs:21:9
    |
 LL |     'LOOP: loop {
    |     ----- a label with a similar name exists
+LL |
 LL |         LOOP;
    |         ^^^^ not found in this scope
 
 error[E0425]: cannot find value `LOOP` in this scope
-  --> $DIR/label_misspelled.rs:22:15
+  --> $DIR/label_misspelled.rs:29:15
    |
 LL |     'LOOP: loop {
    |     ----- a label with a similar name exists
+LL |
 LL |         break LOOP;
    |               ^^^^
    |               |
@@ -42,10 +47,11 @@ LL |         break LOOP;
    |               help: use the similarly named label: `'LOOP`
 
 error[E0425]: cannot find value `while_loop` in this scope
-  --> $DIR/label_misspelled.rs:26:15
+  --> $DIR/label_misspelled.rs:34:15
    |
 LL |     'while_loop: while true {
    |     ----------- a label with a similar name exists
+LL |
 LL |         break while_loop;
    |               ^^^^^^^^^^
    |               |
@@ -53,10 +59,11 @@ LL |         break while_loop;
    |               help: use the similarly named label: `'while_loop`
 
 error[E0425]: cannot find value `while_let` in this scope
-  --> $DIR/label_misspelled.rs:30:15
+  --> $DIR/label_misspelled.rs:39:15
    |
 LL |     'while_let: while let Some(_) = Some(()) {
    |     ---------- a label with a similar name exists
+LL |
 LL |         break while_let;
    |               ^^^^^^^^^
    |               |
@@ -64,41 +71,115 @@ LL |         break while_let;
    |               help: use the similarly named label: `'while_let`
 
 error[E0425]: cannot find value `for_loop` in this scope
-  --> $DIR/label_misspelled.rs:34:15
+  --> $DIR/label_misspelled.rs:44:15
    |
 LL |     'for_loop: for _ in 0..3 {
    |     --------- a label with a similar name exists
+LL |
 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
+   |
+LL |     'while_loop: while true {
+   |     ^^^^^^^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/label_misspelled.rs:1:9
+   |
+LL | #![warn(unused_labels)]
+   |         ^^^^^^^^^^^^^
+
 warning: denote infinite loops with `loop { ... }`
-  --> $DIR/label_misspelled.rs:2:5
+  --> $DIR/label_misspelled.rs:4:5
    |
 LL |     'while_loop: while true {
    |     ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
    |
    = note: `#[warn(while_true)]` on by default
 
+warning: unused label
+  --> $DIR/label_misspelled.rs:9:5
+   |
+LL |     'while_let: while let Some(_) = Some(()) {
+   |     ^^^^^^^^^^
+
+warning: unused label
+  --> $DIR/label_misspelled.rs:14:5
+   |
+LL |     'for_loop: for _ in 0..3 {
+   |     ^^^^^^^^^
+
+warning: unused label
+  --> $DIR/label_misspelled.rs:19:5
+   |
+LL |     'LOOP: loop {
+   |     ^^^^^
+
+warning: unused label
+  --> $DIR/label_misspelled.rs:27:5
+   |
+LL |     'LOOP: loop {
+   |     ^^^^^
+
+warning: unused label
+  --> $DIR/label_misspelled.rs:32:5
+   |
+LL |     'while_loop: while true {
+   |     ^^^^^^^^^^^
+
 warning: denote infinite loops with `loop { ... }`
-  --> $DIR/label_misspelled.rs:25:5
+  --> $DIR/label_misspelled.rs:32:5
    |
 LL |     'while_loop: while true {
    |     ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
 
+warning: unused label
+  --> $DIR/label_misspelled.rs:37:5
+   |
+LL |     'while_let: while let Some(_) = Some(()) {
+   |     ^^^^^^^^^^
+
+warning: unused label
+  --> $DIR/label_misspelled.rs:42:5
+   |
+LL |     'for_loop: for _ in 0..3 {
+   |     ^^^^^^^^^
+
+warning: unused label
+  --> $DIR/label_misspelled.rs:51:5
+   |
+LL |     'while_loop: while true {
+   |     ^^^^^^^^^^^
+
 warning: denote infinite loops with `loop { ... }`
-  --> $DIR/label_misspelled.rs:41:5
+  --> $DIR/label_misspelled.rs:51:5
    |
 LL |     'while_loop: while true {
    |     ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
 
+warning: unused label
+  --> $DIR/label_misspelled.rs:56:5
+   |
+LL |     'while_let: while let Some(_) = Some(()) {
+   |     ^^^^^^^^^^
+
+warning: unused label
+  --> $DIR/label_misspelled.rs:61:5
+   |
+LL |     'for_loop: for _ in 0..3 {
+   |     ^^^^^^^^^
+
 error[E0571]: `break` with value from a `while` loop
-  --> $DIR/label_misspelled.rs:42:9
+  --> $DIR/label_misspelled.rs:53:9
    |
 LL |     'while_loop: while true {
    |     ----------------------- you can't `break` with a value in a `while` loop
+LL |
 LL |         break foo;
    |         ^^^^^^^^^ can only break with a value inside `loop` or breakable block
    |
@@ -112,10 +193,11 @@ LL |         break 'while_loop;
    |               ^^^^^^^^^^^
 
 error[E0571]: `break` with value from a `while` loop
-  --> $DIR/label_misspelled.rs:46:9
+  --> $DIR/label_misspelled.rs:58:9
    |
 LL |     'while_let: while let Some(_) = Some(()) {
    |     ---------------------------------------- you can't `break` with a value in a `while` loop
+LL |
 LL |         break foo;
    |         ^^^^^^^^^ can only break with a value inside `loop` or breakable block
    |
@@ -129,10 +211,11 @@ LL |         break 'while_let;
    |               ^^^^^^^^^^
 
 error[E0571]: `break` with value from a `for` loop
-  --> $DIR/label_misspelled.rs:50:9
+  --> $DIR/label_misspelled.rs:63:9
    |
 LL |     'for_loop: for _ in 0..3 {
    |     ------------------------ you can't `break` with a value in a `for` loop
+LL |
 LL |         break foo;
    |         ^^^^^^^^^ can only break with a value inside `loop` or breakable block
    |
@@ -145,7 +228,7 @@ help: alternatively, you might have meant to use the available loop label
 LL |         break 'for_loop;
    |               ^^^^^^^^^
 
-error: aborting due to 11 previous errors; 3 warnings emitted
+error: aborting due to 11 previous errors; 14 warnings emitted
 
 Some errors have detailed explanations: E0425, E0571.
 For more information about an error, try `rustc --explain E0425`.
diff --git a/src/test/ui/label/label_misspelled_2.rs b/src/test/ui/label/label_misspelled_2.rs
new file mode 100644
index 00000000000..7fa101dbdf8
--- /dev/null
+++ b/src/test/ui/label/label_misspelled_2.rs
@@ -0,0 +1,18 @@
+#![warn(unused_labels)]
+
+fn main() {
+    'a: for _ in 0..1 {
+        break 'a;
+    }
+    'b: for _ in 0..1 {
+        //~^ WARN unused label
+        break b; //~ ERROR cannot find value `b` in this scope
+    }
+    c: for _ in 0..1 { //~ ERROR expected identifier, found keyword `for`
+        //~^ ERROR expected `<`, found reserved identifier `_`
+        break 'c;
+    }
+    d: for _ in 0..1 {
+        break ;
+    }
+}
diff --git a/src/test/ui/label/label_misspelled_2.stderr b/src/test/ui/label/label_misspelled_2.stderr
new file mode 100644
index 00000000000..b56896a77ed
--- /dev/null
+++ b/src/test/ui/label/label_misspelled_2.stderr
@@ -0,0 +1,44 @@
+error: expected identifier, found keyword `for`
+  --> $DIR/label_misspelled_2.rs:11:8
+   |
+LL |     c: for _ in 0..1 {
+   |        ^^^ expected identifier, found keyword
+
+error: expected `<`, found reserved identifier `_`
+  --> $DIR/label_misspelled_2.rs:11:12
+   |
+LL |     c: for _ in 0..1 {
+   |      -     ^ expected `<`
+   |      |
+   |      tried to parse a type due to this type ascription
+   |
+   = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
+   = note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information
+
+error[E0425]: cannot find value `b` in this scope
+  --> $DIR/label_misspelled_2.rs:9:15
+   |
+LL |     'b: for _ in 0..1 {
+   |     -- a label with a similar name exists
+LL |
+LL |         break b;
+   |               ^
+   |               |
+   |               not found in this scope
+   |               help: use the similarly named label: `'b`
+
+warning: unused label
+  --> $DIR/label_misspelled_2.rs:7:5
+   |
+LL |     'b: for _ in 0..1 {
+   |     ^^
+   |
+note: the lint level is defined here
+  --> $DIR/label_misspelled_2.rs:1:9
+   |
+LL | #![warn(unused_labels)]
+   |         ^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0425`.