unify Instance::resolve

This commit is contained in:
Bastian Kauschke 2020-07-15 11:45:01 +02:00
parent e070b45e6a
commit 2666aed498
2 changed files with 16 additions and 13 deletions

View File

@ -39,7 +39,7 @@ impl<'tcx> TyCtxt<'tcx> {
promoted: Option<mir::Promoted>,
span: Option<Span>,
) -> ConstEvalResult<'tcx> {
match ty::Instance::resolve_const_arg(self, param_env, def, substs) {
match ty::Instance::resolve_opt_const_arg(self, param_env, def, substs) {
Ok(Some(instance)) => {
let cid = GlobalId { instance, promoted };
self.const_eval_global_id(param_env, cid, span)

View File

@ -338,6 +338,21 @@ impl<'tcx> Instance<'tcx> {
param_env: ty::ParamEnv<'tcx>,
def_id: DefId,
substs: SubstsRef<'tcx>,
) -> Result<Option<Instance<'tcx>>, ErrorReported> {
Instance::resolve_opt_const_arg(
tcx,
param_env,
ty::WithOptConstParam::unknown(def_id),
substs,
)
}
// This should be kept up to date with `resolve`.
pub fn resolve_opt_const_arg(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
def: ty::WithOptConstParam<DefId>,
substs: SubstsRef<'tcx>,
) -> Result<Option<Instance<'tcx>>, ErrorReported> {
// All regions in the result of this query are erased, so it's
// fine to erase all of the input regions.
@ -348,18 +363,6 @@ impl<'tcx> Instance<'tcx> {
let substs = tcx.erase_regions(&substs);
// FIXME(eddyb) should this always use `param_env.with_reveal_all()`?
tcx.resolve_instance(tcx.erase_regions(&param_env.and((def_id, substs))))
}
// This should be kept up to date with `resolve`.
pub fn resolve_const_arg(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
def: ty::WithOptConstParam<DefId>,
substs: SubstsRef<'tcx>,
) -> Result<Option<Instance<'tcx>>, ErrorReported> {
let substs = tcx.erase_regions(&substs);
if let Some((did, param_did)) = def.as_const_arg() {
tcx.resolve_instance_of_const_arg(
tcx.erase_regions(&param_env.and((did, param_did, substs))),