2020-04-22 14:16:06 +00:00
|
|
|
use rustc_middle::mir::visit::Visitor;
|
2023-09-20 18:51:14 +00:00
|
|
|
use rustc_middle::mir::{Const, ConstOperand, Location};
|
2020-04-22 14:16:06 +00:00
|
|
|
use rustc_middle::ty::ConstKind;
|
|
|
|
|
|
|
|
pub struct RequiredConstsVisitor<'a, 'tcx> {
|
2023-09-20 18:51:14 +00:00
|
|
|
required_consts: &'a mut Vec<ConstOperand<'tcx>>,
|
2020-04-22 14:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> RequiredConstsVisitor<'a, 'tcx> {
|
2023-09-20 18:51:14 +00:00
|
|
|
pub fn new(required_consts: &'a mut Vec<ConstOperand<'tcx>>) -> Self {
|
2020-04-22 14:16:06 +00:00
|
|
|
RequiredConstsVisitor { required_consts }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-06 08:48:37 +00:00
|
|
|
impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> {
|
2023-09-20 18:51:14 +00:00
|
|
|
fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, _: Location) {
|
|
|
|
let const_ = constant.const_;
|
|
|
|
match const_ {
|
|
|
|
Const::Ty(c) => match c.kind() {
|
2023-02-14 09:17:34 +00:00
|
|
|
ConstKind::Param(_) | ConstKind::Error(_) | ConstKind::Value(_) => {}
|
|
|
|
_ => bug!("only ConstKind::Param/Value should be encountered here, got {:#?}", c),
|
2022-06-27 14:32:47 +00:00
|
|
|
},
|
2023-09-20 18:51:14 +00:00
|
|
|
Const::Unevaluated(..) => self.required_consts.push(*constant),
|
|
|
|
Const::Val(..) => {}
|
2020-04-22 14:16:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|