@@ -155,8 +155,9 @@ impl<'tcx> ConstToPat<'tcx> {
155155 } ;
156156
157157 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`.
160161
161162 let structural =
162163 traits:: search_for_structural_match_violation ( self . span , self . tcx ( ) , cv. ty ( ) ) ;
@@ -192,8 +193,10 @@ impl<'tcx> ConstToPat<'tcx> {
192193 } else {
193194 let err = InvalidPattern { span : self . span , non_sm_ty } ;
194195 self . tcx ( ) . sess . emit_err ( err) ;
195- return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind : PatKind :: Wild } ) ;
196196 }
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 } ) ;
197200 } else if !self . saw_const_match_lint . get ( ) {
198201 if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
199202 match non_sm_ty. kind ( ) {
@@ -235,19 +238,20 @@ impl<'tcx> ConstToPat<'tcx> {
235238 PointerPattern ,
236239 ) ;
237240 }
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- }
248241 _ => { }
249242 }
250243 }
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+ }
251255 }
252256
253257 inlined_const_as_pat
0 commit comments