@@ -522,6 +522,29 @@ impl<'a> ModuleData<'a> {
522
522
}
523
523
}
524
524
525
+ /// This modifies `self` in place. The traits will be stored in `self.traits`.
526
+ fn ensure_traits < R > ( & ' a self , resolver : & mut R )
527
+ where
528
+ R : AsMut < Resolver < ' a > > ,
529
+ {
530
+ let mut traits = self . traits . borrow_mut ( ) ;
531
+ if traits. is_none ( ) {
532
+ let mut collected_traits = Vec :: new ( ) ;
533
+ self . for_each_child ( resolver, |_, name, ns, binding| {
534
+ if ns != TypeNS {
535
+ return ;
536
+ }
537
+ match binding. res ( ) {
538
+ Res :: Def ( DefKind :: Trait | DefKind :: TraitAlias , _) => {
539
+ collected_traits. push ( ( name, binding) )
540
+ }
541
+ _ => ( ) ,
542
+ }
543
+ } ) ;
544
+ * traits = Some ( collected_traits. into_boxed_slice ( ) ) ;
545
+ }
546
+ }
547
+
525
548
fn res ( & self ) -> Option < Res > {
526
549
match self . kind {
527
550
ModuleKind :: Def ( kind, def_id, _) => Some ( Res :: Def ( kind, def_id) ) ,
@@ -1440,22 +1463,8 @@ impl<'a> Resolver<'a> {
1440
1463
parent_scope : & ParentScope < ' a > ,
1441
1464
) {
1442
1465
assert ! ( ns == TypeNS || ns == ValueNS ) ;
1443
- let mut traits = module. traits . borrow_mut ( ) ;
1444
- if traits. is_none ( ) {
1445
- let mut collected_traits = Vec :: new ( ) ;
1446
- module. for_each_child ( self , |_, name, ns, binding| {
1447
- if ns != TypeNS {
1448
- return ;
1449
- }
1450
- match binding. res ( ) {
1451
- Res :: Def ( DefKind :: Trait | DefKind :: TraitAlias , _) => {
1452
- collected_traits. push ( ( name, binding) )
1453
- }
1454
- _ => ( ) ,
1455
- }
1456
- } ) ;
1457
- * traits = Some ( collected_traits. into_boxed_slice ( ) ) ;
1458
- }
1466
+ module. ensure_traits ( self ) ;
1467
+ let traits = module. traits . borrow ( ) ;
1459
1468
1460
1469
for & ( trait_name, binding) in traits. as_ref ( ) . unwrap ( ) . iter ( ) {
1461
1470
// Traits have pseudo-modules that can be used to search for the given ident.
0 commit comments