Skip to content

Commit 8fdf0ef

Browse files
committed
loop match: handle opaque patterns
fixes issue 143203
1 parent aa7cc5d commit 8fdf0ef

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,21 @@ fn non_exhaustive() {
172172
}
173173
}
174174
}
175+
176+
fn invalid_range_pattern(state: f32) {
177+
#[loop_match]
178+
loop {
179+
state = 'blk: {
180+
match state {
181+
1.0 => {
182+
#[const_continue]
183+
break 'blk 2.5;
184+
}
185+
4.0..3.0 => {
186+
//~^ ERROR lower range bound must be less than upper
187+
todo!()
188+
}
189+
}
190+
}
191+
}
192+
}

tests/ui/loop-match/invalid.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ LL ~ State::A => State::B,
109109
LL ~ State::B | State::C => todo!(),
110110
|
111111

112-
error: aborting due to 13 previous errors
112+
error[E0579]: lower range bound must be less than upper
113+
--> $DIR/invalid.rs:185:17
114+
|
115+
LL | 4.0..3.0 => {
116+
| ^^^^^^^^
117+
118+
error: aborting due to 14 previous errors
113119

114-
Some errors have detailed explanations: E0004, E0308.
120+
Some errors have detailed explanations: E0004, E0308, E0579.
115121
For more information about an error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)