@@ -7,15 +7,14 @@ use rustc_infer::traits::Obligation;
77use rustc_middle:: mir;
88use rustc_middle:: mir:: interpret:: ErrorHandled ;
99use rustc_middle:: thir:: { FieldPat , Pat , PatKind } ;
10+ use rustc_middle:: ty:: TypeVisitableExt ;
1011use rustc_middle:: ty:: { self , Ty , TyCtxt , ValTree } ;
11- use rustc_span:: { ErrorGuaranteed , Span } ;
12+ use rustc_span:: Span ;
1213use rustc_target:: abi:: { FieldIdx , VariantIdx } ;
1314use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt ;
1415use rustc_trait_selection:: traits:: ObligationCause ;
1516use tracing:: { debug, instrument, trace} ;
1617
17- use std:: cell:: Cell ;
18-
1918use super :: PatCtxt ;
2019use crate :: errors:: {
2120 ConstPatternDependsOnGenericParameter , CouldNotEvalConstPattern , InvalidPattern , NaNPattern ,
@@ -49,11 +48,6 @@ struct ConstToPat<'tcx> {
4948 span : Span ,
5049 param_env : ty:: ParamEnv < ' tcx > ,
5150
52- // This tracks if we emitted some hard error for a given const value, so that
53- // we will not subsequently issue an irrelevant lint for the same const
54- // value.
55- saw_const_match_error : Cell < Option < ErrorGuaranteed > > ,
56-
5751 // inference context used for checking `T: Structural` bounds.
5852 infcx : InferCtxt < ' tcx > ,
5953
@@ -73,7 +67,6 @@ impl<'tcx> ConstToPat<'tcx> {
7367 span,
7468 infcx,
7569 param_env : pat_ctxt. param_env ,
76- saw_const_match_error : Cell :: new ( None ) ,
7770 treat_byte_string_as_slice : pat_ctxt
7871 . typeck_results
7972 . treat_byte_string_as_slice
@@ -131,7 +124,7 @@ impl<'tcx> ConstToPat<'tcx> {
131124 // Convert the valtree to a const.
132125 let inlined_const_as_pat = self . valtree_to_pat ( valtree, ty) ;
133126
134- if self . saw_const_match_error . get ( ) . is_none ( ) {
127+ if !inlined_const_as_pat . references_error ( ) {
135128 // Always check for `PartialEq` if we had no other errors yet.
136129 if !self . type_has_partial_eq_impl ( ty) {
137130 let err = TypeNotPartialEq { span : self . span , non_peq_ty : ty } ;
@@ -205,7 +198,6 @@ impl<'tcx> ConstToPat<'tcx> {
205198 debug ! ( "adt_def {:?} has !type_marked_structural for cv.ty: {:?}" , adt_def, ty, ) ;
206199 let err = TypeNotStructural { span, non_sm_ty : ty } ;
207200 let e = tcx. dcx ( ) . emit_err ( err) ;
208- self . saw_const_match_error . set ( Some ( e) ) ;
209201 // We errored. Signal that in the pattern, so that follow up errors can be silenced.
210202 PatKind :: Error ( e)
211203 }
@@ -273,7 +265,6 @@ impl<'tcx> ConstToPat<'tcx> {
273265 if !pointee_ty. is_sized ( tcx, param_env) && !pointee_ty. is_slice ( ) {
274266 let err = UnsizedPattern { span, non_sm_ty : * pointee_ty } ;
275267 let e = tcx. dcx ( ) . emit_err ( err) ;
276- self . saw_const_match_error . set ( Some ( e) ) ;
277268 // We errored. Signal that in the pattern, so that follow up errors can be silenced.
278269 PatKind :: Error ( e)
279270 } else {
@@ -307,7 +298,6 @@ impl<'tcx> ConstToPat<'tcx> {
307298 // NaNs are not ever equal to anything so they make no sense as patterns.
308299 // Also see <https://github.com/rust-lang/rfcs/pull/3535>.
309300 let e = tcx. dcx ( ) . emit_err ( NaNPattern { span } ) ;
310- self . saw_const_match_error . set ( Some ( e) ) ;
311301 PatKind :: Error ( e)
312302 } else {
313303 PatKind :: Constant {
@@ -328,7 +318,6 @@ impl<'tcx> ConstToPat<'tcx> {
328318 _ => {
329319 let err = InvalidPattern { span, non_sm_ty : ty } ;
330320 let e = tcx. dcx ( ) . emit_err ( err) ;
331- self . saw_const_match_error . set ( Some ( e) ) ;
332321 // We errored. Signal that in the pattern, so that follow up errors can be silenced.
333322 PatKind :: Error ( e)
334323 }
0 commit comments