]> git.lizzy.rs Git - rust.git/blob - src/test/ui/break-outside-loop.rs
Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup
[rust.git] / src / test / ui / break-outside-loop.rs
1 struct Foo {
2     t: String
3 }
4
5 fn cond() -> bool { true }
6
7 fn foo<F>(_: F) where F: FnOnce() {}
8
9 fn main() {
10     let pth = break; //~ ERROR: `break` outside of a loop
11     if cond() { continue } //~ ERROR: `continue` outside of a loop
12
13     while cond() {
14         if cond() { break }
15         if cond() { continue }
16         foo(|| {
17             if cond() { break } //~ ERROR: `break` inside of a closure
18             if cond() { continue } //~ ERROR: `continue` inside of a closure
19         })
20     }
21
22     let rs: Foo = Foo{t: pth};
23
24     let unconstrained = break; //~ ERROR: `break` outside of a loop
25
26     // This used to ICE because `target_id` passed to `check_expr_break` would be the closure and
27     // not the `loop`, which failed in the call to `find_breakable`. (#65383)
28     'lab: loop {
29         || {
30             break 'lab;
31             //~^ ERROR use of unreachable label `'lab`
32             //~| ERROR `break` inside of a closure
33         };
34     }
35 }