Skip to content

Commit 0b83a5a

Browse files
committed
ty/instance: use ParamEnvAnd in the resolve_instance query.
1 parent 339a938 commit 0b83a5a

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/librustc_middle/query/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,10 @@ rustc_queries! {
12581258
desc { "looking up enabled feature gates" }
12591259
}
12601260

1261-
query resolve_instance(key: (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>)) -> Option<ty::Instance<'tcx>> {
1262-
desc { "resolving instance `{:?}` `{:?}` with {:?}", key.1, key.2, key.0 }
1261+
query resolve_instance(
1262+
key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1263+
) -> Option<ty::Instance<'tcx>> {
1264+
desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
12631265
}
12641266
}
12651267
}

src/librustc_middle/ty/instance.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,14 @@ impl<'tcx> Instance<'tcx> {
290290
) -> Option<Instance<'tcx>> {
291291
// All regions in the result of this query are erased, so it's
292292
// fine to erase all of the input regions.
293-
tcx.resolve_instance((tcx.erase_regions(&param_env), def_id, tcx.erase_regions(&substs)))
293+
294+
// HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)`
295+
// below is more likely to ignore the bounds in scope (e.g. if the only
296+
// generic parameters mentioned by `substs` were lifetime ones).
297+
let substs = tcx.erase_regions(&substs);
298+
299+
// FIXME(eddyb) should this always use `param_env.with_reveal_all()`?
300+
tcx.resolve_instance(tcx.erase_regions(&param_env.and((def_id, substs))))
294301
}
295302

296303
pub fn resolve_for_fn_ptr(

src/librustc_middle/ty/query/keys.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,3 @@ impl Key for (Symbol, u32, u32) {
296296
DUMMY_SP
297297
}
298298
}
299-
300-
impl<'tcx> Key for (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>) {
301-
type CacheSelector = DefaultCacheSelector;
302-
303-
fn query_crate(&self) -> CrateNum {
304-
self.1.krate
305-
}
306-
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
307-
tcx.def_span(self.1)
308-
}
309-
}

src/librustc_ty/instance.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ use traits::{translate_substs, Reveal};
99

1010
use log::debug;
1111

12-
pub fn resolve_instance<'tcx>(
12+
fn resolve_instance<'tcx>(
1313
tcx: TyCtxt<'tcx>,
14-
(param_env, def_id, substs): (ty::ParamEnv<'tcx>, DefId, SubstsRef<'tcx>),
14+
key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>,
1515
) -> Option<Instance<'tcx>> {
16+
let (param_env, (def_id, substs)) = key.into_parts();
17+
1618
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
1719
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
1820
debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env);

0 commit comments

Comments
 (0)