From 93de838a90cb45eee3d6dcd785093477eb618274 Mon Sep 17 00:00:00 2001 From: Steven Malis Date: Thu, 23 Oct 2025 21:48:43 -0400 Subject: [PATCH] Add a lot more db lifetimes --- crates/hir-ty/src/db.rs | 6 +- crates/hir-ty/src/dyn_compatibility.rs | 4 +- crates/hir-ty/src/infer.rs | 4 +- crates/hir-ty/src/infer/unify.rs | 6 +- crates/hir-ty/src/lower.rs | 4 +- crates/hir-ty/src/next_solver/consts.rs | 2 +- crates/hir-ty/src/next_solver/def_id.rs | 135 +++++++++++++----- crates/hir-ty/src/next_solver/fold.rs | 12 +- crates/hir-ty/src/next_solver/fulfill.rs | 2 +- .../hir-ty/src/next_solver/fulfill/errors.rs | 2 +- crates/hir-ty/src/next_solver/generic_arg.rs | 6 +- crates/hir-ty/src/next_solver/generics.rs | 2 +- .../infer/canonical/instantiate.rs | 4 +- .../src/next_solver/infer/canonical/mod.rs | 2 +- .../hir-ty/src/next_solver/infer/context.rs | 2 +- crates/hir-ty/src/next_solver/infer/mod.rs | 18 +-- .../infer/region_constraints/mod.rs | 2 +- .../next_solver/infer/relate/generalize.rs | 2 +- .../next_solver/infer/relate/higher_ranked.rs | 4 +- crates/hir-ty/src/next_solver/infer/select.rs | 2 +- .../src/next_solver/infer/snapshot/fudge.rs | 12 +- .../src/next_solver/infer/type_variable.rs | 20 +-- crates/hir-ty/src/next_solver/interner.rs | 48 +++---- crates/hir-ty/src/next_solver/opaques.rs | 2 +- crates/hir-ty/src/next_solver/region.rs | 40 +++--- crates/hir-ty/src/next_solver/solver.rs | 4 +- crates/hir-ty/src/next_solver/ty.rs | 28 ++-- crates/hir-ty/src/next_solver/util.rs | 15 +- crates/hir/src/lib.rs | 2 +- crates/query-group-macro/src/queries.rs | 24 +++- 30 files changed, 247 insertions(+), 169 deletions(-) diff --git a/crates/hir-ty/src/db.rs b/crates/hir-ty/src/db.rs index 9b58abbe4f92..2e11ef397b56 100644 --- a/crates/hir-ty/src/db.rs +++ b/crates/hir-ty/src/db.rs @@ -277,7 +277,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { // Interned IDs for solver integration #[salsa::interned] - fn intern_impl_trait_id(&self, id: ImplTraitId<'_>) -> InternedOpaqueTyId; + fn intern_impl_trait_id<'db>(&'db self, id: ImplTraitId<'db>) -> InternedOpaqueTyId<'db>; #[salsa::interned] fn intern_closure(&self, id: InternedClosure) -> InternedClosureId; @@ -319,9 +319,9 @@ pub struct InternedConstParamId { pub loc: ConstParamId, } -#[salsa_macros::interned(no_lifetime, debug, revisions = usize::MAX)] +#[salsa_macros::interned(debug, revisions = usize::MAX)] #[derive(PartialOrd, Ord)] -pub struct InternedOpaqueTyId { +pub struct InternedOpaqueTyId<'db> { pub loc: ImplTraitId<'db>, } diff --git a/crates/hir-ty/src/dyn_compatibility.rs b/crates/hir-ty/src/dyn_compatibility.rs index 437141e41db9..3d06fbb30f99 100644 --- a/crates/hir-ty/src/dyn_compatibility.rs +++ b/crates/hir-ty/src/dyn_compatibility.rs @@ -495,9 +495,9 @@ fn contains_illegal_impl_trait_in_trait<'db>( db: &'db dyn HirDatabase, sig: &EarlyBinder<'db, Binder<'db, rustc_type_ir::FnSig>>>, ) -> Option { - struct OpaqueTypeCollector(FxHashSet); + struct OpaqueTypeCollector<'x>(FxHashSet>); - impl<'db> rustc_type_ir::TypeVisitor> for OpaqueTypeCollector { + impl<'db> rustc_type_ir::TypeVisitor> for OpaqueTypeCollector<'db> { type Result = ControlFlow<()>; fn visit_ty( diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs index 21b6e053cc3b..1f546b1b3404 100644 --- a/crates/hir-ty/src/infer.rs +++ b/crates/hir-ty/src/infer.rs @@ -1282,8 +1282,8 @@ impl<'body, 'db> InferenceContext<'body, 'db> { struct TypeAliasImplTraitCollector<'a, 'db> { db: &'a dyn HirDatabase, table: &'a mut InferenceTable<'db>, - assocs: FxHashMap)>, - non_assocs: FxHashMap>, + assocs: FxHashMap, (ImplId, Ty<'db>)>, + non_assocs: FxHashMap, Ty<'db>>, } impl<'db> TypeVisitor> for TypeAliasImplTraitCollector<'_, 'db> { diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index a18cdda559d0..adf97ae85843 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -158,7 +158,7 @@ fn could_unify_impl<'db>( pub(crate) struct InferenceTable<'db> { pub(crate) db: &'db dyn HirDatabase, pub(crate) trait_env: Arc>, - pub(crate) tait_coercion_table: Option>>, + pub(crate) tait_coercion_table: Option, Ty<'db>>>, pub(crate) infer_ctxt: InferCtxt<'db>, pub(super) fulfillment_cx: FulfillmentCtxt<'db>, pub(super) diverging_type_vars: FxHashSet>, @@ -478,14 +478,14 @@ impl<'db> InferenceTable<'db> { } /// Create a `GenericArgs` full of infer vars for `def`. - pub(crate) fn fresh_args_for_item(&self, def: SolverDefId) -> GenericArgs<'db> { + pub(crate) fn fresh_args_for_item(&self, def: SolverDefId<'db>) -> GenericArgs<'db> { self.infer_ctxt.fresh_args_for_item(def) } /// Like `fresh_args_for_item()`, but first uses the args from `first`. pub(crate) fn fill_rest_fresh_args( &self, - def_id: SolverDefId, + def_id: SolverDefId<'db>, first: impl IntoIterator>, ) -> GenericArgs<'db> { self.infer_ctxt.fill_rest_fresh_args(def_id, first) diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index 6f7ca4829d52..a9de61bcd14b 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -480,7 +480,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> { |f| ImplTraitId::ReturnTypeImplTrait(f, Idx::from_raw(idx.into_raw())), |a| ImplTraitId::TypeAliasImplTrait(a, Idx::from_raw(idx.into_raw())), ); - let opaque_ty_id: SolverDefId = + let opaque_ty_id: SolverDefId<'db> = self.db.intern_impl_trait_id(impl_trait_id).into(); // We don't want to lower the bounds inside the binders @@ -879,7 +879,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> { fn lower_impl_trait( &mut self, - def_id: SolverDefId, + def_id: SolverDefId<'db>, bounds: &[TypeBound], krate: Crate, ) -> ImplTrait<'db> { diff --git a/crates/hir-ty/src/next_solver/consts.rs b/crates/hir-ty/src/next_solver/consts.rs index 926dbdc03d03..3bd6dd9a1f89 100644 --- a/crates/hir-ty/src/next_solver/consts.rs +++ b/crates/hir-ty/src/next_solver/consts.rs @@ -397,7 +397,7 @@ impl<'db> rustc_type_ir::inherent::BoundVarLike> for BoundConst self.var } - fn assert_eq(self, var: BoundVarKind) { + fn assert_eq(self, var: BoundVarKind<'db>) { var.expect_const() } } diff --git a/crates/hir-ty/src/next_solver/def_id.rs b/crates/hir-ty/src/next_solver/def_id.rs index 928e1321e738..cea1eed8d06c 100644 --- a/crates/hir-ty/src/next_solver/def_id.rs +++ b/crates/hir-ty/src/next_solver/def_id.rs @@ -5,7 +5,6 @@ use hir_def::{ GeneralConstId, GenericDefId, ImplId, StaticId, StructId, TraitId, TypeAliasId, UnionId, }; use rustc_type_ir::inherent; -use stdx::impl_from; use crate::db::{InternedClosureId, InternedCoroutineId, InternedOpaqueTyId}; @@ -18,7 +17,7 @@ pub enum Ctor { } #[derive(PartialOrd, Ord, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)] -pub enum SolverDefId { +pub enum SolverDefId<'db> { AdtId(AdtId), ConstId(ConstId), FunctionId(FunctionId), @@ -28,13 +27,13 @@ pub enum SolverDefId { TypeAliasId(TypeAliasId), InternedClosureId(InternedClosureId), InternedCoroutineId(InternedCoroutineId), - InternedOpaqueTyId(InternedOpaqueTyId), + InternedOpaqueTyId(InternedOpaqueTyId<'db>), EnumVariantId(EnumVariantId), // FIXME(next-solver): Do we need the separation of `Ctor`? It duplicates some variants. Ctor(Ctor), } -impl std::fmt::Debug for SolverDefId { +impl<'db> std::fmt::Debug for SolverDefId<'db> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let interner = DbInterner::conjure(); let db = interner.db; @@ -102,23 +101,83 @@ impl std::fmt::Debug for SolverDefId { } } -impl_from!( - AdtId(StructId, EnumId, UnionId), - ConstId, - FunctionId, - ImplId, - StaticId, - TraitId, - TypeAliasId, - InternedClosureId, - InternedCoroutineId, - InternedOpaqueTyId, - EnumVariantId, - Ctor - for SolverDefId -); +impl<'db> From for SolverDefId<'db> { + fn from(it: AdtId) -> SolverDefId<'db> { + SolverDefId::AdtId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: StructId) -> SolverDefId<'db> { + SolverDefId::AdtId(AdtId::StructId(it)) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: EnumId) -> SolverDefId<'db> { + SolverDefId::AdtId(AdtId::EnumId(it)) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: UnionId) -> SolverDefId<'db> { + SolverDefId::AdtId(AdtId::UnionId(it)) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: ConstId) -> SolverDefId<'db> { + SolverDefId::ConstId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: FunctionId) -> SolverDefId<'db> { + SolverDefId::FunctionId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: ImplId) -> SolverDefId<'db> { + SolverDefId::ImplId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: StaticId) -> SolverDefId<'db> { + SolverDefId::StaticId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: TraitId) -> SolverDefId<'db> { + SolverDefId::TraitId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: TypeAliasId) -> SolverDefId<'db> { + SolverDefId::TypeAliasId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: InternedClosureId) -> SolverDefId<'db> { + SolverDefId::InternedClosureId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: InternedCoroutineId) -> SolverDefId<'db> { + SolverDefId::InternedCoroutineId(it) + } +} +impl<'db> From> for SolverDefId<'db> { + fn from(it: InternedOpaqueTyId<'db>) -> SolverDefId<'db> { + SolverDefId::InternedOpaqueTyId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: EnumVariantId) -> SolverDefId<'db> { + SolverDefId::EnumVariantId(it) + } +} +impl<'db> From for SolverDefId<'db> { + fn from(it: Ctor) -> SolverDefId<'db> { + SolverDefId::Ctor(it) + } +} -impl From for SolverDefId { +impl<'db> From for SolverDefId<'db> { fn from(value: GenericDefId) -> Self { match value { GenericDefId::AdtId(adt_id) => SolverDefId::AdtId(adt_id), @@ -132,7 +191,7 @@ impl From for SolverDefId { } } -impl From for SolverDefId { +impl<'db> From for SolverDefId<'db> { #[inline] fn from(value: GeneralConstId) -> Self { match value { @@ -142,7 +201,7 @@ impl From for SolverDefId { } } -impl From for SolverDefId { +impl<'db> From for SolverDefId<'db> { #[inline] fn from(value: DefWithBodyId) -> Self { match value { @@ -154,10 +213,10 @@ impl From for SolverDefId { } } -impl TryFrom for GenericDefId { +impl<'db> TryFrom> for GenericDefId { type Error = (); - fn try_from(value: SolverDefId) -> Result { + fn try_from(value: SolverDefId<'db>) -> Result { Ok(match value { SolverDefId::AdtId(adt_id) => GenericDefId::AdtId(adt_id), SolverDefId::ConstId(const_id) => GenericDefId::ConstId(const_id), @@ -175,10 +234,10 @@ impl TryFrom for GenericDefId { } } -impl SolverDefId { +impl<'db> SolverDefId<'db> { #[inline] #[track_caller] - pub fn expect_opaque_ty(self) -> InternedOpaqueTyId { + pub fn expect_opaque_ty(self) -> InternedOpaqueTyId<'db> { match self { SolverDefId::InternedOpaqueTyId(it) => it, _ => panic!("expected opaque type, found {self:?}"), @@ -195,8 +254,8 @@ impl SolverDefId { } } -impl<'db> inherent::DefId> for SolverDefId { - fn as_local(self) -> Option { +impl<'db> inherent::DefId> for SolverDefId<'db> { + fn as_local(self) -> Option> { Some(self) } fn is_local(self) -> bool { @@ -229,18 +288,18 @@ macro_rules! declare_id_wrapper { } } - impl From<$name> for SolverDefId { + impl<'db> From<$name> for SolverDefId<'db> { #[inline] - fn from(value: $name) -> SolverDefId { + fn from(value: $name) -> SolverDefId<'db> { value.0.into() } } - impl TryFrom for $name { + impl<'db> TryFrom> for $name { type Error = (); #[inline] - fn try_from(value: SolverDefId) -> Result { + fn try_from(value: SolverDefId<'db>) -> Result { match value { SolverDefId::$wraps(it) => Ok(Self(it)), _ => Err(()), @@ -249,7 +308,7 @@ macro_rules! declare_id_wrapper { } impl<'db> inherent::DefId> for $name { - fn as_local(self) -> Option { + fn as_local(self) -> Option> { Some(self.into()) } fn is_local(self) -> bool { @@ -286,9 +345,9 @@ impl From for CallableIdWrapper { Self(value) } } -impl From for SolverDefId { +impl<'db> From for SolverDefId<'db> { #[inline] - fn from(value: CallableIdWrapper) -> SolverDefId { + fn from(value: CallableIdWrapper) -> SolverDefId<'db> { match value.0 { CallableDefId::FunctionId(it) => it.into(), CallableDefId::StructId(it) => Ctor::Struct(it).into(), @@ -296,10 +355,10 @@ impl From for SolverDefId { } } } -impl TryFrom for CallableIdWrapper { +impl<'db> TryFrom> for CallableIdWrapper { type Error = (); #[inline] - fn try_from(value: SolverDefId) -> Result { + fn try_from(value: SolverDefId<'db>) -> Result { match value { SolverDefId::FunctionId(it) => Ok(Self(it.into())), SolverDefId::Ctor(Ctor::Struct(it)) => Ok(Self(it.into())), @@ -309,7 +368,7 @@ impl TryFrom for CallableIdWrapper { } } impl<'db> inherent::DefId> for CallableIdWrapper { - fn as_local(self) -> Option { + fn as_local(self) -> Option> { Some(self.into()) } fn is_local(self) -> bool { diff --git a/crates/hir-ty/src/next_solver/fold.rs b/crates/hir-ty/src/next_solver/fold.rs index f776b6ecfc43..517fc835904d 100644 --- a/crates/hir-ty/src/next_solver/fold.rs +++ b/crates/hir-ty/src/next_solver/fold.rs @@ -17,8 +17,8 @@ use super::{ /// gets mapped to the same result. `BoundVarReplacer` caches by using /// a `DelayedMap` which does not cache the first few types it encounters. pub trait BoundVarReplacerDelegate<'db> { - fn replace_region(&mut self, br: BoundRegion) -> Region<'db>; - fn replace_ty(&mut self, bt: BoundTy) -> Ty<'db>; + fn replace_region(&mut self, br: BoundRegion<'db>) -> Region<'db>; + fn replace_ty(&mut self, bt: BoundTy<'db>) -> Ty<'db>; fn replace_const(&mut self, bv: BoundConst) -> Const<'db>; } @@ -26,16 +26,16 @@ pub trait BoundVarReplacerDelegate<'db> { /// always return the same result for each bound variable, no matter how /// frequently they are called. pub struct FnMutDelegate<'db, 'a> { - pub regions: &'a mut (dyn FnMut(BoundRegion) -> Region<'db> + 'a), - pub types: &'a mut (dyn FnMut(BoundTy) -> Ty<'db> + 'a), + pub regions: &'a mut (dyn FnMut(BoundRegion<'db>) -> Region<'db> + 'a), + pub types: &'a mut (dyn FnMut(BoundTy<'db>) -> Ty<'db> + 'a), pub consts: &'a mut (dyn FnMut(BoundConst) -> Const<'db> + 'a), } impl<'db, 'a> BoundVarReplacerDelegate<'db> for FnMutDelegate<'db, 'a> { - fn replace_region(&mut self, br: BoundRegion) -> Region<'db> { + fn replace_region(&mut self, br: BoundRegion<'db>) -> Region<'db> { (self.regions)(br) } - fn replace_ty(&mut self, bt: BoundTy) -> Ty<'db> { + fn replace_ty(&mut self, bt: BoundTy<'db>) -> Ty<'db> { (self.types)(bt) } fn replace_const(&mut self, bv: BoundConst) -> Const<'db> { diff --git a/crates/hir-ty/src/next_solver/fulfill.rs b/crates/hir-ty/src/next_solver/fulfill.rs index 7783075d1a36..2a445570ce7b 100644 --- a/crates/hir-ty/src/next_solver/fulfill.rs +++ b/crates/hir-ty/src/next_solver/fulfill.rs @@ -284,7 +284,7 @@ impl<'db> FulfillmentCtxt<'db> { /// This function can be also return false positives, which will lead to poor diagnostics /// so we want to keep this visitor *precise* too. pub struct StalledOnCoroutines<'a, 'db> { - pub stalled_coroutines: &'a [SolverDefId], + pub stalled_coroutines: &'a [SolverDefId<'db>], pub cache: FxHashSet>, } diff --git a/crates/hir-ty/src/next_solver/fulfill/errors.rs b/crates/hir-ty/src/next_solver/fulfill/errors.rs index 82dbf9403cab..a1ad3a9ae126 100644 --- a/crates/hir-ty/src/next_solver/fulfill/errors.rs +++ b/crates/hir-ty/src/next_solver/fulfill/errors.rs @@ -702,7 +702,7 @@ mod wf { #[instrument(level = "debug", skip(self))] fn nominal_obligations( &mut self, - def_id: SolverDefId, + def_id: SolverDefId<'db>, args: GenericArgs<'db>, ) -> PredicateObligations<'db> { // PERF: `Sized`'s predicates include `MetaSized`, but both are compiler implemented marker diff --git a/crates/hir-ty/src/next_solver/generic_arg.rs b/crates/hir-ty/src/next_solver/generic_arg.rs index 24f22bcb0c3e..d3cb875414c1 100644 --- a/crates/hir-ty/src/next_solver/generic_arg.rs +++ b/crates/hir-ty/src/next_solver/generic_arg.rs @@ -180,7 +180,7 @@ impl<'db> GenericArgs<'db> { /// replace defaults of generic parameters. pub fn for_item( interner: DbInterner<'db>, - def_id: SolverDefId, + def_id: SolverDefId<'db>, mut mk_kind: F, ) -> GenericArgs<'db> where @@ -194,7 +194,7 @@ impl<'db> GenericArgs<'db> { } /// Creates an all-error `GenericArgs`. - pub fn error_for_item(interner: DbInterner<'db>, def_id: SolverDefId) -> GenericArgs<'db> { + pub fn error_for_item(interner: DbInterner<'db>, def_id: SolverDefId<'db>) -> GenericArgs<'db> { GenericArgs::for_item(interner, def_id, |_, id, _| GenericArg::error_from_id(interner, id)) } @@ -217,7 +217,7 @@ impl<'db> GenericArgs<'db> { /// Like `for_item()`, but calls first uses the args from `first`. pub fn fill_rest( interner: DbInterner<'db>, - def_id: SolverDefId, + def_id: SolverDefId<'db>, first: impl IntoIterator>, mut fallback: F, ) -> GenericArgs<'db> diff --git a/crates/hir-ty/src/next_solver/generics.rs b/crates/hir-ty/src/next_solver/generics.rs index d5a9a6f527bb..07fb515382df 100644 --- a/crates/hir-ty/src/next_solver/generics.rs +++ b/crates/hir-ty/src/next_solver/generics.rs @@ -14,7 +14,7 @@ use super::SolverDefId; use super::DbInterner; -pub(crate) fn generics(db: &dyn HirDatabase, def: SolverDefId) -> Generics { +pub(crate) fn generics<'db>(db: &'db dyn HirDatabase, def: SolverDefId<'db>) -> Generics { let mk_lt = |parent, index, local_id| { let id = GenericParamId::LifetimeParamId(LifetimeParamId { parent, local_id }); GenericParamDef { index, id } diff --git a/crates/hir-ty/src/next_solver/infer/canonical/instantiate.rs b/crates/hir-ty/src/next_solver/infer/canonical/instantiate.rs index 636029107154..7449b66fd725 100644 --- a/crates/hir-ty/src/next_solver/infer/canonical/instantiate.rs +++ b/crates/hir-ty/src/next_solver/infer/canonical/instantiate.rs @@ -79,11 +79,11 @@ where value } else { let delegate = FnMutDelegate { - regions: &mut |br: BoundRegion| match var_values[br.var].kind() { + regions: &mut |br: BoundRegion<'db>| match var_values[br.var].kind() { GenericArgKind::Lifetime(l) => l, r => panic!("{br:?} is a region but value is {r:?}"), }, - types: &mut |bound_ty: BoundTy| match var_values[bound_ty.var].kind() { + types: &mut |bound_ty: BoundTy<'db>| match var_values[bound_ty.var].kind() { GenericArgKind::Type(ty) => ty, r => panic!("{bound_ty:?} is a type but value is {r:?}"), }, diff --git a/crates/hir-ty/src/next_solver/infer/canonical/mod.rs b/crates/hir-ty/src/next_solver/infer/canonical/mod.rs index b3bd0a437b8d..a040d8c79b40 100644 --- a/crates/hir-ty/src/next_solver/infer/canonical/mod.rs +++ b/crates/hir-ty/src/next_solver/infer/canonical/mod.rs @@ -121,7 +121,7 @@ impl<'db> InferCtxt<'db> { CanonicalVarKind::PlaceholderRegion(PlaceholderRegion { universe, bound }) => { let universe_mapped = universe_map(universe); let placeholder_mapped: crate::next_solver::Placeholder< - crate::next_solver::BoundRegion, + crate::next_solver::BoundRegion<'db>, > = PlaceholderRegion { universe: universe_mapped, bound }; Region::new_placeholder(self.interner, placeholder_mapped).into() } diff --git a/crates/hir-ty/src/next_solver/infer/context.rs b/crates/hir-ty/src/next_solver/infer/context.rs index 397986e2edd3..605a2e681e50 100644 --- a/crates/hir-ty/src/next_solver/infer/context.rs +++ b/crates/hir-ty/src/next_solver/infer/context.rs @@ -150,7 +150,7 @@ impl<'db> rustc_type_ir::InferCtxtLike for InferCtxt<'db> { self.next_const_var() } - fn fresh_args_for_item(&self, def_id: SolverDefId) -> GenericArgs<'db> { + fn fresh_args_for_item(&self, def_id: SolverDefId<'db>) -> GenericArgs<'db> { self.fresh_args_for_item(def_id) } diff --git a/crates/hir-ty/src/next_solver/infer/mod.rs b/crates/hir-ty/src/next_solver/infer/mod.rs index 36c6c48c5a0b..b49ddf9fec53 100644 --- a/crates/hir-ty/src/next_solver/infer/mod.rs +++ b/crates/hir-ty/src/next_solver/infer/mod.rs @@ -279,7 +279,7 @@ pub struct TypeTrace<'db> { /// Times when we replace bound regions with existentials: #[derive(Clone, Copy, Debug)] -pub enum BoundRegionConversionTime { +pub enum BoundRegionConversionTime<'db> { /// when a fn is called FnCall, @@ -287,7 +287,7 @@ pub enum BoundRegionConversionTime { HigherRankedType, /// when projecting an associated type - AssocTypeProjection(SolverDefId), + AssocTypeProjection(SolverDefId<'db>), } #[derive(Copy, Clone, Debug)] @@ -603,7 +603,7 @@ impl<'db> InferCtxt<'db> { .new_var(self.universe(), TypeVariableOrigin { param_def_id: None }) } - pub fn next_ty_var_with_origin(&self, origin: TypeVariableOrigin) -> Ty<'db> { + pub fn next_ty_var_with_origin(&self, origin: TypeVariableOrigin<'db>) -> Ty<'db> { let vid = self.inner.borrow_mut().type_variables().new_var(self.universe(), origin); Ty::new_var(self.interner, vid) } @@ -764,14 +764,14 @@ impl<'db> InferCtxt<'db> { /// Given a set of generics defined on a type or impl, returns the generic parameters mapping /// each type/region parameter to a fresh inference variable. - pub fn fresh_args_for_item(&self, def_id: SolverDefId) -> GenericArgs<'db> { + pub fn fresh_args_for_item(&self, def_id: SolverDefId<'db>) -> GenericArgs<'db> { GenericArgs::for_item(self.interner, def_id, |_index, kind, _| self.var_for_def(kind)) } /// Like `fresh_args_for_item()`, but first uses the args from `first`. pub fn fill_rest_fresh_args( &self, - def_id: SolverDefId, + def_id: SolverDefId<'db>, first: impl IntoIterator>, ) -> GenericArgs<'db> { GenericArgs::fill_rest(self.interner, def_id, first, |_index, kind, _| { @@ -807,7 +807,7 @@ impl<'db> InferCtxt<'db> { } #[inline(always)] - pub fn can_define_opaque_ty(&self, id: impl Into) -> bool { + pub fn can_define_opaque_ty(&self, id: impl Into>) -> bool { match self.typing_mode_unchecked() { TypingMode::Analysis { defining_opaque_types_and_generators } => { defining_opaque_types_and_generators.contains(&id.into()) @@ -983,7 +983,7 @@ impl<'db> InferCtxt<'db> { // use [`InferCtxt::enter_forall`] instead. pub fn instantiate_binder_with_fresh_vars( &self, - _lbrct: BoundRegionConversionTime, + _lbrct: BoundRegionConversionTime<'db>, value: Binder<'db, T>, ) -> T where @@ -1010,10 +1010,10 @@ impl<'db> InferCtxt<'db> { } impl<'db> BoundVarReplacerDelegate<'db> for ToFreshVars<'db> { - fn replace_region(&mut self, br: BoundRegion) -> Region<'db> { + fn replace_region(&mut self, br: BoundRegion<'db>) -> Region<'db> { self.args[br.var.index()].expect_region() } - fn replace_ty(&mut self, bt: BoundTy) -> Ty<'db> { + fn replace_ty(&mut self, bt: BoundTy<'db>) -> Ty<'db> { self.args[bt.var.index()].expect_ty() } fn replace_const(&mut self, bv: BoundConst) -> Const<'db> { diff --git a/crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs b/crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs index ae5930d55c72..620051a34675 100644 --- a/crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs +++ b/crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs @@ -122,7 +122,7 @@ pub struct Verify<'db> { #[derive(Clone, PartialEq, Eq, Hash)] pub enum GenericKind<'db> { Param(ParamTy), - Placeholder(PlaceholderTy), + Placeholder(PlaceholderTy<'db>), Alias(AliasTy<'db>), } diff --git a/crates/hir-ty/src/next_solver/infer/relate/generalize.rs b/crates/hir-ty/src/next_solver/infer/relate/generalize.rs index d06984cac11c..cd15ae1aedf6 100644 --- a/crates/hir-ty/src/next_solver/infer/relate/generalize.rs +++ b/crates/hir-ty/src/next_solver/infer/relate/generalize.rs @@ -386,7 +386,7 @@ impl<'db> TypeRelation> for Generalizer<'_, 'db> { fn relate_item_args( &mut self, - item_def_id: SolverDefId, + item_def_id: SolverDefId<'db>, a_arg: GenericArgs<'db>, b_arg: GenericArgs<'db>, ) -> RelateResult<'db, GenericArgs<'db>> { diff --git a/crates/hir-ty/src/next_solver/infer/relate/higher_ranked.rs b/crates/hir-ty/src/next_solver/infer/relate/higher_ranked.rs index c523751e03e3..3ce939229027 100644 --- a/crates/hir-ty/src/next_solver/infer/relate/higher_ranked.rs +++ b/crates/hir-ty/src/next_solver/infer/relate/higher_ranked.rs @@ -35,13 +35,13 @@ impl<'db> InferCtxt<'db> { let next_universe = self.create_next_universe(); let delegate = FnMutDelegate { - regions: &mut |br: BoundRegion| { + regions: &mut |br: BoundRegion<'db>| { Region::new_placeholder( self.interner, PlaceholderRegion { universe: next_universe, bound: br }, ) }, - types: &mut |bound_ty: BoundTy| { + types: &mut |bound_ty: BoundTy<'db>| { Ty::new_placeholder( self.interner, PlaceholderTy { universe: next_universe, bound: bound_ty }, diff --git a/crates/hir-ty/src/next_solver/infer/select.rs b/crates/hir-ty/src/next_solver/infer/select.rs index 52ad410df6be..2f87ac4463a1 100644 --- a/crates/hir-ty/src/next_solver/infer/select.rs +++ b/crates/hir-ty/src/next_solver/infer/select.rs @@ -39,7 +39,7 @@ pub enum SelectionError<'db> { /// Computing an opaque type's hidden type caused an error (e.g. a cycle error). /// We can thus not know whether the hidden type implements an auto trait, so /// we should not presume anything about it. - OpaqueTypeAutoTraitLeakageUnknown(InternedOpaqueTyId), + OpaqueTypeAutoTraitLeakageUnknown(InternedOpaqueTyId<'db>), /// Error for a `ConstArgHasType` goal ConstArgHasWrongType { ct: Const<'db>, ct_ty: Ty<'db>, expected_ty: Ty<'db> }, } diff --git a/crates/hir-ty/src/next_solver/infer/snapshot/fudge.rs b/crates/hir-ty/src/next_solver/infer/snapshot/fudge.rs index 5902f8043b5e..9edff53be03b 100644 --- a/crates/hir-ty/src/next_solver/infer/snapshot/fudge.rs +++ b/crates/hir-ty/src/next_solver/infer/snapshot/fudge.rs @@ -114,7 +114,7 @@ impl<'db> InferCtxt<'db> { fn fudge_inference>>( &self, - snapshot_vars: SnapshotVarData, + snapshot_vars: SnapshotVarData<'db>, value: T, ) -> T { // Micro-optimization: if no variables have been created, then @@ -127,16 +127,16 @@ impl<'db> InferCtxt<'db> { } } -struct SnapshotVarData { +struct SnapshotVarData<'db> { region_vars: Range, - type_vars: (Range, Vec), + type_vars: (Range, Vec>), int_vars: Range, float_vars: Range, const_vars: (Range, Vec), } -impl SnapshotVarData { - fn new(infcx: &InferCtxt<'_>, vars_pre_snapshot: VariableLengths) -> SnapshotVarData { +impl<'db> SnapshotVarData<'db> { + fn new(infcx: &InferCtxt<'db>, vars_pre_snapshot: VariableLengths) -> SnapshotVarData<'db> { let mut inner = infcx.inner.borrow_mut(); let region_vars = inner .unwrap_region_constraints() @@ -166,7 +166,7 @@ impl SnapshotVarData { struct InferenceFudger<'a, 'db> { infcx: &'a InferCtxt<'db>, - snapshot_vars: SnapshotVarData, + snapshot_vars: SnapshotVarData<'db>, } impl<'a, 'db> TypeFolder> for InferenceFudger<'a, 'db> { diff --git a/crates/hir-ty/src/next_solver/infer/type_variable.rs b/crates/hir-ty/src/next_solver/infer/type_variable.rs index 29e7b883c93b..9097016e6eaa 100644 --- a/crates/hir-ty/src/next_solver/infer/type_variable.rs +++ b/crates/hir-ty/src/next_solver/infer/type_variable.rs @@ -62,7 +62,7 @@ impl<'tcx> Rollback> for TypeVariableStorage<'tcx> { #[derive(Debug, Clone, Default)] pub(crate) struct TypeVariableStorage<'db> { /// The origins of each type variable. - values: IndexVec, + values: IndexVec>, /// Two variables are unified in `eq_relations` when we have a /// constraint `?X == ?Y`. This table also stores, for each key, /// the known value. @@ -95,16 +95,16 @@ pub(crate) struct TypeVariableTable<'a, 'db> { } #[derive(Copy, Clone, Debug)] -pub struct TypeVariableOrigin { +pub struct TypeVariableOrigin<'db> { /// `DefId` of the type parameter this was instantiated for, if any. /// /// This should only be used for diagnostics. - pub param_def_id: Option, + pub param_def_id: Option>, } #[derive(Debug, Clone)] -pub(crate) struct TypeVariableData { - origin: TypeVariableOrigin, +pub(crate) struct TypeVariableData<'db> { + origin: TypeVariableOrigin<'db>, } #[derive(Clone, Debug)] @@ -156,7 +156,7 @@ impl<'db> TypeVariableTable<'_, 'db> { /// /// Note that this function does not return care whether /// `vid` has been unified with something else or not. - pub(crate) fn var_origin(&self, vid: TyVid) -> TypeVariableOrigin { + pub(crate) fn var_origin(&self, vid: TyVid) -> TypeVariableOrigin<'db> { self.storage.values[vid].origin } @@ -205,7 +205,11 @@ impl<'db> TypeVariableTable<'_, 'db> { /// - `origin`: indicates *why* the type variable was created. /// The code in this module doesn't care, but it can be useful /// for improving error messages. - pub(crate) fn new_var(&mut self, universe: UniverseIndex, origin: TypeVariableOrigin) -> TyVid { + pub(crate) fn new_var( + &mut self, + universe: UniverseIndex, + origin: TypeVariableOrigin<'db>, + ) -> TyVid { let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe }); let sub_key = self.sub_unification_table().new_key(()); @@ -271,7 +275,7 @@ impl<'db> TypeVariableTable<'_, 'db> { pub(crate) fn vars_since_snapshot( &mut self, value_count: usize, - ) -> (Range, Vec) { + ) -> (Range, Vec>) { let range = TyVid::from_usize(value_count)..TyVid::from_usize(self.num_vars()); (range.clone(), iter_idx_range(range).map(|index| self.var_origin(index)).collect()) } diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs index 06d35ba93d95..e7365b11e5b5 100644 --- a/crates/hir-ty/src/next_solver/interner.rs +++ b/crates/hir-ty/src/next_solver/interner.rs @@ -299,24 +299,24 @@ impl<'db> inherent::Span> for Span { } } -interned_vec_nolifetime_salsa!(BoundVarKinds, BoundVarKind, nofold); +interned_vec_nolifetime_salsa!(BoundVarKinds, BoundVarKind<'db>, nofold); #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum BoundVarKind { - Ty(BoundTyKind), - Region(BoundRegionKind), +pub enum BoundVarKind<'db> { + Ty(BoundTyKind<'db>), + Region(BoundRegionKind<'db>), Const, } -impl BoundVarKind { - pub fn expect_region(self) -> BoundRegionKind { +impl<'db> BoundVarKind<'db> { + pub fn expect_region(self) -> BoundRegionKind<'db> { match self { BoundVarKind::Region(lt) => lt, _ => panic!("expected a region, but found another kind"), } } - pub fn expect_ty(self) -> BoundTyKind { + pub fn expect_ty(self) -> BoundTyKind<'db> { match self { BoundVarKind::Ty(ty) => ty, _ => panic!("expected a type, but found another kind"), @@ -850,8 +850,8 @@ macro_rules! as_lang_item { } impl<'db> Interner for DbInterner<'db> { - type DefId = SolverDefId; - type LocalDefId = SolverDefId; + type DefId = SolverDefId<'db>; + type LocalDefId = SolverDefId<'db>; type LocalDefIds = SolverDefIds<'db>; type TraitId = TraitIdWrapper; type ForeignId = TypeAliasIdWrapper; @@ -870,7 +870,7 @@ impl<'db> Interner for DbInterner<'db> { type Term = Term<'db>; type BoundVarKinds = BoundVarKinds<'db>; - type BoundVarKind = BoundVarKind; + type BoundVarKind = BoundVarKind<'db>; type PredefinedOpaques = PredefinedOpaques<'db>; @@ -907,8 +907,8 @@ impl<'db> Interner for DbInterner<'db> { type Tys = Tys<'db>; type FnInputTys = Tys<'db>; type ParamTy = ParamTy; - type BoundTy = BoundTy; - type PlaceholderTy = PlaceholderTy; + type BoundTy = BoundTy<'db>; + type PlaceholderTy = PlaceholderTy<'db>; type Symbol = (); type ErrorGuaranteed = ErrorGuaranteed; @@ -929,9 +929,9 @@ impl<'db> Interner for DbInterner<'db> { type Region = Region<'db>; type EarlyParamRegion = EarlyParamRegion; - type LateParamRegion = LateParamRegion; - type BoundRegion = BoundRegion; - type PlaceholderRegion = PlaceholderRegion; + type LateParamRegion = LateParamRegion<'db>; + type BoundRegion = BoundRegion<'db>; + type PlaceholderRegion = PlaceholderRegion<'db>; type RegionAssumptions = RegionAssumptions<'db>; @@ -1796,10 +1796,10 @@ impl<'db> Interner for DbInterner<'db> { ) -> rustc_type_ir::Binder { struct Anonymize<'a, 'db> { interner: DbInterner<'db>, - map: &'a mut FxIndexMap, + map: &'a mut FxIndexMap>, } impl<'db> BoundVarReplacerDelegate<'db> for Anonymize<'_, 'db> { - fn replace_region(&mut self, br: BoundRegion) -> Region<'db> { + fn replace_region(&mut self, br: BoundRegion<'db>) -> Region<'db> { let entry = self.map.entry(br.var); let index = entry.index(); let var = BoundVar::from_usize(index); @@ -1808,7 +1808,7 @@ impl<'db> Interner for DbInterner<'db> { let br = BoundRegion { var, kind }; Region::new_bound(self.interner, DebruijnIndex::ZERO, br) } - fn replace_ty(&mut self, bt: BoundTy) -> Ty<'db> { + fn replace_ty(&mut self, bt: BoundTy<'db>) -> Ty<'db> { let entry = self.map.entry(bt.var); let index = entry.index(); let var = BoundVar::from_usize(index); @@ -1970,14 +1970,14 @@ impl<'db> DbInterner<'db> { self.replace_escaping_bound_vars_uncached( value, FnMutDelegate { - regions: &mut |r: BoundRegion| { + regions: &mut |r: BoundRegion<'db>| { Region::new_bound( self, DebruijnIndex::ZERO, BoundRegion { var: shift_bv(r.var), kind: r.kind }, ) }, - types: &mut |t: BoundTy| { + types: &mut |t: BoundTy<'db>| { Ty::new_bound( self, DebruijnIndex::ZERO, @@ -2070,7 +2070,7 @@ macro_rules! TrivialTypeTraversalImpls { } TrivialTypeTraversalImpls! { - SolverDefId, + SolverDefId<'db>, TraitIdWrapper, TypeAliasIdWrapper, CallableIdWrapper, @@ -2084,10 +2084,10 @@ TrivialTypeTraversalImpls! { Span, ParamConst, ParamTy, - BoundRegion, + BoundRegion<'db>, BoundVar, - Placeholder, - Placeholder, + Placeholder>, + Placeholder>, Placeholder, } diff --git a/crates/hir-ty/src/next_solver/opaques.rs b/crates/hir-ty/src/next_solver/opaques.rs index e8f5be2eb598..e5eff9370245 100644 --- a/crates/hir-ty/src/next_solver/opaques.rs +++ b/crates/hir-ty/src/next_solver/opaques.rs @@ -13,7 +13,7 @@ interned_vec_db!(PredefinedOpaques, PredefinedOpaque); pub type ExternalConstraintsData<'db> = rustc_type_ir::solve::ExternalConstraintsData>; -interned_vec_nolifetime_salsa!(SolverDefIds, SolverDefId); +interned_vec_nolifetime_salsa!(SolverDefIds, SolverDefId<'db>); #[salsa::interned(constructor = new_, debug)] pub struct ExternalConstraints<'db> { diff --git a/crates/hir-ty/src/next_solver/region.rs b/crates/hir-ty/src/next_solver/region.rs index b5f0e6de2910..b39e3388fb89 100644 --- a/crates/hir-ty/src/next_solver/region.rs +++ b/crates/hir-ty/src/next_solver/region.rs @@ -51,7 +51,7 @@ impl<'db> Region<'db> { Region::new(interner, RegionKind::ReEarlyParam(early_bound_region)) } - pub fn new_placeholder(interner: DbInterner<'db>, placeholder: PlaceholderRegion) -> Self { + pub fn new_placeholder(interner: DbInterner<'db>, placeholder: PlaceholderRegion<'db>) -> Self { Region::new(interner, RegionKind::RePlaceholder(placeholder)) } @@ -66,7 +66,7 @@ impl<'db> Region<'db> { pub fn new_bound( interner: DbInterner<'db>, index: DebruijnIndex, - bound: BoundRegion, + bound: BoundRegion<'db>, ) -> Region<'db> { Region::new(interner, RegionKind::ReBound(BoundVarIndexKind::Bound(index), bound)) } @@ -137,7 +137,7 @@ impl<'db> Region<'db> { } } -pub type PlaceholderRegion = Placeholder; +pub type PlaceholderRegion<'db> = Placeholder>; #[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct EarlyParamRegion { @@ -155,19 +155,19 @@ pub struct EarlyParamRegion { /// between others we use the `DefId` of the parameter. For this reason the `bound_region` field /// should basically always be `BoundRegionKind::Named` as otherwise there is no way of telling /// different parameters apart. -pub struct LateParamRegion { - pub scope: SolverDefId, - pub bound_region: BoundRegionKind, +pub struct LateParamRegion<'db> { + pub scope: SolverDefId<'db>, + pub bound_region: BoundRegionKind<'db>, } -impl std::fmt::Debug for LateParamRegion { +impl<'db> std::fmt::Debug for LateParamRegion<'db> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "ReLateParam({:?}, {:?})", self.scope, self.bound_region) } } #[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub enum BoundRegionKind { +pub enum BoundRegionKind<'db> { /// An anonymous region parameter for a given fn (&T) Anon, @@ -175,14 +175,14 @@ pub enum BoundRegionKind { /// /// The `DefId` is needed to distinguish free regions in /// the event of shadowing. - Named(SolverDefId), + Named(SolverDefId<'db>), /// Anonymous region for the implicit env pointer parameter /// to a closure ClosureEnv, } -impl std::fmt::Debug for BoundRegionKind { +impl<'db> std::fmt::Debug for BoundRegionKind<'db> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { BoundRegionKind::Anon => write!(f, "BrAnon"), @@ -195,9 +195,9 @@ impl std::fmt::Debug for BoundRegionKind { } #[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub struct BoundRegion { +pub struct BoundRegion<'db> { pub var: BoundVar, - pub kind: BoundRegionKind, + pub kind: BoundRegionKind<'db>, } impl rustc_type_ir::inherent::ParamLike for EarlyParamRegion { @@ -213,17 +213,17 @@ impl std::fmt::Debug for EarlyParamRegion { } } -impl<'db> rustc_type_ir::inherent::BoundVarLike> for BoundRegion { +impl<'db> rustc_type_ir::inherent::BoundVarLike> for BoundRegion<'db> { fn var(self) -> BoundVar { self.var } - fn assert_eq(self, var: BoundVarKind) { + fn assert_eq(self, var: BoundVarKind<'db>) { assert_eq!(self.kind, var.expect_region()) } } -impl core::fmt::Debug for BoundRegion { +impl<'db> core::fmt::Debug for BoundRegion<'db> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self.kind { BoundRegionKind::Anon => write!(f, "{:?}", self.var), @@ -235,7 +235,7 @@ impl core::fmt::Debug for BoundRegion { } } -impl BoundRegionKind { +impl<'db> BoundRegionKind<'db> { pub fn is_named(&self) -> bool { matches!(self, BoundRegionKind::Named(_)) } @@ -244,7 +244,7 @@ impl BoundRegionKind { None } - pub fn get_id(&self) -> Option { + pub fn get_id(&self) -> Option> { match self { BoundRegionKind::Named(id) => Some(*id), _ => None, @@ -308,7 +308,7 @@ impl<'db> rustc_type_ir::inherent::Region> for Region<'db> { fn new_bound( interner: DbInterner<'db>, debruijn: rustc_type_ir::DebruijnIndex, - var: BoundRegion, + var: BoundRegion<'db>, ) -> Self { Region::new(interner, RegionKind::ReBound(BoundVarIndexKind::Bound(debruijn), var)) } @@ -349,8 +349,8 @@ impl<'db> rustc_type_ir::inherent::Region> for Region<'db> { } } -impl<'db> PlaceholderLike> for PlaceholderRegion { - type Bound = BoundRegion; +impl<'db> PlaceholderLike> for PlaceholderRegion<'db> { + type Bound = BoundRegion<'db>; fn universe(self) -> rustc_type_ir::UniverseIndex { self.universe diff --git a/crates/hir-ty/src/next_solver/solver.rs b/crates/hir-ty/src/next_solver/solver.rs index 487d164f8691..e35a196af2fa 100644 --- a/crates/hir-ty/src/next_solver/solver.rs +++ b/crates/hir-ty/src/next_solver/solver.rs @@ -142,9 +142,9 @@ impl<'db> SolverDelegate for SolverContext<'db> { fn fetch_eligible_assoc_item( &self, _goal_trait_ref: rustc_type_ir::TraitRef, - trait_assoc_def_id: SolverDefId, + trait_assoc_def_id: SolverDefId<'db>, impl_id: ImplIdWrapper, - ) -> Result, ErrorGuaranteed> { + ) -> Result>, ErrorGuaranteed> { let impl_items = impl_id.0.impl_items(self.0.interner.db()); let id = match trait_assoc_def_id { SolverDefId::TypeAliasId(trait_assoc_id) => { diff --git a/crates/hir-ty/src/next_solver/ty.rs b/crates/hir-ty/src/next_solver/ty.rs index 95ee00d2754b..2e78fd79f869 100644 --- a/crates/hir-ty/src/next_solver/ty.rs +++ b/crates/hir-ty/src/next_solver/ty.rs @@ -83,7 +83,7 @@ impl<'db> Ty<'db> { Ty::new(interner, TyKind::Param(ParamTy { id, index })) } - pub fn new_placeholder(interner: DbInterner<'db>, placeholder: PlaceholderTy) -> Self { + pub fn new_placeholder(interner: DbInterner<'db>, placeholder: PlaceholderTy<'db>) -> Self { Ty::new(interner, TyKind::Placeholder(placeholder)) } @@ -889,11 +889,11 @@ impl<'db> rustc_type_ir::inherent::Ty> for Ty<'db> { Ty::new(interner, TyKind::Param(param)) } - fn new_placeholder(interner: DbInterner<'db>, param: PlaceholderTy) -> Self { + fn new_placeholder(interner: DbInterner<'db>, param: PlaceholderTy<'db>) -> Self { Ty::new(interner, TyKind::Placeholder(param)) } - fn new_bound(interner: DbInterner<'db>, debruijn: DebruijnIndex, var: BoundTy) -> Self { + fn new_bound(interner: DbInterner<'db>, debruijn: DebruijnIndex, var: BoundTy<'db>) -> Self { Ty::new(interner, TyKind::Bound(BoundVarIndexKind::Bound(debruijn), var)) } @@ -1195,7 +1195,7 @@ impl<'db> rustc_type_ir::inherent::Tys> for Tys<'db> { } } -pub type PlaceholderTy = Placeholder; +pub type PlaceholderTy<'db> = Placeholder>; #[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct ParamTy { @@ -1219,13 +1219,13 @@ impl std::fmt::Debug for ParamTy { } #[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub struct BoundTy { +pub struct BoundTy<'db> { pub var: BoundVar, // FIXME: This is for diagnostics in rustc, do we really need it? - pub kind: BoundTyKind, + pub kind: BoundTyKind<'db>, } -impl std::fmt::Debug for BoundTy { +impl<'db> std::fmt::Debug for BoundTy<'db> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self.kind { BoundTyKind::Anon => write!(f, "{:?}", self.var), @@ -1235,9 +1235,9 @@ impl std::fmt::Debug for BoundTy { } #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -pub enum BoundTyKind { +pub enum BoundTyKind<'db> { Anon, - Param(SolverDefId), + Param(SolverDefId<'db>), } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] @@ -1270,18 +1270,18 @@ impl ParamLike for ParamTy { } } -impl<'db> BoundVarLike> for BoundTy { +impl<'db> BoundVarLike> for BoundTy<'db> { fn var(self) -> BoundVar { self.var } - fn assert_eq(self, var: BoundVarKind) { + fn assert_eq(self, var: BoundVarKind<'db>) { assert_eq!(self.kind, var.expect_ty()) } } -impl<'db> PlaceholderLike> for PlaceholderTy { - type Bound = BoundTy; +impl<'db> PlaceholderLike> for PlaceholderTy<'db> { + type Bound = BoundTy<'db>; fn universe(self) -> rustc_type_ir::UniverseIndex { self.universe @@ -1295,7 +1295,7 @@ impl<'db> PlaceholderLike> for PlaceholderTy { Placeholder { universe: ui, bound: self.bound } } - fn new(ui: rustc_type_ir::UniverseIndex, bound: BoundTy) -> Self { + fn new(ui: rustc_type_ir::UniverseIndex, bound: BoundTy<'db>) -> Self { Placeholder { universe: ui, bound } } diff --git a/crates/hir-ty/src/next_solver/util.rs b/crates/hir-ty/src/next_solver/util.rs index bb0d0552c710..637746742d66 100644 --- a/crates/hir-ty/src/next_solver/util.rs +++ b/crates/hir-ty/src/next_solver/util.rs @@ -499,8 +499,9 @@ pub fn apply_args_to_binder<'db, T: TypeFoldable>>( args: GenericArgs<'db>, interner: DbInterner<'db>, ) -> T { - let types = &mut |ty: BoundTy| args.as_slice()[ty.var.index()].expect_ty(); - let regions = &mut |region: BoundRegion| args.as_slice()[region.var.index()].expect_region(); + let types = &mut |ty: BoundTy<'db>| args.as_slice()[ty.var.index()].expect_ty(); + let regions = + &mut |region: BoundRegion<'db>| args.as_slice()[region.var.index()].expect_region(); let consts = &mut |const_: BoundConst| args.as_slice()[const_.var.index()].expect_const(); let mut instantiate = BoundVarReplacer::new(interner, FnMutDelegate { types, regions, consts }); b.skip_binder().fold_with(&mut instantiate) @@ -508,7 +509,7 @@ pub fn apply_args_to_binder<'db, T: TypeFoldable>>( pub fn explicit_item_bounds<'db>( interner: DbInterner<'db>, - def_id: SolverDefId, + def_id: SolverDefId<'db>, ) -> EarlyBinder<'db, Clauses<'db>> { let db = interner.db(); match def_id { @@ -689,8 +690,8 @@ impl<'db> TypeVisitor> for ContainsTypeErrors { /// The inverse of [`BoundVarReplacer`]: replaces placeholders with the bound vars from which they came. pub struct PlaceholderReplacer<'a, 'db> { infcx: &'a InferCtxt<'db>, - mapped_regions: FxIndexMap, - mapped_types: FxIndexMap, BoundTy>, + mapped_regions: FxIndexMap, BoundRegion<'db>>, + mapped_types: FxIndexMap>, BoundTy<'db>>, mapped_consts: FxIndexMap, universe_indices: &'a [Option], current_index: DebruijnIndex, @@ -699,8 +700,8 @@ pub struct PlaceholderReplacer<'a, 'db> { impl<'a, 'db> PlaceholderReplacer<'a, 'db> { pub fn replace_placeholders>>( infcx: &'a InferCtxt<'db>, - mapped_regions: FxIndexMap, - mapped_types: FxIndexMap, BoundTy>, + mapped_regions: FxIndexMap, BoundRegion<'db>>, + mapped_types: FxIndexMap>, BoundTy<'db>>, mapped_consts: FxIndexMap, universe_indices: &'a [Option], value: T, diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 941890312317..29e208421db0 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -6434,7 +6434,7 @@ fn as_name_opt(name: Option) -> Name { fn generic_args_from_tys<'db>( interner: DbInterner<'db>, - def_id: SolverDefId, + def_id: SolverDefId<'db>, args: impl IntoIterator>, ) -> GenericArgs<'db> { let mut args = args.into_iter(); diff --git a/crates/query-group-macro/src/queries.rs b/crates/query-group-macro/src/queries.rs index 7698ce5fff13..4c4a274e69b9 100644 --- a/crates/query-group-macro/src/queries.rs +++ b/crates/query-group-macro/src/queries.rs @@ -282,11 +282,16 @@ impl ToTokens for Intern { let interned_pat = ty.first().expect("at least one pat; this is a bug"); let interned_pat = &interned_pat.pat; - let wrapper_struct = self.interned_struct_path.to_token_stream(); + let mut type_constructor = proc_macro2::TokenStream::new(); + self.interned_struct_path.leading_colon.to_tokens(&mut type_constructor); + for segment in &self.interned_struct_path.segments { + segment.ident.to_tokens(&mut type_constructor); + quote! {::}.to_tokens(&mut type_constructor); + } let method = quote! { #sig { - #wrapper_struct::new(self, #interned_pat) + #type_constructor new(self, #interned_pat) } }; @@ -306,6 +311,7 @@ impl Lookup { let sig = &self.signature; let ident = format_ident!("lookup_{}", sig.ident); + let generics = &sig.generics; let ty = self.pat_and_tys.to_vec(); @@ -314,8 +320,10 @@ impl Lookup { let interned_pat = ty.first().expect("at least one pat; this is a bug"); let interned_return_ty = &interned_pat.ty; + let FnArg::Receiver(receiver) = sig.inputs.first().unwrap() else { unreachable!() }; + self.signature = parse_quote!( - fn #ident(&self, id: #interned_key) -> #interned_return_ty + fn #ident #generics(#receiver, id: #interned_key) -> #interned_return_ty ); } } @@ -324,11 +332,17 @@ impl ToTokens for Lookup { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let sig = &self.signature; - let wrapper_struct = self.interned_struct_path.to_token_stream(); + let mut type_constructor = proc_macro2::TokenStream::new(); + self.interned_struct_path.leading_colon.to_tokens(&mut type_constructor); + for segment in &self.interned_struct_path.segments { + segment.ident.to_tokens(&mut type_constructor); + quote! {::}.to_tokens(&mut type_constructor); + } + let method = quote! { #sig { let zalsa = self.zalsa(); - #wrapper_struct::ingredient(zalsa).data(zalsa, id.as_id()).0.clone() + #type_constructor ingredient(zalsa).data(zalsa, id.as_id()).0.clone() } };