Skip to content

Commit 2666aed

Browse files
committed
unify Instance::resolve
1 parent e070b45 commit 2666aed

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/librustc_middle/mir/interpret/queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'tcx> TyCtxt<'tcx> {
3939
promoted: Option<mir::Promoted>,
4040
span: Option<Span>,
4141
) -> ConstEvalResult<'tcx> {
42-
match ty::Instance::resolve_const_arg(self, param_env, def, substs) {
42+
match ty::Instance::resolve_opt_const_arg(self, param_env, def, substs) {
4343
Ok(Some(instance)) => {
4444
let cid = GlobalId { instance, promoted };
4545
self.const_eval_global_id(param_env, cid, span)

src/librustc_middle/ty/instance.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -339,27 +339,30 @@ impl<'tcx> Instance<'tcx> {
339339
def_id: DefId,
340340
substs: SubstsRef<'tcx>,
341341
) -> Result<Option<Instance<'tcx>>, ErrorReported> {
342-
// All regions in the result of this query are erased, so it's
343-
// fine to erase all of the input regions.
344-
345-
// HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)`
346-
// below is more likely to ignore the bounds in scope (e.g. if the only
347-
// generic parameters mentioned by `substs` were lifetime ones).
348-
let substs = tcx.erase_regions(&substs);
349-
350-
// FIXME(eddyb) should this always use `param_env.with_reveal_all()`?
351-
tcx.resolve_instance(tcx.erase_regions(&param_env.and((def_id, substs))))
342+
Instance::resolve_opt_const_arg(
343+
tcx,
344+
param_env,
345+
ty::WithOptConstParam::unknown(def_id),
346+
substs,
347+
)
352348
}
353349

354350
// This should be kept up to date with `resolve`.
355-
pub fn resolve_const_arg(
351+
pub fn resolve_opt_const_arg(
356352
tcx: TyCtxt<'tcx>,
357353
param_env: ty::ParamEnv<'tcx>,
358354
def: ty::WithOptConstParam<DefId>,
359355
substs: SubstsRef<'tcx>,
360356
) -> Result<Option<Instance<'tcx>>, ErrorReported> {
357+
// All regions in the result of this query are erased, so it's
358+
// fine to erase all of the input regions.
359+
360+
// HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)`
361+
// below is more likely to ignore the bounds in scope (e.g. if the only
362+
// generic parameters mentioned by `substs` were lifetime ones).
361363
let substs = tcx.erase_regions(&substs);
362364

365+
// FIXME(eddyb) should this always use `param_env.with_reveal_all()`?
363366
if let Some((did, param_did)) = def.as_const_arg() {
364367
tcx.resolve_instance_of_const_arg(
365368
tcx.erase_regions(&param_env.and((did, param_did, substs))),

0 commit comments

Comments
 (0)