]>
Commit | Line | Data |
---|---|---|
3c0e092e XL |
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 { | |
a2a8927a | 11 | fn is_enabled(&self, sess: &rustc_session::Session) -> bool { |
064997fb | 12 | sess.mir_opt_level() >= 3 || super::inline::Inline.is_enabled(sess) |
a2a8927a XL |
13 | } |
14 | ||
3c0e092e | 15 | fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { |
3c0e092e | 16 | // Do not apply this transformation to generators. |
a2a8927a XL |
17 | if body.generator.is_some() { |
18 | return; | |
3c0e092e | 19 | } |
a2a8927a XL |
20 | |
21 | let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); | |
f2b60f7d | 22 | RevealAllVisitor { tcx, param_env }.visit_body_preserves_cfg(body); |
3c0e092e XL |
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) { | |
a2a8927a XL |
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 | |
5099ac24 | 42 | *ty = self.tcx.try_normalize_erasing_regions(self.param_env, *ty).unwrap_or(*ty); |
3c0e092e XL |
43 | } |
44 | } |