Remove WithOptconstParam.
This commit is contained in:
parent
0e017fc94a
commit
b275d2c30b
68 changed files with 335 additions and 960 deletions
|
@ -132,7 +132,7 @@ fn recurse_build<'tcx>(
|
|||
tcx.mk_const(val, node.ty)
|
||||
}
|
||||
&ExprKind::NamedConst { def_id, substs, user_ty: _ } => {
|
||||
let uneval = ty::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);
|
||||
let uneval = ty::UnevaluatedConst::new(def_id, substs);
|
||||
tcx.mk_const(uneval, node.ty)
|
||||
}
|
||||
ExprKind::ConstParam { param, .. } => tcx.mk_const(*param, node.ty),
|
||||
|
@ -391,52 +391,36 @@ impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
|
|||
/// Builds an abstract const, do not use this directly, but use `AbstractConst::new` instead.
|
||||
pub fn thir_abstract_const(
|
||||
tcx: TyCtxt<'_>,
|
||||
def: ty::WithOptConstParam<LocalDefId>,
|
||||
def: LocalDefId,
|
||||
) -> Result<Option<ty::Const<'_>>, ErrorGuaranteed> {
|
||||
if tcx.features().generic_const_exprs {
|
||||
match tcx.def_kind(def.did) {
|
||||
// FIXME(generic_const_exprs): We currently only do this for anonymous constants,
|
||||
// meaning that we do not look into associated constants. I(@lcnr) am not yet sure whether
|
||||
// we want to look into them or treat them as opaque projections.
|
||||
//
|
||||
// Right now we do neither of that and simply always fail to unify them.
|
||||
DefKind::AnonConst | DefKind::InlineConst => (),
|
||||
_ => return Ok(None),
|
||||
}
|
||||
|
||||
let body = tcx.thir_body(def)?;
|
||||
let (body, body_id) = (&*body.0.borrow(), body.1);
|
||||
|
||||
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body };
|
||||
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
|
||||
if !is_poly_vis.is_poly {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let root_span = body.exprs[body_id].span;
|
||||
|
||||
Some(recurse_build(tcx, body, body_id, root_span)).transpose()
|
||||
} else {
|
||||
Ok(None)
|
||||
if !tcx.features().generic_const_exprs {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
match tcx.def_kind(def) {
|
||||
// FIXME(generic_const_exprs): We currently only do this for anonymous constants,
|
||||
// meaning that we do not look into associated constants. I(@lcnr) am not yet sure whether
|
||||
// we want to look into them or treat them as opaque projections.
|
||||
//
|
||||
// Right now we do neither of that and simply always fail to unify them.
|
||||
DefKind::AnonConst | DefKind::InlineConst => (),
|
||||
_ => return Ok(None),
|
||||
}
|
||||
|
||||
let body = tcx.thir_body(def)?;
|
||||
let (body, body_id) = (&*body.0.borrow(), body.1);
|
||||
|
||||
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body };
|
||||
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
|
||||
if !is_poly_vis.is_poly {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let root_span = body.exprs[body_id].span;
|
||||
|
||||
Some(recurse_build(tcx, body, body_id, root_span)).transpose()
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
*providers = ty::query::Providers {
|
||||
destructure_const,
|
||||
thir_abstract_const: |tcx, def_id| {
|
||||
if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
|
||||
tcx.thir_abstract_const_of_const_arg(def)
|
||||
} else {
|
||||
thir_abstract_const(tcx, ty::WithOptConstParam::unknown(def_id))
|
||||
}
|
||||
},
|
||||
thir_abstract_const_of_const_arg: |tcx, (did, param_did)| {
|
||||
thir_abstract_const(
|
||||
tcx,
|
||||
ty::WithOptConstParam { did, const_param_did: Some(param_did) },
|
||||
)
|
||||
},
|
||||
..*providers
|
||||
};
|
||||
*providers = ty::query::Providers { destructure_const, thir_abstract_const, ..*providers };
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_middle::traits::CodegenObligationError;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
|
@ -13,49 +13,27 @@ use crate::errors::UnexpectedFnPtrAssociatedItem;
|
|||
fn resolve_instance<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>,
|
||||
) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
|
||||
let (param_env, (did, substs)) = key.into_parts();
|
||||
inner_resolve_instance(tcx, param_env.and((ty::WithOptConstParam::unknown(did), substs)))
|
||||
}
|
||||
|
||||
fn resolve_instance_of_const_arg<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>,
|
||||
) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
|
||||
let (param_env, (did, const_param_did, substs)) = key.into_parts();
|
||||
inner_resolve_instance(
|
||||
tcx,
|
||||
param_env.and((
|
||||
ty::WithOptConstParam { did: did.to_def_id(), const_param_did: Some(const_param_did) },
|
||||
substs,
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
||||
fn inner_resolve_instance<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
key: ty::ParamEnvAnd<'tcx, (ty::WithOptConstParam<DefId>, SubstsRef<'tcx>)>,
|
||||
) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
|
||||
let (param_env, (def, substs)) = key.into_parts();
|
||||
|
||||
let result = if let Some(trait_def_id) = tcx.trait_of_item(def.did) {
|
||||
let result = if let Some(trait_def_id) = tcx.trait_of_item(def) {
|
||||
debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env);
|
||||
resolve_associated_item(
|
||||
tcx,
|
||||
def.did,
|
||||
def,
|
||||
param_env,
|
||||
trait_def_id,
|
||||
tcx.normalize_erasing_regions(param_env, substs),
|
||||
)
|
||||
} else {
|
||||
let ty = tcx.type_of(def.def_id_for_type_of());
|
||||
let ty = tcx.type_of(def);
|
||||
let item_type =
|
||||
tcx.subst_and_normalize_erasing_regions(substs, param_env, ty.skip_binder());
|
||||
|
||||
let def = match *item_type.kind() {
|
||||
ty::FnDef(def_id, ..) if tcx.is_intrinsic(def_id) => {
|
||||
debug!(" => intrinsic");
|
||||
ty::InstanceDef::Intrinsic(def.did)
|
||||
ty::InstanceDef::Intrinsic(def)
|
||||
}
|
||||
ty::FnDef(def_id, substs) if Some(def_id) == tcx.lang_items().drop_in_place_fn() => {
|
||||
let ty = substs.type_at(0);
|
||||
|
@ -200,15 +178,11 @@ fn resolve_associated_item<'tcx>(
|
|||
Some(ty::Instance::new(leaf_def.item.def_id, substs))
|
||||
}
|
||||
traits::ImplSource::Generator(generator_data) => Some(Instance {
|
||||
def: ty::InstanceDef::Item(ty::WithOptConstParam::unknown(
|
||||
generator_data.generator_def_id,
|
||||
)),
|
||||
def: ty::InstanceDef::Item(generator_data.generator_def_id),
|
||||
substs: generator_data.substs,
|
||||
}),
|
||||
traits::ImplSource::Future(future_data) => Some(Instance {
|
||||
def: ty::InstanceDef::Item(ty::WithOptConstParam::unknown(
|
||||
future_data.generator_def_id,
|
||||
)),
|
||||
def: ty::InstanceDef::Item(future_data.generator_def_id),
|
||||
substs: future_data.substs,
|
||||
}),
|
||||
traits::ImplSource::Closure(closure_data) => {
|
||||
|
@ -292,6 +266,5 @@ fn resolve_associated_item<'tcx>(
|
|||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
*providers =
|
||||
ty::query::Providers { resolve_instance, resolve_instance_of_const_arg, ..*providers };
|
||||
*providers = ty::query::Providers { resolve_instance, ..*providers };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue