about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDaiki Ihara <sasurau4@gmail.com>2020-12-14 21:14:17 +0900
committerDaiki Ihara <sasurau4@gmail.com>2020-12-17 20:22:27 +0900
commite9ca2909ad49b9a15c7da29cc4350dda4aeefb10 (patch)
tree42ae77a5efcb8cc6f6cbc9cd0e0d6d32df12578d /src
parent7b9ee11a4c1d4fde0ecb0e45e0ebf674e5c775a8 (diff)
downloadrust-e9ca2909ad49b9a15c7da29cc4350dda4aeefb10.tar.gz
rust-e9ca2909ad49b9a15c7da29cc4350dda4aeefb10.zip
Add test case for break expr with misspelled value
Update src/test/ui/loops/loop-break-value.rs

Co-authored-by: Ivan Tham <pickfire@riseup.net>
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/label/label_misspelled.rs18
-rw-r--r--src/test/ui/label/label_misspelled.stderr47
-rw-r--r--src/test/ui/loops/loop-break-value.rs6
-rw-r--r--src/test/ui/loops/loop-break-value.stderr24
4 files changed, 93 insertions, 2 deletions
diff --git a/src/test/ui/label/label_misspelled.rs b/src/test/ui/label/label_misspelled.rs
new file mode 100644
index 00000000000..ebfd5642c9f
--- /dev/null
+++ b/src/test/ui/label/label_misspelled.rs
@@ -0,0 +1,18 @@
+fn main() {
+    'LOOP: loop {
+        LOOP;
+        //~^ ERROR cannot find value `LOOP` in this scope
+    };
+    'while_loop: while true { //~ WARN denote infinite loops with
+        while_loop;
+        //~^ ERROR cannot find value `while_loop` in this scope
+    };
+    'while_let: while let Some(_) = Some(()) {
+        while_let;
+        //~^ ERROR cannot find value `while_let` in this scope
+    }
+    'for_loop: for _ in 0..3 {
+        for_loop;
+        //~^ ERROR cannot find value `for_loop` in this scope
+    };
+}
diff --git a/src/test/ui/label/label_misspelled.stderr b/src/test/ui/label/label_misspelled.stderr
new file mode 100644
index 00000000000..1368ca4126c
--- /dev/null
+++ b/src/test/ui/label/label_misspelled.stderr
@@ -0,0 +1,47 @@
+error[E0425]: cannot find value `LOOP` in this scope
+  --> $DIR/label_misspelled.rs:3:9
+   |
+LL |         LOOP;
+   |         ^^^^
+   |         |
+   |         not found in this scope
+   |         help: a label with a similar name exists: `'LOOP`
+
+error[E0425]: cannot find value `while_loop` in this scope
+  --> $DIR/label_misspelled.rs:7:9
+   |
+LL |         while_loop;
+   |         ^^^^^^^^^^
+   |         |
+   |         not found in this scope
+   |         help: a label with a similar name exists: `'while_loop`
+
+error[E0425]: cannot find value `while_let` in this scope
+  --> $DIR/label_misspelled.rs:11:9
+   |
+LL |         while_let;
+   |         ^^^^^^^^^
+   |         |
+   |         not found in this scope
+   |         help: a label with a similar name exists: `'while_let`
+
+error[E0425]: cannot find value `for_loop` in this scope
+  --> $DIR/label_misspelled.rs:15:9
+   |
+LL |         for_loop;
+   |         ^^^^^^^^
+   |         |
+   |         not found in this scope
+   |         help: a label with a similar name exists: `'for_loop`
+
+warning: denote infinite loops with `loop { ... }`
+  --> $DIR/label_misspelled.rs:6:5
+   |
+LL |     'while_loop: while true {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
+   |
+   = note: `#[warn(while_true)]` on by default
+
+error: aborting due to 4 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/loops/loop-break-value.rs b/src/test/ui/loops/loop-break-value.rs
index 6c4160c36aa..8a080cfdf49 100644
--- a/src/test/ui/loops/loop-break-value.rs
+++ b/src/test/ui/loops/loop-break-value.rs
@@ -90,4 +90,10 @@ fn main() {
         break; //~ ERROR mismatched types
         break 4;
     };
+
+    'LOOP: for _ in 0 .. 9 {
+        break LOOP;
+        //~^ ERROR cannot find value `LOOP` in this scope
+        //~| ERROR `break` with value from a `for` loop
+    }
 }
diff --git a/src/test/ui/loops/loop-break-value.stderr b/src/test/ui/loops/loop-break-value.stderr
index 0503d3d4c78..0237435c8b4 100644
--- a/src/test/ui/loops/loop-break-value.stderr
+++ b/src/test/ui/loops/loop-break-value.stderr
@@ -1,3 +1,12 @@
+error[E0425]: cannot find value `LOOP` in this scope
+  --> $DIR/loop-break-value.rs:95:15
+   |
+LL |         break LOOP;
+   |               ^^^^
+   |               |
+   |               not found in this scope
+   |               help: a label with a similar name exists: `'LOOP`
+
 warning: denote infinite loops with `loop { ... }`
   --> $DIR/loop-break-value.rs:26:5
    |
@@ -94,6 +103,17 @@ help: instead, use `break` on its own without a value inside this `for` loop
 LL |             break;
    |             ^^^^^
 
+error[E0571]: `break` with value from a `for` loop
+  --> $DIR/loop-break-value.rs:95:9
+   |
+LL |         break LOOP;
+   |         ^^^^^^^^^^ can only break with a value inside `loop` or breakable block
+   |
+help: instead, use `break` on its own without a value inside this `for` loop
+   |
+LL |         break;
+   |         ^^^^^
+
 error[E0308]: mismatched types
   --> $DIR/loop-break-value.rs:4:31
    |
@@ -151,7 +171,7 @@ LL |         break;
    |         expected integer, found `()`
    |         help: give it a value of the expected type: `break value`
 
-error: aborting due to 16 previous errors; 1 warning emitted
+error: aborting due to 18 previous errors; 1 warning emitted
 
-Some errors have detailed explanations: E0308, E0571.
+Some errors have detailed explanations: E0308, E0425, E0571.
 For more information about an error, try `rustc --explain E0308`.