rust/compiler/rustc_mir_transform/src/reveal_all.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.4 KiB
Rust
Raw Normal View History

//! Normalizes MIR in RevealAll mode.
use crate::MirPass;
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, Ty, TyCtxt};
pub struct RevealAll;
impl<'tcx> MirPass<'tcx> for RevealAll {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
2021-12-02 17:17:32 +00:00
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
RevealAllVisitor { tcx, param_env }.visit_body_preserves_cfg(body);
}
}
struct RevealAllVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
}
impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
2023-04-14 18:59:17 +00:00
#[inline]
fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, _: Location) {
2023-04-14 18:59:17 +00:00
// We have to use `try_normalize_erasing_regions` here, since it's
// possible that we visit impossible-to-satisfy where clauses here,
// see #91745
if let Ok(c) = self.tcx.try_normalize_erasing_regions(self.param_env, constant.const_) {
constant.const_ = c;
2023-04-14 18:59:17 +00:00
}
}
#[inline]
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
// We have to use `try_normalize_erasing_regions` here, since it's
// possible that we visit impossible-to-satisfy where clauses here,
// see #91745
2023-04-14 18:59:17 +00:00
if let Ok(t) = self.tcx.try_normalize_erasing_regions(self.param_env, *ty) {
*ty = t;
}
}
}