diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-07-29 20:19:49 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-29 20:19:49 +1000 |
| commit | dbcf16856850bc7f32256df3543e6936d2bbc864 (patch) | |
| tree | 5a9a21823f954bb812f1d68fdd46b395eac3ee8b /tests | |
| parent | b3962e88114a5f633011d8670f318e1c20ba41b6 (diff) | |
| parent | d87b4f2c77add3404f7469ea72f1d7c51e2a29dc (diff) | |
| download | rust-dbcf16856850bc7f32256df3543e6936d2bbc864.tar.gz rust-dbcf16856850bc7f32256df3543e6936d2bbc864.zip | |
Rollup merge of #144451 - ShoyuVanilla:loop-match-upvar, r=oli-obk
fix: Reject upvar scrutinees for `loop_match` Fixes https://github.com/rust-lang/rust/issues/144051 I think we should reject upvars as they are not locals but somewhat like field access
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/loop-match/upvar-scrutinee.rs | 81 | ||||
| -rw-r--r-- | tests/ui/loop-match/upvar-scrutinee.stderr | 18 |
2 files changed, 99 insertions, 0 deletions
diff --git a/tests/ui/loop-match/upvar-scrutinee.rs b/tests/ui/loop-match/upvar-scrutinee.rs new file mode 100644 index 00000000000..a93e3a0e59a --- /dev/null +++ b/tests/ui/loop-match/upvar-scrutinee.rs @@ -0,0 +1,81 @@ +#![allow(incomplete_features)] +#![feature(loop_match)] + +#[derive(Clone, Copy)] +enum State { + A, + B, +} + +fn main() { + let mut state = State::A; + + #[loop_match] + loop { + state = 'blk: { + match state { + State::A => { + #[const_continue] + break 'blk State::B; + } + State::B => { + return; + } + } + } + } + + || { + #[loop_match] + loop { + state = 'blk: { + match state { + //~^ ERROR invalid match on `#[loop_match]` state + State::A => { + #[const_continue] + break 'blk State::B; + } + State::B => { + return; + } + } + } + } + }; + + || { + let mut state = state; + #[loop_match] + loop { + state = 'blk: { + match state { + State::A => { + #[const_continue] + break 'blk State::B; + } + State::B => { + return; + } + } + } + } + }; + + move || { + #[loop_match] + loop { + state = 'blk: { + match state { + //~^ ERROR invalid match on `#[loop_match]` state + State::A => { + #[const_continue] + break 'blk State::B; + } + State::B => { + return; + } + } + } + } + }; +} diff --git a/tests/ui/loop-match/upvar-scrutinee.stderr b/tests/ui/loop-match/upvar-scrutinee.stderr new file mode 100644 index 00000000000..b7a0a90193d --- /dev/null +++ b/tests/ui/loop-match/upvar-scrutinee.stderr @@ -0,0 +1,18 @@ +error: invalid match on `#[loop_match]` state + --> $DIR/upvar-scrutinee.rs:32:23 + | +LL | match state { + | ^^^^^ + | + = note: a local variable must be the scrutinee within a `#[loop_match]` + +error: invalid match on `#[loop_match]` state + --> $DIR/upvar-scrutinee.rs:68:23 + | +LL | match state { + | ^^^^^ + | + = note: a local variable must be the scrutinee within a `#[loop_match]` + +error: aborting due to 2 previous errors + |
