1
1
mod expr;
2
+ mod item;
2
3
3
4
use crate :: pp:: Breaks :: { Consistent , Inconsistent } ;
4
5
use crate :: pp:: { self , Breaks } ;
@@ -11,7 +12,7 @@ use rustc_ast::util::classify;
11
12
use rustc_ast:: util:: comments:: { gather_comments, Comment , CommentStyle } ;
12
13
use rustc_ast:: util:: parser;
13
14
use rustc_ast:: { self as ast, BlockCheckMode , PatKind , RangeEnd , RangeSyntax } ;
14
- use rustc_ast:: { GenericArg , MacArgs , ModKind } ;
15
+ use rustc_ast:: { GenericArg , MacArgs } ;
15
16
use rustc_ast:: { GenericBound , SelfKind , TraitBoundModifier } ;
16
17
use rustc_ast:: { InlineAsmOperand , InlineAsmRegOrRegClass } ;
17
18
use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
@@ -212,10 +213,6 @@ pub fn literal_to_string(lit: token::Lit) -> String {
212
213
out
213
214
}
214
215
215
- fn visibility_qualified ( vis : & ast:: Visibility , s : & str ) -> String {
216
- format ! ( "{}{}" , State :: to_string( |s| s. print_visibility( vis) ) , s)
217
- }
218
-
219
216
impl std:: ops:: Deref for State < ' _ > {
220
217
type Target = pp:: Printer ;
221
218
fn deref ( & self ) -> & Self :: Target {
@@ -940,13 +937,6 @@ impl<'a> State<'a> {
940
937
self . commasep_cmnt ( b, exprs, |s, e| s. print_expr ( e) , |e| e. span )
941
938
}
942
939
943
- crate fn print_foreign_mod ( & mut self , nmod : & ast:: ForeignMod , attrs : & [ ast:: Attribute ] ) {
944
- self . print_inner_attributes ( attrs) ;
945
- for item in & nmod. items {
946
- self . print_foreign_item ( item) ;
947
- }
948
- }
949
-
950
940
pub fn print_opt_lifetime ( & mut self , lifetime : & Option < ast:: Lifetime > ) {
951
941
if let Some ( lt) = * lifetime {
952
942
self . print_lifetime ( lt) ;
@@ -1058,343 +1048,6 @@ impl<'a> State<'a> {
1058
1048
self . end ( ) ;
1059
1049
}
1060
1050
1061
- crate fn print_foreign_item ( & mut self , item : & ast:: ForeignItem ) {
1062
- let ast:: Item { id, span, ident, ref attrs, ref kind, ref vis, tokens : _ } = * item;
1063
- self . ann . pre ( self , AnnNode :: SubItem ( id) ) ;
1064
- self . hardbreak_if_not_bol ( ) ;
1065
- self . maybe_print_comment ( span. lo ( ) ) ;
1066
- self . print_outer_attributes ( attrs) ;
1067
- match kind {
1068
- ast:: ForeignItemKind :: Fn ( box ast:: Fn { defaultness, sig, generics, body } ) => {
1069
- self . print_fn_full ( sig, ident, generics, vis, * defaultness, body. as_deref ( ) , attrs) ;
1070
- }
1071
- ast:: ForeignItemKind :: Static ( ty, mutbl, body) => {
1072
- let def = ast:: Defaultness :: Final ;
1073
- self . print_item_const ( ident, Some ( * mutbl) , ty, body. as_deref ( ) , vis, def) ;
1074
- }
1075
- ast:: ForeignItemKind :: TyAlias ( box ast:: TyAlias {
1076
- defaultness,
1077
- generics,
1078
- bounds,
1079
- ty,
1080
- } ) => {
1081
- self . print_associated_type (
1082
- ident,
1083
- generics,
1084
- bounds,
1085
- ty. as_deref ( ) ,
1086
- vis,
1087
- * defaultness,
1088
- ) ;
1089
- }
1090
- ast:: ForeignItemKind :: MacCall ( m) => {
1091
- self . print_mac ( m) ;
1092
- if m. args . need_semicolon ( ) {
1093
- self . word ( ";" ) ;
1094
- }
1095
- }
1096
- }
1097
- self . ann . post ( self , AnnNode :: SubItem ( id) )
1098
- }
1099
-
1100
- fn print_item_const (
1101
- & mut self ,
1102
- ident : Ident ,
1103
- mutbl : Option < ast:: Mutability > ,
1104
- ty : & ast:: Ty ,
1105
- body : Option < & ast:: Expr > ,
1106
- vis : & ast:: Visibility ,
1107
- defaultness : ast:: Defaultness ,
1108
- ) {
1109
- self . head ( "" ) ;
1110
- self . print_visibility ( vis) ;
1111
- self . print_defaultness ( defaultness) ;
1112
- let leading = match mutbl {
1113
- None => "const" ,
1114
- Some ( ast:: Mutability :: Not ) => "static" ,
1115
- Some ( ast:: Mutability :: Mut ) => "static mut" ,
1116
- } ;
1117
- self . word_space ( leading) ;
1118
- self . print_ident ( ident) ;
1119
- self . word_space ( ":" ) ;
1120
- self . print_type ( ty) ;
1121
- if body. is_some ( ) {
1122
- self . space ( ) ;
1123
- }
1124
- self . end ( ) ; // end the head-ibox
1125
- if let Some ( body) = body {
1126
- self . word_space ( "=" ) ;
1127
- self . print_expr ( body) ;
1128
- }
1129
- self . word ( ";" ) ;
1130
- self . end ( ) ; // end the outer cbox
1131
- }
1132
-
1133
- fn print_associated_type (
1134
- & mut self ,
1135
- ident : Ident ,
1136
- generics : & ast:: Generics ,
1137
- bounds : & ast:: GenericBounds ,
1138
- ty : Option < & ast:: Ty > ,
1139
- vis : & ast:: Visibility ,
1140
- defaultness : ast:: Defaultness ,
1141
- ) {
1142
- self . head ( "" ) ;
1143
- self . print_visibility ( vis) ;
1144
- self . print_defaultness ( defaultness) ;
1145
- self . word_space ( "type" ) ;
1146
- self . print_ident ( ident) ;
1147
- self . print_generic_params ( & generics. params ) ;
1148
- self . print_type_bounds ( ":" , bounds) ;
1149
- self . print_where_clause ( & generics. where_clause ) ;
1150
- if let Some ( ty) = ty {
1151
- self . space ( ) ;
1152
- self . word_space ( "=" ) ;
1153
- self . print_type ( ty) ;
1154
- }
1155
- self . word ( ";" ) ;
1156
- self . end ( ) ; // end inner head-block
1157
- self . end ( ) ; // end outer head-block
1158
- }
1159
-
1160
- /// Pretty-prints an item.
1161
- crate fn print_item ( & mut self , item : & ast:: Item ) {
1162
- self . hardbreak_if_not_bol ( ) ;
1163
- self . maybe_print_comment ( item. span . lo ( ) ) ;
1164
- self . print_outer_attributes ( & item. attrs ) ;
1165
- self . ann . pre ( self , AnnNode :: Item ( item) ) ;
1166
- match item. kind {
1167
- ast:: ItemKind :: ExternCrate ( orig_name) => {
1168
- self . head ( visibility_qualified ( & item. vis , "extern crate" ) ) ;
1169
- if let Some ( orig_name) = orig_name {
1170
- self . print_name ( orig_name) ;
1171
- self . space ( ) ;
1172
- self . word ( "as" ) ;
1173
- self . space ( ) ;
1174
- }
1175
- self . print_ident ( item. ident ) ;
1176
- self . word ( ";" ) ;
1177
- self . end ( ) ; // end inner head-block
1178
- self . end ( ) ; // end outer head-block
1179
- }
1180
- ast:: ItemKind :: Use ( ref tree) => {
1181
- self . head ( visibility_qualified ( & item. vis , "use" ) ) ;
1182
- self . print_use_tree ( tree) ;
1183
- self . word ( ";" ) ;
1184
- self . end ( ) ; // end inner head-block
1185
- self . end ( ) ; // end outer head-block
1186
- }
1187
- ast:: ItemKind :: Static ( ref ty, mutbl, ref body) => {
1188
- let def = ast:: Defaultness :: Final ;
1189
- self . print_item_const ( item. ident , Some ( mutbl) , ty, body. as_deref ( ) , & item. vis , def) ;
1190
- }
1191
- ast:: ItemKind :: Const ( def, ref ty, ref body) => {
1192
- self . print_item_const ( item. ident , None , ty, body. as_deref ( ) , & item. vis , def) ;
1193
- }
1194
- ast:: ItemKind :: Fn ( box ast:: Fn { defaultness, ref sig, ref generics, ref body } ) => {
1195
- let body = body. as_deref ( ) ;
1196
- self . print_fn_full (
1197
- sig,
1198
- item. ident ,
1199
- generics,
1200
- & item. vis ,
1201
- defaultness,
1202
- body,
1203
- & item. attrs ,
1204
- ) ;
1205
- }
1206
- ast:: ItemKind :: Mod ( unsafety, ref mod_kind) => {
1207
- self . head ( Self :: to_string ( |s| {
1208
- s. print_visibility ( & item. vis ) ;
1209
- s. print_unsafety ( unsafety) ;
1210
- s. word ( "mod" ) ;
1211
- } ) ) ;
1212
- self . print_ident ( item. ident ) ;
1213
-
1214
- match mod_kind {
1215
- ModKind :: Loaded ( items, ..) => {
1216
- self . nbsp ( ) ;
1217
- self . bopen ( ) ;
1218
- self . print_inner_attributes ( & item. attrs ) ;
1219
- for item in items {
1220
- self . print_item ( item) ;
1221
- }
1222
- let empty = item. attrs . is_empty ( ) && items. is_empty ( ) ;
1223
- self . bclose ( item. span , empty) ;
1224
- }
1225
- ModKind :: Unloaded => {
1226
- self . word ( ";" ) ;
1227
- self . end ( ) ; // end inner head-block
1228
- self . end ( ) ; // end outer head-block
1229
- }
1230
- }
1231
- }
1232
- ast:: ItemKind :: ForeignMod ( ref nmod) => {
1233
- self . head ( Self :: to_string ( |s| {
1234
- s. print_unsafety ( nmod. unsafety ) ;
1235
- s. word ( "extern" ) ;
1236
- } ) ) ;
1237
- if let Some ( abi) = nmod. abi {
1238
- self . print_literal ( & abi. as_lit ( ) ) ;
1239
- self . nbsp ( ) ;
1240
- }
1241
- self . bopen ( ) ;
1242
- self . print_foreign_mod ( nmod, & item. attrs ) ;
1243
- let empty = item. attrs . is_empty ( ) && nmod. items . is_empty ( ) ;
1244
- self . bclose ( item. span , empty) ;
1245
- }
1246
- ast:: ItemKind :: GlobalAsm ( ref asm) => {
1247
- self . head ( visibility_qualified ( & item. vis , "global_asm!" ) ) ;
1248
- self . print_inline_asm ( asm) ;
1249
- self . end ( ) ;
1250
- }
1251
- ast:: ItemKind :: TyAlias ( box ast:: TyAlias {
1252
- defaultness,
1253
- ref generics,
1254
- ref bounds,
1255
- ref ty,
1256
- } ) => {
1257
- let ty = ty. as_deref ( ) ;
1258
- self . print_associated_type (
1259
- item. ident ,
1260
- generics,
1261
- bounds,
1262
- ty,
1263
- & item. vis ,
1264
- defaultness,
1265
- ) ;
1266
- }
1267
- ast:: ItemKind :: Enum ( ref enum_definition, ref params) => {
1268
- self . print_enum_def ( enum_definition, params, item. ident , item. span , & item. vis ) ;
1269
- }
1270
- ast:: ItemKind :: Struct ( ref struct_def, ref generics) => {
1271
- self . head ( visibility_qualified ( & item. vis , "struct" ) ) ;
1272
- self . print_struct ( struct_def, generics, item. ident , item. span , true ) ;
1273
- }
1274
- ast:: ItemKind :: Union ( ref struct_def, ref generics) => {
1275
- self . head ( visibility_qualified ( & item. vis , "union" ) ) ;
1276
- self . print_struct ( struct_def, generics, item. ident , item. span , true ) ;
1277
- }
1278
- ast:: ItemKind :: Impl ( box ast:: Impl {
1279
- unsafety,
1280
- polarity,
1281
- defaultness,
1282
- constness,
1283
- ref generics,
1284
- ref of_trait,
1285
- ref self_ty,
1286
- ref items,
1287
- } ) => {
1288
- self . head ( "" ) ;
1289
- self . print_visibility ( & item. vis ) ;
1290
- self . print_defaultness ( defaultness) ;
1291
- self . print_unsafety ( unsafety) ;
1292
- self . word ( "impl" ) ;
1293
-
1294
- if generics. params . is_empty ( ) {
1295
- self . nbsp ( ) ;
1296
- } else {
1297
- self . print_generic_params ( & generics. params ) ;
1298
- self . space ( ) ;
1299
- }
1300
-
1301
- self . print_constness ( constness) ;
1302
-
1303
- if let ast:: ImplPolarity :: Negative ( _) = polarity {
1304
- self . word ( "!" ) ;
1305
- }
1306
-
1307
- if let Some ( ref t) = * of_trait {
1308
- self . print_trait_ref ( t) ;
1309
- self . space ( ) ;
1310
- self . word_space ( "for" ) ;
1311
- }
1312
-
1313
- self . print_type ( self_ty) ;
1314
- self . print_where_clause ( & generics. where_clause ) ;
1315
-
1316
- self . space ( ) ;
1317
- self . bopen ( ) ;
1318
- self . print_inner_attributes ( & item. attrs ) ;
1319
- for impl_item in items {
1320
- self . print_assoc_item ( impl_item) ;
1321
- }
1322
- let empty = item. attrs . is_empty ( ) && items. is_empty ( ) ;
1323
- self . bclose ( item. span , empty) ;
1324
- }
1325
- ast:: ItemKind :: Trait ( box ast:: Trait {
1326
- is_auto,
1327
- unsafety,
1328
- ref generics,
1329
- ref bounds,
1330
- ref items,
1331
- ..
1332
- } ) => {
1333
- self . head ( "" ) ;
1334
- self . print_visibility ( & item. vis ) ;
1335
- self . print_unsafety ( unsafety) ;
1336
- self . print_is_auto ( is_auto) ;
1337
- self . word_nbsp ( "trait" ) ;
1338
- self . print_ident ( item. ident ) ;
1339
- self . print_generic_params ( & generics. params ) ;
1340
- let mut real_bounds = Vec :: with_capacity ( bounds. len ( ) ) ;
1341
- for b in bounds. iter ( ) {
1342
- if let GenericBound :: Trait ( ref ptr, ast:: TraitBoundModifier :: Maybe ) = * b {
1343
- self . space ( ) ;
1344
- self . word_space ( "for ?" ) ;
1345
- self . print_trait_ref ( & ptr. trait_ref ) ;
1346
- } else {
1347
- real_bounds. push ( b. clone ( ) ) ;
1348
- }
1349
- }
1350
- self . print_type_bounds ( ":" , & real_bounds) ;
1351
- self . print_where_clause ( & generics. where_clause ) ;
1352
- self . word ( " " ) ;
1353
- self . bopen ( ) ;
1354
- self . print_inner_attributes ( & item. attrs ) ;
1355
- for trait_item in items {
1356
- self . print_assoc_item ( trait_item) ;
1357
- }
1358
- let empty = item. attrs . is_empty ( ) && items. is_empty ( ) ;
1359
- self . bclose ( item. span , empty) ;
1360
- }
1361
- ast:: ItemKind :: TraitAlias ( ref generics, ref bounds) => {
1362
- self . head ( "" ) ;
1363
- self . print_visibility ( & item. vis ) ;
1364
- self . word_nbsp ( "trait" ) ;
1365
- self . print_ident ( item. ident ) ;
1366
- self . print_generic_params ( & generics. params ) ;
1367
- let mut real_bounds = Vec :: with_capacity ( bounds. len ( ) ) ;
1368
- // FIXME(durka) this seems to be some quite outdated syntax
1369
- for b in bounds. iter ( ) {
1370
- if let GenericBound :: Trait ( ref ptr, ast:: TraitBoundModifier :: Maybe ) = * b {
1371
- self . space ( ) ;
1372
- self . word_space ( "for ?" ) ;
1373
- self . print_trait_ref ( & ptr. trait_ref ) ;
1374
- } else {
1375
- real_bounds. push ( b. clone ( ) ) ;
1376
- }
1377
- }
1378
- self . nbsp ( ) ;
1379
- self . print_type_bounds ( "=" , & real_bounds) ;
1380
- self . print_where_clause ( & generics. where_clause ) ;
1381
- self . word ( ";" ) ;
1382
- }
1383
- ast:: ItemKind :: MacCall ( ref mac) => {
1384
- self . print_mac ( mac) ;
1385
- if mac. args . need_semicolon ( ) {
1386
- self . word ( ";" ) ;
1387
- }
1388
- }
1389
- ast:: ItemKind :: MacroDef ( ref macro_def) => {
1390
- self . print_mac_def ( macro_def, & item. ident , & item. span , |state| {
1391
- state. print_visibility ( & item. vis )
1392
- } ) ;
1393
- }
1394
- }
1395
- self . ann . post ( self , AnnNode :: Item ( item) )
1396
- }
1397
-
1398
1051
fn print_trait_ref ( & mut self , t : & ast:: TraitRef ) {
1399
1052
self . print_path ( & t. path , false , 0 )
1400
1053
}
@@ -1412,167 +1065,6 @@ impl<'a> State<'a> {
1412
1065
self . print_trait_ref ( & t. trait_ref )
1413
1066
}
1414
1067
1415
- crate fn print_enum_def (
1416
- & mut self ,
1417
- enum_definition : & ast:: EnumDef ,
1418
- generics : & ast:: Generics ,
1419
- ident : Ident ,
1420
- span : rustc_span:: Span ,
1421
- visibility : & ast:: Visibility ,
1422
- ) {
1423
- self . head ( visibility_qualified ( visibility, "enum" ) ) ;
1424
- self . print_ident ( ident) ;
1425
- self . print_generic_params ( & generics. params ) ;
1426
- self . print_where_clause ( & generics. where_clause ) ;
1427
- self . space ( ) ;
1428
- self . print_variants ( & enum_definition. variants , span)
1429
- }
1430
-
1431
- crate fn print_variants ( & mut self , variants : & [ ast:: Variant ] , span : rustc_span:: Span ) {
1432
- self . bopen ( ) ;
1433
- for v in variants {
1434
- self . space_if_not_bol ( ) ;
1435
- self . maybe_print_comment ( v. span . lo ( ) ) ;
1436
- self . print_outer_attributes ( & v. attrs ) ;
1437
- self . ibox ( INDENT_UNIT ) ;
1438
- self . print_variant ( v) ;
1439
- self . word ( "," ) ;
1440
- self . end ( ) ;
1441
- self . maybe_print_trailing_comment ( v. span , None ) ;
1442
- }
1443
- let empty = variants. is_empty ( ) ;
1444
- self . bclose ( span, empty)
1445
- }
1446
-
1447
- crate fn print_visibility ( & mut self , vis : & ast:: Visibility ) {
1448
- match vis. kind {
1449
- ast:: VisibilityKind :: Public => self . word_nbsp ( "pub" ) ,
1450
- ast:: VisibilityKind :: Crate ( sugar) => match sugar {
1451
- ast:: CrateSugar :: PubCrate => self . word_nbsp ( "pub(crate)" ) ,
1452
- ast:: CrateSugar :: JustCrate => self . word_nbsp ( "crate" ) ,
1453
- } ,
1454
- ast:: VisibilityKind :: Restricted { ref path, .. } => {
1455
- let path = Self :: to_string ( |s| s. print_path ( path, false , 0 ) ) ;
1456
- if path == "self" || path == "super" {
1457
- self . word_nbsp ( format ! ( "pub({})" , path) )
1458
- } else {
1459
- self . word_nbsp ( format ! ( "pub(in {})" , path) )
1460
- }
1461
- }
1462
- ast:: VisibilityKind :: Inherited => { }
1463
- }
1464
- }
1465
-
1466
- crate fn print_defaultness ( & mut self , defaultness : ast:: Defaultness ) {
1467
- if let ast:: Defaultness :: Default ( _) = defaultness {
1468
- self . word_nbsp ( "default" ) ;
1469
- }
1470
- }
1471
-
1472
- crate fn print_record_struct_body ( & mut self , fields : & [ ast:: FieldDef ] , span : rustc_span:: Span ) {
1473
- self . nbsp ( ) ;
1474
- self . bopen ( ) ;
1475
-
1476
- let empty = fields. is_empty ( ) ;
1477
- if !empty {
1478
- self . hardbreak_if_not_bol ( ) ;
1479
-
1480
- for field in fields {
1481
- self . hardbreak_if_not_bol ( ) ;
1482
- self . maybe_print_comment ( field. span . lo ( ) ) ;
1483
- self . print_outer_attributes ( & field. attrs ) ;
1484
- self . print_visibility ( & field. vis ) ;
1485
- self . print_ident ( field. ident . unwrap ( ) ) ;
1486
- self . word_nbsp ( ":" ) ;
1487
- self . print_type ( & field. ty ) ;
1488
- self . word ( "," ) ;
1489
- }
1490
- }
1491
-
1492
- self . bclose ( span, empty) ;
1493
- }
1494
-
1495
- crate fn print_struct (
1496
- & mut self ,
1497
- struct_def : & ast:: VariantData ,
1498
- generics : & ast:: Generics ,
1499
- ident : Ident ,
1500
- span : rustc_span:: Span ,
1501
- print_finalizer : bool ,
1502
- ) {
1503
- self . print_ident ( ident) ;
1504
- self . print_generic_params ( & generics. params ) ;
1505
- match struct_def {
1506
- ast:: VariantData :: Tuple ( ..) | ast:: VariantData :: Unit ( ..) => {
1507
- if let ast:: VariantData :: Tuple ( ..) = struct_def {
1508
- self . popen ( ) ;
1509
- self . commasep ( Inconsistent , struct_def. fields ( ) , |s, field| {
1510
- s. maybe_print_comment ( field. span . lo ( ) ) ;
1511
- s. print_outer_attributes ( & field. attrs ) ;
1512
- s. print_visibility ( & field. vis ) ;
1513
- s. print_type ( & field. ty )
1514
- } ) ;
1515
- self . pclose ( ) ;
1516
- }
1517
- self . print_where_clause ( & generics. where_clause ) ;
1518
- if print_finalizer {
1519
- self . word ( ";" ) ;
1520
- }
1521
- self . end ( ) ;
1522
- self . end ( ) ; // Close the outer-box.
1523
- }
1524
- ast:: VariantData :: Struct ( ref fields, ..) => {
1525
- self . print_where_clause ( & generics. where_clause ) ;
1526
- self . print_record_struct_body ( fields, span) ;
1527
- }
1528
- }
1529
- }
1530
-
1531
- crate fn print_variant ( & mut self , v : & ast:: Variant ) {
1532
- self . head ( "" ) ;
1533
- self . print_visibility ( & v. vis ) ;
1534
- let generics = ast:: Generics :: default ( ) ;
1535
- self . print_struct ( & v. data , & generics, v. ident , v. span , false ) ;
1536
- if let Some ( ref d) = v. disr_expr {
1537
- self . space ( ) ;
1538
- self . word_space ( "=" ) ;
1539
- self . print_expr ( & d. value )
1540
- }
1541
- }
1542
-
1543
- crate fn print_assoc_item ( & mut self , item : & ast:: AssocItem ) {
1544
- let ast:: Item { id, span, ident, ref attrs, ref kind, ref vis, tokens : _ } = * item;
1545
- self . ann . pre ( self , AnnNode :: SubItem ( id) ) ;
1546
- self . hardbreak_if_not_bol ( ) ;
1547
- self . maybe_print_comment ( span. lo ( ) ) ;
1548
- self . print_outer_attributes ( attrs) ;
1549
- match kind {
1550
- ast:: AssocItemKind :: Fn ( box ast:: Fn { defaultness, sig, generics, body } ) => {
1551
- self . print_fn_full ( sig, ident, generics, vis, * defaultness, body. as_deref ( ) , attrs) ;
1552
- }
1553
- ast:: AssocItemKind :: Const ( def, ty, body) => {
1554
- self . print_item_const ( ident, None , ty, body. as_deref ( ) , vis, * def) ;
1555
- }
1556
- ast:: AssocItemKind :: TyAlias ( box ast:: TyAlias { defaultness, generics, bounds, ty } ) => {
1557
- self . print_associated_type (
1558
- ident,
1559
- generics,
1560
- bounds,
1561
- ty. as_deref ( ) ,
1562
- vis,
1563
- * defaultness,
1564
- ) ;
1565
- }
1566
- ast:: AssocItemKind :: MacCall ( m) => {
1567
- self . print_mac ( m) ;
1568
- if m. args . need_semicolon ( ) {
1569
- self . word ( ";" ) ;
1570
- }
1571
- }
1572
- }
1573
- self . ann . post ( self , AnnNode :: SubItem ( id) )
1574
- }
1575
-
1576
1068
crate fn print_stmt ( & mut self , st : & ast:: Stmt ) {
1577
1069
self . maybe_print_comment ( st. span . lo ( ) ) ;
1578
1070
match st. kind {
@@ -2011,55 +1503,6 @@ impl<'a> State<'a> {
2011
1503
}
2012
1504
}
2013
1505
2014
- fn print_fn_full (
2015
- & mut self ,
2016
- sig : & ast:: FnSig ,
2017
- name : Ident ,
2018
- generics : & ast:: Generics ,
2019
- vis : & ast:: Visibility ,
2020
- defaultness : ast:: Defaultness ,
2021
- body : Option < & ast:: Block > ,
2022
- attrs : & [ ast:: Attribute ] ,
2023
- ) {
2024
- if body. is_some ( ) {
2025
- self . head ( "" ) ;
2026
- }
2027
- self . print_visibility ( vis) ;
2028
- self . print_defaultness ( defaultness) ;
2029
- self . print_fn ( & sig. decl , sig. header , Some ( name) , generics) ;
2030
- if let Some ( body) = body {
2031
- self . nbsp ( ) ;
2032
- self . print_block_with_attrs ( body, attrs) ;
2033
- } else {
2034
- self . word ( ";" ) ;
2035
- }
2036
- }
2037
-
2038
- crate fn print_fn (
2039
- & mut self ,
2040
- decl : & ast:: FnDecl ,
2041
- header : ast:: FnHeader ,
2042
- name : Option < Ident > ,
2043
- generics : & ast:: Generics ,
2044
- ) {
2045
- self . print_fn_header_info ( header) ;
2046
- if let Some ( name) = name {
2047
- self . nbsp ( ) ;
2048
- self . print_ident ( name) ;
2049
- }
2050
- self . print_generic_params ( & generics. params ) ;
2051
- self . print_fn_params_and_ret ( decl, false ) ;
2052
- self . print_where_clause ( & generics. where_clause )
2053
- }
2054
-
2055
- crate fn print_fn_params_and_ret ( & mut self , decl : & ast:: FnDecl , is_closure : bool ) {
2056
- let ( open, close) = if is_closure { ( "|" , "|" ) } else { ( "(" , ")" ) } ;
2057
- self . word ( open) ;
2058
- self . commasep ( Inconsistent , & decl. inputs , |s, param| s. print_param ( param, is_closure) ) ;
2059
- self . word ( close) ;
2060
- self . print_fn_ret_ty ( & decl. output )
2061
- }
2062
-
2063
1506
crate fn print_asyncness ( & mut self , asyncness : ast:: Async ) {
2064
1507
if asyncness. is_async ( ) {
2065
1508
self . word_nbsp ( "async" ) ;
@@ -2160,83 +1603,6 @@ impl<'a> State<'a> {
2160
1603
self . word ( ">" ) ;
2161
1604
}
2162
1605
2163
- crate fn print_where_clause ( & mut self , where_clause : & ast:: WhereClause ) {
2164
- if where_clause. predicates . is_empty ( ) && !where_clause. has_where_token {
2165
- return ;
2166
- }
2167
-
2168
- self . space ( ) ;
2169
- self . word_space ( "where" ) ;
2170
-
2171
- for ( i, predicate) in where_clause. predicates . iter ( ) . enumerate ( ) {
2172
- if i != 0 {
2173
- self . word_space ( "," ) ;
2174
- }
2175
-
2176
- self . print_where_predicate ( predicate) ;
2177
- }
2178
- }
2179
-
2180
- pub fn print_where_predicate ( & mut self , predicate : & ast:: WherePredicate ) {
2181
- match predicate {
2182
- ast:: WherePredicate :: BoundPredicate ( ast:: WhereBoundPredicate {
2183
- bound_generic_params,
2184
- bounded_ty,
2185
- bounds,
2186
- ..
2187
- } ) => {
2188
- self . print_formal_generic_params ( bound_generic_params) ;
2189
- self . print_type ( bounded_ty) ;
2190
- self . print_type_bounds ( ":" , bounds) ;
2191
- }
2192
- ast:: WherePredicate :: RegionPredicate ( ast:: WhereRegionPredicate {
2193
- lifetime,
2194
- bounds,
2195
- ..
2196
- } ) => {
2197
- self . print_lifetime_bounds ( * lifetime, bounds) ;
2198
- }
2199
- ast:: WherePredicate :: EqPredicate ( ast:: WhereEqPredicate { lhs_ty, rhs_ty, .. } ) => {
2200
- self . print_type ( lhs_ty) ;
2201
- self . space ( ) ;
2202
- self . word_space ( "=" ) ;
2203
- self . print_type ( rhs_ty) ;
2204
- }
2205
- }
2206
- }
2207
-
2208
- crate fn print_use_tree ( & mut self , tree : & ast:: UseTree ) {
2209
- match tree. kind {
2210
- ast:: UseTreeKind :: Simple ( rename, ..) => {
2211
- self . print_path ( & tree. prefix , false , 0 ) ;
2212
- if let Some ( rename) = rename {
2213
- self . space ( ) ;
2214
- self . word_space ( "as" ) ;
2215
- self . print_ident ( rename) ;
2216
- }
2217
- }
2218
- ast:: UseTreeKind :: Glob => {
2219
- if !tree. prefix . segments . is_empty ( ) {
2220
- self . print_path ( & tree. prefix , false , 0 ) ;
2221
- self . word ( "::" ) ;
2222
- }
2223
- self . word ( "*" ) ;
2224
- }
2225
- ast:: UseTreeKind :: Nested ( ref items) => {
2226
- if tree. prefix . segments . is_empty ( ) {
2227
- self . word ( "{" ) ;
2228
- } else {
2229
- self . print_path ( & tree. prefix , false , 0 ) ;
2230
- self . word ( "::{" ) ;
2231
- }
2232
- self . commasep ( Inconsistent , & items, |this, & ( ref tree, _) | {
2233
- this. print_use_tree ( tree)
2234
- } ) ;
2235
- self . word ( "}" ) ;
2236
- }
2237
- }
2238
- }
2239
-
2240
1606
pub fn print_mutability ( & mut self , mutbl : ast:: Mutability , print_const : bool ) {
2241
1607
match mutbl {
2242
1608
ast:: Mutability :: Mut => self . word_nbsp ( "mut" ) ,
0 commit comments