Skip to content

Commit 2c4d9b9

Browse files
committed
Newtype for InstanceOfArg semi-traversable tuple
1 parent 5d73e5b commit 2c4d9b9

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

compiler/rustc_middle/src/query/keys.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ impl<'tcx> Key for (DefId, GenericArgsRef<'tcx>) {
335335
}
336336
}
337337

338+
impl<'tcx> Key for ty::InstanceOfArg<'tcx> {
339+
type CacheSelector = DefaultCacheSelector<Self>;
340+
341+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
342+
self.0.default_span(tcx)
343+
}
344+
}
345+
338346
impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) {
339347
type CacheSelector = DefaultCacheSelector<Self>;
340348

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,7 @@ rustc_queries! {
21032103
/// from `Ok(None)` to avoid misleading diagnostics when an error
21042104
/// has already been/will be emitted, for the original cause
21052105
query resolve_instance(
2106-
key: ty::ParamEnvAnd<'tcx, (DefId, GenericArgsRef<'tcx>)>
2106+
key: ty::ParamEnvAnd<'tcx, ty::InstanceOfArg<'tcx>>
21072107
) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
21082108
desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
21092109
}

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
334334
}
335335
}
336336

337+
#[derive(Clone, Copy, Debug, Eq, Hash, HashStable, PartialEq, TypeFoldable, TypeVisitable)]
338+
pub struct InstanceOfArg<'tcx>(pub DefId, pub GenericArgsRef<'tcx>);
339+
337340
impl<'tcx> Instance<'tcx> {
338341
pub fn new(def_id: DefId, args: GenericArgsRef<'tcx>) -> Instance<'tcx> {
339342
assert!(
@@ -400,7 +403,7 @@ impl<'tcx> Instance<'tcx> {
400403
// below is more likely to ignore the bounds in scope (e.g. if the only
401404
// generic parameters mentioned by `args` were lifetime ones).
402405
let args = tcx.erase_regions(args);
403-
tcx.resolve_instance(tcx.erase_regions(param_env.and((def_id, args))))
406+
tcx.resolve_instance(tcx.erase_regions(param_env.and(InstanceOfArg(def_id, args))))
404407
}
405408

406409
pub fn expect_resolve(

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ pub use self::consts::{
9090
pub use self::context::{
9191
tls, CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed,
9292
};
93-
pub use self::instance::{Instance, InstanceDef, ShortInstance, UnusedGenericParams};
93+
pub use self::instance::{
94+
Instance, InstanceDef, InstanceOfArg, ShortInstance, UnusedGenericParams,
95+
};
9496
pub use self::list::List;
9597
pub use self::parameterized::ParameterizedOverTcx;
9698
pub use self::rvalue_scopes::RvalueScopes;

compiler/rustc_ty_utils/src/instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use crate::errors::UnexpectedFnPtrAssociatedItem;
1414

1515
fn resolve_instance<'tcx>(
1616
tcx: TyCtxt<'tcx>,
17-
key: ty::ParamEnvAnd<'tcx, (DefId, GenericArgsRef<'tcx>)>,
17+
key: ty::ParamEnvAnd<'tcx, ty::InstanceOfArg<'tcx>>,
1818
) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
19-
let (param_env, (def_id, args)) = key.into_parts();
19+
let (param_env, ty::InstanceOfArg(def_id, args)) = key.into_parts();
2020

2121
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
2222
debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env);

0 commit comments

Comments
 (0)