token::CloseDelim(token::Bracket) => "]".to_string(),
token::OpenDelim(token::Brace) => "{".to_string(),
token::CloseDelim(token::Brace) => "}".to_string(),
- token::OpenDelim(token::NoDelim) => " ".to_string(),
+ token::OpenDelim(token::NoDelim) |
token::CloseDelim(token::NoDelim) => " ".to_string(),
token::Pound => "#".to_string(),
token::Dollar => "$".to_string(),
let mut out = match lit {
token::Byte(b) => format!("b'{}'", b),
token::Char(c) => format!("'{}'", c),
- token::Float(c) => c.to_string(),
+ token::Float(c) |
token::Integer(c) => c.to_string(),
token::Str_(s) => format!("\"{}\"", s),
token::StrRaw(s, n) => format!("r{delim}\"{string}\"{delim}",
token::Shebang(s) => format!("/* shebang: {}*/", s),
token::Interpolated(ref nt) => match **nt {
- token::NtExpr(ref e) => expr_to_string(&e),
- token::NtMeta(ref e) => meta_item_to_string(&e),
- token::NtTy(ref e) => ty_to_string(&e),
- token::NtPath(ref e) => path_to_string(&e),
- token::NtItem(ref e) => item_to_string(&e),
- token::NtBlock(ref e) => block_to_string(&e),
- token::NtStmt(ref e) => stmt_to_string(&e),
- token::NtPat(ref e) => pat_to_string(&e),
+ token::NtExpr(ref e) => expr_to_string(e),
+ token::NtMeta(ref e) => meta_item_to_string(e),
+ token::NtTy(ref e) => ty_to_string(e),
+ token::NtPath(ref e) => path_to_string(e),
+ token::NtItem(ref e) => item_to_string(e),
+ token::NtBlock(ref e) => block_to_string(e),
+ token::NtStmt(ref e) => stmt_to_string(e),
+ token::NtPat(ref e) => pat_to_string(e),
token::NtIdent(ref e) => ident_to_string(e.node),
token::NtTT(ref tree) => tt_to_string(tree.clone()),
- token::NtArm(ref e) => arm_to_string(&e),
- token::NtImplItem(ref e) => impl_item_to_string(&e),
- token::NtTraitItem(ref e) => trait_item_to_string(&e),
- token::NtGenerics(ref e) => generics_to_string(&e),
- token::NtWhereClause(ref e) => where_clause_to_string(&e),
- token::NtArg(ref e) => arg_to_string(&e),
- token::NtVis(ref e) => vis_to_string(&e),
+ token::NtArm(ref e) => arm_to_string(e),
+ token::NtImplItem(ref e) => impl_item_to_string(e),
+ token::NtTraitItem(ref e) => trait_item_to_string(e),
+ token::NtGenerics(ref e) => generics_to_string(e),
+ token::NtWhereClause(ref e) => where_clause_to_string(e),
+ token::NtArg(ref e) => arg_to_string(e),
+ token::NtVis(ref e) => vis_to_string(e),
}
}
}
to_string(|s| s.print_path(p, false, 0, false))
}
+pub fn path_segment_to_string(p: &ast::PathSegment) -> String {
+ to_string(|s| s.print_path_segment(p, false))
+}
+
pub fn ident_to_string(id: ast::Ident) -> String {
to_string(|s| s.print_ident(id))
}
let mut result = None;
- if let &Some(ref lits) = self.literals()
- {
+ if let Some(ref lits) = *self.literals() {
while cur_lit < lits.len() {
let ltrl = (*lits)[cur_lit].clone();
if ltrl.pos > pos { break; }
fn print_literal(&mut self, lit: &ast::Lit) -> io::Result<()> {
self.maybe_print_comment(lit.span.lo)?;
- match self.next_lit(lit.span.lo) {
- Some(ref ltrl) => {
- return word(self.writer(), &(*ltrl).lit);
- }
- _ => ()
+ if let Some(ref ltrl) = self.next_lit(lit.span.lo) {
+ return word(self.writer(), &(*ltrl).lit);
}
match lit.node {
ast::LitKind::Str(st, style) => self.print_string(&st.as_str(), style),
self.popen()?;
self.commasep(Consistent,
&items[..],
- |s, i| s.print_meta_list_item(&i))?;
+ |s, i| s.print_meta_list_item(i))?;
self.pclose()?;
}
}
pub fn commasep_exprs(&mut self, b: Breaks,
exprs: &[P<ast::Expr>]) -> io::Result<()> {
- self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |e| e.span)
+ self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e), |e| e.span)
}
pub fn print_mod(&mut self, _mod: &ast::Mod,
attrs: &[ast::Attribute]) -> io::Result<()> {
self.print_inner_attributes(attrs)?;
for item in &_mod.items {
- self.print_item(&item)?;
+ self.print_item(item)?;
}
Ok(())
}
match ty.node {
ast::TyKind::Slice(ref ty) => {
word(&mut self.s, "[")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
word(&mut self.s, "]")?;
}
ast::TyKind::Ptr(ref mt) => {
ast::TyKind::Tup(ref elts) => {
self.popen()?;
self.commasep(Inconsistent, &elts[..],
- |s, ty| s.print_type(&ty))?;
+ |s, ty| s.print_type(ty))?;
if elts.len() == 1 {
word(&mut self.s, ",")?;
}
}
ast::TyKind::Paren(ref typ) => {
self.popen()?;
- self.print_type(&typ)?;
+ self.print_type(typ)?;
self.pclose()?;
}
ast::TyKind::BareFn(ref f) => {
}
ast::TyKind::Array(ref ty, ref v) => {
word(&mut self.s, "[")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
word(&mut self.s, "; ")?;
- self.print_expr(&v)?;
+ self.print_expr(v)?;
word(&mut self.s, "]")?;
}
ast::TyKind::Typeof(ref e) => {
word(&mut self.s, "typeof(")?;
- self.print_expr(&e)?;
+ self.print_expr(e)?;
word(&mut self.s, ")")?;
}
ast::TyKind::Infer => {
}
self.print_ident(item.ident)?;
self.word_space(":")?;
- self.print_type(&t)?;
+ self.print_type(t)?;
word(&mut self.s, ";")?;
self.end()?; // end the head-ibox
self.end() // end the outer cbox
self.head(&visibility_qualified(&item.vis, "extern crate"))?;
if let Some(p) = *optional_path {
let val = p.as_str();
- if val.contains("-") {
+ if val.contains('-') {
self.print_string(&val, ast::StrStyle::Cooked)?;
} else {
self.print_name(p)?;
}
ast::ItemKind::Use(ref vp) => {
self.head(&visibility_qualified(&item.vis, "use"))?;
- self.print_view_path(&vp)?;
+ self.print_view_path(vp)?;
word(&mut self.s, ";")?;
self.end()?; // end inner head-block
self.end()?; // end outer head-block
}
self.print_ident(item.ident)?;
self.word_space(":")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
space(&mut self.s)?;
self.end()?; // end the head-ibox
self.word_space("=")?;
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
word(&mut self.s, ";")?;
self.end()?; // end the outer cbox
}
self.head(&visibility_qualified(&item.vis, "const"))?;
self.print_ident(item.ident)?;
self.word_space(":")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
space(&mut self.s)?;
self.end()?; // end the head-ibox
self.word_space("=")?;
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
word(&mut self.s, ";")?;
self.end()?; // end the outer cbox
}
&item.vis
)?;
word(&mut self.s, " ")?;
- self.print_block_with_attrs(&body, &item.attrs)?;
+ self.print_block_with_attrs(body, &item.attrs)?;
}
ast::ItemKind::Mod(ref _mod) => {
self.head(&visibility_qualified(&item.vis, "mod"))?;
self.print_where_clause(¶ms.where_clause)?;
space(&mut self.s)?;
self.word_space("=")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
word(&mut self.s, ";")?;
self.end()?; // end the outer ibox
}
}
ast::ItemKind::Struct(ref struct_def, ref generics) => {
self.head(&visibility_qualified(&item.vis, "struct"))?;
- self.print_struct(&struct_def, generics, item.ident, item.span, true)?;
+ self.print_struct(struct_def, generics, item.ident, item.span, true)?;
}
ast::ItemKind::Union(ref struct_def, ref generics) => {
self.head(&visibility_qualified(&item.vis, "union"))?;
- self.print_struct(&struct_def, generics, item.ident, item.span, true)?;
+ self.print_struct(struct_def, generics, item.ident, item.span, true)?;
}
ast::ItemKind::DefaultImpl(unsafety, ref trait_ref) => {
self.head("")?;
space(&mut self.s)?;
}
- match polarity {
- ast::ImplPolarity::Negative => {
- word(&mut self.s, "!")?;
- },
- _ => {}
+ if polarity == ast::ImplPolarity::Negative {
+ word(&mut self.s, "!")?;
}
if let Some(ref t) = *opt_trait {
self.word_space("for")?;
}
- self.print_type(&ty)?;
+ self.print_type(ty)?;
self.print_where_clause(&generics.where_clause)?;
space(&mut self.s)?;
self.print_ident(item.ident)?;
self.cbox(INDENT_UNIT)?;
self.popen()?;
- self.print_tts(tts.clone().into())?;
+ self.print_tts(tts.stream())?;
self.pclose()?;
word(&mut self.s, ";")?;
self.end()?;
Some(ref d) => {
space(&mut self.s)?;
self.word_space("=")?;
- self.print_expr(&d)
+ self.print_expr(d)
}
_ => Ok(())
}
self.print_outer_attributes(&ti.attrs)?;
match ti.node {
ast::TraitItemKind::Const(ref ty, ref default) => {
- self.print_associated_const(ti.ident, &ty,
+ self.print_associated_const(ti.ident, ty,
default.as_ref().map(|expr| &**expr),
&ast::Visibility::Inherited)?;
}
self.print_defaultness(ii.defaultness)?;
match ii.node {
ast::ImplItemKind::Const(ref ty, ref expr) => {
- self.print_associated_const(ii.ident, &ty, Some(&expr), &ii.vis)?;
+ self.print_associated_const(ii.ident, ty, Some(expr), &ii.vis)?;
}
ast::ImplItemKind::Method(ref sig, ref body) => {
self.head("")?;
self.word_nbsp("let")?;
self.ibox(INDENT_UNIT)?;
- self.print_local_decl(&loc)?;
+ self.print_local_decl(loc)?;
self.end()?;
if let Some(ref init) = loc.init {
self.nbsp()?;
self.word_space("=")?;
- self.print_expr(&init)?;
+ self.print_expr(init)?;
}
word(&mut self.s, ";")?;
self.end()?;
}
- ast::StmtKind::Item(ref item) => self.print_item(&item)?,
+ ast::StmtKind::Item(ref item) => self.print_item(item)?,
ast::StmtKind::Expr(ref expr) => {
self.space_if_not_bol()?;
- self.print_expr_outer_attr_style(&expr, false)?;
+ self.print_expr_outer_attr_style(expr, false)?;
if parse::classify::expr_requires_semi_to_be_stmt(expr) {
word(&mut self.s, ";")?;
}
}
ast::StmtKind::Semi(ref expr) => {
self.space_if_not_bol()?;
- self.print_expr_outer_attr_style(&expr, false)?;
+ self.print_expr_outer_attr_style(expr, false)?;
word(&mut self.s, ";")?;
}
ast::StmtKind::Mac(ref mac) => {
let (ref mac, style, ref attrs) = **mac;
self.space_if_not_bol()?;
- self.print_outer_attributes(&attrs)?;
+ self.print_outer_attributes(attrs)?;
let delim = match style {
ast::MacStmtStyle::Braces => token::Brace,
_ => token::Paren
};
- self.print_mac(&mac, delim)?;
+ self.print_mac(mac, delim)?;
if style == ast::MacStmtStyle::Semicolon {
word(&mut self.s, ";")?;
}
ast::StmtKind::Expr(ref expr) if i == blk.stmts.len() - 1 => {
self.maybe_print_comment(st.span.lo)?;
self.space_if_not_bol()?;
- self.print_expr_outer_attr_style(&expr, false)?;
+ self.print_expr_outer_attr_style(expr, false)?;
self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi))?;
}
_ => self.print_stmt(st)?,
self.cbox(INDENT_UNIT - 1)?;
self.ibox(0)?;
word(&mut self.s, " else if ")?;
- self.print_expr(&i)?;
+ self.print_expr(i)?;
space(&mut self.s)?;
- self.print_block(&then)?;
+ self.print_block(then)?;
self.print_else(e.as_ref().map(|e| &**e))
}
// "another else-if-let"
self.cbox(INDENT_UNIT - 1)?;
self.ibox(0)?;
word(&mut self.s, " else if let ")?;
- self.print_pat(&pat)?;
+ self.print_pat(pat)?;
space(&mut self.s)?;
self.word_space("=")?;
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
space(&mut self.s)?;
- self.print_block(&then)?;
+ self.print_block(then)?;
self.print_else(e.as_ref().map(|e| &**e))
}
// "final else"
self.cbox(INDENT_UNIT - 1)?;
self.ibox(0)?;
word(&mut self.s, " else ")?;
- self.print_block(&b)
+ self.print_block(b)
}
// BLEAH, constraints would be great here
_ => {
binop: ast::BinOp) -> bool {
match sub_expr.node {
ast::ExprKind::Binary(ref sub_op, _, _) => {
- if AssocOp::from_ast_binop(sub_op.node).precedence() <
- AssocOp::from_ast_binop(binop.node).precedence() {
- true
- } else {
- false
- }
+ AssocOp::from_ast_binop(sub_op.node).precedence() <
+ AssocOp::from_ast_binop(binop.node).precedence()
}
_ => true
}
space(&mut self.s)?;
}
word(&mut self.s, "..")?;
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
self.end()?;
}
_ => if !fields.is_empty() {
if !tys.is_empty() {
word(&mut self.s, "::<")?;
self.commasep(Inconsistent, tys,
- |s, ty| s.print_type(&ty))?;
+ |s, ty| s.print_type(ty))?;
word(&mut self.s, ">")?;
}
self.print_call_post(base_args)
self.print_expr_vec(&exprs[..], attrs)?;
}
ast::ExprKind::Repeat(ref element, ref count) => {
- self.print_expr_repeat(&element, &count, attrs)?;
+ self.print_expr_repeat(element, count, attrs)?;
}
ast::ExprKind::Struct(ref path, ref fields, ref wth) => {
self.print_expr_struct(path, &fields[..], wth, attrs)?;
self.print_expr_tup(&exprs[..], attrs)?;
}
ast::ExprKind::Call(ref func, ref args) => {
- self.print_expr_call(&func, &args[..])?;
+ self.print_expr_call(func, &args[..])?;
}
ast::ExprKind::MethodCall(ident, ref tys, ref args) => {
self.print_expr_method_call(ident, &tys[..], &args[..])?;
}
ast::ExprKind::Binary(op, ref lhs, ref rhs) => {
- self.print_expr_binary(op, &lhs, &rhs)?;
+ self.print_expr_binary(op, lhs, rhs)?;
}
ast::ExprKind::Unary(op, ref expr) => {
- self.print_expr_unary(op, &expr)?;
+ self.print_expr_unary(op, expr)?;
}
ast::ExprKind::AddrOf(m, ref expr) => {
- self.print_expr_addr_of(m, &expr)?;
+ self.print_expr_addr_of(m, expr)?;
}
ast::ExprKind::Lit(ref lit) => {
- self.print_literal(&lit)?;
+ self.print_literal(lit)?;
}
ast::ExprKind::Cast(ref expr, ref ty) => {
if let ast::ExprKind::Cast(..) = expr.node {
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
} else {
- self.print_expr_maybe_paren(&expr)?;
+ self.print_expr_maybe_paren(expr)?;
}
space(&mut self.s)?;
self.word_space("as")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
}
ast::ExprKind::Type(ref expr, ref ty) => {
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
self.word_space(":")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
}
ast::ExprKind::If(ref test, ref blk, ref elseopt) => {
- self.print_if(&test, &blk, elseopt.as_ref().map(|e| &**e))?;
+ self.print_if(test, blk, elseopt.as_ref().map(|e| &**e))?;
}
ast::ExprKind::IfLet(ref pat, ref expr, ref blk, ref elseopt) => {
- self.print_if_let(&pat, &expr, &blk, elseopt.as_ref().map(|e| &**e))?;
+ self.print_if_let(pat, expr, blk, elseopt.as_ref().map(|e| &**e))?;
}
ast::ExprKind::While(ref test, ref blk, opt_ident) => {
if let Some(ident) = opt_ident {
self.word_space(":")?;
}
self.head("while")?;
- self.print_expr(&test)?;
+ self.print_expr(test)?;
space(&mut self.s)?;
- self.print_block_with_attrs(&blk, attrs)?;
+ self.print_block_with_attrs(blk, attrs)?;
}
ast::ExprKind::WhileLet(ref pat, ref expr, ref blk, opt_ident) => {
if let Some(ident) = opt_ident {
self.word_space(":")?;
}
self.head("while let")?;
- self.print_pat(&pat)?;
+ self.print_pat(pat)?;
space(&mut self.s)?;
self.word_space("=")?;
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
space(&mut self.s)?;
- self.print_block_with_attrs(&blk, attrs)?;
+ self.print_block_with_attrs(blk, attrs)?;
}
ast::ExprKind::ForLoop(ref pat, ref iter, ref blk, opt_ident) => {
if let Some(ident) = opt_ident {
self.word_space(":")?;
}
self.head("for")?;
- self.print_pat(&pat)?;
+ self.print_pat(pat)?;
space(&mut self.s)?;
self.word_space("in")?;
- self.print_expr(&iter)?;
+ self.print_expr(iter)?;
space(&mut self.s)?;
- self.print_block_with_attrs(&blk, attrs)?;
+ self.print_block_with_attrs(blk, attrs)?;
}
ast::ExprKind::Loop(ref blk, opt_ident) => {
if let Some(ident) = opt_ident {
}
self.head("loop")?;
space(&mut self.s)?;
- self.print_block_with_attrs(&blk, attrs)?;
+ self.print_block_with_attrs(blk, attrs)?;
}
ast::ExprKind::Match(ref expr, ref arms) => {
self.cbox(INDENT_UNIT)?;
self.ibox(4)?;
self.word_nbsp("match")?;
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
space(&mut self.s)?;
self.bopen()?;
self.print_inner_attributes_no_trailing_hardbreak(attrs)?;
ast::ExprKind::Closure(capture_clause, ref decl, ref body, _) => {
self.print_capture_clause(capture_clause)?;
- self.print_fn_block_args(&decl)?;
+ self.print_fn_block_args(decl)?;
space(&mut self.s)?;
self.print_expr(body)?;
self.end()?; // need to close a box
self.cbox(INDENT_UNIT)?;
// head-box, will be closed by print-block after {
self.ibox(0)?;
- self.print_block_with_attrs(&blk, attrs)?;
+ self.print_block_with_attrs(blk, attrs)?;
}
ast::ExprKind::Assign(ref lhs, ref rhs) => {
- self.print_expr(&lhs)?;
+ self.print_expr(lhs)?;
space(&mut self.s)?;
self.word_space("=")?;
- self.print_expr(&rhs)?;
+ self.print_expr(rhs)?;
}
ast::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
- self.print_expr(&lhs)?;
+ self.print_expr(lhs)?;
space(&mut self.s)?;
word(&mut self.s, op.node.to_string())?;
self.word_space("=")?;
- self.print_expr(&rhs)?;
+ self.print_expr(rhs)?;
}
ast::ExprKind::Field(ref expr, id) => {
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
word(&mut self.s, ".")?;
self.print_ident(id.node)?;
}
ast::ExprKind::TupField(ref expr, id) => {
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
word(&mut self.s, ".")?;
self.print_usize(id.node)?;
}
ast::ExprKind::Index(ref expr, ref index) => {
- self.print_expr(&expr)?;
+ self.print_expr(expr)?;
word(&mut self.s, "[")?;
- self.print_expr(&index)?;
+ self.print_expr(index)?;
word(&mut self.s, "]")?;
}
ast::ExprKind::Range(ref start, ref end, limits) => {
- if let &Some(ref e) = start {
- self.print_expr(&e)?;
+ if let Some(ref e) = *start {
+ self.print_expr(e)?;
}
if limits == ast::RangeLimits::HalfOpen {
word(&mut self.s, "..")?;
} else {
word(&mut self.s, "...")?;
}
- if let &Some(ref e) = end {
- self.print_expr(&e)?;
+ if let Some(ref e) = *end {
+ self.print_expr(e)?;
}
}
ast::ExprKind::Path(None, ref path) => {
}
ast::ExprKind::Ret(ref result) => {
word(&mut self.s, "return")?;
- match *result {
- Some(ref expr) => {
- word(&mut self.s, " ")?;
- self.print_expr(&expr)?;
- }
- _ => ()
+ if let Some(ref expr) = *result {
+ word(&mut self.s, " ")?;
+ self.print_expr(expr)?;
}
}
ast::ExprKind::InlineAsm(ref a) => {
self.commasep(Inconsistent, &a.inputs, |s, &(co, ref o)| {
s.print_string(&co.as_str(), ast::StrStyle::Cooked)?;
s.popen()?;
- s.print_expr(&o)?;
+ s.print_expr(o)?;
s.pclose()?;
Ok(())
})?;
ast::ExprKind::Paren(ref e) => {
self.popen()?;
self.print_inner_attributes_inline(attrs)?;
- self.print_expr(&e)?;
+ self.print_expr(e)?;
self.pclose()?;
},
ast::ExprKind::Try(ref e) => {
ast::ExprKind::Catch(ref blk) => {
self.head("do catch")?;
space(&mut self.s)?;
- self.print_block_with_attrs(&blk, attrs)?
+ self.print_block_with_attrs(blk, attrs)?
}
}
self.ann.post(self, NodeExpr(expr))?;
self.print_pat(&loc.pat)?;
if let Some(ref ty) = loc.ty {
self.word_space(":")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
}
Ok(())
}
if i > 0 {
word(&mut self.s, "::")?
}
- if segment.identifier.name != keywords::CrateRoot.name() &&
- segment.identifier.name != "$crate" {
- self.print_ident(segment.identifier)?;
- if let Some(ref parameters) = segment.parameters {
- self.print_path_parameters(parameters, colons_before_params)?;
- }
- }
+ self.print_path_segment(segment, colons_before_params)?;
}
Ok(())
}
+ fn print_path_segment(&mut self,
+ segment: &ast::PathSegment,
+ colons_before_params: bool)
+ -> io::Result<()>
+ {
+ if segment.identifier.name != keywords::CrateRoot.name() &&
+ segment.identifier.name != "$crate" {
+ self.print_ident(segment.identifier)?;
+ if let Some(ref parameters) = segment.parameters {
+ self.print_path_parameters(parameters, colons_before_params)?;
+ }
+ }
+ Ok(())
+ }
+
fn print_qpath(&mut self,
path: &ast::Path,
qself: &ast::QSelf,
space(&mut self.s)?;
self.word_space("as")?;
let depth = path.segments.len() - qself.position;
- self.print_path(&path, false, depth, false)?;
+ self.print_path(path, false, depth, false)?;
}
word(&mut self.s, ">")?;
word(&mut self.s, "::")?;
self.commasep(
Inconsistent,
&data.types,
- |s, ty| s.print_type(&ty))?;
+ |s, ty| s.print_type(ty))?;
comma = true;
}
self.commasep(
Inconsistent,
&data.inputs,
- |s, ty| s.print_type(&ty))?;
+ |s, ty| s.print_type(ty))?;
word(&mut self.s, ")")?;
if let Some(ref ty) = data.output {
self.space_if_not_bol()?;
self.word_space("->")?;
- self.print_type(&ty)?;
+ self.print_type(ty)?;
}
}
}
self.print_ident(path1.node)?;
if let Some(ref p) = *sub {
word(&mut self.s, "@")?;
- self.print_pat(&p)?;
+ self.print_pat(p)?;
}
}
PatKind::TupleStruct(ref path, ref elts, ddpos) => {
self.print_path(path, true, 0, false)?;
self.popen()?;
if let Some(ddpos) = ddpos {
- self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(&p))?;
+ self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p))?;
if ddpos != 0 {
self.word_space(",")?;
}
word(&mut self.s, "..")?;
if ddpos != elts.len() {
word(&mut self.s, ",")?;
- self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(&p))?;
+ self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(p))?;
}
} else {
- self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(&p))?;
+ self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(p))?;
}
self.pclose()?;
}
PatKind::Tuple(ref elts, ddpos) => {
self.popen()?;
if let Some(ddpos) = ddpos {
- self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(&p))?;
+ self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p))?;
if ddpos != 0 {
self.word_space(",")?;
}
word(&mut self.s, "..")?;
if ddpos != elts.len() {
word(&mut self.s, ",")?;
- self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(&p))?;
+ self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(p))?;
}
} else {
- self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(&p))?;
+ self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(p))?;
if elts.len() == 1 {
word(&mut self.s, ",")?;
}
}
PatKind::Box(ref inner) => {
word(&mut self.s, "box ")?;
- self.print_pat(&inner)?;
+ self.print_pat(inner)?;
}
PatKind::Ref(ref inner, mutbl) => {
word(&mut self.s, "&")?;
if mutbl == ast::Mutability::Mutable {
word(&mut self.s, "mut ")?;
}
- self.print_pat(&inner)?;
+ self.print_pat(inner)?;
}
PatKind::Lit(ref e) => self.print_expr(&**e)?,
PatKind::Range(ref begin, ref end, ref end_kind) => {
- self.print_expr(&begin)?;
+ self.print_expr(begin)?;
space(&mut self.s)?;
match *end_kind {
RangeEnd::Included => word(&mut self.s, "...")?,
RangeEnd::Excluded => word(&mut self.s, "..")?,
}
- self.print_expr(&end)?;
+ self.print_expr(end)?;
}
PatKind::Slice(ref before, ref slice, ref after) => {
word(&mut self.s, "[")?;
self.commasep(Inconsistent,
&before[..],
- |s, p| s.print_pat(&p))?;
+ |s, p| s.print_pat(p))?;
if let Some(ref p) = *slice {
if !before.is_empty() { self.word_space(",")?; }
if p.node != PatKind::Wild {
- self.print_pat(&p)?;
+ self.print_pat(p)?;
}
word(&mut self.s, "..")?;
if !after.is_empty() { self.word_space(",")?; }
}
self.commasep(Inconsistent,
&after[..],
- |s, p| s.print_pat(&p))?;
+ |s, p| s.print_pat(p))?;
word(&mut self.s, "]")?;
}
PatKind::Mac(ref m) => self.print_mac(m, token::Paren)?,
space(&mut self.s)?;
self.word_space("|")?;
}
- self.print_pat(&p)?;
+ self.print_pat(p)?;
}
space(&mut self.s)?;
if let Some(ref e) = arm.guard {
self.word_space("if")?;
- self.print_expr(&e)?;
+ self.print_expr(e)?;
space(&mut self.s)?;
}
self.word_space("=>")?;
match arm.body.node {
ast::ExprKind::Block(ref blk) => {
// the block will close the pattern's ibox
- self.print_block_unclosed_indent(&blk, INDENT_UNIT)?;
+ self.print_block_unclosed_indent(blk, INDENT_UNIT)?;
// If it is a user-provided unsafe block, print a comma after it
if let BlockCheckMode::Unsafe(ast::UserProvided) = blk.rules {
self.print_mutability(m)?;
word(&mut self.s, "self")?;
self.word_space(":")?;
- self.print_type(&typ)
+ self.print_type(typ)
}
}
}
self.word_space("->")?;
match decl.output {
ast::FunctionRetTy::Ty(ref ty) => {
- self.print_type(&ty)?;
+ self.print_type(ty)?;
self.maybe_print_comment(ty.span.lo)
}
ast::FunctionRetTy::Default(..) => unreachable!(),
lifetime: &ast::Lifetime)
-> io::Result<()>
{
- self.print_name(lifetime.name)
+ self.print_name(lifetime.ident.name)
}
pub fn print_lifetime_bounds(&mut self,
Some(ref default) => {
space(&mut self.s)?;
self.word_space("=")?;
- self.print_type(&default)
+ self.print_type(default)
}
_ => Ok(())
}
ref bounds,
..}) => {
self.print_formal_lifetime_list(bound_lifetimes)?;
- self.print_type(&bounded_ty)?;
+ self.print_type(bounded_ty)?;
self.print_bounds(":", bounds)?;
}
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime,
match decl.output {
ast::FunctionRetTy::Default(..) => unreachable!(),
ast::FunctionRetTy::Ty(ref ty) =>
- self.print_type(&ty)?
+ self.print_type(ty)?
}
self.end()?;
if self.next_comment().is_none() {
hardbreak(&mut self.s)?;
}
- loop {
- match self.next_comment() {
- Some(ref cmnt) => {
- self.print_comment(cmnt)?;
- self.cur_cmnt_and_lit.cur_cmnt += 1;
- }
- _ => break
- }
+ while let Some(ref cmnt) = self.next_comment() {
+ self.print_comment(cmnt)?;
+ self.cur_cmnt_and_lit.cur_cmnt += 1;
}
Ok(())
}