@@ -13,6 +13,7 @@ use smallvec::{SmallVec, smallvec};
13
13
use span:: Edition ;
14
14
use stdx:: format_to;
15
15
use syntax:: ast;
16
+ use thin_vec:: ThinVec ;
16
17
17
18
use crate :: {
18
19
AdtId , BuiltinType , ConstId , ExternBlockId , ExternCrateId , FxIndexMap , HasModule , ImplId ,
@@ -155,22 +156,21 @@ pub struct ItemScope {
155
156
156
157
/// The defs declared in this scope. Each def has a single scope where it is
157
158
/// declared.
158
- declarations : Vec < ModuleDefId > ,
159
+ declarations : ThinVec < ModuleDefId > ,
159
160
160
- impls : Vec < ImplId > ,
161
- #[ allow( clippy:: box_collection) ]
162
- extern_blocks : Option < Box < Vec < ExternBlockId > > > ,
163
- unnamed_consts : Vec < ConstId > ,
161
+ impls : ThinVec < ImplId > ,
162
+ extern_blocks : ThinVec < ExternBlockId > ,
163
+ unnamed_consts : ThinVec < ConstId > ,
164
164
/// Traits imported via `use Trait as _;`.
165
- unnamed_trait_imports : FxHashMap < TraitId , Item < ( ) > > ,
165
+ unnamed_trait_imports : ThinVec < ( TraitId , Item < ( ) > ) > ,
166
166
167
167
// the resolutions of the imports of this scope
168
168
use_imports_types : FxHashMap < ImportOrExternCrate , ImportOrDef > ,
169
169
use_imports_values : FxHashMap < ImportOrGlob , ImportOrDef > ,
170
170
use_imports_macros : FxHashMap < ImportOrExternCrate , ImportOrDef > ,
171
171
172
- use_decls : Vec < UseId > ,
173
- extern_crate_decls : Vec < ExternCrateId > ,
172
+ use_decls : ThinVec < UseId > ,
173
+ extern_crate_decls : ThinVec < ExternCrateId > ,
174
174
/// Macros visible in current module in legacy textual scope
175
175
///
176
176
/// For macros invoked by an unqualified identifier like `bar!()`, `legacy_macros` will be searched in first.
@@ -183,7 +183,7 @@ pub struct ItemScope {
183
183
/// Module scoped macros will be inserted into `items` instead of here.
184
184
// FIXME: Macro shadowing in one module is not properly handled. Non-item place macros will
185
185
// be all resolved to the last one defined if shadowing happens.
186
- legacy_macros : FxHashMap < Name , SmallVec < [ MacroId ; 1 ] > > ,
186
+ legacy_macros : FxHashMap < Name , SmallVec < [ MacroId ; 2 ] > > ,
187
187
/// The attribute macro invocations in this scope.
188
188
attr_macros : FxHashMap < AstId < ast:: Item > , MacroCallId > ,
189
189
/// The macro invocations in this scope.
@@ -198,7 +198,7 @@ struct DeriveMacroInvocation {
198
198
attr_id : AttrId ,
199
199
/// The `#[derive]` call
200
200
attr_call_id : MacroCallId ,
201
- derive_call_ids : SmallVec < [ Option < MacroCallId > ; 1 ] > ,
201
+ derive_call_ids : SmallVec < [ Option < MacroCallId > ; 4 ] > ,
202
202
}
203
203
204
204
pub ( crate ) static BUILTIN_SCOPE : LazyLock < FxIndexMap < Name , PerNs > > = LazyLock :: new ( || {
@@ -322,7 +322,7 @@ impl ItemScope {
322
322
}
323
323
324
324
pub fn extern_blocks ( & self ) -> impl Iterator < Item = ExternBlockId > + ' _ {
325
- self . extern_blocks . iter ( ) . flat_map ( |it| it . iter ( ) ) . copied ( )
325
+ self . extern_blocks . iter ( ) . copied ( )
326
326
}
327
327
328
328
pub fn use_decls ( & self ) -> impl ExactSizeIterator < Item = UseId > + ' _ {
@@ -435,7 +435,7 @@ impl ItemScope {
435
435
ModuleDefId :: TraitId ( t) => Some ( t) ,
436
436
_ => None ,
437
437
} )
438
- . chain ( self . unnamed_trait_imports . keys ( ) . copied ( ) )
438
+ . chain ( self . unnamed_trait_imports . iter ( ) . map ( | & ( t , _ ) | t ) )
439
439
}
440
440
441
441
pub ( crate ) fn resolutions ( & self ) -> impl Iterator < Item = ( Option < Name > , PerNs ) > + ' _ {
@@ -476,7 +476,7 @@ impl ItemScope {
476
476
}
477
477
478
478
pub ( crate ) fn define_extern_block ( & mut self , extern_block : ExternBlockId ) {
479
- self . extern_blocks . get_or_insert_default ( ) . push ( extern_block) ;
479
+ self . extern_blocks . push ( extern_block) ;
480
480
}
481
481
482
482
pub ( crate ) fn define_extern_crate_decl ( & mut self , extern_crate : ExternCrateId ) {
@@ -564,7 +564,7 @@ impl ItemScope {
564
564
565
565
// FIXME: This is only used in collection, we should move the relevant parts of it out of ItemScope
566
566
pub ( crate ) fn unnamed_trait_vis ( & self , tr : TraitId ) -> Option < Visibility > {
567
- self . unnamed_trait_imports . get ( & tr) . map ( |trait_| trait_. vis )
567
+ self . unnamed_trait_imports . iter ( ) . find ( | & & ( t , _ ) | t == tr) . map ( |( _ , trait_) | trait_. vis )
568
568
}
569
569
570
570
pub ( crate ) fn push_unnamed_trait (
@@ -573,7 +573,7 @@ impl ItemScope {
573
573
vis : Visibility ,
574
574
import : Option < ImportId > ,
575
575
) {
576
- self . unnamed_trait_imports . insert ( tr, Item { def : ( ) , vis, import } ) ;
576
+ self . unnamed_trait_imports . push ( ( tr, Item { def : ( ) , vis, import } ) ) ;
577
577
}
578
578
579
579
pub ( crate ) fn push_res_with_import (
@@ -725,7 +725,7 @@ impl ItemScope {
725
725
. values_mut ( )
726
726
. map ( |def| & mut def. vis )
727
727
. chain ( self . values . values_mut ( ) . map ( |def| & mut def. vis ) )
728
- . chain ( self . unnamed_trait_imports . values_mut ( ) . map ( |def| & mut def. vis ) )
728
+ . chain ( self . unnamed_trait_imports . iter_mut ( ) . map ( |( _ , def) | & mut def. vis ) )
729
729
. for_each ( |vis| match vis {
730
730
& mut Visibility :: Module ( _, visibility_explicitness) => {
731
731
* vis = Visibility :: Module ( this_module, visibility_explicitness)
@@ -817,9 +817,7 @@ impl ItemScope {
817
817
macro_invocations,
818
818
extern_blocks,
819
819
} = self ;
820
- if let Some ( it) = extern_blocks {
821
- it. shrink_to_fit ( ) ;
822
- }
820
+ extern_blocks. shrink_to_fit ( ) ;
823
821
types. shrink_to_fit ( ) ;
824
822
values. shrink_to_fit ( ) ;
825
823
macros. shrink_to_fit ( ) ;
0 commit comments