@@ -109,7 +109,7 @@ impl<'a> Ctx<'a> {
109
109
ast:: Item :: Static ( ast) => self . lower_static ( ast) ?. into ( ) ,
110
110
ast:: Item :: Const ( ast) => self . lower_const ( ast) . into ( ) ,
111
111
ast:: Item :: Module ( ast) => self . lower_module ( ast) ?. into ( ) ,
112
- ast:: Item :: Trait ( ast) => self . lower_trait ( ast) ?. into ( ) ,
112
+ ast:: Item :: Trait ( ast) => self . lower_trait ( ast) ?,
113
113
ast:: Item :: Impl ( ast) => self . lower_impl ( ast) ?. into ( ) ,
114
114
ast:: Item :: Use ( ast) => self . lower_use ( ast) ?. into ( ) ,
115
115
ast:: Item :: ExternCrate ( ast) => self . lower_extern_crate ( ast) ?. into ( ) ,
@@ -439,26 +439,39 @@ impl<'a> Ctx<'a> {
439
439
Some ( id ( self . data ( ) . mods . alloc ( res) ) )
440
440
}
441
441
442
- fn lower_trait ( & mut self , trait_def : & ast:: Trait ) -> Option < FileItemTreeId < Trait > > {
442
+ fn lower_trait ( & mut self , trait_def : & ast:: Trait ) -> Option < ModItem > {
443
443
let name = trait_def. name ( ) ?. as_name ( ) ;
444
444
let visibility = self . lower_visibility ( trait_def) ;
445
445
let generic_params = self . lower_generic_params ( GenericsOwner :: Trait ( trait_def) , trait_def) ;
446
446
let is_auto = trait_def. auto_token ( ) . is_some ( ) ;
447
447
let is_unsafe = trait_def. unsafe_token ( ) . is_some ( ) ;
448
- let items = trait_def. assoc_item_list ( ) . map ( |list| {
449
- list. assoc_items ( )
448
+ let ast_id = self . source_ast_id_map . ast_id ( trait_def) ;
449
+
450
+ let item = if trait_def. eq_token ( ) . is_some ( ) {
451
+ // trait aliases
452
+ let bounds = self . lower_type_bounds ( trait_def) . into_boxed_slice ( ) ;
453
+ let alias = TraitAlias { name, visibility, generic_params, bounds, ast_id } ;
454
+ id ( self . data ( ) . trait_aliases . alloc ( alias) ) . into ( )
455
+ } else {
456
+ // trait definition
457
+ let items = trait_def
458
+ . assoc_item_list ( )
459
+ . into_iter ( )
460
+ . flat_map ( |list| list. assoc_items ( ) )
450
461
. filter_map ( |item| {
451
462
let attrs = RawAttrs :: new ( self . db . upcast ( ) , & item, self . hygiene ( ) ) ;
452
463
self . lower_assoc_item ( & item) . map ( |item| {
453
464
self . add_attrs ( ModItem :: from ( item) . into ( ) , attrs) ;
454
465
item
455
466
} )
456
467
} )
457
- . collect ( )
458
- } ) ;
459
- let ast_id = self . source_ast_id_map . ast_id ( trait_def) ;
460
- let res = Trait { name, visibility, generic_params, is_auto, is_unsafe, items, ast_id } ;
461
- Some ( id ( self . data ( ) . traits . alloc ( res) ) )
468
+ . collect ( ) ;
469
+
470
+ let def = Trait { name, visibility, generic_params, is_auto, is_unsafe, items, ast_id } ;
471
+ id ( self . data ( ) . traits . alloc ( def) ) . into ( )
472
+ } ;
473
+
474
+ Some ( item)
462
475
}
463
476
464
477
fn lower_impl ( & mut self , impl_def : & ast:: Impl ) -> Option < FileItemTreeId < Impl > > {
0 commit comments