@@ -10,6 +10,7 @@ use indexmap::map::Entry;
1010use itertools:: Itertools ;
1111use la_arena:: Idx ;
1212use rustc_hash:: { FxHashMap , FxHashSet } ;
13+ use salsa:: SalsaValue ;
1314use smallvec:: SmallVec ;
1415use span:: Edition ;
1516use stdx:: { format_to, impl_from} ;
@@ -121,8 +122,8 @@ impl PerNsGlobImports {
121122 }
122123}
123124
124- #[ derive( Debug , Default , PartialEq , Eq ) ]
125- pub struct ItemScope {
125+ #[ derive( Debug , Default , PartialEq , Eq , SalsaValue ) ]
126+ pub struct ItemScope < ' db > {
126127 /// Defs visible in this scope. This includes `declarations`, but also
127128 /// imports. The imports belong to this module and can be resolved by using them on
128129 /// the `use_imports_*` fields.
@@ -136,7 +137,7 @@ pub struct ItemScope {
136137 declarations : ThinVec < ModuleDefId > ,
137138
138139 impls : ThinVec < ( ImplId , /* trait impl */ bool ) > ,
139- builtin_derive_impls : ThinVec < BuiltinDeriveImplId > ,
140+ builtin_derive_impls : ThinVec < BuiltinDeriveImplId < ' db > > ,
140141 extern_blocks : ThinVec < ExternBlockId > ,
141142 unnamed_consts : ThinVec < ConstId > ,
142143 /// Traits imported via `use Trait as _;`.
@@ -168,15 +169,15 @@ pub struct ItemScope {
168169 macro_invocations : FxHashMap < AstId < ast:: MacroCall > , MacroCallId > ,
169170 /// The derive macro invocations in this scope, keyed by the owner item over the actual derive attributes
170171 /// paired with the derive macro invocations for the specific attribute.
171- derive_macros : FxHashMap < AstId < ast:: Adt > , SmallVec < [ DeriveMacroInvocation ; 1 ] > > ,
172+ derive_macros : FxHashMap < AstId < ast:: Adt > , SmallVec < [ DeriveMacroInvocation < ' db > ; 1 ] > > ,
172173}
173174
174- #[ derive( Debug , PartialEq , Eq ) ]
175- struct DeriveMacroInvocation {
175+ #[ derive( Debug , PartialEq , Eq , SalsaValue ) ]
176+ struct DeriveMacroInvocation < ' db > {
176177 attr_id : AttrId ,
177178 /// The `#[derive]` call
178179 attr_call_id : MacroCallId ,
179- derive_call_ids : SmallVec < [ Option < Either < MacroCallId , BuiltinDeriveImplId > > ; 4 ] > ,
180+ derive_call_ids : SmallVec < [ Option < Either < MacroCallId , BuiltinDeriveImplId < ' db > > > ; 4 ] > ,
180181}
181182
182183pub ( crate ) static BUILTIN_SCOPE : LazyLock < FxIndexMap < Name , PerNs > > = LazyLock :: new ( || {
@@ -197,7 +198,7 @@ pub(crate) enum BuiltinShadowMode {
197198
198199/// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
199200/// Other methods will only resolve values, types and module scoped macros only.
200- impl ItemScope {
201+ impl < ' db > ItemScope < ' db > {
201202 pub fn entries ( & self ) -> impl Iterator < Item = ( & Name , PerNs ) > {
202203 // FIXME: shadowing
203204 self . types
@@ -234,7 +235,7 @@ impl ItemScope {
234235 . dedup ( )
235236 }
236237
237- pub fn fully_resolve_import ( & self , db : & dyn SourceDatabase , mut import : ImportId ) -> PerNs {
238+ pub fn fully_resolve_import ( & self , db : & ' db dyn SourceDatabase , mut import : ImportId ) -> PerNs {
238239 let mut res = PerNs :: none ( ) ;
239240
240241 let mut scope = self ;
@@ -313,7 +314,7 @@ impl ItemScope {
313314 self . impls . iter ( ) . filter ( |& & ( _, is_trait_impl) | !is_trait_impl) . map ( |& ( id, _) | id)
314315 }
315316
316- pub fn builtin_derive_impls ( & self ) -> impl ExactSizeIterator < Item = BuiltinDeriveImplId > {
317+ pub fn builtin_derive_impls ( & self ) -> impl ExactSizeIterator < Item = BuiltinDeriveImplId < ' db > > {
317318 self . builtin_derive_impls . iter ( ) . copied ( )
318319 }
319320
@@ -452,7 +453,7 @@ impl ItemScope {
452453 }
453454}
454455
455- impl ItemScope {
456+ impl < ' db > ItemScope < ' db > {
456457 pub ( crate ) fn declare ( & mut self , def : ModuleDefId ) {
457458 self . declarations . push ( def)
458459 }
@@ -473,7 +474,7 @@ impl ItemScope {
473474 self . impls . push ( ( imp, is_trait_impl) ) ;
474475 }
475476
476- pub ( crate ) fn define_builtin_derive_impl ( & mut self , imp : BuiltinDeriveImplId ) {
477+ pub ( crate ) fn define_builtin_derive_impl ( & mut self , imp : BuiltinDeriveImplId < ' db > ) {
477478 self . builtin_derive_impls . push ( imp) ;
478479 }
479480
@@ -508,7 +509,7 @@ impl ItemScope {
508509 pub ( crate ) fn set_derive_macro_invoc (
509510 & mut self ,
510511 adt : AstId < ast:: Adt > ,
511- call : Either < MacroCallId , BuiltinDeriveImplId > ,
512+ call : Either < MacroCallId , BuiltinDeriveImplId < ' db > > ,
512513 id : AttrId ,
513514 idx : usize ,
514515 ) {
@@ -528,7 +529,7 @@ impl ItemScope {
528529 adt : AstId < ast:: Adt > ,
529530 attr_id : AttrId ,
530531 attr_call_id : MacroCallId ,
531- mut derive_call_ids : SmallVec < [ Option < Either < MacroCallId , BuiltinDeriveImplId > > ; 4 ] > ,
532+ mut derive_call_ids : SmallVec < [ Option < Either < MacroCallId , BuiltinDeriveImplId < ' db > > > ; 4 ] > ,
532533 ) {
533534 derive_call_ids. shrink_to_fit ( ) ;
534535 self . derive_macros . entry ( adt) . or_default ( ) . push ( DeriveMacroInvocation {
@@ -544,7 +545,11 @@ impl ItemScope {
544545 Item = (
545546 AstId < ast:: Adt > ,
546547 impl Iterator <
547- Item = ( AttrId , MacroCallId , & [ Option < Either < MacroCallId , BuiltinDeriveImplId > > ] ) ,
548+ Item = (
549+ AttrId ,
550+ MacroCallId ,
551+ & [ Option < Either < MacroCallId , BuiltinDeriveImplId < ' db > > > ] ,
552+ ) ,
548553 > ,
549554 ) ,
550555 > + ' _ {
@@ -863,7 +868,7 @@ impl ItemScope {
863868}
864869
865870// These methods are a temporary measure only meant to be used by `DefCollector::push_res_and_update_glob_vis()`.
866- impl ItemScope {
871+ impl < ' db > ItemScope < ' db > {
867872 pub ( crate ) fn update_visibility_types ( & mut self , name : & Name , vis : Visibility ) {
868873 let res =
869874 self . types . get_mut ( name) . expect ( "tried to update visibility of non-existent type" ) ;
0 commit comments