@@ -672,10 +672,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
672672 // We may have introduced e.g. `ty::Error`, if inference failed, make sure
673673 // to mark the `TypeckResults` as tainted in that case, so that downstream
674674 // users of the typeck results don't produce extra errors, or worse, ICEs.
675- if resolver. replaced_with_error {
675+ if let Some ( e ) = resolver. replaced_with_error {
676676 // FIXME(eddyb) keep track of `ErrorGuaranteed` from where the error was emitted.
677- self . typeck_results . tainted_by_errors =
678- Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
677+ self . typeck_results . tainted_by_errors = Some ( e) ;
679678 }
680679
681680 x
@@ -706,8 +705,8 @@ struct Resolver<'cx, 'tcx> {
706705 span : & ' cx dyn Locatable ,
707706 body : & ' tcx hir:: Body < ' tcx > ,
708707
709- /// Set to `true ` if any `Ty` or `ty::Const` had to be replaced with an `Error`.
710- replaced_with_error : bool ,
708+ /// Set to `Some ` if any `Ty` or `ty::Const` had to be replaced with an `Error`.
709+ replaced_with_error : Option < ErrorGuaranteed > ,
711710}
712711
713712impl < ' cx , ' tcx > Resolver < ' cx , ' tcx > {
@@ -716,12 +715,14 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
716715 span : & ' cx dyn Locatable ,
717716 body : & ' tcx hir:: Body < ' tcx > ,
718717 ) -> Resolver < ' cx , ' tcx > {
719- Resolver { tcx : fcx. tcx , infcx : fcx, span, body, replaced_with_error : false }
718+ Resolver { tcx : fcx. tcx , infcx : fcx, span, body, replaced_with_error : None }
720719 }
721720
722- fn report_error ( & self , p : impl Into < ty:: GenericArg < ' tcx > > ) {
723- if !self . tcx . sess . has_errors ( ) . is_some ( ) {
724- self . infcx
721+ fn report_error ( & self , p : impl Into < ty:: GenericArg < ' tcx > > ) -> ErrorGuaranteed {
722+ match self . tcx . sess . has_errors ( ) {
723+ Some ( e) => e,
724+ None => self
725+ . infcx
725726 . err_ctxt ( )
726727 . emit_inference_failure_err (
727728 Some ( self . body . id ( ) ) ,
@@ -730,7 +731,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
730731 E0282 ,
731732 false ,
732733 )
733- . emit ( ) ;
734+ . emit ( ) ,
734735 }
735736 }
736737}
@@ -771,9 +772,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
771772 }
772773 Err ( _) => {
773774 debug ! ( "Resolver::fold_ty: input type `{:?}` not fully resolvable" , t) ;
774- self . report_error ( t) ;
775- self . replaced_with_error = true ;
776- self . tcx ( ) . ty_error ( )
775+ let e = self . report_error ( t) ;
776+ self . replaced_with_error = Some ( e ) ;
777+ self . tcx ( ) . ty_error_with_guaranteed ( e )
777778 }
778779 }
779780 }
@@ -788,9 +789,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
788789 Ok ( ct) => self . tcx . erase_regions ( ct) ,
789790 Err ( _) => {
790791 debug ! ( "Resolver::fold_const: input const `{:?}` not fully resolvable" , ct) ;
791- self . report_error ( ct) ;
792- self . replaced_with_error = true ;
793- self . tcx ( ) . const_error ( ct. ty ( ) )
792+ let e = self . report_error ( ct) ;
793+ self . replaced_with_error = Some ( e ) ;
794+ self . tcx ( ) . const_error_with_guaranteed ( ct. ty ( ) , e )
794795 }
795796 }
796797 }
0 commit comments