Skip to content

Commit ae7004e

Browse files
committed
Add context to fall-through "const pattern of non-structural type" error
Unify wording with the regular non-structural type error.
1 parent 62da0af commit ae7004e

File tree

7 files changed

+22
-7
lines changed

7 files changed

+22
-7
lines changed

compiler/rustc_mir_build/messages.ftl

+3-3
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ mir_build_non_exhaustive_patterns_type_not_empty = non-exhaustive patterns: type
263263
.suggestion = ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
264264
.help = ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
265265
266-
mir_build_non_partial_eq_match = constant of non-structural type `{$non_peq_ty}` in a pattern
266+
mir_build_non_partial_eq_match = constant of non-structural type `{$ty}` in a pattern
267267
.label = constant of non-structural type
268268
269269
mir_build_pattern_not_covered = refutable pattern in {$origin}
@@ -312,9 +312,9 @@ mir_build_trailing_irrefutable_let_patterns = trailing irrefutable {$count ->
312312
*[other] them
313313
} into the body
314314
315-
mir_build_type_not_structural = constant of non-structural type `{$non_sm_ty}` in a pattern
315+
mir_build_type_not_structural = constant of non-structural type `{$ty}` in a pattern
316316
.label = constant of non-structural type
317-
mir_build_type_not_structural_def = `{$non_sm_ty}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
317+
mir_build_type_not_structural_def = `{$ty}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
318318
mir_build_type_not_structural_more_info = see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
319319
mir_build_type_not_structural_tip =
320320
the `PartialEq` trait must be derived, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details

compiler/rustc_mir_build/src/errors.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ pub(crate) struct TypeNotStructural<'tcx> {
799799
pub(crate) span: Span,
800800
#[label(mir_build_type_not_structural_def)]
801801
pub(crate) ty_def_span: Span,
802-
pub(crate) non_sm_ty: Ty<'tcx>,
802+
pub(crate) ty: Ty<'tcx>,
803803
#[note(mir_build_type_not_structural_tip)]
804804
pub(crate) manual_partialeq_impl_span: Option<Span>,
805805
#[note(mir_build_type_not_structural_more_info)]
@@ -808,11 +808,13 @@ pub(crate) struct TypeNotStructural<'tcx> {
808808

809809
#[derive(Diagnostic)]
810810
#[diag(mir_build_non_partial_eq_match)]
811+
#[note(mir_build_type_not_structural_def)]
812+
#[note(mir_build_type_not_structural_more_info)]
811813
pub(crate) struct TypeNotPartialEq<'tcx> {
812814
#[primary_span]
813815
#[label]
814816
pub(crate) span: Span,
815-
pub(crate) non_peq_ty: Ty<'tcx>,
817+
pub(crate) ty: Ty<'tcx>,
816818
}
817819

818820
#[derive(Diagnostic)]

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ impl<'tcx> ConstToPat<'tcx> {
190190
if !inlined_const_as_pat.references_error() {
191191
// Always check for `PartialEq` if we had no other errors yet.
192192
if !self.type_has_partial_eq_impl(ty) {
193-
let err = TypeNotPartialEq { span: self.span, non_peq_ty: ty };
193+
let err = TypeNotPartialEq { span: self.span, ty };
194+
// FIXME: visit every type in `ty` and if it doesn't derive `PartialEq`, mention it.
194195
return self.mk_err(self.tcx.dcx().create_err(err), ty);
195196
}
196197
}
@@ -265,7 +266,7 @@ impl<'tcx> ConstToPat<'tcx> {
265266
});
266267
let err = TypeNotStructural {
267268
span,
268-
non_sm_ty: ty,
269+
ty,
269270
ty_def_span,
270271
manual_partialeq_impl_span,
271272
manual_partialeq_impl_note: manual_partialeq_impl_span.is_none(),

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

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ LL | const C: &[O<B>] = &[O::None];
66
...
77
LL | C => (),
88
| ^ constant of non-structural type
9+
|
10+
= note: `&[O<B>]` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
11+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
912

1013
error: aborting due to 1 previous error
1114

tests/ui/consts/const_in_pattern/reject_non_partial_eq.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ LL | const NO_PARTIAL_EQ_NONE: Option<NoPartialEq> = None;
66
...
77
LL | NO_PARTIAL_EQ_NONE => println!("NO_PARTIAL_EQ_NONE"),
88
| ^^^^^^^^^^^^^^^^^^ constant of non-structural type
9+
|
10+
= note: `Option<NoPartialEq>` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
11+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
912

1013
error: aborting due to 1 previous error
1114

tests/ui/match/issue-72896-non-partial-eq-const.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ LL | const CONST_SET: EnumSet<Enum8> = EnumSet { __enumset_underlying: 3 };
66
...
77
LL | CONST_SET => { /* ok */ }
88
| ^^^^^^^^^ constant of non-structural type
9+
|
10+
= note: `EnumSet<Enum8>` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
11+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
912

1013
error: aborting due to 1 previous error
1114

tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/issue-61188-match-slice-forbidden-without-eq.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ LL | const A: &[B] = &[];
66
...
77
LL | A => (),
88
| ^ constant of non-structural type
9+
|
10+
= note: `&[B]` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
11+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
912

1013
error: aborting due to 1 previous error
1114

0 commit comments

Comments
 (0)