use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::mir::interpret::{AllocId, ConstValue};
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
-use rustc::ty::subst::{InternalSubsts, SubstsRef};
+use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef};
use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind, Instance};
use rustc::ty::print::obsolete::DefPathBasedNames;
use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast};
_context: mir::visit::PlaceContext,
location: Location) {
match place_base {
- PlaceBase::Static(box Static { kind: StaticKind::Static(def_id), .. }) => {
+ PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }) => {
debug!("visiting static {:?} @ {:?}", def_id, location);
let tcx = self.tcx;
self.output.push(MonoItem::Static(*def_id));
}
}
- PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. }) => {
- // FIXME: should we handle promoteds here instead of eagerly in collect_neighbours?
+ PlaceBase::Static(box Static { kind: StaticKind::Promoted(promoted, substs), def_id, .. }) => {
+ debug!("collecting promoted(def_id: {:?}, promoted: {:?}, substs: {:?})", def_id, promoted, substs);
+ debug!("param_substs: {:?}", self.param_substs);
+ let param_env = ty::ParamEnv::reveal_all();
+ let cid = GlobalId {
+ instance: Instance::new(*def_id, substs.subst(self.tcx, self.param_substs)),
+ promoted: Some(*promoted),
+ };
+ debug!("cid: {:?}", cid);
+ match self.tcx.const_eval(param_env.and(cid)) {
+ Ok(val) => collect_const(self.tcx, val, substs, self.output),
+ Err(ErrorHandled::Reported) => {},
+ Err(ErrorHandled::TooGeneric) => {
+ let span = self.tcx.promoted_mir(*def_id)[*promoted].span;
+ span_bug!(span, "collection encountered polymorphic constant")
+ },
+ }
}
PlaceBase::Local(_) => {
// Locals have no relevance for collector
output,
param_substs: instance.substs,
}.visit_body(&body);
-
- if let ty::InstanceDef::Item(def_id) = instance.def {
- let param_env = ty::ParamEnv::reveal_all();
- let promoted = tcx.promoted_mir(def_id);
- for (promoted, promoted_body) in promoted.iter_enumerated() {
- let cid = GlobalId {
- instance,
- promoted: Some(promoted),
- };
- match tcx.const_eval(param_env.and(cid)) {
- Ok(val) => collect_const(tcx, val, instance.substs, output),
- Err(ErrorHandled::Reported) => {},
- Err(ErrorHandled::TooGeneric) => span_bug!(
- promoted_body.span, "collection encountered polymorphic constant",
- ),
- }
- }
- }
}
fn def_id_to_string(tcx: TyCtxt<'_>, def_id: DefId) -> String {