summaryrefslogtreecommitdiffstats
path: root/tests/ui/label
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/label
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/label')
-rw-r--r--tests/ui/label/label-beginning-with-underscore.rs10
-rw-r--r--tests/ui/label/label-static.rs5
-rw-r--r--tests/ui/label/label-static.stderr14
-rw-r--r--tests/ui/label/label-underscore.rs5
-rw-r--r--tests/ui/label/label-underscore.stderr14
-rw-r--r--tests/ui/label/label_break_value_continue.rs26
-rw-r--r--tests/ui/label/label_break_value_continue.stderr25
-rw-r--r--tests/ui/label/label_break_value_desugared_break.rs19
-rw-r--r--tests/ui/label/label_break_value_illegal_uses.fixed29
-rw-r--r--tests/ui/label/label_break_value_illegal_uses.rs29
-rw-r--r--tests/ui/label/label_break_value_illegal_uses.stderr26
-rw-r--r--tests/ui/label/label_break_value_unlabeled_break.rs19
-rw-r--r--tests/ui/label/label_break_value_unlabeled_break.stderr15
-rw-r--r--tests/ui/label/label_misspelled.rs62
-rw-r--r--tests/ui/label/label_misspelled.stderr206
-rw-r--r--tests/ui/label/label_misspelled_2.rs16
-rw-r--r--tests/ui/label/label_misspelled_2.stderr37
17 files changed, 557 insertions, 0 deletions
diff --git a/tests/ui/label/label-beginning-with-underscore.rs b/tests/ui/label/label-beginning-with-underscore.rs
new file mode 100644
index 000000000..4b620864a
--- /dev/null
+++ b/tests/ui/label/label-beginning-with-underscore.rs
@@ -0,0 +1,10 @@
+// check-pass
+
+#![deny(unused_labels)]
+
+fn main() {
+ // `unused_label` shouldn't warn labels beginning with `_`
+ '_unused: loop {
+ break;
+ }
+}
diff --git a/tests/ui/label/label-static.rs b/tests/ui/label/label-static.rs
new file mode 100644
index 000000000..95e764d01
--- /dev/null
+++ b/tests/ui/label/label-static.rs
@@ -0,0 +1,5 @@
+fn main() {
+ 'static: loop { //~ ERROR invalid label name `'static`
+ break 'static //~ ERROR invalid label name `'static`
+ }
+}
diff --git a/tests/ui/label/label-static.stderr b/tests/ui/label/label-static.stderr
new file mode 100644
index 000000000..1d3251d1b
--- /dev/null
+++ b/tests/ui/label/label-static.stderr
@@ -0,0 +1,14 @@
+error: invalid label name `'static`
+ --> $DIR/label-static.rs:2:5
+ |
+LL | 'static: loop {
+ | ^^^^^^^
+
+error: invalid label name `'static`
+ --> $DIR/label-static.rs:3:15
+ |
+LL | break 'static
+ | ^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/label/label-underscore.rs b/tests/ui/label/label-underscore.rs
new file mode 100644
index 000000000..de67f3d2c
--- /dev/null
+++ b/tests/ui/label/label-underscore.rs
@@ -0,0 +1,5 @@
+fn main() {
+ '_: loop { //~ ERROR invalid label name `'_`
+ break '_ //~ ERROR invalid label name `'_`
+ }
+}
diff --git a/tests/ui/label/label-underscore.stderr b/tests/ui/label/label-underscore.stderr
new file mode 100644
index 000000000..4558ec4cb
--- /dev/null
+++ b/tests/ui/label/label-underscore.stderr
@@ -0,0 +1,14 @@
+error: invalid label name `'_`
+ --> $DIR/label-underscore.rs:2:5
+ |
+LL | '_: loop {
+ | ^^
+
+error: invalid label name `'_`
+ --> $DIR/label-underscore.rs:3:15
+ |
+LL | break '_
+ | ^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/label/label_break_value_continue.rs b/tests/ui/label/label_break_value_continue.rs
new file mode 100644
index 000000000..22172f4fd
--- /dev/null
+++ b/tests/ui/label/label_break_value_continue.rs
@@ -0,0 +1,26 @@
+#![allow(unused_labels)]
+
+// Simple continue pointing to an unlabeled break should yield in an error
+fn continue_simple() {
+ 'b: {
+ continue; //~ ERROR unlabeled `continue` inside of a labeled block
+ }
+}
+
+// Labeled continue pointing to an unlabeled break should yield in an error
+fn continue_labeled() {
+ 'b: {
+ continue 'b; //~ ERROR `continue` pointing to a labeled block
+ }
+}
+
+// Simple continue that would cross a labeled block should yield in an error
+fn continue_crossing() {
+ loop {
+ 'b: {
+ continue; //~ ERROR unlabeled `continue` inside of a labeled block
+ }
+ }
+}
+
+pub fn main() {}
diff --git a/tests/ui/label/label_break_value_continue.stderr b/tests/ui/label/label_break_value_continue.stderr
new file mode 100644
index 000000000..284d213d6
--- /dev/null
+++ b/tests/ui/label/label_break_value_continue.stderr
@@ -0,0 +1,25 @@
+error[E0695]: unlabeled `continue` inside of a labeled block
+ --> $DIR/label_break_value_continue.rs:6:9
+ |
+LL | continue;
+ | ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label
+
+error[E0696]: `continue` pointing to a labeled block
+ --> $DIR/label_break_value_continue.rs:13:9
+ |
+LL | / 'b: {
+LL | | continue 'b;
+ | | ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
+LL | | }
+ | |_____- labeled block the `continue` points to
+
+error[E0695]: unlabeled `continue` inside of a labeled block
+ --> $DIR/label_break_value_continue.rs:21:13
+ |
+LL | continue;
+ | ^^^^^^^^ `continue` statements that would diverge to or through a labeled block need to bear a label
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0695, E0696.
+For more information about an error, try `rustc --explain E0695`.
diff --git a/tests/ui/label/label_break_value_desugared_break.rs b/tests/ui/label/label_break_value_desugared_break.rs
new file mode 100644
index 000000000..70227d869
--- /dev/null
+++ b/tests/ui/label/label_break_value_desugared_break.rs
@@ -0,0 +1,19 @@
+// compile-flags: --edition 2018
+#![feature(try_blocks)]
+
+// run-pass
+fn main() {
+ let _: Result<(), ()> = try {
+ 'foo: {
+ Err(())?;
+ break 'foo;
+ }
+ };
+
+ 'foo: {
+ let _: Result<(), ()> = try {
+ Err(())?;
+ break 'foo;
+ };
+ }
+}
diff --git a/tests/ui/label/label_break_value_illegal_uses.fixed b/tests/ui/label/label_break_value_illegal_uses.fixed
new file mode 100644
index 000000000..fb75276b4
--- /dev/null
+++ b/tests/ui/label/label_break_value_illegal_uses.fixed
@@ -0,0 +1,29 @@
+// run-rustfix
+
+// These are forbidden occurrences of label-break-value
+
+#[allow(unused_unsafe)]
+fn labeled_unsafe() {
+ unsafe {} //~ ERROR block label not supported here
+}
+
+fn labeled_if() {
+ if true {} //~ ERROR block label not supported here
+}
+
+fn labeled_else() {
+ if true {} else {} //~ ERROR block label not supported here
+}
+
+fn labeled_match() {
+ match false { //~ ERROR block label not supported here
+ _ => {}
+ }
+}
+
+fn main() {
+ labeled_unsafe();
+ labeled_if();
+ labeled_else();
+ labeled_match();
+}
diff --git a/tests/ui/label/label_break_value_illegal_uses.rs b/tests/ui/label/label_break_value_illegal_uses.rs
new file mode 100644
index 000000000..3cbf41380
--- /dev/null
+++ b/tests/ui/label/label_break_value_illegal_uses.rs
@@ -0,0 +1,29 @@
+// run-rustfix
+
+// These are forbidden occurrences of label-break-value
+
+#[allow(unused_unsafe)]
+fn labeled_unsafe() {
+ unsafe 'b: {} //~ ERROR block label not supported here
+}
+
+fn labeled_if() {
+ if true 'b: {} //~ ERROR block label not supported here
+}
+
+fn labeled_else() {
+ if true {} else 'b: {} //~ ERROR block label not supported here
+}
+
+fn labeled_match() {
+ match false 'b: { //~ ERROR block label not supported here
+ _ => {}
+ }
+}
+
+fn main() {
+ labeled_unsafe();
+ labeled_if();
+ labeled_else();
+ labeled_match();
+}
diff --git a/tests/ui/label/label_break_value_illegal_uses.stderr b/tests/ui/label/label_break_value_illegal_uses.stderr
new file mode 100644
index 000000000..15016ffd5
--- /dev/null
+++ b/tests/ui/label/label_break_value_illegal_uses.stderr
@@ -0,0 +1,26 @@
+error: block label not supported here
+ --> $DIR/label_break_value_illegal_uses.rs:7:12
+ |
+LL | unsafe 'b: {}
+ | ^^^ not supported here
+
+error: block label not supported here
+ --> $DIR/label_break_value_illegal_uses.rs:11:13
+ |
+LL | if true 'b: {}
+ | ^^^ not supported here
+
+error: block label not supported here
+ --> $DIR/label_break_value_illegal_uses.rs:15:21
+ |
+LL | if true {} else 'b: {}
+ | ^^^ not supported here
+
+error: block label not supported here
+ --> $DIR/label_break_value_illegal_uses.rs:19:17
+ |
+LL | match false 'b: {
+ | ^^^ not supported here
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/label/label_break_value_unlabeled_break.rs b/tests/ui/label/label_break_value_unlabeled_break.rs
new file mode 100644
index 000000000..2a4f5d574
--- /dev/null
+++ b/tests/ui/label/label_break_value_unlabeled_break.rs
@@ -0,0 +1,19 @@
+#![allow(unused_labels)]
+
+// Simple unlabeled break should yield in an error
+fn unlabeled_break_simple() {
+ 'b: {
+ break; //~ ERROR unlabeled `break` inside of a labeled block
+ }
+}
+
+// Unlabeled break that would cross a labeled block should yield in an error
+fn unlabeled_break_crossing() {
+ loop {
+ 'b: {
+ break; //~ ERROR unlabeled `break` inside of a labeled block
+ }
+ }
+}
+
+pub fn main() {}
diff --git a/tests/ui/label/label_break_value_unlabeled_break.stderr b/tests/ui/label/label_break_value_unlabeled_break.stderr
new file mode 100644
index 000000000..a2ccd27b8
--- /dev/null
+++ b/tests/ui/label/label_break_value_unlabeled_break.stderr
@@ -0,0 +1,15 @@
+error[E0695]: unlabeled `break` inside of a labeled block
+ --> $DIR/label_break_value_unlabeled_break.rs:6:9
+ |
+LL | break;
+ | ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label
+
+error[E0695]: unlabeled `break` inside of a labeled block
+ --> $DIR/label_break_value_unlabeled_break.rs:14:13
+ |
+LL | break;
+ | ^^^^^ `break` statements that would diverge to or through a labeled block need to bear a label
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0695`.
diff --git a/tests/ui/label/label_misspelled.rs b/tests/ui/label/label_misspelled.rs
new file mode 100644
index 000000000..e3180b06e
--- /dev/null
+++ b/tests/ui/label/label_misspelled.rs
@@ -0,0 +1,62 @@
+#![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
+ };
+}
+
+fn foo() {
+ 'LOOP: loop {
+ break LOOP;
+ //~^ ERROR cannot find value `LOOP` in this scope
+ };
+ 'while_loop: while true { //~ WARN denote infinite loops with
+ break while_loop;
+ //~^ ERROR cannot find value `while_loop` in this scope
+ };
+ 'while_let: while let Some(_) = Some(()) {
+ break while_let;
+ //~^ ERROR cannot find value `while_let` in this scope
+ }
+ 'for_loop: for _ in 0..3 {
+ break for_loop;
+ //~^ ERROR cannot find value `for_loop` in this scope
+ };
+}
+
+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/tests/ui/label/label_misspelled.stderr b/tests/ui/label/label_misspelled.stderr
new file mode 100644
index 000000000..4b5b9e92c
--- /dev/null
+++ b/tests/ui/label/label_misspelled.stderr
@@ -0,0 +1,206 @@
+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
+LL |
+LL | while_loop;
+ | ^^^^^^^^^^ not found in this scope
+
+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
+LL |
+LL | while_let;
+ | ^^^^^^^^^ not found in this scope
+
+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
+LL |
+LL | for_loop;
+ | ^^^^^^^^ not found in this scope
+
+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
+LL |
+LL | LOOP;
+ | ^^^^ not found in this scope
+
+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
+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
+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
+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
+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: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: denote infinite loops with `loop { ... }`
+ --> $DIR/label_misspelled.rs:31:5
+ |
+LL | 'while_loop: while true {
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
+
+warning: unused label
+ --> $DIR/label_misspelled.rs:47:5
+ |
+LL | 'while_loop: while true {
+ | ^^^^^^^^^^^
+
+warning: denote infinite loops with `loop { ... }`
+ --> $DIR/label_misspelled.rs:47:5
+ |
+LL | 'while_loop: while true {
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
+
+warning: unused label
+ --> $DIR/label_misspelled.rs:52:5
+ |
+LL | 'while_let: while let Some(_) = Some(()) {
+ | ^^^^^^^^^^
+
+warning: unused label
+ --> $DIR/label_misspelled.rs:57:5
+ |
+LL | 'for_loop: for _ in 0..3 {
+ | ^^^^^^^^^
+
+error[E0571]: `break` with value from a `while` loop
+ --> $DIR/label_misspelled.rs:49: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
+ |
+help: use `break` on its own without a value inside this `while` loop
+ |
+LL | break;
+ | ~~~~~
+help: alternatively, you might have meant to use the available loop label
+ |
+LL | break 'while_loop;
+ | ~~~~~~~~~~~
+
+error[E0571]: `break` with value from a `while` loop
+ --> $DIR/label_misspelled.rs:54: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
+ |
+help: use `break` on its own without a value inside this `while` loop
+ |
+LL | break;
+ | ~~~~~
+help: alternatively, you might have meant to use the available loop label
+ |
+LL | break 'while_let;
+ | ~~~~~~~~~~
+
+error[E0571]: `break` with value from a `for` loop
+ --> $DIR/label_misspelled.rs:59: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
+ |
+help: use `break` on its own without a value inside this `for` loop
+ |
+LL | break;
+ | ~~~~~
+help: alternatively, you might have meant to use the available loop label
+ |
+LL | break 'for_loop;
+ | ~~~~~~~~~
+
+error: aborting due to 11 previous errors; 10 warnings emitted
+
+Some errors have detailed explanations: E0425, E0571.
+For more information about an error, try `rustc --explain E0425`.
diff --git a/tests/ui/label/label_misspelled_2.rs b/tests/ui/label/label_misspelled_2.rs
new file mode 100644
index 000000000..55bbe6b30
--- /dev/null
+++ b/tests/ui/label/label_misspelled_2.rs
@@ -0,0 +1,16 @@
+#![warn(unused_labels)]
+
+fn main() {
+ 'a: for _ in 0..1 {
+ break 'a;
+ }
+ 'b: for _ in 0..1 {
+ break b; //~ ERROR cannot find value `b` in this scope
+ }
+ c: for _ in 0..1 { //~ ERROR malformed loop label
+ break 'c;
+ }
+ d: for _ in 0..1 { //~ ERROR malformed loop label
+ break d; //~ ERROR cannot find value `d` in this scope
+ }
+}
diff --git a/tests/ui/label/label_misspelled_2.stderr b/tests/ui/label/label_misspelled_2.stderr
new file mode 100644
index 000000000..960646d98
--- /dev/null
+++ b/tests/ui/label/label_misspelled_2.stderr
@@ -0,0 +1,37 @@
+error: malformed loop label
+ --> $DIR/label_misspelled_2.rs:10:5
+ |
+LL | c: for _ in 0..1 {
+ | ^ help: use the correct loop label format: `'c`
+
+error: malformed loop label
+ --> $DIR/label_misspelled_2.rs:13:5
+ |
+LL | d: for _ in 0..1 {
+ | ^ help: use the correct loop label format: `'d`
+
+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
+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
+LL | break d;
+ | ^
+ | |
+ | not found in this scope
+ | help: use the similarly named label: `'d`
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0425`.