Skip to content

Commit

Permalink
generic_const_exprs: yeet TypingEnv::from_param_env
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Nov 19, 2024
1 parent 84cb829 commit 7f67ec1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {

// Normalize consts in writeback, because GCE doesn't normalize eagerly.
if tcx.features().generic_const_exprs() {
value =
value.fold_with(&mut EagerlyNormalizeConsts { tcx, param_env: self.fcx.param_env });
value = value.fold_with(&mut EagerlyNormalizeConsts::new(self.fcx));
}

value
Expand Down Expand Up @@ -873,16 +872,22 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {

struct EagerlyNormalizeConsts<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
typing_env: ty::TypingEnv<'tcx>,
}
impl<'tcx> EagerlyNormalizeConsts<'tcx> {
fn new(fcx: &FnCtxt<'_, 'tcx>) -> Self {
// FIXME(#132279, generic_const_exprs): Using `try_normalize_erasing_regions` here
// means we can't handle opaque types in their defining scope.
EagerlyNormalizeConsts { tcx: fcx.tcx, typing_env: fcx.typing_env(fcx.param_env) }
}
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerlyNormalizeConsts<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
self.tcx
.try_normalize_erasing_regions(ty::TypingEnv::from_param_env(self.param_env), ct)
.unwrap_or(ct)
self.tcx.try_normalize_erasing_regions(self.typing_env, ct).unwrap_or(ct)
}
}

0 comments on commit 7f67ec1

Please sign in to comment.