Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit da21764

Browse files
committed
Make sure we keep emitting a hard error
1 parent 0174231 commit da21764

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -409,25 +409,43 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
409409
// reference. This makes the rest of the matching logic simpler as it doesn't have
410410
// to figure out how to get a reference again.
411411
ty::Adt(adt_def, _) if !self.type_marked_structural(pointee_ty) => {
412-
if self.include_lint_checks
413-
&& !self.saw_const_match_error.get()
414-
&& !self.saw_const_match_lint.get()
415-
{
416-
self.saw_const_match_lint.set(true);
417-
let path = self.tcx().def_path_str(adt_def.did);
418-
let msg = format!(
419-
"to use a constant of type `{}` in a pattern, \
420-
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
421-
path, path,
422-
);
423-
self.tcx().struct_span_lint_hir(
424-
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
425-
self.id,
426-
self.span,
427-
|lint| lint.build(&msg).emit(),
428-
);
412+
if self.behind_reference.get() {
413+
if self.include_lint_checks
414+
&& !self.saw_const_match_error.get()
415+
&& !self.saw_const_match_lint.get()
416+
{
417+
self.saw_const_match_lint.set(true);
418+
let path = self.tcx().def_path_str(adt_def.did);
419+
let msg = format!(
420+
"to use a constant of type `{}` in a pattern, \
421+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
422+
path, path,
423+
);
424+
self.tcx().struct_span_lint_hir(
425+
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
426+
self.id,
427+
self.span,
428+
|lint| lint.build(&msg).emit(),
429+
);
430+
}
431+
PatKind::Constant { value: cv }
432+
} else {
433+
if !self.saw_const_match_error.get() {
434+
self.saw_const_match_error.set(true);
435+
let path = self.tcx().def_path_str(adt_def.did);
436+
let msg = format!(
437+
"to use a constant of type `{}` in a pattern, \
438+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
439+
path, path,
440+
);
441+
if self.include_lint_checks {
442+
tcx.sess.span_err(span, &msg);
443+
} else {
444+
tcx.sess.delay_span_bug(span, &msg)
445+
}
446+
}
447+
PatKind::Wild
429448
}
430-
PatKind::Constant { value: cv }
431449
}
432450
// All other references are converted into deref patterns and then recursively
433451
// convert the dereferenced constant to a pattern that is the sub-pattern of the

src/test/ui/consts/match_ice.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ fn main() {
1010
match C {
1111
C => {}
1212
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
13-
//~| WARN must be annotated
14-
//~| WARN previously accepted
1513
}
1614
const K: &T = &T;
1715
match K {

src/test/ui/consts/match_ice.stderr

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
warning: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
2-
--> $DIR/match_ice.rs:11:9
3-
|
4-
LL | C => {}
5-
| ^
6-
|
7-
= note: `#[warn(indirect_structural_match)]` on by default
8-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9-
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
10-
111
error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
122
--> $DIR/match_ice.rs:11:9
133
|
144
LL | C => {}
155
| ^
166

17-
error: aborting due to previous error; 1 warning emitted
7+
error: aborting due to previous error
188

0 commit comments

Comments
 (0)