about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs54
-rw-r--r--src/test/ui/consts/match_ice.rs2
-rw-r--r--src/test/ui/consts/match_ice.stderr12
3 files changed, 37 insertions, 31 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
index cf731a076ff..5025bacafa1 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
@@ -409,25 +409,43 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
                 // reference. This makes the rest of the matching logic simpler as it doesn't have
                 // to figure out how to get a reference again.
                 ty::Adt(adt_def, _) if !self.type_marked_structural(pointee_ty) => {
-                    if self.include_lint_checks
-                        && !self.saw_const_match_error.get()
-                        && !self.saw_const_match_lint.get()
-                    {
-                        self.saw_const_match_lint.set(true);
-                        let path = self.tcx().def_path_str(adt_def.did);
-                        let msg = format!(
-                            "to use a constant of type `{}` in a pattern, \
-                             `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
-                            path, path,
-                        );
-                        self.tcx().struct_span_lint_hir(
-                            lint::builtin::INDIRECT_STRUCTURAL_MATCH,
-                            self.id,
-                            self.span,
-                            |lint| lint.build(&msg).emit(),
-                        );
+                    if self.behind_reference.get() {
+                        if self.include_lint_checks
+                            && !self.saw_const_match_error.get()
+                            && !self.saw_const_match_lint.get()
+                        {
+                            self.saw_const_match_lint.set(true);
+                            let path = self.tcx().def_path_str(adt_def.did);
+                            let msg = format!(
+                                "to use a constant of type `{}` in a pattern, \
+                                `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
+                                path, path,
+                            );
+                            self.tcx().struct_span_lint_hir(
+                                lint::builtin::INDIRECT_STRUCTURAL_MATCH,
+                                self.id,
+                                self.span,
+                                |lint| lint.build(&msg).emit(),
+                            );
+                        }
+                        PatKind::Constant { value: cv }
+                    } else {
+                        if !self.saw_const_match_error.get() {
+                            self.saw_const_match_error.set(true);
+                            let path = self.tcx().def_path_str(adt_def.did);
+                            let msg = format!(
+                                "to use a constant of type `{}` in a pattern, \
+                                `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
+                                path, path,
+                            );
+                            if self.include_lint_checks {
+                                tcx.sess.span_err(span, &msg);
+                            } else {
+                                tcx.sess.delay_span_bug(span, &msg)
+                            }
+                        }
+                        PatKind::Wild
                     }
-                    PatKind::Constant { value: cv }
                 }
                 // All other references are converted into deref patterns and then recursively
                 // convert the dereferenced constant to a pattern that is the sub-pattern of the
diff --git a/src/test/ui/consts/match_ice.rs b/src/test/ui/consts/match_ice.rs
index 73ff15f2122..632335c841e 100644
--- a/src/test/ui/consts/match_ice.rs
+++ b/src/test/ui/consts/match_ice.rs
@@ -10,8 +10,6 @@ fn main() {
     match C {
         C => {}
         //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
-        //~| WARN must be annotated
-        //~| WARN previously accepted
     }
     const K: &T = &T;
     match K {
diff --git a/src/test/ui/consts/match_ice.stderr b/src/test/ui/consts/match_ice.stderr
index c46f2c2e972..699b4a5e200 100644
--- a/src/test/ui/consts/match_ice.stderr
+++ b/src/test/ui/consts/match_ice.stderr
@@ -1,18 +1,8 @@
-warning: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
-  --> $DIR/match_ice.rs:11:9
-   |
-LL |         C => {}
-   |         ^
-   |
-   = note: `#[warn(indirect_structural_match)]` on by default
-   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
-
 error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
   --> $DIR/match_ice.rs:11:9
    |
 LL |         C => {}
    |         ^
 
-error: aborting due to previous error; 1 warning emitted
+error: aborting due to previous error