@@ -155,8 +155,9 @@ impl<'tcx> ConstToPat<'tcx> {
155
155
} ;
156
156
157
157
if !self . saw_const_match_error . get ( ) {
158
- // If we were able to successfully convert the const to some pat,
159
- // double-check that all types in the const implement `Structural`.
158
+ // If we were able to successfully convert the const to some pat (possibly with some
159
+ // lints, but no errors), double-check that all types in the const implement
160
+ // `Structural` and `PartialEq`.
160
161
161
162
let structural =
162
163
traits:: search_for_structural_match_violation ( self . span , self . tcx ( ) , cv. ty ( ) ) ;
@@ -192,8 +193,10 @@ impl<'tcx> ConstToPat<'tcx> {
192
193
} else {
193
194
let err = InvalidPattern { span : self . span , non_sm_ty } ;
194
195
self . tcx ( ) . sess . emit_err ( err) ;
195
- return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind : PatKind :: Wild } ) ;
196
196
}
197
+ // All branches above emitted an error. Don't print any more lints.
198
+ // The pattern we return is irrelevant since we errored.
199
+ return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind : PatKind :: Wild } ) ;
197
200
} else if !self . saw_const_match_lint . get ( ) {
198
201
if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
199
202
match non_sm_ty. kind ( ) {
@@ -235,19 +238,20 @@ impl<'tcx> ConstToPat<'tcx> {
235
238
PointerPattern ,
236
239
) ;
237
240
}
238
- _ if !self . type_may_have_partial_eq_impl ( cv. ty ( ) ) => {
239
- // Value is structural-match but the type doesn't even implement `PartialEq`...
240
- self . saw_const_match_lint . set ( true ) ;
241
- self . tcx ( ) . emit_spanned_lint (
242
- lint:: builtin:: MATCH_WITHOUT_PARTIAL_EQ ,
243
- self . id ,
244
- self . span ,
245
- NonPartialEqMatch { non_peq_ty : cv. ty ( ) } ,
246
- ) ;
247
- }
248
241
_ => { }
249
242
}
250
243
}
244
+
245
+ // Always check for `PartialEq`, even if we emitted other lints. (But not if there were
246
+ // any errors.) This ensures it shows up in cargo's future-compat reports as well.
247
+ if !self . type_may_have_partial_eq_impl ( cv. ty ( ) ) {
248
+ self . tcx ( ) . emit_spanned_lint (
249
+ lint:: builtin:: MATCH_WITHOUT_PARTIAL_EQ ,
250
+ self . id ,
251
+ self . span ,
252
+ NonPartialEqMatch { non_peq_ty : cv. ty ( ) } ,
253
+ ) ;
254
+ }
251
255
}
252
256
253
257
inlined_const_as_pat
0 commit comments