self.print_string(sym.as_str(), style);
}
- fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) {
+ fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) -> bool {
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
}
- fn print_inner_attributes_no_trailing_hardbreak(&mut self, attrs: &[ast::Attribute]) {
+ fn print_inner_attributes_no_trailing_hardbreak(&mut self, attrs: &[ast::Attribute]) -> bool {
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, false)
}
- fn print_outer_attributes(&mut self, attrs: &[ast::Attribute]) {
+ fn print_outer_attributes(&mut self, attrs: &[ast::Attribute]) -> bool {
self.print_either_attributes(attrs, ast::AttrStyle::Outer, false, true)
}
- fn print_inner_attributes_inline(&mut self, attrs: &[ast::Attribute]) {
+ fn print_inner_attributes_inline(&mut self, attrs: &[ast::Attribute]) -> bool {
self.print_either_attributes(attrs, ast::AttrStyle::Inner, true, true)
}
- fn print_outer_attributes_inline(&mut self, attrs: &[ast::Attribute]) {
+ fn print_outer_attributes_inline(&mut self, attrs: &[ast::Attribute]) -> bool {
self.print_either_attributes(attrs, ast::AttrStyle::Outer, true, true)
}
kind: ast::AttrStyle,
is_inline: bool,
trailing_hardbreak: bool,
- ) {
- let mut count = 0;
+ ) -> bool {
+ let mut printed = false;
for attr in attrs {
if attr.style == kind {
self.print_attribute_inline(attr, is_inline);
if is_inline {
self.nbsp();
}
- count += 1;
+ printed = true;
}
}
- if count > 0 && trailing_hardbreak && !is_inline {
+ if printed && trailing_hardbreak && !is_inline {
self.hardbreak_if_not_bol();
}
+ printed
}
fn print_attribute(&mut self, attr: &ast::Attribute) {
self.print_ident(ident);
self.word_space(":");
self.print_type(ty);
- self.space();
+ if body.is_some() {
+ self.space();
+ }
self.end(); // end the head-ibox
if let Some(body) = body {
self.word_space("=");
self.ann.pre(self, AnnNode::Block(blk));
self.bopen();
- self.print_inner_attributes(attrs);
+ let has_attrs = self.print_inner_attributes(attrs);
for (i, st) in blk.stmts.iter().enumerate() {
match st.kind {
}
}
- let empty = attrs.is_empty() && blk.stmts.is_empty();
+ let empty = !has_attrs && blk.stmts.is_empty();
self.bclose_maybe_open(blk.span, empty, close_box);
self.ann.post(self, AnnNode::Block(blk))
}
}
ast::ExprKind::TryBlock(ref blk) => {
self.head("try");
- self.space();
self.print_block_with_attrs(blk, attrs)
}
ast::ExprKind::Err => {
self.print_path(path, true, 0);
}
self.nbsp();
- self.word_space("{");
+ self.word("{");
+ let empty = fields.is_empty() && !etc;
+ if !empty {
+ self.space();
+ }
self.commasep_cmnt(
Consistent,
&fields,
}
self.word("..");
}
- self.space();
+ if !empty {
+ self.space();
+ }
self.word("}");
}
PatKind::Tuple(ref elts) => {
PatKind::Range(ref begin, ref end, Spanned { node: ref end_kind, .. }) => {
if let Some(e) = begin {
self.print_expr(e);
- self.space();
}
match *end_kind {
RangeEnd::Included(RangeSyntax::DotDotDot) => self.word("..."),
self.word_space(",");
}
- match *predicate {
- ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
- ref bound_generic_params,
- ref bounded_ty,
- ref bounds,
- ..
- }) => {
- self.print_formal_generic_params(bound_generic_params);
- self.print_type(bounded_ty);
- self.print_type_bounds(":", bounds);
- }
- ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
- ref lifetime,
- ref bounds,
- ..
- }) => {
- self.print_lifetime_bounds(*lifetime, bounds);
- }
- ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
- ref lhs_ty,
- ref rhs_ty,
- ..
- }) => {
- self.print_type(lhs_ty);
- self.space();
- self.word_space("=");
- self.print_type(rhs_ty);
- }
+ self.print_where_predicate(predicate);
+ }
+ }
+
+ pub fn print_where_predicate(&mut self, predicate: &ast::WherePredicate) {
+ match predicate {
+ ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
+ bound_generic_params,
+ bounded_ty,
+ bounds,
+ ..
+ }) => {
+ self.print_formal_generic_params(bound_generic_params);
+ self.print_type(bounded_ty);
+ self.print_type_bounds(":", bounds);
+ }
+ ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
+ lifetime,
+ bounds,
+ ..
+ }) => {
+ self.print_lifetime_bounds(*lifetime, bounds);
+ }
+ ast::WherePredicate::EqPredicate(ast::WhereEqPredicate { lhs_ty, rhs_ty, .. }) => {
+ self.print_type(lhs_ty);
+ self.space();
+ self.word_space("=");
+ self.print_type(rhs_ty);
}
}
}
generic_params: &[ast::GenericParam],
) {
self.ibox(INDENT_UNIT);
- if !generic_params.is_empty() {
- self.word("for");
- self.print_generic_params(generic_params);
- }
+ self.print_formal_generic_params(generic_params);
let generics = ast::Generics {
params: Vec::new(),
where_clause: ast::WhereClause {