Skip to content

Commit 92bd1af

Browse files
committed
loop match: handle opaque patterns
fixes issue 143203
1 parent f46ce66 commit 92bd1af

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,6 +2970,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
29702970
}
29712971
Constructor::Wildcard => true,
29722972

2973+
// Opaque patterns must not be matched on structurally.
2974+
Constructor::Opaque(_) => false,
2975+
29732976
// These we may eventually support:
29742977
Constructor::Struct
29752978
| Constructor::Ref
@@ -2980,8 +2983,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
29802983
| Constructor::Str(_) => bug!("unsupported pattern constructor {:?}", pat.ctor()),
29812984

29822985
// These should never occur here:
2983-
Constructor::Opaque(_)
2984-
| Constructor::Never
2986+
Constructor::Never
29852987
| Constructor::NonExhaustive
29862988
| Constructor::Hidden
29872989
| Constructor::Missing

compiler/rustc_mir_build/src/errors.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,6 @@ pub(crate) struct ConstContinueMissingValue {
12301230

12311231
#[derive(Diagnostic)]
12321232
#[diag(mir_build_const_continue_unknown_jump_target)]
1233-
#[note]
12341233
pub(crate) struct ConstContinueUnknownJumpTarget {
12351234
#[primary_span]
12361235
pub span: Span,

tests/ui/loop-match/invalid.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,22 @@ fn arm_has_guard(cond: bool) {
159159
}
160160
}
161161
}
162+
163+
fn invalid_range_pattern(state: f32) {
164+
#[loop_match]
165+
loop {
166+
state = 'blk: {
167+
match state {
168+
1.0 => {
169+
#[const_continue]
170+
break 'blk 2.5;
171+
//~^ ERROR the target of this `#[const_continue]` is not statically known
172+
}
173+
4.0..3.0 => {
174+
//~^ ERROR lower range bound must be less than upper
175+
todo!()
176+
}
177+
}
178+
}
179+
}
180+
}

tests/ui/loop-match/invalid.stderr

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ error: match arms that are part of a `#[loop_match]` cannot have guards
8686
LL | State::B if cond => break 'a,
8787
| ^^^^
8888

89-
error: aborting due to 12 previous errors
89+
error[E0579]: lower range bound must be less than upper
90+
--> $DIR/invalid.rs:173:17
91+
|
92+
LL | 4.0..3.0 => {
93+
| ^^^^^^^^
94+
95+
error: the target of this `#[const_continue]` is not statically known
96+
--> $DIR/invalid.rs:170:21
97+
|
98+
LL | break 'blk 2.5;
99+
| ^^^^^^^^^^^^^^
100+
101+
error: aborting due to 14 previous errors
90102

91-
For more information about this error, try `rustc --explain E0308`.
103+
Some errors have detailed explanations: E0308, E0579.
104+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)