}
fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
- format!("{}{}", State::new().to_string(|s| s.print_visibility(vis)), s)
+ format!("{}{}", State::to_string(|s| s.print_visibility(vis)), s)
}
impl std::ops::Deref for State<'_> {
}
fn ty_to_string(&self, ty: &ast::Ty) -> String {
- self.to_string(|s| s.print_type(ty))
+ Self::to_string(|s| s.print_type(ty))
}
fn bounds_to_string(&self, bounds: &[ast::GenericBound]) -> String {
- self.to_string(|s| s.print_type_bounds("", bounds))
+ Self::to_string(|s| s.print_type_bounds("", bounds))
}
fn pat_to_string(&self, pat: &ast::Pat) -> String {
- self.to_string(|s| s.print_pat(pat))
+ Self::to_string(|s| s.print_pat(pat))
}
fn expr_to_string(&self, e: &ast::Expr) -> String {
- self.to_string(|s| s.print_expr(e))
+ Self::to_string(|s| s.print_expr(e))
}
fn tt_to_string(&self, tt: &TokenTree) -> String {
- self.to_string(|s| s.print_tt(tt, false))
+ Self::to_string(|s| s.print_tt(tt, false))
}
fn tts_to_string(&self, tokens: &TokenStream) -> String {
- self.to_string(|s| s.print_tts(tokens, false))
+ Self::to_string(|s| s.print_tts(tokens, false))
}
fn stmt_to_string(&self, stmt: &ast::Stmt) -> String {
- self.to_string(|s| s.print_stmt(stmt))
+ Self::to_string(|s| s.print_stmt(stmt))
}
fn item_to_string(&self, i: &ast::Item) -> String {
- self.to_string(|s| s.print_item(i))
+ Self::to_string(|s| s.print_item(i))
}
fn generic_params_to_string(&self, generic_params: &[ast::GenericParam]) -> String {
- self.to_string(|s| s.print_generic_params(generic_params))
+ Self::to_string(|s| s.print_generic_params(generic_params))
}
fn path_to_string(&self, p: &ast::Path) -> String {
- self.to_string(|s| s.print_path(p, false, 0))
+ Self::to_string(|s| s.print_path(p, false, 0))
}
fn path_segment_to_string(&self, p: &ast::PathSegment) -> String {
- self.to_string(|s| s.print_path_segment(p, false))
+ Self::to_string(|s| s.print_path_segment(p, false))
}
fn vis_to_string(&self, v: &ast::Visibility) -> String {
- self.to_string(|s| s.print_visibility(v))
+ Self::to_string(|s| s.print_visibility(v))
}
fn block_to_string(&self, blk: &ast::Block) -> String {
- self.to_string(|s| {
+ Self::to_string(|s| {
// Containing cbox, will be closed by `print_block` at `}`.
s.cbox(INDENT_UNIT);
// Head-ibox, will be closed by `print_block` after `{`.
}
fn meta_list_item_to_string(&self, li: &ast::NestedMetaItem) -> String {
- self.to_string(|s| s.print_meta_list_item(li))
+ Self::to_string(|s| s.print_meta_list_item(li))
}
fn attr_item_to_string(&self, ai: &ast::AttrItem) -> String {
- self.to_string(|s| s.print_attr_item(ai, ai.path.span))
+ Self::to_string(|s| s.print_attr_item(ai, ai.path.span))
}
fn attribute_to_string(&self, attr: &ast::Attribute) -> String {
- self.to_string(|s| s.print_attribute(attr))
+ Self::to_string(|s| s.print_attribute(attr))
}
fn param_to_string(&self, arg: &ast::Param) -> String {
- self.to_string(|s| s.print_param(arg, false))
+ Self::to_string(|s| s.print_param(arg, false))
}
- fn to_string(&self, f: impl FnOnce(&mut State<'_>)) -> String {
+ fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
let mut printer = State::new();
f(&mut printer);
printer.s.eof()
);
}
ast::ItemKind::Mod(unsafety, ref mod_kind) => {
- self.head(self.to_string(|s| {
+ self.head(Self::to_string(|s| {
s.print_visibility(&item.vis);
s.print_unsafety(unsafety);
s.word("mod");
}
}
ast::ItemKind::ForeignMod(ref nmod) => {
- self.head(self.to_string(|s| {
+ self.head(Self::to_string(|s| {
s.print_unsafety(nmod.unsafety);
s.word("extern");
}));
self.print_visibility(&item.vis);
self.print_defaultness(defaultness);
self.print_unsafety(unsafety);
- self.word_nbsp("impl");
- self.print_constness(constness);
+ self.word("impl");
- if !generics.params.is_empty() {
+ if generics.params.is_empty() {
+ self.nbsp();
+ } else {
self.print_generic_params(&generics.params);
self.space();
}
+ self.print_constness(constness);
+
if let ast::ImplPolarity::Negative(_) = polarity {
self.word("!");
}
ast::CrateSugar::JustCrate => self.word_nbsp("crate"),
},
ast::VisibilityKind::Restricted { ref path, .. } => {
- let path = self.to_string(|s| s.print_path(path, false, 0));
+ let path = Self::to_string(|s| s.print_path(path, false, 0));
if path == "self" || path == "super" {
self.word_nbsp(format!("pub({})", path))
} else {
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) => {