Skip to content

Commit 73c34cb

Browse files
committed
Add notes to non-structural const in pattern error message
1 parent 553ecbe commit 73c34cb

27 files changed

+168
-10
lines changed

compiler/rustc_mir_build/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ mir_build_indirect_structural_match =
331331
mir_build_nontrivial_structural_match =
332332
to use a constant of type `{$non_sm_ty}` in a pattern, the constant's initializer must be trivial or `{$non_sm_ty}` must be annotated with `#[derive(PartialEq, Eq)]`
333333
334+
mir_build_type_not_structural_tip = the traits must be derived, manual `impl`s are not sufficient
335+
336+
mir_build_type_not_structural_more_info = see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
337+
334338
mir_build_overlapping_range_endpoints = multiple patterns overlap on their endpoints
335339
.range = ... with this range
336340
.note = you likely meant to write mutually exclusive ranges

compiler/rustc_mir_build/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,8 @@ pub struct UnionPattern {
663663

664664
#[derive(Diagnostic)]
665665
#[diag(mir_build_type_not_structural)]
666+
#[note(mir_build_type_not_structural_tip)]
667+
#[note(mir_build_type_not_structural_more_info)]
666668
pub struct TypeNotStructural<'tcx> {
667669
#[primary_span]
668670
pub span: Span,
@@ -695,12 +697,16 @@ pub struct PointerPattern;
695697

696698
#[derive(LintDiagnostic)]
697699
#[diag(mir_build_indirect_structural_match)]
700+
#[note(mir_build_type_not_structural_tip)]
701+
#[note(mir_build_type_not_structural_more_info)]
698702
pub struct IndirectStructuralMatch<'tcx> {
699703
pub non_sm_ty: Ty<'tcx>,
700704
}
701705

702706
#[derive(LintDiagnostic)]
703707
#[diag(mir_build_nontrivial_structural_match)]
708+
#[note(mir_build_type_not_structural_tip)]
709+
#[note(mir_build_type_not_structural_more_info)]
704710
pub struct NontrivialStructuralMatch<'tcx> {
705711
pub non_sm_ty: Ty<'tcx>,
706712
}

src/tools/clippy/tests/ui/crashes/ice-6254.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LL | FOO_REF_REF => {},
66
|
77
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
88
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
9+
= note: the traits must be derived, manual `impl`s are not sufficient
10+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
911
= note: `-D indirect-structural-match` implied by `-D warnings`
1012

1113
error: aborting due to previous error

tests/ui/consts/const_in_pattern/cross-crate-fail.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ error: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be ann
33
|
44
LL | consts::SOME => panic!(),
55
| ^^^^^^^^^^^^
6+
|
7+
= note: the traits must be derived, manual `impl`s are not sufficient
8+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
69

710
error: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
811
--> $DIR/cross-crate-fail.rs:20:9
912
|
1013
LL | <Defaulted as consts::AssocConst>::SOME => panic!(),
1114
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: the traits must be derived, manual `impl`s are not sufficient
17+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
1218

1319
error: aborting due to 2 previous errors
1420

tests/ui/consts/const_in_pattern/custom-eq-branch-warn.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ fn main() {
2828
match Foo::Qux(CustomEq) {
2929
BAR_BAZ => panic!(),
3030
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
31+
//~| NOTE the traits must be derived
32+
//~| NOTE StructuralEq.html for details
3133
//~| WARN this was previously accepted
3234
//~| NOTE see issue #73448
3335
//~| NOTE `#[warn(nontrivial_structural_match)]` on by default

tests/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LL | BAR_BAZ => panic!(),
66
|
77
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
88
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
9+
= note: the traits must be derived, manual `impl`s are not sufficient
10+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
911
= note: `#[warn(nontrivial_structural_match)]` on by default
1012

1113
warning: 1 warning emitted

tests/ui/consts/const_in_pattern/incomplete-slice.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LL | E_SL => {}
66
|
77
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
88
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
9+
= note: the traits must be derived, manual `impl`s are not sufficient
10+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
911
= note: `#[warn(indirect_structural_match)]` on by default
1012

1113
error[E0004]: non-exhaustive patterns: `&_` not covered

tests/ui/consts/const_in_pattern/issue-78057.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: to use a constant of type `Opaque` in a pattern, `Opaque` must be annotat
33
|
44
LL | FOO => {},
55
| ^^^
6+
|
7+
= note: the traits must be derived, manual `impl`s are not sufficient
8+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
69

710
error: unreachable pattern
811
--> $DIR/issue-78057.rs:14:9

tests/ui/consts/const_in_pattern/no-eq-branch-fail.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated wit
33
|
44
LL | BAR_BAZ => panic!(),
55
| ^^^^^^^
6+
|
7+
= note: the traits must be derived, manual `impl`s are not sufficient
8+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
69

710
error: aborting due to previous error
811

tests/ui/consts/const_in_pattern/reject_non_partial_eq.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: to use a constant of type `NoPartialEq` in a pattern, `NoPartialEq` must
33
|
44
LL | NO_PARTIAL_EQ_NONE => println!("NO_PARTIAL_EQ_NONE"),
55
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: the traits must be derived, manual `impl`s are not sufficient
8+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
69

710
error: aborting due to previous error
811

0 commit comments

Comments
 (0)