Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 94521b7

Browse files
committedJan 15, 2022
Move item-related pretty printing functions to module
1 parent 35c6efc commit 94521b7

File tree

2 files changed

+646
-636
lines changed

2 files changed

+646
-636
lines changed
 

‎compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 636 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod expr;
2+
mod item;
23

34
use crate::pp::Breaks::{Consistent, Inconsistent};
45
use crate::pp::{self, Breaks};
@@ -11,7 +12,7 @@ use rustc_ast::util::classify;
1112
use rustc_ast::util::comments::{gather_comments, Comment, CommentStyle};
1213
use rustc_ast::util::parser;
1314
use rustc_ast::{self as ast, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
14-
use rustc_ast::{GenericArg, MacArgs, ModKind};
15+
use rustc_ast::{GenericArg, MacArgs};
1516
use rustc_ast::{GenericBound, SelfKind, TraitBoundModifier};
1617
use rustc_ast::{InlineAsmOperand, InlineAsmRegOrRegClass};
1718
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
@@ -212,10 +213,6 @@ pub fn literal_to_string(lit: token::Lit) -> String {
212213
out
213214
}
214215

215-
fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
216-
format!("{}{}", State::to_string(|s| s.print_visibility(vis)), s)
217-
}
218-
219216
impl std::ops::Deref for State<'_> {
220217
type Target = pp::Printer;
221218
fn deref(&self) -> &Self::Target {
@@ -940,13 +937,6 @@ impl<'a> State<'a> {
940937
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e), |e| e.span)
941938
}
942939

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-
950940
pub fn print_opt_lifetime(&mut self, lifetime: &Option<ast::Lifetime>) {
951941
if let Some(lt) = *lifetime {
952942
self.print_lifetime(lt);
@@ -1058,343 +1048,6 @@ impl<'a> State<'a> {
10581048
self.end();
10591049
}
10601050

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-
13981051
fn print_trait_ref(&mut self, t: &ast::TraitRef) {
13991052
self.print_path(&t.path, false, 0)
14001053
}
@@ -1412,167 +1065,6 @@ impl<'a> State<'a> {
14121065
self.print_trait_ref(&t.trait_ref)
14131066
}
14141067

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-
15761068
crate fn print_stmt(&mut self, st: &ast::Stmt) {
15771069
self.maybe_print_comment(st.span.lo());
15781070
match st.kind {
@@ -2011,55 +1503,6 @@ impl<'a> State<'a> {
20111503
}
20121504
}
20131505

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-
20631506
crate fn print_asyncness(&mut self, asyncness: ast::Async) {
20641507
if asyncness.is_async() {
20651508
self.word_nbsp("async");
@@ -2160,83 +1603,6 @@ impl<'a> State<'a> {
21601603
self.word(">");
21611604
}
21621605

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-
22401606
pub fn print_mutability(&mut self, mutbl: ast::Mutability, print_const: bool) {
22411607
match mutbl {
22421608
ast::Mutability::Mut => self.word_nbsp("mut"),
Lines changed: 644 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,644 @@
1+
use crate::pp::Breaks::Inconsistent;
2+
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
3+
4+
use rustc_ast as ast;
5+
use rustc_ast::GenericBound;
6+
use rustc_ast::ModKind;
7+
use rustc_span::symbol::Ident;
8+
9+
fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
10+
format!("{}{}", State::to_string(|s| s.print_visibility(vis)), s)
11+
}
12+
13+
impl<'a> State<'a> {
14+
fn print_foreign_mod(&mut self, nmod: &ast::ForeignMod, attrs: &[ast::Attribute]) {
15+
self.print_inner_attributes(attrs);
16+
for item in &nmod.items {
17+
self.print_foreign_item(item);
18+
}
19+
}
20+
21+
fn print_foreign_item(&mut self, item: &ast::ForeignItem) {
22+
let ast::Item { id, span, ident, ref attrs, ref kind, ref vis, tokens: _ } = *item;
23+
self.ann.pre(self, AnnNode::SubItem(id));
24+
self.hardbreak_if_not_bol();
25+
self.maybe_print_comment(span.lo());
26+
self.print_outer_attributes(attrs);
27+
match kind {
28+
ast::ForeignItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
29+
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
30+
}
31+
ast::ForeignItemKind::Static(ty, mutbl, body) => {
32+
let def = ast::Defaultness::Final;
33+
self.print_item_const(ident, Some(*mutbl), ty, body.as_deref(), vis, def);
34+
}
35+
ast::ForeignItemKind::TyAlias(box ast::TyAlias {
36+
defaultness,
37+
generics,
38+
bounds,
39+
ty,
40+
}) => {
41+
self.print_associated_type(
42+
ident,
43+
generics,
44+
bounds,
45+
ty.as_deref(),
46+
vis,
47+
*defaultness,
48+
);
49+
}
50+
ast::ForeignItemKind::MacCall(m) => {
51+
self.print_mac(m);
52+
if m.args.need_semicolon() {
53+
self.word(";");
54+
}
55+
}
56+
}
57+
self.ann.post(self, AnnNode::SubItem(id))
58+
}
59+
60+
fn print_item_const(
61+
&mut self,
62+
ident: Ident,
63+
mutbl: Option<ast::Mutability>,
64+
ty: &ast::Ty,
65+
body: Option<&ast::Expr>,
66+
vis: &ast::Visibility,
67+
defaultness: ast::Defaultness,
68+
) {
69+
self.head("");
70+
self.print_visibility(vis);
71+
self.print_defaultness(defaultness);
72+
let leading = match mutbl {
73+
None => "const",
74+
Some(ast::Mutability::Not) => "static",
75+
Some(ast::Mutability::Mut) => "static mut",
76+
};
77+
self.word_space(leading);
78+
self.print_ident(ident);
79+
self.word_space(":");
80+
self.print_type(ty);
81+
if body.is_some() {
82+
self.space();
83+
}
84+
self.end(); // end the head-ibox
85+
if let Some(body) = body {
86+
self.word_space("=");
87+
self.print_expr(body);
88+
}
89+
self.word(";");
90+
self.end(); // end the outer cbox
91+
}
92+
93+
fn print_associated_type(
94+
&mut self,
95+
ident: Ident,
96+
generics: &ast::Generics,
97+
bounds: &ast::GenericBounds,
98+
ty: Option<&ast::Ty>,
99+
vis: &ast::Visibility,
100+
defaultness: ast::Defaultness,
101+
) {
102+
self.head("");
103+
self.print_visibility(vis);
104+
self.print_defaultness(defaultness);
105+
self.word_space("type");
106+
self.print_ident(ident);
107+
self.print_generic_params(&generics.params);
108+
self.print_type_bounds(":", bounds);
109+
self.print_where_clause(&generics.where_clause);
110+
if let Some(ty) = ty {
111+
self.space();
112+
self.word_space("=");
113+
self.print_type(ty);
114+
}
115+
self.word(";");
116+
self.end(); // end inner head-block
117+
self.end(); // end outer head-block
118+
}
119+
120+
/// Pretty-prints an item.
121+
crate fn print_item(&mut self, item: &ast::Item) {
122+
self.hardbreak_if_not_bol();
123+
self.maybe_print_comment(item.span.lo());
124+
self.print_outer_attributes(&item.attrs);
125+
self.ann.pre(self, AnnNode::Item(item));
126+
match item.kind {
127+
ast::ItemKind::ExternCrate(orig_name) => {
128+
self.head(visibility_qualified(&item.vis, "extern crate"));
129+
if let Some(orig_name) = orig_name {
130+
self.print_name(orig_name);
131+
self.space();
132+
self.word("as");
133+
self.space();
134+
}
135+
self.print_ident(item.ident);
136+
self.word(";");
137+
self.end(); // end inner head-block
138+
self.end(); // end outer head-block
139+
}
140+
ast::ItemKind::Use(ref tree) => {
141+
self.head(visibility_qualified(&item.vis, "use"));
142+
self.print_use_tree(tree);
143+
self.word(";");
144+
self.end(); // end inner head-block
145+
self.end(); // end outer head-block
146+
}
147+
ast::ItemKind::Static(ref ty, mutbl, ref body) => {
148+
let def = ast::Defaultness::Final;
149+
self.print_item_const(item.ident, Some(mutbl), ty, body.as_deref(), &item.vis, def);
150+
}
151+
ast::ItemKind::Const(def, ref ty, ref body) => {
152+
self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis, def);
153+
}
154+
ast::ItemKind::Fn(box ast::Fn { defaultness, ref sig, ref generics, ref body }) => {
155+
let body = body.as_deref();
156+
self.print_fn_full(
157+
sig,
158+
item.ident,
159+
generics,
160+
&item.vis,
161+
defaultness,
162+
body,
163+
&item.attrs,
164+
);
165+
}
166+
ast::ItemKind::Mod(unsafety, ref mod_kind) => {
167+
self.head(Self::to_string(|s| {
168+
s.print_visibility(&item.vis);
169+
s.print_unsafety(unsafety);
170+
s.word("mod");
171+
}));
172+
self.print_ident(item.ident);
173+
174+
match mod_kind {
175+
ModKind::Loaded(items, ..) => {
176+
self.nbsp();
177+
self.bopen();
178+
self.print_inner_attributes(&item.attrs);
179+
for item in items {
180+
self.print_item(item);
181+
}
182+
let empty = item.attrs.is_empty() && items.is_empty();
183+
self.bclose(item.span, empty);
184+
}
185+
ModKind::Unloaded => {
186+
self.word(";");
187+
self.end(); // end inner head-block
188+
self.end(); // end outer head-block
189+
}
190+
}
191+
}
192+
ast::ItemKind::ForeignMod(ref nmod) => {
193+
self.head(Self::to_string(|s| {
194+
s.print_unsafety(nmod.unsafety);
195+
s.word("extern");
196+
}));
197+
if let Some(abi) = nmod.abi {
198+
self.print_literal(&abi.as_lit());
199+
self.nbsp();
200+
}
201+
self.bopen();
202+
self.print_foreign_mod(nmod, &item.attrs);
203+
let empty = item.attrs.is_empty() && nmod.items.is_empty();
204+
self.bclose(item.span, empty);
205+
}
206+
ast::ItemKind::GlobalAsm(ref asm) => {
207+
self.head(visibility_qualified(&item.vis, "global_asm!"));
208+
self.print_inline_asm(asm);
209+
self.end();
210+
}
211+
ast::ItemKind::TyAlias(box ast::TyAlias {
212+
defaultness,
213+
ref generics,
214+
ref bounds,
215+
ref ty,
216+
}) => {
217+
let ty = ty.as_deref();
218+
self.print_associated_type(
219+
item.ident,
220+
generics,
221+
bounds,
222+
ty,
223+
&item.vis,
224+
defaultness,
225+
);
226+
}
227+
ast::ItemKind::Enum(ref enum_definition, ref params) => {
228+
self.print_enum_def(enum_definition, params, item.ident, item.span, &item.vis);
229+
}
230+
ast::ItemKind::Struct(ref struct_def, ref generics) => {
231+
self.head(visibility_qualified(&item.vis, "struct"));
232+
self.print_struct(struct_def, generics, item.ident, item.span, true);
233+
}
234+
ast::ItemKind::Union(ref struct_def, ref generics) => {
235+
self.head(visibility_qualified(&item.vis, "union"));
236+
self.print_struct(struct_def, generics, item.ident, item.span, true);
237+
}
238+
ast::ItemKind::Impl(box ast::Impl {
239+
unsafety,
240+
polarity,
241+
defaultness,
242+
constness,
243+
ref generics,
244+
ref of_trait,
245+
ref self_ty,
246+
ref items,
247+
}) => {
248+
self.head("");
249+
self.print_visibility(&item.vis);
250+
self.print_defaultness(defaultness);
251+
self.print_unsafety(unsafety);
252+
self.word("impl");
253+
254+
if generics.params.is_empty() {
255+
self.nbsp();
256+
} else {
257+
self.print_generic_params(&generics.params);
258+
self.space();
259+
}
260+
261+
self.print_constness(constness);
262+
263+
if let ast::ImplPolarity::Negative(_) = polarity {
264+
self.word("!");
265+
}
266+
267+
if let Some(ref t) = *of_trait {
268+
self.print_trait_ref(t);
269+
self.space();
270+
self.word_space("for");
271+
}
272+
273+
self.print_type(self_ty);
274+
self.print_where_clause(&generics.where_clause);
275+
276+
self.space();
277+
self.bopen();
278+
self.print_inner_attributes(&item.attrs);
279+
for impl_item in items {
280+
self.print_assoc_item(impl_item);
281+
}
282+
let empty = item.attrs.is_empty() && items.is_empty();
283+
self.bclose(item.span, empty);
284+
}
285+
ast::ItemKind::Trait(box ast::Trait {
286+
is_auto,
287+
unsafety,
288+
ref generics,
289+
ref bounds,
290+
ref items,
291+
..
292+
}) => {
293+
self.head("");
294+
self.print_visibility(&item.vis);
295+
self.print_unsafety(unsafety);
296+
self.print_is_auto(is_auto);
297+
self.word_nbsp("trait");
298+
self.print_ident(item.ident);
299+
self.print_generic_params(&generics.params);
300+
let mut real_bounds = Vec::with_capacity(bounds.len());
301+
for b in bounds.iter() {
302+
if let GenericBound::Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
303+
self.space();
304+
self.word_space("for ?");
305+
self.print_trait_ref(&ptr.trait_ref);
306+
} else {
307+
real_bounds.push(b.clone());
308+
}
309+
}
310+
self.print_type_bounds(":", &real_bounds);
311+
self.print_where_clause(&generics.where_clause);
312+
self.word(" ");
313+
self.bopen();
314+
self.print_inner_attributes(&item.attrs);
315+
for trait_item in items {
316+
self.print_assoc_item(trait_item);
317+
}
318+
let empty = item.attrs.is_empty() && items.is_empty();
319+
self.bclose(item.span, empty);
320+
}
321+
ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
322+
self.head("");
323+
self.print_visibility(&item.vis);
324+
self.word_nbsp("trait");
325+
self.print_ident(item.ident);
326+
self.print_generic_params(&generics.params);
327+
let mut real_bounds = Vec::with_capacity(bounds.len());
328+
// FIXME(durka) this seems to be some quite outdated syntax
329+
for b in bounds.iter() {
330+
if let GenericBound::Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
331+
self.space();
332+
self.word_space("for ?");
333+
self.print_trait_ref(&ptr.trait_ref);
334+
} else {
335+
real_bounds.push(b.clone());
336+
}
337+
}
338+
self.nbsp();
339+
self.print_type_bounds("=", &real_bounds);
340+
self.print_where_clause(&generics.where_clause);
341+
self.word(";");
342+
}
343+
ast::ItemKind::MacCall(ref mac) => {
344+
self.print_mac(mac);
345+
if mac.args.need_semicolon() {
346+
self.word(";");
347+
}
348+
}
349+
ast::ItemKind::MacroDef(ref macro_def) => {
350+
self.print_mac_def(macro_def, &item.ident, &item.span, |state| {
351+
state.print_visibility(&item.vis)
352+
});
353+
}
354+
}
355+
self.ann.post(self, AnnNode::Item(item))
356+
}
357+
358+
fn print_enum_def(
359+
&mut self,
360+
enum_definition: &ast::EnumDef,
361+
generics: &ast::Generics,
362+
ident: Ident,
363+
span: rustc_span::Span,
364+
visibility: &ast::Visibility,
365+
) {
366+
self.head(visibility_qualified(visibility, "enum"));
367+
self.print_ident(ident);
368+
self.print_generic_params(&generics.params);
369+
self.print_where_clause(&generics.where_clause);
370+
self.space();
371+
self.print_variants(&enum_definition.variants, span)
372+
}
373+
374+
fn print_variants(&mut self, variants: &[ast::Variant], span: rustc_span::Span) {
375+
self.bopen();
376+
for v in variants {
377+
self.space_if_not_bol();
378+
self.maybe_print_comment(v.span.lo());
379+
self.print_outer_attributes(&v.attrs);
380+
self.ibox(INDENT_UNIT);
381+
self.print_variant(v);
382+
self.word(",");
383+
self.end();
384+
self.maybe_print_trailing_comment(v.span, None);
385+
}
386+
let empty = variants.is_empty();
387+
self.bclose(span, empty)
388+
}
389+
390+
crate fn print_visibility(&mut self, vis: &ast::Visibility) {
391+
match vis.kind {
392+
ast::VisibilityKind::Public => self.word_nbsp("pub"),
393+
ast::VisibilityKind::Crate(sugar) => match sugar {
394+
ast::CrateSugar::PubCrate => self.word_nbsp("pub(crate)"),
395+
ast::CrateSugar::JustCrate => self.word_nbsp("crate"),
396+
},
397+
ast::VisibilityKind::Restricted { ref path, .. } => {
398+
let path = Self::to_string(|s| s.print_path(path, false, 0));
399+
if path == "self" || path == "super" {
400+
self.word_nbsp(format!("pub({})", path))
401+
} else {
402+
self.word_nbsp(format!("pub(in {})", path))
403+
}
404+
}
405+
ast::VisibilityKind::Inherited => {}
406+
}
407+
}
408+
409+
fn print_defaultness(&mut self, defaultness: ast::Defaultness) {
410+
if let ast::Defaultness::Default(_) = defaultness {
411+
self.word_nbsp("default");
412+
}
413+
}
414+
415+
fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
416+
self.nbsp();
417+
self.bopen();
418+
419+
let empty = fields.is_empty();
420+
if !empty {
421+
self.hardbreak_if_not_bol();
422+
423+
for field in fields {
424+
self.hardbreak_if_not_bol();
425+
self.maybe_print_comment(field.span.lo());
426+
self.print_outer_attributes(&field.attrs);
427+
self.print_visibility(&field.vis);
428+
self.print_ident(field.ident.unwrap());
429+
self.word_nbsp(":");
430+
self.print_type(&field.ty);
431+
self.word(",");
432+
}
433+
}
434+
435+
self.bclose(span, empty);
436+
}
437+
438+
fn print_struct(
439+
&mut self,
440+
struct_def: &ast::VariantData,
441+
generics: &ast::Generics,
442+
ident: Ident,
443+
span: rustc_span::Span,
444+
print_finalizer: bool,
445+
) {
446+
self.print_ident(ident);
447+
self.print_generic_params(&generics.params);
448+
match struct_def {
449+
ast::VariantData::Tuple(..) | ast::VariantData::Unit(..) => {
450+
if let ast::VariantData::Tuple(..) = struct_def {
451+
self.popen();
452+
self.commasep(Inconsistent, struct_def.fields(), |s, field| {
453+
s.maybe_print_comment(field.span.lo());
454+
s.print_outer_attributes(&field.attrs);
455+
s.print_visibility(&field.vis);
456+
s.print_type(&field.ty)
457+
});
458+
self.pclose();
459+
}
460+
self.print_where_clause(&generics.where_clause);
461+
if print_finalizer {
462+
self.word(";");
463+
}
464+
self.end();
465+
self.end(); // Close the outer-box.
466+
}
467+
ast::VariantData::Struct(ref fields, ..) => {
468+
self.print_where_clause(&generics.where_clause);
469+
self.print_record_struct_body(fields, span);
470+
}
471+
}
472+
}
473+
474+
crate fn print_variant(&mut self, v: &ast::Variant) {
475+
self.head("");
476+
self.print_visibility(&v.vis);
477+
let generics = ast::Generics::default();
478+
self.print_struct(&v.data, &generics, v.ident, v.span, false);
479+
if let Some(ref d) = v.disr_expr {
480+
self.space();
481+
self.word_space("=");
482+
self.print_expr(&d.value)
483+
}
484+
}
485+
486+
fn print_assoc_item(&mut self, item: &ast::AssocItem) {
487+
let ast::Item { id, span, ident, ref attrs, ref kind, ref vis, tokens: _ } = *item;
488+
self.ann.pre(self, AnnNode::SubItem(id));
489+
self.hardbreak_if_not_bol();
490+
self.maybe_print_comment(span.lo());
491+
self.print_outer_attributes(attrs);
492+
match kind {
493+
ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
494+
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
495+
}
496+
ast::AssocItemKind::Const(def, ty, body) => {
497+
self.print_item_const(ident, None, ty, body.as_deref(), vis, *def);
498+
}
499+
ast::AssocItemKind::TyAlias(box ast::TyAlias { defaultness, generics, bounds, ty }) => {
500+
self.print_associated_type(
501+
ident,
502+
generics,
503+
bounds,
504+
ty.as_deref(),
505+
vis,
506+
*defaultness,
507+
);
508+
}
509+
ast::AssocItemKind::MacCall(m) => {
510+
self.print_mac(m);
511+
if m.args.need_semicolon() {
512+
self.word(";");
513+
}
514+
}
515+
}
516+
self.ann.post(self, AnnNode::SubItem(id))
517+
}
518+
519+
fn print_fn_full(
520+
&mut self,
521+
sig: &ast::FnSig,
522+
name: Ident,
523+
generics: &ast::Generics,
524+
vis: &ast::Visibility,
525+
defaultness: ast::Defaultness,
526+
body: Option<&ast::Block>,
527+
attrs: &[ast::Attribute],
528+
) {
529+
if body.is_some() {
530+
self.head("");
531+
}
532+
self.print_visibility(vis);
533+
self.print_defaultness(defaultness);
534+
self.print_fn(&sig.decl, sig.header, Some(name), generics);
535+
if let Some(body) = body {
536+
self.nbsp();
537+
self.print_block_with_attrs(body, attrs);
538+
} else {
539+
self.word(";");
540+
}
541+
}
542+
543+
crate fn print_fn(
544+
&mut self,
545+
decl: &ast::FnDecl,
546+
header: ast::FnHeader,
547+
name: Option<Ident>,
548+
generics: &ast::Generics,
549+
) {
550+
self.print_fn_header_info(header);
551+
if let Some(name) = name {
552+
self.nbsp();
553+
self.print_ident(name);
554+
}
555+
self.print_generic_params(&generics.params);
556+
self.print_fn_params_and_ret(decl, false);
557+
self.print_where_clause(&generics.where_clause)
558+
}
559+
560+
crate fn print_fn_params_and_ret(&mut self, decl: &ast::FnDecl, is_closure: bool) {
561+
let (open, close) = if is_closure { ("|", "|") } else { ("(", ")") };
562+
self.word(open);
563+
self.commasep(Inconsistent, &decl.inputs, |s, param| s.print_param(param, is_closure));
564+
self.word(close);
565+
self.print_fn_ret_ty(&decl.output)
566+
}
567+
568+
fn print_where_clause(&mut self, where_clause: &ast::WhereClause) {
569+
if where_clause.predicates.is_empty() && !where_clause.has_where_token {
570+
return;
571+
}
572+
573+
self.space();
574+
self.word_space("where");
575+
576+
for (i, predicate) in where_clause.predicates.iter().enumerate() {
577+
if i != 0 {
578+
self.word_space(",");
579+
}
580+
581+
self.print_where_predicate(predicate);
582+
}
583+
}
584+
585+
pub fn print_where_predicate(&mut self, predicate: &ast::WherePredicate) {
586+
match predicate {
587+
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
588+
bound_generic_params,
589+
bounded_ty,
590+
bounds,
591+
..
592+
}) => {
593+
self.print_formal_generic_params(bound_generic_params);
594+
self.print_type(bounded_ty);
595+
self.print_type_bounds(":", bounds);
596+
}
597+
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
598+
lifetime,
599+
bounds,
600+
..
601+
}) => {
602+
self.print_lifetime_bounds(*lifetime, bounds);
603+
}
604+
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate { lhs_ty, rhs_ty, .. }) => {
605+
self.print_type(lhs_ty);
606+
self.space();
607+
self.word_space("=");
608+
self.print_type(rhs_ty);
609+
}
610+
}
611+
}
612+
613+
fn print_use_tree(&mut self, tree: &ast::UseTree) {
614+
match tree.kind {
615+
ast::UseTreeKind::Simple(rename, ..) => {
616+
self.print_path(&tree.prefix, false, 0);
617+
if let Some(rename) = rename {
618+
self.space();
619+
self.word_space("as");
620+
self.print_ident(rename);
621+
}
622+
}
623+
ast::UseTreeKind::Glob => {
624+
if !tree.prefix.segments.is_empty() {
625+
self.print_path(&tree.prefix, false, 0);
626+
self.word("::");
627+
}
628+
self.word("*");
629+
}
630+
ast::UseTreeKind::Nested(ref items) => {
631+
if tree.prefix.segments.is_empty() {
632+
self.word("{");
633+
} else {
634+
self.print_path(&tree.prefix, false, 0);
635+
self.word("::{");
636+
}
637+
self.commasep(Inconsistent, &items, |this, &(ref tree, _)| {
638+
this.print_use_tree(tree)
639+
});
640+
self.word("}");
641+
}
642+
}
643+
}
644+
}

0 commit comments

Comments
 (0)
Please sign in to comment.