@@ -9,7 +9,6 @@ use rustc_errors::ErrorGuaranteed;
9
9
use rustc_hir as hir;
10
10
use rustc_hir:: intravisit:: { self , Visitor } ;
11
11
use rustc_infer:: infer:: error_reporting:: TypeAnnotationNeeded :: E0282 ;
12
- use rustc_infer:: infer:: InferCtxt ;
13
12
use rustc_middle:: hir:: place:: Place as HirPlace ;
14
13
use rustc_middle:: mir:: FakeReadCause ;
15
14
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , PointerCast } ;
@@ -737,8 +736,7 @@ impl Locatable for hir::HirId {
737
736
/// The Resolver. This is the type folding engine that detects
738
737
/// unresolved types and so forth.
739
738
struct Resolver < ' cx , ' tcx > {
740
- tcx : TyCtxt < ' tcx > ,
741
- infcx : & ' cx InferCtxt < ' tcx > ,
739
+ fcx : & ' cx FnCtxt < ' cx , ' tcx > ,
742
740
span : & ' cx dyn Locatable ,
743
741
body : & ' tcx hir:: Body < ' tcx > ,
744
742
@@ -752,18 +750,18 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
752
750
span : & ' cx dyn Locatable ,
753
751
body : & ' tcx hir:: Body < ' tcx > ,
754
752
) -> Resolver < ' cx , ' tcx > {
755
- Resolver { tcx : fcx . tcx , infcx : fcx, span, body, replaced_with_error : None }
753
+ Resolver { fcx, span, body, replaced_with_error : None }
756
754
}
757
755
758
756
fn report_error ( & self , p : impl Into < ty:: GenericArg < ' tcx > > ) -> ErrorGuaranteed {
759
- match self . tcx . sess . has_errors ( ) {
757
+ match self . fcx . tcx . sess . has_errors ( ) {
760
758
Some ( e) => e,
761
759
None => self
762
- . infcx
760
+ . fcx
763
761
. err_ctxt ( )
764
762
. emit_inference_failure_err (
765
- self . tcx . hir ( ) . body_owner_def_id ( self . body . id ( ) ) ,
766
- self . span . to_span ( self . tcx ) ,
763
+ self . fcx . tcx . hir ( ) . body_owner_def_id ( self . body . id ( ) ) ,
764
+ self . span . to_span ( self . fcx . tcx ) ,
767
765
p. into ( ) ,
768
766
E0282 ,
769
767
false ,
@@ -795,40 +793,46 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EraseEarlyRegions<'tcx> {
795
793
796
794
impl < ' cx , ' tcx > TypeFolder < TyCtxt < ' tcx > > for Resolver < ' cx , ' tcx > {
797
795
fn interner ( & self ) -> TyCtxt < ' tcx > {
798
- self . tcx
796
+ self . fcx . tcx
799
797
}
800
798
801
799
fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
802
- match self . infcx . fully_resolve ( t) {
800
+ match self . fcx . fully_resolve ( t) {
801
+ Ok ( t) if self . fcx . tcx . trait_solver_next ( ) => {
802
+ // We must normalize erasing regions here, since later lints
803
+ // expect that types that show up in the typeck are fully
804
+ // normalized.
805
+ self . fcx . tcx . try_normalize_erasing_regions ( self . fcx . param_env , t) . unwrap_or ( t)
806
+ }
803
807
Ok ( t) => {
804
808
// Do not anonymize late-bound regions
805
809
// (e.g. keep `for<'a>` named `for<'a>`).
806
810
// This allows NLL to generate error messages that
807
811
// refer to the higher-ranked lifetime names written by the user.
808
- EraseEarlyRegions { tcx : self . tcx } . fold_ty ( t)
812
+ EraseEarlyRegions { tcx : self . fcx . tcx } . fold_ty ( t)
809
813
}
810
814
Err ( _) => {
811
815
debug ! ( "Resolver::fold_ty: input type `{:?}` not fully resolvable" , t) ;
812
816
let e = self . report_error ( t) ;
813
817
self . replaced_with_error = Some ( e) ;
814
- self . interner ( ) . ty_error ( e)
818
+ self . fcx . tcx . ty_error ( e)
815
819
}
816
820
}
817
821
}
818
822
819
823
fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
820
824
debug_assert ! ( !r. is_late_bound( ) , "Should not be resolving bound region." ) ;
821
- self . tcx . lifetimes . re_erased
825
+ self . fcx . tcx . lifetimes . re_erased
822
826
}
823
827
824
828
fn fold_const ( & mut self , ct : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
825
- match self . infcx . fully_resolve ( ct) {
826
- Ok ( ct) => self . tcx . erase_regions ( ct) ,
829
+ match self . fcx . fully_resolve ( ct) {
830
+ Ok ( ct) => self . fcx . tcx . erase_regions ( ct) ,
827
831
Err ( _) => {
828
832
debug ! ( "Resolver::fold_const: input const `{:?}` not fully resolvable" , ct) ;
829
833
let e = self . report_error ( ct) ;
830
834
self . replaced_with_error = Some ( e) ;
831
- self . interner ( ) . const_error ( ct. ty ( ) , e)
835
+ self . fcx . tcx . const_error ( ct. ty ( ) , e)
832
836
}
833
837
}
834
838
}
0 commit comments