]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_mir_transform/src/reveal_all.rs
Rollup merge of #100291 - WaffleLapkin:cstr_const_methods, r=oli-obk
[rust.git] / compiler / rustc_mir_transform / src / reveal_all.rs
1 //! Normalizes MIR in RevealAll mode.
2
3 use crate::MirPass;
4 use rustc_middle::mir::visit::*;
5 use rustc_middle::mir::*;
6 use rustc_middle::ty::{self, Ty, TyCtxt};
7
8 pub struct RevealAll;
9
10 impl<'tcx> MirPass<'tcx> for RevealAll {
11     fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
12         sess.mir_opt_level() >= 3 || super::inline::Inline.is_enabled(sess)
13     }
14
15     fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
16         // Do not apply this transformation to generators.
17         if body.generator.is_some() {
18             return;
19         }
20
21         let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
22         RevealAllVisitor { tcx, param_env }.visit_body_preserves_cfg(body);
23     }
24 }
25
26 struct RevealAllVisitor<'tcx> {
27     tcx: TyCtxt<'tcx>,
28     param_env: ty::ParamEnv<'tcx>,
29 }
30
31 impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
32     #[inline]
33     fn tcx(&self) -> TyCtxt<'tcx> {
34         self.tcx
35     }
36
37     #[inline]
38     fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
39         // We have to use `try_normalize_erasing_regions` here, since it's
40         // possible that we visit impossible-to-satisfy where clauses here,
41         // see #91745
42         *ty = self.tcx.try_normalize_erasing_regions(self.param_env, *ty).unwrap_or(*ty);
43     }
44 }