diff options
Diffstat (limited to '')
-rw-r--r-- | compiler/rustc_mir_transform/src/required_consts.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/required_consts.rs b/compiler/rustc_mir_transform/src/required_consts.rs new file mode 100644 index 000000000..827ce0c02 --- /dev/null +++ b/compiler/rustc_mir_transform/src/required_consts.rs @@ -0,0 +1,22 @@ +use rustc_middle::mir::visit::Visitor; +use rustc_middle::mir::{Constant, Location}; +use rustc_middle::ty::ConstKind; + +pub struct RequiredConstsVisitor<'a, 'tcx> { + required_consts: &'a mut Vec<Constant<'tcx>>, +} + +impl<'a, 'tcx> RequiredConstsVisitor<'a, 'tcx> { + pub fn new(required_consts: &'a mut Vec<Constant<'tcx>>) -> Self { + RequiredConstsVisitor { required_consts } + } +} + +impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> { + fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) { + let literal = constant.literal; + if let Some(ct) = literal.const_for_ty() && let ConstKind::Unevaluated(_) = ct.kind() { + self.required_consts.push(*constant); + } + } +} |