@@ -672,10 +672,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
672
672
// We may have introduced e.g. `ty::Error`, if inference failed, make sure
673
673
// to mark the `TypeckResults` as tainted in that case, so that downstream
674
674
// 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 {
676
676
// 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) ;
679
678
}
680
679
681
680
x
@@ -706,8 +705,8 @@ struct Resolver<'cx, 'tcx> {
706
705
span : & ' cx dyn Locatable ,
707
706
body : & ' tcx hir:: Body < ' tcx > ,
708
707
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 > ,
711
710
}
712
711
713
712
impl < ' cx , ' tcx > Resolver < ' cx , ' tcx > {
@@ -716,12 +715,14 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
716
715
span : & ' cx dyn Locatable ,
717
716
body : & ' tcx hir:: Body < ' tcx > ,
718
717
) -> 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 }
720
719
}
721
720
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
725
726
. err_ctxt ( )
726
727
. emit_inference_failure_err (
727
728
Some ( self . body . id ( ) ) ,
@@ -730,7 +731,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
730
731
E0282 ,
731
732
false ,
732
733
)
733
- . emit ( ) ;
734
+ . emit ( ) ,
734
735
}
735
736
}
736
737
}
@@ -771,9 +772,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
771
772
}
772
773
Err ( _) => {
773
774
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 )
777
778
}
778
779
}
779
780
}
@@ -788,9 +789,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
788
789
Ok ( ct) => self . tcx . erase_regions ( ct) ,
789
790
Err ( _) => {
790
791
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 )
794
795
}
795
796
}
796
797
}
0 commit comments