Skip to content

Commit eaf10dc

Browse files
Normalize types in writeback results with new solver
1 parent cfcde24 commit eaf10dc

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

compiler/rustc_hir_typeck/src/writeback.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_errors::ErrorGuaranteed;
99
use rustc_hir as hir;
1010
use rustc_hir::intravisit::{self, Visitor};
1111
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
12-
use rustc_infer::infer::InferCtxt;
1312
use rustc_middle::hir::place::Place as HirPlace;
1413
use rustc_middle::mir::FakeReadCause;
1514
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};
@@ -737,8 +736,7 @@ impl Locatable for hir::HirId {
737736
/// The Resolver. This is the type folding engine that detects
738737
/// unresolved types and so forth.
739738
struct Resolver<'cx, 'tcx> {
740-
tcx: TyCtxt<'tcx>,
741-
infcx: &'cx InferCtxt<'tcx>,
739+
fcx: &'cx FnCtxt<'cx, 'tcx>,
742740
span: &'cx dyn Locatable,
743741
body: &'tcx hir::Body<'tcx>,
744742

@@ -752,18 +750,18 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
752750
span: &'cx dyn Locatable,
753751
body: &'tcx hir::Body<'tcx>,
754752
) -> 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 }
756754
}
757755

758756
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() {
760758
Some(e) => e,
761759
None => self
762-
.infcx
760+
.fcx
763761
.err_ctxt()
764762
.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),
767765
p.into(),
768766
E0282,
769767
false,
@@ -795,40 +793,46 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EraseEarlyRegions<'tcx> {
795793

796794
impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
797795
fn interner(&self) -> TyCtxt<'tcx> {
798-
self.tcx
796+
self.fcx.tcx
799797
}
800798

801799
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+
}
803807
Ok(t) => {
804808
// Do not anonymize late-bound regions
805809
// (e.g. keep `for<'a>` named `for<'a>`).
806810
// This allows NLL to generate error messages that
807811
// 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)
809813
}
810814
Err(_) => {
811815
debug!("Resolver::fold_ty: input type `{:?}` not fully resolvable", t);
812816
let e = self.report_error(t);
813817
self.replaced_with_error = Some(e);
814-
self.interner().ty_error(e)
818+
self.fcx.tcx.ty_error(e)
815819
}
816820
}
817821
}
818822

819823
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
820824
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
822826
}
823827

824828
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),
827831
Err(_) => {
828832
debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct);
829833
let e = self.report_error(ct);
830834
self.replaced_with_error = Some(e);
831-
self.interner().const_error(ct.ty(), e)
835+
self.fcx.tcx.const_error(ct.ty(), e)
832836
}
833837
}
834838
}

0 commit comments

Comments
 (0)