rust/tests/ui/for-loop-while/break-outside-loop.rs
reddevilmidzy 77b2a196fb cleaned up some tests
merge privacy/privacy-sanity-2 with privacy/privacy-sanity.rs

Add comment to generics/type-args-on-module-in-bound.rs

Add comment to array-slice-vec/closure-in-array-eln.rs

Add comment to array-slice-vec/return-in-array-len.rs

Merge for-loop-while/break-outside-loop-2.rs with
for-loop-while/break-outside-loop.rs

Add comment to macros/column-macro-collision.rs

Add comment to privacy/private-extern-fn-visibility.rs

Add comment to mismatched_types/vec-hashset-type-mismatch.rs

Merge std-sync-right-kind-impls-2.rs with std-sync-right-kind-impls.rs

Add comment to array-slice-vec/slice-of-multi-ref.rs

Add comment to mismatched_types\vec-hashset-type-mismatch.rs

Add comment to derives/derive-hygiene-struct-builder.rs

Add comment to label/undeclared-label-span.rs

Add comment to label\undeclared-label-span.rs

Add comment to mismatched_types/array-repeat-unit-struct.rs
2026-01-16 06:50:34 +09:00

57 lines
1.2 KiB
Rust

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
};
}
// Make sure that a continue span actually contains the keyword. (#28105)
continue //~ ERROR `continue` outside of a loop
;
break //~ ERROR `break` outside of a loop
;
}