2020-04-22 11:16:06 -03:00
|
|
|
use rustc_middle::mir::visit::Visitor;
|
2022-06-27 16:32:47 +02:00
|
|
|
use rustc_middle::mir::{Constant, ConstantKind, Location};
|
2020-04-22 11:16:06 -03:00
|
|
|
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 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-06 00:48:37 -08:00
|
|
|
impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> {
|
2020-04-22 11:16:06 -03:00
|
|
|
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) {
|
2022-03-01 07:43:12 -03:00
|
|
|
let literal = constant.literal;
|
2022-06-27 16:32:47 +02:00
|
|
|
match literal {
|
|
|
|
ConstantKind::Ty(c) => match c.kind() {
|
2022-09-14 15:35:24 +02:00
|
|
|
ConstKind::Param(_) => {}
|
|
|
|
_ => bug!("only ConstKind::Param should be encountered here, got {:#?}", c),
|
2022-06-27 16:32:47 +02:00
|
|
|
},
|
|
|
|
ConstantKind::Unevaluated(..) => self.required_consts.push(*constant),
|
|
|
|
ConstantKind::Val(..) => {}
|
2020-04-22 11:16:06 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|