Skip to content

Commit

Permalink
change writeback: ICEs as the regions have already been resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Dec 8, 2023
1 parent ac50f4b commit 193abb3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
22 changes: 16 additions & 6 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ use rustc_errors::{ErrorGuaranteed, StashKey};
use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor};
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_trait_selection::solve;
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;

use std::mem;

Expand Down Expand Up @@ -778,14 +781,21 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
let tcx = self.fcx.tcx;
match self.fcx.fully_resolve(t) {
Ok(t) if self.fcx.next_trait_solver() => {
// We must normalize erasing regions here, since later lints
Ok(ty) if self.fcx.next_trait_solver() => {
// We must deeply normalize here, since later lints
// expect that types that show up in the typeck are fully
// normalized.
if let Ok(t) = tcx.try_normalize_erasing_regions(self.fcx.param_env, t) {
t
} else {
tcx.fold_regions(t, |_, _| tcx.lifetimes.re_erased)

// FIXME(-Ztrait-solver=next): This is probably not
// very performant.
let body_id = tcx.hir().body_owner_def_id(self.body.id());
let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);
match solve::deeply_normalize(self.fcx.at(&cause, self.fcx.param_env), ty) {
Ok(ty) => tcx.fold_regions(ty, |_, _| tcx.lifetimes.re_erased),
Err(errors) => {
let guar = self.fcx.err_ctxt().report_fulfillment_errors(errors);
Ty::new_error(tcx, guar)
}
}
}
Ok(t) => {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_trait_selection/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ mod trait_goals;

pub use eval_ctxt::{EvalCtxt, GenerateProofTree, InferCtxtEvalExt, InferCtxtSelectExt};
pub use fulfill::FulfillmentCtxt;
pub use normalize::deeply_normalize;
pub(crate) use normalize::{
deeply_normalize, deeply_normalize_for_diagnostics, deeply_normalize_with_skipped_universes,
deeply_normalize_for_diagnostics, deeply_normalize_with_skipped_universes,
};

#[derive(Debug, Clone, Copy)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/solve/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::FulfillmentCtxt;

/// Deeply normalize all aliases in `value`. This does not handle inference and expects
/// its input to be already fully resolved.
pub(crate) fn deeply_normalize<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
pub fn deeply_normalize<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
at: At<'_, 'tcx>,
value: T,
) -> Result<T, Vec<FulfillmentError<'tcx>>> {
Expand Down

0 comments on commit 193abb3

Please sign in to comment.