about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2025-07-01 11:48:42 +0200
committerFolkert de Vries <folkert@folkertdev.nl>2025-07-01 15:53:52 +0200
commit8fdf0ef0ae32369a6fe82b2ef69b1f5e5dc68be1 (patch)
tree7d47dc2c2b3089b8e3f9e1d97c6f1db6aab90ad8
parentaa7cc5d2f453853a4025cf029f3e42625c7e1e18 (diff)
downloadrust-8fdf0ef0ae32369a6fe82b2ef69b1f5e5dc68be1.tar.gz
rust-8fdf0ef0ae32369a6fe82b2ef69b1f5e5dc68be1.zip
loop match: handle opaque patterns
fixes issue 143203
-rw-r--r--compiler/rustc_mir_build/src/builder/matches/mod.rs6
-rw-r--r--compiler/rustc_mir_build/src/errors.rs1
-rw-r--r--tests/ui/loop-match/invalid.rs18
-rw-r--r--tests/ui/loop-match/invalid.stderr10
4 files changed, 30 insertions, 5 deletions
diff --git a/compiler/rustc_mir_build/src/builder/matches/mod.rs b/compiler/rustc_mir_build/src/builder/matches/mod.rs
index 9600067a85f..2c29b862841 100644
--- a/compiler/rustc_mir_build/src/builder/matches/mod.rs
+++ b/compiler/rustc_mir_build/src/builder/matches/mod.rs
@@ -2970,6 +2970,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             }
             Constructor::Wildcard => true,
 
+            // Opaque patterns must not be matched on structurally.
+            Constructor::Opaque(_) => false,
+
             // These we may eventually support:
             Constructor::Struct
             | Constructor::Ref
@@ -2980,8 +2983,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             | Constructor::Str(_) => bug!("unsupported pattern constructor {:?}", pat.ctor()),
 
             // These should never occur here:
-            Constructor::Opaque(_)
-            | Constructor::Never
+            Constructor::Never
             | Constructor::NonExhaustive
             | Constructor::Hidden
             | Constructor::Missing
diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs
index 20e836f6bf2..16b49bf384c 100644
--- a/compiler/rustc_mir_build/src/errors.rs
+++ b/compiler/rustc_mir_build/src/errors.rs
@@ -1230,7 +1230,6 @@ pub(crate) struct ConstContinueMissingValue {
 
 #[derive(Diagnostic)]
 #[diag(mir_build_const_continue_unknown_jump_target)]
-#[note]
 pub(crate) struct ConstContinueUnknownJumpTarget {
     #[primary_span]
     pub span: Span,
diff --git a/tests/ui/loop-match/invalid.rs b/tests/ui/loop-match/invalid.rs
index 2f3b0a00f1f..0c47b1e0057 100644
--- a/tests/ui/loop-match/invalid.rs
+++ b/tests/ui/loop-match/invalid.rs
@@ -172,3 +172,21 @@ fn non_exhaustive() {
         }
     }
 }
+
+fn invalid_range_pattern(state: f32) {
+    #[loop_match]
+    loop {
+        state = 'blk: {
+            match state {
+                1.0 => {
+                    #[const_continue]
+                    break 'blk 2.5;
+                }
+                4.0..3.0 => {
+                    //~^ ERROR lower range bound must be less than upper
+                    todo!()
+                }
+            }
+        }
+    }
+}
diff --git a/tests/ui/loop-match/invalid.stderr b/tests/ui/loop-match/invalid.stderr
index 0444c713d92..70f246caa9c 100644
--- a/tests/ui/loop-match/invalid.stderr
+++ b/tests/ui/loop-match/invalid.stderr
@@ -109,7 +109,13 @@ LL ~                 State::A => State::B,
 LL ~                 State::B | State::C => todo!(),
    |
 
-error: aborting due to 13 previous errors
+error[E0579]: lower range bound must be less than upper
+  --> $DIR/invalid.rs:185:17
+   |
+LL |                 4.0..3.0 => {
+   |                 ^^^^^^^^
+
+error: aborting due to 14 previous errors
 
-Some errors have detailed explanations: E0004, E0308.
+Some errors have detailed explanations: E0004, E0308, E0579.
 For more information about an error, try `rustc --explain E0004`.