Skip to content

Commit 8829dda

Browse files
author
Saleem Jaffer
committed
remove visit_static from librustc::mir
1 parent 776407e commit 8829dda

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

src/librustc/mir/visit.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,6 @@ macro_rules! make_mir_visitor {
156156
self.super_place(place, context, location);
157157
}
158158

159-
fn visit_static(&mut self,
160-
static_: & $($mutability)? Static<'tcx>,
161-
context: PlaceContext<'tcx>,
162-
location: Location) {
163-
self.super_static(static_, context, location);
164-
}
165-
166159
fn visit_projection(&mut self,
167160
place: & $($mutability)? PlaceProjection<'tcx>,
168161
context: PlaceContext<'tcx>,
@@ -737,23 +730,17 @@ macro_rules! make_mir_visitor {
737730
self.visit_local(local, context, location);
738731
}
739732
Place::Base(PlaceBase::Static(static_)) => {
740-
self.visit_static(static_, context, location);
733+
if static_.promoted.is_none() {
734+
self.visit_def_id(& $($mutability)? static_.def_id, location);
735+
}
736+
self.visit_ty(& $($mutability)? static_.ty, TyContext::Location(location));
741737
}
742738
Place::Projection(proj) => {
743739
self.visit_projection(proj, context, location);
744740
}
745741
}
746742
}
747743

748-
fn super_static(&mut self,
749-
static_: & $($mutability)? Static<'tcx>,
750-
_context: PlaceContext<'tcx>,
751-
location: Location) {
752-
let Static { def_id, ty, promoted: _ } = static_;
753-
self.visit_def_id(def_id, location);
754-
self.visit_ty(ty, TyContext::Location(location));
755-
}
756-
757744
fn super_projection(&mut self,
758745
proj: & $($mutability)? PlaceProjection<'tcx>,
759746
context: PlaceContext<'tcx>,

src/librustc_mir/monomorphize/collector.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -650,19 +650,26 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
650650
self.super_terminator_kind(block, kind, location);
651651
}
652652

653-
fn visit_static(&mut self,
654-
static_: &mir::Static<'tcx>,
653+
fn visit_place(&mut self,
654+
place: &mir::Place<'tcx>,
655655
context: mir::visit::PlaceContext<'tcx>,
656656
location: Location) {
657-
debug!("visiting static {:?} @ {:?}", static_.def_id, location);
657+
match place {
658+
mir::Place::Base(
659+
mir::PlaceBase::Static(box mir::Static{def_id, promoted:None, ..})
660+
) => {
661+
debug!("visiting static {:?} @ {:?}", def_id, location);
658662

659-
let tcx = self.tcx;
660-
let instance = Instance::mono(tcx, static_.def_id);
661-
if should_monomorphize_locally(tcx, &instance) {
662-
self.output.push(MonoItem::Static(static_.def_id));
663+
let tcx = self.tcx;
664+
let instance = Instance::mono(tcx, *def_id);
665+
if should_monomorphize_locally(tcx, &instance) {
666+
self.output.push(MonoItem::Static(*def_id));
667+
}
668+
}
669+
_ => {}
663670
}
664671

665-
self.super_static(static_, context, location);
672+
self.super_place(place, context, location);
666673
}
667674
}
668675

src/librustc_mir/transform/qualify_min_const_fn.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,10 @@ fn check_place(
256256
) -> McfResult {
257257
match place {
258258
Place::Base(PlaceBase::Local(_)) => Ok(()),
259-
Place::Base(PlaceBase::Static(st)) => {
260-
match st.promoted {
261-
// promoteds are always fine, they are essentially constants
262-
Some(..) => Ok(()),
263-
None => Err((span, "cannot access `static` items in const fn".into())),
264-
}
265-
}
259+
// promoteds are always fine, they are essentially constants
260+
Place::Base(PlaceBase::Static(box Static {def_id: _, ty: _, promoted: Some(_)})) => Ok(()),
261+
Place::Base(PlaceBase::Static(box Static {def_id: _, ty: _, promoted: None})) =>
262+
Err((span, "cannot access `static` items in const fn".into())),
266263
Place::Projection(proj) => {
267264
match proj.elem {
268265
| ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. }

0 commit comments

Comments
 (0)