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

Commit 0174231

Browse files
committed
Make sure we report a future incompat error in all cases
1 parent 6a33de0 commit 0174231

File tree

5 files changed

+42
-16
lines changed

5 files changed

+42
-16
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,25 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
408408
// this pattern to a `PartialEq::eq` comparison and `PartialEq::eq` takes a
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.
411-
ty::Adt(..) if !self.type_marked_structural(pointee_ty) => {
411+
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+
);
429+
}
412430
PatKind::Constant { value: cv }
413431
}
414432
// All other references are converted into deref patterns and then recursively

src/test/ui/consts/match_ice.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
warning: to use a constant of type `&S` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
1+
warning: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
22
--> $DIR/match_ice.rs:11:9
33
|
44
LL | C => {}
55
| ^
66
|
7-
= note: `#[warn(nontrivial_structural_match)]` on by default
7+
= note: `#[warn(indirect_structural_match)]` on by default
88
= 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 #73448 <https://github.com/rust-lang/rust/issues/73448>
9+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
1010

1111
error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
1212
--> $DIR/match_ice.rs:11:9
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
warning: to use a constant of type `&&WrapInline` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
1+
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
22
--> $DIR/cant-hide-behind-doubly-indirect-embedded.rs:24:9
33
|
44
LL | WRAP_DOUBLY_INDIRECT_INLINE => { panic!("WRAP_DOUBLY_INDIRECT_INLINE matched itself"); }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `#[warn(nontrivial_structural_match)]` on by default
7+
note: the lint level is defined here
8+
--> $DIR/cant-hide-behind-doubly-indirect-embedded.rs:7:9
9+
|
10+
LL | #![warn(indirect_structural_match)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
812
= 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 #73448 <https://github.com/rust-lang/rust/issues/73448>
13+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
1014

1115
warning: 1 warning emitted
1216

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
warning: to use a constant of type `&&WrapParam<NoDerive>` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
1+
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
22
--> $DIR/cant-hide-behind-doubly-indirect-param.rs:24:9
33
|
44
LL | WRAP_DOUBLY_INDIRECT_PARAM => { panic!("WRAP_DOUBLY_INDIRECT_PARAM matched itself"); }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `#[warn(nontrivial_structural_match)]` on by default
7+
note: the lint level is defined here
8+
--> $DIR/cant-hide-behind-doubly-indirect-param.rs:7:9
9+
|
10+
LL | #![warn(indirect_structural_match)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
812
= 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 #73448 <https://github.com/rust-lang/rust/issues/73448>
13+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
1014

1115
warning: 1 warning emitted
1216

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
warning: to use a constant of type `&&B` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
1+
warning: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
22
--> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:31:9
33
|
44
LL | RR_B1 => { println!("CLAIM RR0: {:?} matches {:?}", RR_B1, RR_B0); }
55
| ^^^^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:13:36
8+
--> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:13:9
99
|
1010
LL | #![warn(indirect_structural_match, nontrivial_structural_match)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
13-
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
13+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
1414

15-
warning: to use a constant of type `&&B` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
15+
warning: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
1616
--> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:38:9
1717
|
1818
LL | RR_B1 => { println!("CLAIM RR1: {:?} matches {:?}", RR_B1, RR_B1); }
1919
| ^^^^^
2020
|
2121
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22-
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
22+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
2323

2424
warning: 2 warnings emitted
2525

0 commit comments

Comments
 (0)