1
Fork 0

Move a const-prop-lint specific hack from mir interpret to const-prop-lint and make it fallible

This commit is contained in:
Oli Scherer 2023-04-04 10:39:26 +00:00
parent 35d06f9c74
commit b5d96d5ec5
4 changed files with 64 additions and 12 deletions

View file

@ -284,7 +284,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
return None;
}
self.use_ecx(source_info, |this| this.ecx.eval_mir_constant(&c.literal, Some(c.span), None))
// Normalization needed b/c const prop lint runs in
// `mir_drops_elaborated_and_const_checked`, which happens before
// optimized MIR. Only after optimizing the MIR can we guarantee
// that the `RevealAll` pass has happened and that the body's consts
// are normalized, so any call to resolve before that needs to be
// manually normalized.
let val = self.tcx.try_normalize_erasing_regions(self.param_env, c.literal).ok()?;
self.use_ecx(source_info, |this| this.ecx.eval_mir_constant(&val, Some(c.span), None))
}
/// Returns the value, if any, of evaluating `place`.