Skip to content

Commit 372c4fd

Browse files
committed
remove visit_const from mir visitors
1 parent 0726265 commit 372c4fd

File tree

5 files changed

+24
-60
lines changed

5 files changed

+24
-60
lines changed

compiler/rustc_borrowck/src/renumber.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,4 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
106106

107107
debug!("constant: {:#?}", constant);
108108
}
109-
110-
fn visit_const(&mut self, _constant: &mut ty::Const<'tcx>, _location: Location) {
111-
bug!("should never be called");
112-
}
113109
}

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,12 @@ pub fn write_allocations<'tcx>(
706706
struct CollectAllocIds(BTreeSet<AllocId>);
707707

708708
impl<'tcx> Visitor<'tcx> for CollectAllocIds {
709-
fn visit_constant(&mut self, c: &Constant<'tcx>, loc: Location) {
709+
fn visit_constant(&mut self, c: &Constant<'tcx>, _: Location) {
710710
match c.literal {
711-
ConstantKind::Ty(c) => self.visit_const(c, loc),
711+
ConstantKind::Ty(_) | ConstantKind::Unevaluated(..) => {}
712712
ConstantKind::Val(val, _) => {
713713
self.0.extend(alloc_ids_from_const_val(val));
714714
}
715-
ConstantKind::Unevaluated(..) => {}
716715
}
717716
}
718717
}

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,6 @@ macro_rules! make_mir_visitor {
237237
self.super_region(region);
238238
}
239239

240-
fn visit_const(
241-
&mut self,
242-
constant: $(& $mutability)? ty::Const<'tcx>,
243-
_: Location,
244-
) {
245-
self.super_const(constant);
246-
}
247-
248240
fn visit_substs(
249241
&mut self,
250242
substs: & $($mutability)? SubstsRef<'tcx>,
@@ -877,7 +869,7 @@ macro_rules! make_mir_visitor {
877869
self.visit_span($(& $mutability)? *span);
878870
drop(user_ty); // no visit method for this
879871
match literal {
880-
ConstantKind::Ty(ct) => self.visit_const($(& $mutability)? *ct, location),
872+
ConstantKind::Ty(_) => {}
881873
ConstantKind::Val(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
882874
ConstantKind::Unevaluated(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)),
883875
}
@@ -917,9 +909,6 @@ macro_rules! make_mir_visitor {
917909
fn super_region(&mut self, _region: $(& $mutability)? ty::Region<'tcx>) {
918910
}
919911

920-
fn super_const(&mut self, _const: $(& $mutability)? ty::Const<'tcx>) {
921-
}
922-
923912
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
924913
}
925914

@@ -1088,12 +1077,20 @@ macro_rules! visit_place_fns {
10881077
location,
10891078
);
10901079

1091-
if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
1080+
if new_local == local {
1081+
None
1082+
} else {
1083+
Some(PlaceElem::Index(new_local))
1084+
}
10921085
}
10931086
PlaceElem::Field(field, ty) => {
10941087
let mut new_ty = ty;
10951088
self.visit_ty(&mut new_ty, TyContext::Location(location));
1096-
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
1089+
if ty != new_ty {
1090+
Some(PlaceElem::Field(field, new_ty))
1091+
} else {
1092+
None
1093+
}
10971094
}
10981095
PlaceElem::Deref
10991096
| PlaceElem::ConstantIndex { .. }

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -795,42 +795,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
795795
}
796796
};
797797
collect_const_value(self.tcx, val, self.output);
798-
self.visit_ty(literal.ty(), TyContext::Location(location));
799-
}
800-
801-
#[instrument(skip(self), level = "debug")]
802-
fn visit_const(&mut self, constant: ty::Const<'tcx>, location: Location) {
803-
debug!("visiting const {:?} @ {:?}", constant, location);
804-
805-
let substituted_constant = self.monomorphize(constant);
806-
let param_env = ty::ParamEnv::reveal_all();
807-
808-
match substituted_constant.kind() {
809-
ty::ConstKind::Value(val) => {
810-
let const_val = self.tcx.valtree_to_const_val((constant.ty(), val));
811-
collect_const_value(self.tcx, const_val, self.output)
812-
}
813-
ty::ConstKind::Unevaluated(unevaluated) => {
814-
match self.tcx.const_eval_resolve(param_env, unevaluated.expand(), None) {
815-
// The `monomorphize` call should have evaluated that constant already.
816-
Ok(val) => span_bug!(
817-
self.body.source_info(location).span,
818-
"collection encountered the unevaluated constant {} which evaluated to {:?}",
819-
substituted_constant,
820-
val
821-
),
822-
Err(ErrorHandled::Reported(_) | ErrorHandled::Linted) => {}
823-
Err(ErrorHandled::TooGeneric) => span_bug!(
824-
self.body.source_info(location).span,
825-
"collection encountered polymorphic constant: {}",
826-
substituted_constant
827-
),
828-
}
829-
}
830-
_ => {}
831-
}
832-
833-
self.super_const(constant);
798+
MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
834799
}
835800

836801
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {

compiler/rustc_monomorphize/src/polymorphize.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::{def::DefKind, def_id::DefId, ConstContext};
99
use rustc_index::bit_set::FiniteBitSet;
1010
use rustc_middle::mir::{
1111
visit::{TyContext, Visitor},
12-
ConstantKind, Local, LocalDecl, Location,
12+
Constant, ConstantKind, Local, LocalDecl, Location,
1313
};
1414
use rustc_middle::ty::{
1515
self,
@@ -270,8 +270,15 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
270270
self.super_local_decl(local, local_decl);
271271
}
272272

273-
fn visit_const(&mut self, c: Const<'tcx>, _: Location) {
274-
c.visit_with(self);
273+
fn visit_constant(&mut self, ct: &Constant<'tcx>, location: Location) {
274+
match ct.literal {
275+
ConstantKind::Ty(c) => {
276+
c.visit_with(self);
277+
}
278+
ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => {
279+
Visitor::visit_ty(self, ty, TyContext::Location(location))
280+
}
281+
}
275282
}
276283

277284
fn visit_ty(&mut self, ty: Ty<'tcx>, _: TyContext) {

0 commit comments

Comments
 (0)