diff options
| author | Caio <c410.f3r@gmail.com> | 2021-11-18 12:09:34 -0300 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2021-11-18 12:09:34 -0300 |
| commit | 41d9abd76cd514aca23e3409fe6896a3a7d61d1a (patch) | |
| tree | aff7d6c42e88201c903006083095106fd082f16b /src/test/ui/for-loop-while | |
| parent | 6414e0b5b308d3ae27da83c6a25098cc8aadc1a9 (diff) | |
| download | rust-41d9abd76cd514aca23e3409fe6896a3a7d61d1a.tar.gz rust-41d9abd76cd514aca23e3409fe6896a3a7d61d1a.zip | |
Move some tests to more reasonable directories
Diffstat (limited to 'src/test/ui/for-loop-while')
4 files changed, 159 insertions, 0 deletions
diff --git a/src/test/ui/for-loop-while/break-outside-loop.rs b/src/test/ui/for-loop-while/break-outside-loop.rs new file mode 100644 index 00000000000..26769b30dd5 --- /dev/null +++ b/src/test/ui/for-loop-while/break-outside-loop.rs @@ -0,0 +1,35 @@ +struct Foo { + t: String +} + +fn cond() -> bool { true } + +fn foo<F>(_: F) where F: FnOnce() {} + +fn main() { + let pth = break; //~ ERROR: `break` outside of a loop + if cond() { continue } //~ ERROR: `continue` outside of a loop + + while cond() { + if cond() { break } + if cond() { continue } + foo(|| { + if cond() { break } //~ ERROR: `break` inside of a closure + if cond() { continue } //~ ERROR: `continue` inside of a closure + }) + } + + let rs: Foo = Foo{t: pth}; + + let unconstrained = break; //~ ERROR: `break` outside of a loop + + // This used to ICE because `target_id` passed to `check_expr_break` would be the closure and + // not the `loop`, which failed in the call to `find_breakable`. (#65383) + 'lab: loop { + || { + break 'lab; + //~^ ERROR use of unreachable label `'lab` + //~| ERROR `break` inside of a closure + }; + } +} diff --git a/src/test/ui/for-loop-while/break-outside-loop.stderr b/src/test/ui/for-loop-while/break-outside-loop.stderr new file mode 100644 index 00000000000..287bf9af62e --- /dev/null +++ b/src/test/ui/for-loop-while/break-outside-loop.stderr @@ -0,0 +1,58 @@ +error[E0767]: use of unreachable label `'lab` + --> $DIR/break-outside-loop.rs:30:19 + | +LL | 'lab: loop { + | ---- unreachable label defined here +LL | || { +LL | break 'lab; + | ^^^^ unreachable label `'lab` + | + = note: labels are unreachable through functions, closures, async blocks and modules + +error[E0268]: `break` outside of a loop + --> $DIR/break-outside-loop.rs:10:15 + | +LL | let pth = break; + | ^^^^^ cannot `break` outside of a loop + +error[E0268]: `continue` outside of a loop + --> $DIR/break-outside-loop.rs:11:17 + | +LL | if cond() { continue } + | ^^^^^^^^ cannot `continue` outside of a loop + +error[E0267]: `break` inside of a closure + --> $DIR/break-outside-loop.rs:17:25 + | +LL | foo(|| { + | -- enclosing closure +LL | if cond() { break } + | ^^^^^ cannot `break` inside of a closure + +error[E0267]: `continue` inside of a closure + --> $DIR/break-outside-loop.rs:18:25 + | +LL | foo(|| { + | -- enclosing closure +LL | if cond() { break } +LL | if cond() { continue } + | ^^^^^^^^ cannot `continue` inside of a closure + +error[E0268]: `break` outside of a loop + --> $DIR/break-outside-loop.rs:24:25 + | +LL | let unconstrained = break; + | ^^^^^ cannot `break` outside of a loop + +error[E0267]: `break` inside of a closure + --> $DIR/break-outside-loop.rs:30:13 + | +LL | || { + | -- enclosing closure +LL | break 'lab; + | ^^^^^^^^^^ cannot `break` inside of a closure + +error: aborting due to 7 previous errors + +Some errors have detailed explanations: E0267, E0268, E0767. +For more information about an error, try `rustc --explain E0267`. diff --git a/src/test/ui/for-loop-while/break-while-condition.rs b/src/test/ui/for-loop-while/break-while-condition.rs new file mode 100644 index 00000000000..6064e6ab002 --- /dev/null +++ b/src/test/ui/for-loop-while/break-while-condition.rs @@ -0,0 +1,29 @@ +#![feature(never_type)] + +fn main() { + // The `if false` expressions are simply to + // make sure we don't avoid checking everything + // simply because a few expressions are unreachable. + + if false { + let _: ! = { //~ ERROR mismatched types + 'a: while break 'a {}; + }; + } + + if false { + let _: ! = { + while false { //~ ERROR mismatched types + break + } + }; + } + + if false { + let _: ! = { + while false { //~ ERROR mismatched types + return + } + }; + } +} diff --git a/src/test/ui/for-loop-while/break-while-condition.stderr b/src/test/ui/for-loop-while/break-while-condition.stderr new file mode 100644 index 00000000000..6960c4fd867 --- /dev/null +++ b/src/test/ui/for-loop-while/break-while-condition.stderr @@ -0,0 +1,37 @@ +error[E0308]: mismatched types + --> $DIR/break-while-condition.rs:9:20 + | +LL | let _: ! = { + | ____________________^ +LL | | 'a: while break 'a {}; +LL | | }; + | |_________^ expected `!`, found `()` + | + = note: expected type `!` + found unit type `()` + +error[E0308]: mismatched types + --> $DIR/break-while-condition.rs:16:13 + | +LL | / while false { +LL | | break +LL | | } + | |_____________^ expected `!`, found `()` + | + = note: expected type `!` + found unit type `()` + +error[E0308]: mismatched types + --> $DIR/break-while-condition.rs:24:13 + | +LL | / while false { +LL | | return +LL | | } + | |_____________^ expected `!`, found `()` + | + = note: expected type `!` + found unit type `()` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. |
