@@ -335,8 +335,8 @@ pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
335
335
token:: NtLifetime ( e) => e. to_string ( ) ,
336
336
token:: NtLiteral ( ref e) => expr_to_string ( e) ,
337
337
token:: NtTT ( ref tree) => tt_to_string ( tree. clone ( ) ) ,
338
- token :: NtImplItem ( ref e ) => impl_item_to_string ( e ) ,
339
- token:: NtTraitItem ( ref e) => trait_item_to_string ( e) ,
338
+ // FIXME(Centril): merge these variants.
339
+ token:: NtImplItem ( ref e) | token :: NtTraitItem ( ref e ) => assoc_item_to_string ( e) ,
340
340
token:: NtVis ( ref e) => vis_to_string ( e) ,
341
341
token:: NtForeignItem ( ref e) => foreign_item_to_string ( e) ,
342
342
}
@@ -374,12 +374,8 @@ pub fn item_to_string(i: &ast::Item) -> String {
374
374
to_string ( |s| s. print_item ( i) )
375
375
}
376
376
377
- fn impl_item_to_string ( i : & ast:: ImplItem ) -> String {
378
- to_string ( |s| s. print_impl_item ( i) )
379
- }
380
-
381
- fn trait_item_to_string ( i : & ast:: TraitItem ) -> String {
382
- to_string ( |s| s. print_trait_item ( i) )
377
+ fn assoc_item_to_string ( i : & ast:: AssocItem ) -> String {
378
+ to_string ( |s| s. print_assoc_item ( i) )
383
379
}
384
380
385
381
pub fn generic_params_to_string ( generic_params : & [ ast:: GenericParam ] ) -> String {
@@ -1301,7 +1297,7 @@ impl<'a> State<'a> {
1301
1297
self . bopen ( ) ;
1302
1298
self . print_inner_attributes ( & item. attrs ) ;
1303
1299
for impl_item in impl_items {
1304
- self . print_impl_item ( impl_item) ;
1300
+ self . print_assoc_item ( impl_item) ;
1305
1301
}
1306
1302
self . bclose ( item. span ) ;
1307
1303
}
@@ -1328,7 +1324,7 @@ impl<'a> State<'a> {
1328
1324
self . s . word ( " " ) ;
1329
1325
self . bopen ( ) ;
1330
1326
for trait_item in trait_items {
1331
- self . print_trait_item ( trait_item) ;
1327
+ self . print_assoc_item ( trait_item) ;
1332
1328
}
1333
1329
self . bclose ( item. span ) ;
1334
1330
}
@@ -1522,89 +1518,39 @@ impl<'a> State<'a> {
1522
1518
}
1523
1519
}
1524
1520
1525
- crate fn print_method_sig ( & mut self ,
1526
- ident : ast:: Ident ,
1527
- generics : & ast:: Generics ,
1528
- m : & ast:: FnSig ,
1529
- vis : & ast:: Visibility )
1530
- {
1531
- self . print_fn ( & m. decl ,
1532
- m. header ,
1533
- Some ( ident) ,
1534
- & generics,
1535
- vis)
1536
- }
1537
-
1538
- crate fn print_trait_item ( & mut self , ti : & ast:: TraitItem )
1539
- {
1540
- self . ann . pre ( self , AnnNode :: SubItem ( ti. id ) ) ;
1521
+ crate fn print_assoc_item ( & mut self , item : & ast:: AssocItem ) {
1522
+ self . ann . pre ( self , AnnNode :: SubItem ( item. id ) ) ;
1541
1523
self . hardbreak_if_not_bol ( ) ;
1542
- self . maybe_print_comment ( ti. span . lo ( ) ) ;
1543
- self . print_outer_attributes ( & ti. attrs ) ;
1544
- self . print_defaultness ( ti. defaultness ) ;
1545
- match ti. kind {
1546
- ast:: TraitItemKind :: Const ( ref ty, ref default) => {
1547
- self . print_associated_const ( ti. ident , ty, default. as_deref ( ) , & ti. vis ) ;
1548
- }
1549
- ast:: TraitItemKind :: Method ( ref sig, ref body) => {
1550
- if body. is_some ( ) {
1551
- self . head ( "" ) ;
1552
- }
1553
- self . print_method_sig ( ti. ident , & ti. generics , sig, & ti. vis ) ;
1554
- if let Some ( ref body) = * body {
1555
- self . nbsp ( ) ;
1556
- self . print_block_with_attrs ( body, & ti. attrs ) ;
1557
- } else {
1558
- self . s . word ( ";" ) ;
1559
- }
1560
- }
1561
- ast:: TraitItemKind :: TyAlias ( ref bounds, ref default) => {
1562
- self . print_associated_type ( ti. ident , bounds, default. as_deref ( ) ) ;
1563
- }
1564
- ast:: TraitItemKind :: Macro ( ref mac) => {
1565
- self . print_mac ( mac) ;
1566
- if mac. args . need_semicolon ( ) {
1567
- self . s . word ( ";" ) ;
1568
- }
1524
+ self . maybe_print_comment ( item. span . lo ( ) ) ;
1525
+ self . print_outer_attributes ( & item. attrs ) ;
1526
+ self . print_defaultness ( item. defaultness ) ;
1527
+ match & item. kind {
1528
+ ast:: AssocItemKind :: Const ( ty, expr) => {
1529
+ self . print_associated_const ( item. ident , ty, expr. as_deref ( ) , & item. vis ) ;
1569
1530
}
1570
- }
1571
- self . ann . post ( self , AnnNode :: SubItem ( ti. id ) )
1572
- }
1573
-
1574
- // FIXME(Centril): merge with function above.
1575
- crate fn print_impl_item ( & mut self , ii : & ast:: ImplItem ) {
1576
- self . ann . pre ( self , AnnNode :: SubItem ( ii. id ) ) ;
1577
- self . hardbreak_if_not_bol ( ) ;
1578
- self . maybe_print_comment ( ii. span . lo ( ) ) ;
1579
- self . print_outer_attributes ( & ii. attrs ) ;
1580
- self . print_defaultness ( ii. defaultness ) ;
1581
- match ii. kind {
1582
- ast:: ImplItemKind :: Const ( ref ty, ref expr) => {
1583
- self . print_associated_const ( ii. ident , ty, expr. as_deref ( ) , & ii. vis ) ;
1584
- }
1585
- ast:: ImplItemKind :: Method ( ref sig, ref body) => {
1531
+ ast:: AssocItemKind :: Method ( sig, body) => {
1586
1532
if body. is_some ( ) {
1587
1533
self . head ( "" ) ;
1588
1534
}
1589
- self . print_method_sig ( ii . ident , & ii . generics , sig , & ii . vis ) ;
1535
+ self . print_fn ( & sig . decl , sig . header , Some ( item . ident ) , & item . generics , & item . vis ) ;
1590
1536
if let Some ( body) = body {
1591
1537
self . nbsp ( ) ;
1592
- self . print_block_with_attrs ( body, & ii . attrs ) ;
1538
+ self . print_block_with_attrs ( body, & item . attrs ) ;
1593
1539
} else {
1594
1540
self . s . word ( ";" ) ;
1595
1541
}
1596
1542
}
1597
- ast:: ImplItemKind :: TyAlias ( ref bounds, ref ty) => {
1598
- self . print_associated_type ( ii . ident , bounds, ty. as_deref ( ) ) ;
1543
+ ast:: AssocItemKind :: TyAlias ( bounds, ty) => {
1544
+ self . print_associated_type ( item . ident , bounds, ty. as_deref ( ) ) ;
1599
1545
}
1600
- ast:: ImplItemKind :: Macro ( ref mac) => {
1546
+ ast:: AssocItemKind :: Macro ( mac) => {
1601
1547
self . print_mac ( mac) ;
1602
1548
if mac. args . need_semicolon ( ) {
1603
1549
self . s . word ( ";" ) ;
1604
1550
}
1605
1551
}
1606
1552
}
1607
- self . ann . post ( self , AnnNode :: SubItem ( ii . id ) )
1553
+ self . ann . post ( self , AnnNode :: SubItem ( item . id ) )
1608
1554
}
1609
1555
1610
1556
crate fn print_stmt ( & mut self , st : & ast:: Stmt ) {
0 commit comments