WithOptConstParam::dummy -> WithOptConstParam::unknown

This commit is contained in:
Bastian Kauschke 2020-07-15 10:55:41 +02:00
parent 8003ccfdcd
commit aca66bd052
12 changed files with 21 additions and 20 deletions

View File

@ -892,7 +892,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
if tcx.hir().body_const_context(def_id).is_some() { if tcx.hir().body_const_context(def_id).is_some() {
tcx.ensure() tcx.ensure()
.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::dummy(def_id)); .mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(def_id));
} }
} }
}); });

View File

@ -196,7 +196,7 @@ impl<'tcx> InstanceDef<'tcx> {
| InstanceDef::Intrinsic(def_id) | InstanceDef::Intrinsic(def_id)
| InstanceDef::ClosureOnceShim { call_once: def_id } | InstanceDef::ClosureOnceShim { call_once: def_id }
| InstanceDef::DropGlue(def_id, _) | InstanceDef::DropGlue(def_id, _)
| InstanceDef::CloneShim(def_id, _) => ty::WithOptConstParam::dummy(def_id), | InstanceDef::CloneShim(def_id, _) => ty::WithOptConstParam::unknown(def_id),
} }
} }
@ -298,7 +298,7 @@ impl<'tcx> Instance<'tcx> {
def_id, def_id,
substs substs
); );
Instance { def: InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), substs } Instance { def: InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)), substs }
} }
pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> { pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {

View File

@ -1613,7 +1613,8 @@ pub struct WithOptConstParam<T> {
} }
impl<T> WithOptConstParam<T> { impl<T> WithOptConstParam<T> {
pub fn dummy(did: T) -> WithOptConstParam<T> { /// Creates a new `WithOptConstParam` setting `const_param_did` to `None`.
pub fn unknown(did: T) -> WithOptConstParam<T> {
WithOptConstParam { did, const_param_did: None } WithOptConstParam { did, const_param_did: None }
} }
} }

View File

@ -2210,7 +2210,7 @@ impl<'tcx> Const<'tcx> {
/// Literals and const generic parameters are eagerly converted to a constant, everything else /// Literals and const generic parameters are eagerly converted to a constant, everything else
/// becomes `Unevaluated`. /// becomes `Unevaluated`.
pub fn from_anon_const(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx Self { pub fn from_anon_const(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx Self {
Self::from_opt_const_arg_anon_const(tcx, ty::WithOptConstParam::dummy(def_id)) Self::from_opt_const_arg_anon_const(tcx, ty::WithOptConstParam::unknown(def_id))
} }
pub fn from_opt_const_arg_anon_const( pub fn from_opt_const_arg_anon_const(

View File

@ -88,7 +88,7 @@ const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref];
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
*providers = Providers { *providers = Providers {
mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptConstParam::dummy(did)), mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptConstParam::unknown(did)),
mir_borrowck_const_arg: |tcx, (did, param_did)| { mir_borrowck_const_arg: |tcx, (did, param_did)| {
mir_borrowck(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) mir_borrowck(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
}, },

View File

@ -491,7 +491,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
pub(crate) fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { *providers = Providers {
unsafety_check_result: |tcx, def_id| { unsafety_check_result: |tcx, def_id| {
unsafety_check_result(tcx, ty::WithOptConstParam::dummy(def_id)) unsafety_check_result(tcx, ty::WithOptConstParam::unknown(def_id))
}, },
unsafety_check_result_const_arg: |tcx, (did, param_did)| { unsafety_check_result_const_arg: |tcx, (did, param_did)| {
unsafety_check_result( unsafety_check_result(

View File

@ -49,7 +49,7 @@ pub(crate) fn provide(providers: &mut Providers) {
mir_keys, mir_keys,
mir_const, mir_const,
mir_const_qualif: |tcx, did| { mir_const_qualif: |tcx, did| {
mir_const_qualif(tcx, ty::WithOptConstParam::dummy(did.expect_local())) mir_const_qualif(tcx, ty::WithOptConstParam::unknown(did.expect_local()))
}, },
mir_const_qualif_const_arg: |tcx, (did, param_did)| { mir_const_qualif_const_arg: |tcx, (did, param_did)| {
mir_const_qualif(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) mir_const_qualif(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
@ -60,7 +60,7 @@ pub(crate) fn provide(providers: &mut Providers) {
optimized_mir_of_const_arg, optimized_mir_of_const_arg,
is_mir_available, is_mir_available,
promoted_mir: |tcx, def_id| { promoted_mir: |tcx, def_id| {
promoted_mir(tcx, ty::WithOptConstParam::dummy(def_id.expect_local())) promoted_mir(tcx, ty::WithOptConstParam::unknown(def_id.expect_local()))
}, },
promoted_mir_of_const_arg: |tcx, (did, param_did)| { promoted_mir_of_const_arg: |tcx, (did, param_did)| {
promoted_mir(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) promoted_mir(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
@ -128,7 +128,7 @@ pub struct MirSource<'tcx> {
impl<'tcx> MirSource<'tcx> { impl<'tcx> MirSource<'tcx> {
pub fn item(def_id: DefId) -> Self { pub fn item(def_id: DefId) -> Self {
MirSource { MirSource {
instance: InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), instance: InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)),
promoted: None, promoted: None,
} }
} }
@ -414,7 +414,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(
run_passes( run_passes(
tcx, tcx,
body, body,
InstanceDef::Item(ty::WithOptConstParam::dummy(def_id.to_def_id())), InstanceDef::Item(ty::WithOptConstParam::unknown(def_id.to_def_id())),
promoted, promoted,
MirPhase::DropElab, MirPhase::DropElab,
&[post_borrowck_cleanup], &[post_borrowck_cleanup],
@ -478,7 +478,7 @@ fn run_optimization_passes<'tcx>(
run_passes( run_passes(
tcx, tcx,
body, body,
InstanceDef::Item(ty::WithOptConstParam::dummy(def_id.to_def_id())), InstanceDef::Item(ty::WithOptConstParam::unknown(def_id.to_def_id())),
promoted, promoted,
MirPhase::Optimized, MirPhase::Optimized,
&[ &[
@ -493,7 +493,7 @@ fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> {
if let Some(param_did) = tcx.opt_const_param_of(did) { if let Some(param_did) = tcx.opt_const_param_of(did) {
tcx.optimized_mir_of_const_arg((did, param_did)) tcx.optimized_mir_of_const_arg((did, param_did))
} else { } else {
tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptConstParam::dummy(did))) tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptConstParam::unknown(did)))
} }
} }

View File

@ -249,7 +249,7 @@ pub fn write_mir_pretty<'tcx>(
for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() { for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() {
writeln!(w)?; writeln!(w)?;
let src = MirSource { let src = MirSource {
instance: ty::InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), instance: ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)),
promoted: Some(i), promoted: Some(i),
}; };
write_mir_fn(tcx, src, body, &mut |_, _| Ok(()), w)?; write_mir_fn(tcx, src, body, &mut |_, _| Ok(()), w)?;

View File

@ -601,7 +601,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
let substs = InternalSubsts::identity_for_item(cx.tcx(), did); let substs = InternalSubsts::identity_for_item(cx.tcx(), did);
let lhs = mk_const(cx.tcx().mk_const(ty::Const { let lhs = mk_const(cx.tcx().mk_const(ty::Const {
val: ty::ConstKind::Unevaluated( val: ty::ConstKind::Unevaluated(
ty::WithOptConstParam::dummy(did), ty::WithOptConstParam::unknown(did),
substs, substs,
None, None,
), ),
@ -801,7 +801,7 @@ fn convert_path_expr<'a, 'tcx>(
ExprKind::Literal { ExprKind::Literal {
literal: cx.tcx.mk_const(ty::Const { literal: cx.tcx.mk_const(ty::Const {
val: ty::ConstKind::Unevaluated( val: ty::ConstKind::Unevaluated(
ty::WithOptConstParam::dummy(def_id), ty::WithOptConstParam::unknown(def_id),
substs, substs,
None, None,
), ),

View File

@ -21,7 +21,7 @@ fn resolve_instance<'tcx>(
} }
} }
inner_resolve_instance(tcx, param_env.and((ty::WithOptConstParam::dummy(did), substs))) inner_resolve_instance(tcx, param_env.and((ty::WithOptConstParam::unknown(did), substs)))
} }
fn resolve_instance_of_const_arg<'tcx>( fn resolve_instance_of_const_arg<'tcx>(
@ -210,7 +210,7 @@ fn resolve_associated_item<'tcx>(
Some(ty::Instance::new(leaf_def.item.def_id, substs)) Some(ty::Instance::new(leaf_def.item.def_id, substs))
} }
traits::ImplSourceGenerator(generator_data) => Some(Instance { traits::ImplSourceGenerator(generator_data) => Some(Instance {
def: ty::InstanceDef::Item(ty::WithOptConstParam::dummy( def: ty::InstanceDef::Item(ty::WithOptConstParam::unknown(
generator_data.generator_def_id, generator_data.generator_def_id,
)), )),
substs: generator_data.substs, substs: generator_data.substs,

View File

@ -424,7 +424,7 @@ fn check_type_defn<'tcx, F>(
cause, cause,
fcx.param_env, fcx.param_env,
ty::PredicateKind::ConstEvaluatable( ty::PredicateKind::ConstEvaluatable(
ty::WithOptConstParam::dummy(discr_def_id.to_def_id()), ty::WithOptConstParam::unknown(discr_def_id.to_def_id()),
discr_substs, discr_substs,
) )
.to_predicate(fcx.tcx), .to_predicate(fcx.tcx),

View File

@ -332,7 +332,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
let result = self let result = self
.lcx .lcx
.tcx .tcx
.const_eval_resolve(self.param_env, ty::WithOptConstParam::dummy(def_id), substs, None, None) .const_eval_resolve(self.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None)
.ok() .ok()
.map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?;
let result = miri_to_const(&result); let result = miri_to_const(&result);