summaryrefslogtreecommitdiffstats
path: root/src/test/ui/label
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/label
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/label')
-rw-r--r--src/test/ui/label/label-beginning-with-underscore.rs10
-rw-r--r--src/test/ui/label/label-static.rs5
-rw-r--r--src/test/ui/label/label-static.stderr14
-rw-r--r--src/test/ui/label/label-underscore.rs5
-rw-r--r--src/test/ui/label/label-underscore.stderr14
-rw-r--r--src/test/ui/label/label_break_value_continue.rs27
-rw-r--r--src/test/ui/label/label_break_value_continue.stderr25
-rw-r--r--src/test/ui/label/label_break_value_desugared_break.rs12
-rw-r--r--src/test/ui/label/label_break_value_illegal_uses.fixed30
-rw-r--r--src/test/ui/label/label_break_value_illegal_uses.rs30
-rw-r--r--src/test/ui/label/label_break_value_illegal_uses.stderr26
-rw-r--r--src/test/ui/label/label_break_value_unlabeled_break.rs20
-rw-r--r--src/test/ui/label/label_break_value_unlabeled_break.stderr15
-rw-r--r--src/test/ui/label/label_misspelled.rs62
-rw-r--r--src/test/ui/label/label_misspelled.stderr206
-rw-r--r--src/test/ui/label/label_misspelled_2.rs16
-rw-r--r--src/test/ui/label/label_misspelled_2.stderr37
17 files changed, 554 insertions, 0 deletions
diff --git a/src/test/ui/label/label-beginning-with-underscore.rs b/src/test/ui/label/label-beginning-with-underscore.rs
new file mode 100644
index 000000000..4b620864a
--- /dev/null
+++ b/src/test/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/src/test/ui/label/label-static.rs b/src/test/ui/label/label-static.rs
new file mode 100644
index 000000000..95e764d01
--- /dev/null
+++ b/src/test/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/src/test/ui/label/label-static.stderr b/src/test/ui/label/label-static.stderr
new file mode 100644
index 000000000..1d3251d1b
--- /dev/null
+++ b/src/test/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/src/test/ui/label/label-underscore.rs b/src/test/ui/label/label-underscore.rs
new file mode 100644
index 000000000..de67f3d2c
--- /dev/null
+++ b/src/test/ui/label/label-underscore.rs
@@ -0,0 +1,5 @@
+fn main() {
+ '_: loop { //~ ERROR invalid label name `'_`
+ break '_ //~ ERROR invalid label name `'_`
+ }
+}
diff --git a/src/test/ui/label/label-underscore.stderr b/src/test/ui/label/label-underscore.stderr
new file mode 100644
index 000000000..4558ec4cb
--- /dev/null
+++ b/src/test/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/src/test/ui/label/label_break_value_continue.rs b/src/test/ui/label/label_break_value_continue.rs
new file mode 100644
index 000000000..e0deb30c9
--- /dev/null
+++ b/src/test/ui/label/label_break_value_continue.rs
@@ -0,0 +1,27 @@
+#![feature(label_break_value)]
+#![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/src/test/ui/label/label_break_value_continue.stderr b/src/test/ui/label/label_break_value_continue.stderr
new file mode 100644
index 000000000..9b8693dc5
--- /dev/null
+++ b/src/test/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:7: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:14: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:22: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/src/test/ui/label/label_break_value_desugared_break.rs b/src/test/ui/label/label_break_value_desugared_break.rs
new file mode 100644
index 000000000..de883b611
--- /dev/null
+++ b/src/test/ui/label/label_break_value_desugared_break.rs
@@ -0,0 +1,12 @@
+// compile-flags: --edition 2018
+#![feature(label_break_value, try_blocks)]
+
+// run-pass
+fn main() {
+ let _: Result<(), ()> = try {
+ 'foo: {
+ Err(())?;
+ break 'foo;
+ }
+ };
+}
diff --git a/src/test/ui/label/label_break_value_illegal_uses.fixed b/src/test/ui/label/label_break_value_illegal_uses.fixed
new file mode 100644
index 000000000..c1d2023a2
--- /dev/null
+++ b/src/test/ui/label/label_break_value_illegal_uses.fixed
@@ -0,0 +1,30 @@
+// run-rustfix
+#![feature(label_break_value)]
+
+// 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/src/test/ui/label/label_break_value_illegal_uses.rs b/src/test/ui/label/label_break_value_illegal_uses.rs
new file mode 100644
index 000000000..5b20c95e5
--- /dev/null
+++ b/src/test/ui/label/label_break_value_illegal_uses.rs
@@ -0,0 +1,30 @@
+// run-rustfix
+#![feature(label_break_value)]
+
+// 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/src/test/ui/label/label_break_value_illegal_uses.stderr b/src/test/ui/label/label_break_value_illegal_uses.stderr
new file mode 100644
index 000000000..24b733fec
--- /dev/null
+++ b/src/test/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:8:12
+ |
+LL | unsafe 'b: {}
+ | ^^^ not supported here
+
+error: block label not supported here
+ --> $DIR/label_break_value_illegal_uses.rs:12:13
+ |
+LL | if true 'b: {}
+ | ^^^ not supported here
+
+error: block label not supported here
+ --> $DIR/label_break_value_illegal_uses.rs:16:21
+ |
+LL | if true {} else 'b: {}
+ | ^^^ not supported here
+
+error: block label not supported here
+ --> $DIR/label_break_value_illegal_uses.rs:20:17
+ |
+LL | match false 'b: {
+ | ^^^ not supported here
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/ui/label/label_break_value_unlabeled_break.rs b/src/test/ui/label/label_break_value_unlabeled_break.rs
new file mode 100644
index 000000000..fa0c70edc
--- /dev/null
+++ b/src/test/ui/label/label_break_value_unlabeled_break.rs
@@ -0,0 +1,20 @@
+#![feature(label_break_value)]
+#![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/src/test/ui/label/label_break_value_unlabeled_break.stderr b/src/test/ui/label/label_break_value_unlabeled_break.stderr
new file mode 100644
index 000000000..0c4f573d2
--- /dev/null
+++ b/src/test/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:7: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:15: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/src/test/ui/label/label_misspelled.rs b/src/test/ui/label/label_misspelled.rs
new file mode 100644
index 000000000..e3180b06e
--- /dev/null
+++ b/src/test/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/src/test/ui/label/label_misspelled.stderr b/src/test/ui/label/label_misspelled.stderr
new file mode 100644
index 000000000..4b5b9e92c
--- /dev/null
+++ b/src/test/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/src/test/ui/label/label_misspelled_2.rs b/src/test/ui/label/label_misspelled_2.rs
new file mode 100644
index 000000000..55bbe6b30
--- /dev/null
+++ b/src/test/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/src/test/ui/label/label_misspelled_2.stderr b/src/test/ui/label/label_misspelled_2.stderr
new file mode 100644
index 000000000..960646d98
--- /dev/null
+++ b/src/test/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`.