Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,14 +1439,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.next_trait_solver()
&& let ty::Alias(..) = ty.kind()
{
if let Some(&normalized_ty) = self.normalization_cache.borrow().get(&ty) {
return normalized_ty;
}
// We need to use a separate variable here as otherwise the temporary for
// `self.fulfillment_cx.borrow_mut()` is alive in the `Err` branch, resulting
// in a reentrant borrow, causing an ICE.
let result = self
.at(&self.misc(sp), self.param_env)
.structurally_normalize_ty(ty, &mut **self.fulfillment_cx.borrow_mut());
match result {
Ok(normalized_ty) => normalized_ty,
Ok(normalized_ty) => {
self.normalization_cache.borrow_mut().insert(ty, normalized_ty);
self.resolve_vars_with_obligations(normalized_ty)
}
Err(errors) => {
let guar = self.err_ctxt().report_fulfillment_errors(errors);
return Ty::new_error(self.tcx, guar);
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::cell::{Cell, RefCell};
use std::ops::Deref;

use hir::def_id::CRATE_DEF_ID;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::DiagCtxtHandle;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, HirId, ItemLocalMap};
Expand Down Expand Up @@ -122,6 +123,8 @@ pub(crate) struct FnCtxt<'a, 'tcx> {
/// These are stored here so we may collect them when canonicalizing user
/// type ascriptions later.
pub(super) trait_ascriptions: RefCell<ItemLocalMap<Vec<ty::Clause<'tcx>>>>,

pub(super) normalization_cache: RefCell<FxHashMap<Ty<'tcx>, Ty<'tcx>>>,
}

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Expand Down Expand Up @@ -150,6 +153,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
diverging_fallback_behavior,
diverging_block_behavior,
trait_ascriptions: Default::default(),
normalization_cache: Default::default(),
}
}

Expand Down
Loading