remove visit_const from mir visitors
This commit is contained in:
parent
0726265442
commit
372c4fd67f
@ -106,8 +106,4 @@ fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location)
|
||||
|
||||
debug!("constant: {:#?}", constant);
|
||||
}
|
||||
|
||||
fn visit_const(&mut self, _constant: &mut ty::Const<'tcx>, _location: Location) {
|
||||
bug!("should never be called");
|
||||
}
|
||||
}
|
||||
|
@ -706,13 +706,12 @@ fn alloc_ids_from_const_val(val: ConstValue<'_>) -> impl Iterator<Item = AllocId
|
||||
struct CollectAllocIds(BTreeSet<AllocId>);
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for CollectAllocIds {
|
||||
fn visit_constant(&mut self, c: &Constant<'tcx>, loc: Location) {
|
||||
fn visit_constant(&mut self, c: &Constant<'tcx>, _: Location) {
|
||||
match c.literal {
|
||||
ConstantKind::Ty(c) => self.visit_const(c, loc),
|
||||
ConstantKind::Ty(_) | ConstantKind::Unevaluated(..) => {}
|
||||
ConstantKind::Val(val, _) => {
|
||||
self.0.extend(alloc_ids_from_const_val(val));
|
||||
}
|
||||
ConstantKind::Unevaluated(..) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,14 +237,6 @@ fn visit_region(
|
||||
self.super_region(region);
|
||||
}
|
||||
|
||||
fn visit_const(
|
||||
&mut self,
|
||||
constant: $(& $mutability)? ty::Const<'tcx>,
|
||||
_: Location,
|
||||
) {
|
||||
self.super_const(constant);
|
||||
}
|
||||
|
||||
fn visit_substs(
|
||||
&mut self,
|
||||
substs: & $($mutability)? SubstsRef<'tcx>,
|
||||
@ -877,7 +869,7 @@ fn super_constant(
|
||||
self.visit_span($(& $mutability)? *span);
|
||||
drop(user_ty); // no visit method for this
|
||||
match literal {
|
||||
ConstantKind::Ty(ct) => self.visit_const($(& $mutability)? *ct, location),
|
||||
ConstantKind::Ty(_) => {}
|
||||
ConstantKind::Val(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
|
||||
ConstantKind::Unevaluated(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
|
||||
}
|
||||
@ -917,9 +909,6 @@ fn super_ty(&mut self, _ty: $(& $mutability)? Ty<'tcx>) {
|
||||
fn super_region(&mut self, _region: $(& $mutability)? ty::Region<'tcx>) {
|
||||
}
|
||||
|
||||
fn super_const(&mut self, _const: $(& $mutability)? ty::Const<'tcx>) {
|
||||
}
|
||||
|
||||
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
|
||||
}
|
||||
|
||||
@ -1088,12 +1077,20 @@ fn process_projection_elem(
|
||||
location,
|
||||
);
|
||||
|
||||
if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
|
||||
if new_local == local {
|
||||
None
|
||||
} else {
|
||||
Some(PlaceElem::Index(new_local))
|
||||
}
|
||||
}
|
||||
PlaceElem::Field(field, ty) => {
|
||||
let mut new_ty = ty;
|
||||
self.visit_ty(&mut new_ty, TyContext::Location(location));
|
||||
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
|
||||
if ty != new_ty {
|
||||
Some(PlaceElem::Field(field, new_ty))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
PlaceElem::Deref
|
||||
| PlaceElem::ConstantIndex { .. }
|
||||
|
@ -795,42 +795,7 @@ fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: Location)
|
||||
}
|
||||
};
|
||||
collect_const_value(self.tcx, val, self.output);
|
||||
self.visit_ty(literal.ty(), TyContext::Location(location));
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_const(&mut self, constant: ty::Const<'tcx>, location: Location) {
|
||||
debug!("visiting const {:?} @ {:?}", constant, location);
|
||||
|
||||
let substituted_constant = self.monomorphize(constant);
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
|
||||
match substituted_constant.kind() {
|
||||
ty::ConstKind::Value(val) => {
|
||||
let const_val = self.tcx.valtree_to_const_val((constant.ty(), val));
|
||||
collect_const_value(self.tcx, const_val, self.output)
|
||||
}
|
||||
ty::ConstKind::Unevaluated(unevaluated) => {
|
||||
match self.tcx.const_eval_resolve(param_env, unevaluated.expand(), None) {
|
||||
// The `monomorphize` call should have evaluated that constant already.
|
||||
Ok(val) => span_bug!(
|
||||
self.body.source_info(location).span,
|
||||
"collection encountered the unevaluated constant {} which evaluated to {:?}",
|
||||
substituted_constant,
|
||||
val
|
||||
),
|
||||
Err(ErrorHandled::Reported(_) | ErrorHandled::Linted) => {}
|
||||
Err(ErrorHandled::TooGeneric) => span_bug!(
|
||||
self.body.source_info(location).span,
|
||||
"collection encountered polymorphic constant: {}",
|
||||
substituted_constant
|
||||
),
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.super_const(constant);
|
||||
MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
|
||||
}
|
||||
|
||||
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
use rustc_index::bit_set::FiniteBitSet;
|
||||
use rustc_middle::mir::{
|
||||
visit::{TyContext, Visitor},
|
||||
ConstantKind, Local, LocalDecl, Location,
|
||||
Constant, ConstantKind, Local, LocalDecl, Location,
|
||||
};
|
||||
use rustc_middle::ty::{
|
||||
self,
|
||||
@ -270,8 +270,15 @@ fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
|
||||
self.super_local_decl(local, local_decl);
|
||||
}
|
||||
|
||||
fn visit_const(&mut self, c: Const<'tcx>, _: Location) {
|
||||
c.visit_with(self);
|
||||
fn visit_constant(&mut self, ct: &Constant<'tcx>, location: Location) {
|
||||
match ct.literal {
|
||||
ConstantKind::Ty(c) => {
|
||||
c.visit_with(self);
|
||||
}
|
||||
ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => {
|
||||
Visitor::visit_ty(self, ty, TyContext::Location(location))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: Ty<'tcx>, _: TyContext) {
|
||||
|
Loading…
Reference in New Issue
Block a user