mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-30 12:07:40 +00:00

And likewise for the `Const::val` method. Because its type is called `ConstKind`. Also `val` is a confusing name because `ConstKind` is an enum with seven variants, one of which is called `Value`. Also, this gives consistency with `TyS` and `PredicateS` which have `kind` fields. The commit also renames a few `Const` variables from `val` to `c`, to avoid confusion with the `ConstKind::Value` variant.
23 lines
737 B
Rust
23 lines
737 B
Rust
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);
|
|
}
|
|
}
|
|
}
|