-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Expand file tree
/
Copy pathrequired_consts.rs
More file actions
23 lines (20 loc) · 739 Bytes
/
Copy pathrequired_consts.rs
File metadata and controls
23 lines (20 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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<'a, 'tcx> Visitor<'tcx> for RequiredConstsVisitor<'a, 'tcx> {
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) {
if let Some(ct) = constant.literal.const_for_ty() {
if let ConstKind::Unevaluated(_) = ct.val {
self.required_consts.push(*constant);
}
}
}
}