1 //! Normalizes MIR in RevealAll mode.
4 use rustc_middle::mir::visit::*;
5 use rustc_middle::mir::*;
6 use rustc_middle::ty::{self, Ty, TyCtxt};
10 impl<'tcx> MirPass<'tcx> for RevealAll {
11 fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
12 // This pass must run before inlining, since we insert callee bodies in RevealAll mode.
13 // Do not apply this transformation to generators.
14 if (tcx.sess.mir_opt_level() >= 3 || !super::inline::is_enabled(tcx))
15 && body.generator.is_none()
17 let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
18 RevealAllVisitor { tcx, param_env }.visit_body(body);
23 struct RevealAllVisitor<'tcx> {
25 param_env: ty::ParamEnv<'tcx>,
28 impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
30 fn tcx(&self) -> TyCtxt<'tcx> {
35 fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
36 *ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
40 fn process_projection_elem(
42 elem: PlaceElem<'tcx>,
44 ) -> Option<PlaceElem<'tcx>> {
46 PlaceElem::Field(field, ty) => {
47 let new_ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
48 if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
50 // None of those contain a Ty.
53 | PlaceElem::ConstantIndex { .. }
54 | PlaceElem::Subslice { .. }
55 | PlaceElem::Downcast(..) => None,