diff options
Diffstat (limited to 'src/libsyntax/print/pprust.rs')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 382 |
1 files changed, 193 insertions, 189 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7cdc93c7314..82d74ff07f3 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -26,11 +26,11 @@ use print::pp::{break_offset, word, space, zerobreak, hardbreak}; use print::pp::{Breaks, Consistent, Inconsistent, eof}; use print::pp; +use std::gc::Gc; use std::io::{IoResult, MemWriter}; use std::io; use std::mem; use std::str; -use std::string::String; pub enum AnnNode<'a> { NodeBlock(&'a ast::Block), @@ -421,8 +421,8 @@ impl<'a> State<'a> { } pub fn commasep_exprs(&mut self, b: Breaks, - exprs: &[@ast::Expr]) -> IoResult<()> { - self.commasep_cmnt(b, exprs, |s, &e| s.print_expr(e), |e| e.span) + exprs: &[Gc<ast::Expr>]) -> IoResult<()> { + self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&**e), |e| e.span) } pub fn print_mod(&mut self, _mod: &ast::Mod, @@ -432,7 +432,7 @@ impl<'a> State<'a> { try!(self.print_view_item(vitem)); } for item in _mod.items.iter() { - try!(self.print_item(*item)); + try!(self.print_item(&**item)); } Ok(()) } @@ -444,7 +444,7 @@ impl<'a> State<'a> { try!(self.print_view_item(vitem)); } for item in nmod.items.iter() { - try!(self.print_foreign_item(*item)); + try!(self.print_foreign_item(&**item)); } Ok(()) } @@ -464,17 +464,17 @@ impl<'a> State<'a> { match ty.node { ast::TyNil => try!(word(&mut self.s, "()")), ast::TyBot => try!(word(&mut self.s, "!")), - ast::TyBox(ty) => { + ast::TyBox(ref ty) => { try!(word(&mut self.s, "@")); - try!(self.print_type(ty)); + try!(self.print_type(&**ty)); } - ast::TyUniq(ty) => { + ast::TyUniq(ref ty) => { try!(word(&mut self.s, "~")); - try!(self.print_type(ty)); + try!(self.print_type(&**ty)); } - ast::TyVec(ty) => { + ast::TyVec(ref ty) => { try!(word(&mut self.s, "[")); - try!(self.print_type(ty)); + try!(self.print_type(&**ty)); try!(word(&mut self.s, "]")); } ast::TyPtr(ref mt) => { @@ -505,7 +505,7 @@ impl<'a> State<'a> { &None, f.fn_style, ast::Many, - f.decl, + &*f.decl, None, &None, Some(&generics), @@ -522,14 +522,14 @@ impl<'a> State<'a> { region, f.fn_style, f.onceness, - f.decl, + &*f.decl, None, &f.bounds, Some(&generics), None, false)); } - ast::TyProc(f) => { + ast::TyProc(ref f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), ty_params: OwnedSlice::empty() @@ -539,7 +539,7 @@ impl<'a> State<'a> { &None, f.fn_style, f.onceness, - f.decl, + &*f.decl, None, &f.bounds, Some(&generics), @@ -552,7 +552,7 @@ impl<'a> State<'a> { &None, ast::NormalFn, ast::Many, - f.decl, + &*f.decl, None, &None, None, @@ -562,16 +562,16 @@ impl<'a> State<'a> { ast::TyPath(ref path, ref bounds, _) => { try!(self.print_bounded_path(path, bounds)); } - ast::TyFixedLengthVec(ty, v) => { + ast::TyFixedLengthVec(ref ty, ref v) => { try!(word(&mut self.s, "[")); - try!(self.print_type(ty)); + try!(self.print_type(&**ty)); try!(word(&mut self.s, ", ..")); - try!(self.print_expr(v)); + try!(self.print_expr(&**v)); try!(word(&mut self.s, "]")); } - ast::TyTypeof(e) => { + ast::TyTypeof(ref e) => { try!(word(&mut self.s, "typeof(")); - try!(self.print_expr(e)); + try!(self.print_expr(&**e)); try!(word(&mut self.s, ")")); } ast::TyInfer => { @@ -582,7 +582,7 @@ impl<'a> State<'a> { } pub fn print_type_ref(&mut self, ty: &P<ast::Ty>) -> IoResult<()> { - self.print_type(*ty) + self.print_type(&**ty) } pub fn print_foreign_item(&mut self, @@ -591,14 +591,14 @@ impl<'a> State<'a> { try!(self.maybe_print_comment(item.span.lo)); try!(self.print_outer_attributes(item.attrs.as_slice())); match item.node { - ast::ForeignItemFn(decl, ref generics) => { - try!(self.print_fn(decl, None, abi::Rust, item.ident, generics, - None, item.vis)); + ast::ForeignItemFn(ref decl, ref generics) => { + try!(self.print_fn(&**decl, None, abi::Rust, item.ident, generics, + None, item.vis)); try!(self.end()); // end head-ibox try!(word(&mut self.s, ";")); self.end() // end the outer fn box } - ast::ForeignItemStatic(t, m) => { + ast::ForeignItemStatic(ref t, m) => { try!(self.head(visibility_qualified(item.vis, "static").as_slice())); if m { @@ -606,7 +606,7 @@ impl<'a> State<'a> { } try!(self.print_ident(item.ident)); try!(self.word_space(":")); - try!(self.print_type(t)); + try!(self.print_type(&**t)); try!(word(&mut self.s, ";")); try!(self.end()); // end the head-ibox self.end() // end the outer cbox @@ -620,7 +620,7 @@ impl<'a> State<'a> { try!(self.print_outer_attributes(item.attrs.as_slice())); try!(self.ann.pre(self, NodeItem(item))); match item.node { - ast::ItemStatic(ty, m, expr) => { + ast::ItemStatic(ref ty, m, ref expr) => { try!(self.head(visibility_qualified(item.vis, "static").as_slice())); if m == ast::MutMutable { @@ -628,18 +628,18 @@ impl<'a> State<'a> { } try!(self.print_ident(item.ident)); try!(self.word_space(":")); - try!(self.print_type(ty)); + try!(self.print_type(&**ty)); try!(space(&mut self.s)); try!(self.end()); // end the head-ibox try!(self.word_space("=")); - try!(self.print_expr(expr)); + try!(self.print_expr(&**expr)); try!(word(&mut self.s, ";")); try!(self.end()); // end the outer cbox } - ast::ItemFn(decl, fn_style, abi, ref typarams, body) => { + ast::ItemFn(ref decl, fn_style, abi, ref typarams, ref body) => { try!(self.print_fn( - decl, + &**decl, Some(fn_style), abi, item.ident, @@ -648,7 +648,7 @@ impl<'a> State<'a> { item.vis )); try!(word(&mut self.s, " ")); - try!(self.print_block_with_attrs(body, item.attrs.as_slice())); + try!(self.print_block_with_attrs(&**body, item.attrs.as_slice())); } ast::ItemMod(ref _mod) => { try!(self.head(visibility_qualified(item.vis, @@ -666,7 +666,7 @@ impl<'a> State<'a> { try!(self.print_foreign_mod(nmod, item.attrs.as_slice())); try!(self.bclose(item.span)); } - ast::ItemTy(ty, ref params) => { + ast::ItemTy(ref ty, ref params) => { try!(self.ibox(indent_unit)); try!(self.ibox(0u)); try!(self.word_nbsp(visibility_qualified(item.vis, @@ -677,7 +677,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); try!(self.word_space("=")); - try!(self.print_type(ty)); + try!(self.print_type(&**ty)); try!(word(&mut self.s, ";")); try!(self.end()); // end the outer ibox } @@ -690,16 +690,17 @@ impl<'a> State<'a> { item.vis )); } - ast::ItemStruct(struct_def, ref generics) => { + ast::ItemStruct(ref struct_def, ref generics) => { if struct_def.is_virtual { try!(self.word_space("virtual")); } try!(self.head(visibility_qualified(item.vis, "struct").as_slice())); - try!(self.print_struct(struct_def, generics, item.ident, item.span)); + try!(self.print_struct(&**struct_def, generics, item.ident, + item.span)); } - ast::ItemImpl(ref generics, ref opt_trait, ty, ref methods) => { + ast::ItemImpl(ref generics, ref opt_trait, ref ty, ref methods) => { try!(self.head(visibility_qualified(item.vis, "impl").as_slice())); if generics.is_parameterized() { @@ -716,13 +717,13 @@ impl<'a> State<'a> { &None => {} } - try!(self.print_type(ty)); + try!(self.print_type(&**ty)); try!(space(&mut self.s)); try!(self.bopen()); try!(self.print_inner_attributes(item.attrs.as_slice())); for meth in methods.iter() { - try!(self.print_method(*meth)); + try!(self.print_method(&**meth)); } try!(self.bclose(item.span)); } @@ -788,12 +789,12 @@ impl<'a> State<'a> { variants: &[P<ast::Variant>], span: codemap::Span) -> IoResult<()> { try!(self.bopen()); - for &v in variants.iter() { + for v in variants.iter() { try!(self.space_if_not_bol()); try!(self.maybe_print_comment(v.span.lo)); try!(self.print_outer_attributes(v.node.attrs.as_slice())); try!(self.ibox(indent_unit)); - try!(self.print_variant(v)); + try!(self.print_variant(&**v)); try!(word(&mut self.s, ",")); try!(self.end()); try!(self.maybe_print_trailing_comment(v.span, None)); @@ -816,9 +817,9 @@ impl<'a> State<'a> { try!(self.print_ident(ident)); try!(self.print_generics(generics)); match struct_def.super_struct { - Some(t) => { + Some(ref t) => { try!(self.word_space(":")); - try!(self.print_type(t)); + try!(self.print_type(&**t)); }, None => {}, } @@ -833,7 +834,7 @@ impl<'a> State<'a> { ast::UnnamedField(vis) => { try!(s.print_visibility(vis)); try!(s.maybe_print_comment(field.span.lo)); - s.print_type(field.node.ty) + s.print_type(&*field.node.ty) } } } @@ -858,7 +859,7 @@ impl<'a> State<'a> { try!(self.print_visibility(visibility)); try!(self.print_ident(ident)); try!(self.word_nbsp(":")); - try!(self.print_type(field.node.ty)); + try!(self.print_type(&*field.node.ty)); try!(word(&mut self.s, ",")); } } @@ -929,21 +930,21 @@ impl<'a> State<'a> { try!(self.popen()); try!(self.commasep(Consistent, args.as_slice(), - |s, arg| s.print_type(arg.ty))); + |s, arg| s.print_type(&*arg.ty))); try!(self.pclose()); } } - ast::StructVariantKind(struct_def) => { + ast::StructVariantKind(ref struct_def) => { try!(self.head("")); let generics = ast_util::empty_generics(); - try!(self.print_struct(struct_def, &generics, v.node.name, v.span)); + try!(self.print_struct(&**struct_def, &generics, v.node.name, v.span)); } } match v.node.disr_expr { - Some(d) => { + Some(ref d) => { try!(space(&mut self.s)); try!(self.word_space("=")); - self.print_expr(d) + self.print_expr(&**d) } _ => Ok(()) } @@ -958,7 +959,7 @@ impl<'a> State<'a> { &None, m.fn_style, ast::Many, - m.decl, + &*m.decl, Some(m.ident), &None, Some(&m.generics), @@ -971,7 +972,7 @@ impl<'a> State<'a> { m: &ast::TraitMethod) -> IoResult<()> { match *m { Required(ref ty_m) => self.print_ty_method(ty_m), - Provided(m) => self.print_method(m) + Provided(ref m) => self.print_method(&**m) } } @@ -979,11 +980,11 @@ impl<'a> State<'a> { try!(self.hardbreak_if_not_bol()); try!(self.maybe_print_comment(meth.span.lo)); try!(self.print_outer_attributes(meth.attrs.as_slice())); - try!(self.print_fn(meth.decl, Some(meth.fn_style), abi::Rust, + try!(self.print_fn(&*meth.decl, Some(meth.fn_style), abi::Rust, meth.ident, &meth.generics, Some(meth.explicit_self.node), meth.vis)); try!(word(&mut self.s, " ")); - self.print_block_with_attrs(meth.body, meth.attrs.as_slice()) + self.print_block_with_attrs(&*meth.body, meth.attrs.as_slice()) } pub fn print_outer_attributes(&mut self, @@ -1032,7 +1033,7 @@ impl<'a> State<'a> { ast::AttrInner => try!(word(&mut self.s, "#![")), ast::AttrOuter => try!(word(&mut self.s, "#[")), } - try!(self.print_meta_item(attr.meta())); + try!(self.print_meta_item(&*attr.meta())); word(&mut self.s, "]") } } @@ -1041,16 +1042,16 @@ impl<'a> State<'a> { pub fn print_stmt(&mut self, st: &ast::Stmt) -> IoResult<()> { try!(self.maybe_print_comment(st.span.lo)); match st.node { - ast::StmtDecl(decl, _) => { - try!(self.print_decl(decl)); + ast::StmtDecl(ref decl, _) => { + try!(self.print_decl(&**decl)); } - ast::StmtExpr(expr, _) => { + ast::StmtExpr(ref expr, _) => { try!(self.space_if_not_bol()); - try!(self.print_expr(expr)); + try!(self.print_expr(&**expr)); } - ast::StmtSemi(expr, _) => { + ast::StmtSemi(ref expr, _) => { try!(self.space_if_not_bol()); - try!(self.print_expr(expr)); + try!(self.print_expr(&**expr)); try!(word(&mut self.s, ";")); } ast::StmtMac(ref mac, semi) => { @@ -1105,12 +1106,12 @@ impl<'a> State<'a> { try!(self.print_view_item(vi)); } for st in blk.stmts.iter() { - try!(self.print_stmt(*st)); + try!(self.print_stmt(&**st)); } match blk.expr { - Some(expr) => { + Some(ref expr) => { try!(self.space_if_not_bol()); - try!(self.print_expr(expr)); + try!(self.print_expr(&**expr)); try!(self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi))); } _ => () @@ -1119,26 +1120,26 @@ impl<'a> State<'a> { self.ann.post(self, NodeBlock(blk)) } - fn print_else(&mut self, els: Option<@ast::Expr>) -> IoResult<()> { + fn print_else(&mut self, els: Option<Gc<ast::Expr>>) -> IoResult<()> { match els { Some(_else) => { match _else.node { // "another else-if" - ast::ExprIf(i, t, e) => { + ast::ExprIf(ref i, ref t, e) => { try!(self.cbox(indent_unit - 1u)); try!(self.ibox(0u)); try!(word(&mut self.s, " else if ")); - try!(self.print_expr(i)); + try!(self.print_expr(&**i)); try!(space(&mut self.s)); - try!(self.print_block(t)); + try!(self.print_block(&**t)); self.print_else(e) } // "final else" - ast::ExprBlock(b) => { + ast::ExprBlock(ref b) => { try!(self.cbox(indent_unit - 1u)); try!(self.ibox(0u)); try!(word(&mut self.s, " else ")); - self.print_block(b) + self.print_block(&**b) } // BLEAH, constraints would be great here _ => { @@ -1151,7 +1152,7 @@ impl<'a> State<'a> { } pub fn print_if(&mut self, test: &ast::Expr, blk: &ast::Block, - elseopt: Option<@ast::Expr>, chk: bool) -> IoResult<()> { + elseopt: Option<Gc<ast::Expr>>, chk: bool) -> IoResult<()> { try!(self.head("if")); if chk { try!(self.word_nbsp("check")); } try!(self.print_expr(test)); @@ -1184,7 +1185,7 @@ impl<'a> State<'a> { } } - fn print_call_post(&mut self, args: &[@ast::Expr]) -> IoResult<()> { + fn print_call_post(&mut self, args: &[Gc<ast::Expr>]) -> IoResult<()> { try!(self.popen()); try!(self.commasep_exprs(Inconsistent, args)); self.pclose() @@ -1207,16 +1208,16 @@ impl<'a> State<'a> { try!(self.ibox(indent_unit)); try!(self.ann.pre(self, NodeExpr(expr))); match expr.node { - ast::ExprVstore(e, v) => { + ast::ExprVstore(ref e, v) => { try!(self.print_expr_vstore(v)); - try!(self.print_expr(e)); + try!(self.print_expr(&**e)); }, - ast::ExprBox(p, e) => { + ast::ExprBox(ref p, ref e) => { try!(word(&mut self.s, "box")); try!(word(&mut self.s, "(")); - try!(self.print_expr(p)); + try!(self.print_expr(&**p)); try!(self.word_space(")")); - try!(self.print_expr(e)); + try!(self.print_expr(&**e)); } ast::ExprVec(ref exprs) => { try!(self.ibox(indent_unit)); @@ -1226,13 +1227,13 @@ impl<'a> State<'a> { try!(self.end()); } - ast::ExprRepeat(element, count) => { + ast::ExprRepeat(ref element, ref count) => { try!(self.ibox(indent_unit)); try!(word(&mut self.s, "[")); - try!(self.print_expr(element)); + try!(self.print_expr(&**element)); try!(word(&mut self.s, ",")); try!(word(&mut self.s, "..")); - try!(self.print_expr(count)); + try!(self.print_expr(&**count)); try!(word(&mut self.s, "]")); try!(self.end()); } @@ -1247,19 +1248,19 @@ impl<'a> State<'a> { try!(s.ibox(indent_unit)); try!(s.print_ident(field.ident.node)); try!(s.word_space(":")); - try!(s.print_expr(field.expr)); + try!(s.print_expr(&*field.expr)); s.end() }, |f| f.span)); match wth { - Some(expr) => { + Some(ref expr) => { try!(self.ibox(indent_unit)); if !fields.is_empty() { try!(word(&mut self.s, ",")); try!(space(&mut self.s)); } try!(word(&mut self.s, "..")); - try!(self.print_expr(expr)); + try!(self.print_expr(&**expr)); try!(self.end()); } _ => try!(word(&mut self.s, ",")) @@ -1274,13 +1275,13 @@ impl<'a> State<'a> { } try!(self.pclose()); } - ast::ExprCall(func, ref args) => { - try!(self.print_expr_maybe_paren(func)); + ast::ExprCall(ref func, ref args) => { + try!(self.print_expr_maybe_paren(&**func)); try!(self.print_call_post(args.as_slice())); } ast::ExprMethodCall(ident, ref tys, ref args) => { let base_args = args.slice_from(1); - try!(self.print_expr(*args.get(0))); + try!(self.print_expr(&**args.get(0))); try!(word(&mut self.s, ".")); try!(self.print_ident(ident.node)); if tys.len() > 0u { @@ -1291,52 +1292,52 @@ impl<'a> State<'a> { } try!(self.print_call_post(base_args)); } - ast::ExprBinary(op, lhs, rhs) => { - try!(self.print_expr(lhs)); + ast::ExprBinary(op, ref lhs, ref rhs) => { + try!(self.print_expr(&**lhs)); try!(space(&mut self.s)); try!(self.word_space(ast_util::binop_to_str(op))); - try!(self.print_expr(rhs)); + try!(self.print_expr(&**rhs)); } - ast::ExprUnary(op, expr) => { + ast::ExprUnary(op, ref expr) => { try!(word(&mut self.s, ast_util::unop_to_str(op))); - try!(self.print_expr_maybe_paren(expr)); + try!(self.print_expr_maybe_paren(&**expr)); } - ast::ExprAddrOf(m, expr) => { + ast::ExprAddrOf(m, ref expr) => { try!(word(&mut self.s, "&")); try!(self.print_mutability(m)); - try!(self.print_expr_maybe_paren(expr)); + try!(self.print_expr_maybe_paren(&**expr)); } - ast::ExprLit(lit) => try!(self.print_literal(lit)), - ast::ExprCast(expr, ty) => { - try!(self.print_expr(expr)); + ast::ExprLit(ref lit) => try!(self.print_literal(&**lit)), + ast::ExprCast(ref expr, ref ty) => { + try!(self.print_expr(&**expr)); try!(space(&mut self.s)); try!(self.word_space("as")); - try!(self.print_type(ty)); + try!(self.print_type(&**ty)); } - ast::ExprIf(test, blk, elseopt) => { - try!(self.print_if(test, blk, elseopt, false)); + ast::ExprIf(ref test, ref blk, elseopt) => { + try!(self.print_if(&**test, &**blk, elseopt, false)); } - ast::ExprWhile(test, blk) => { + ast::ExprWhile(ref test, ref blk) => { try!(self.head("while")); - try!(self.print_expr(test)); + try!(self.print_expr(&**test)); try!(space(&mut self.s)); - try!(self.print_block(blk)); + try!(self.print_block(&**blk)); } - ast::ExprForLoop(pat, iter, blk, opt_ident) => { + ast::ExprForLoop(ref pat, ref iter, ref blk, opt_ident) => { for ident in opt_ident.iter() { try!(word(&mut self.s, "'")); try!(self.print_ident(*ident)); try!(self.word_space(":")); } try!(self.head("for")); - try!(self.print_pat(pat)); + try!(self.print_pat(&**pat)); try!(space(&mut self.s)); try!(self.word_space("in")); - try!(self.print_expr(iter)); + try!(self.print_expr(&**iter)); try!(space(&mut self.s)); - try!(self.print_block(blk)); + try!(self.print_block(&**blk)); } - ast::ExprLoop(blk, opt_ident) => { + ast::ExprLoop(ref blk, opt_ident) => { for ident in opt_ident.iter() { try!(word(&mut self.s, "'")); try!(self.print_ident(*ident)); @@ -1344,13 +1345,13 @@ impl<'a> State<'a> { } try!(self.head("loop")); try!(space(&mut self.s)); - try!(self.print_block(blk)); + try!(self.print_block(&**blk)); } - ast::ExprMatch(expr, ref arms) => { + ast::ExprMatch(ref expr, ref arms) => { try!(self.cbox(indent_unit)); try!(self.ibox(4)); try!(self.word_nbsp("match")); - try!(self.print_expr(expr)); + try!(self.print_expr(&**expr)); try!(space(&mut self.s)); try!(self.bopen()); let len = arms.len(); @@ -1371,13 +1372,13 @@ impl<'a> State<'a> { try!(space(&mut self.s)); try!(self.word_space("|")); } - try!(self.print_pat(*p)); + try!(self.print_pat(&**p)); } try!(space(&mut self.s)); match arm.guard { - Some(e) => { + Some(ref e) => { try!(self.word_space("if")); - try!(self.print_expr(e)); + try!(self.print_expr(&**e)); try!(space(&mut self.s)); } None => () @@ -1385,16 +1386,17 @@ impl<'a> State<'a> { try!(self.word_space("=>")); match arm.body.node { - ast::ExprBlock(blk) => { + ast::ExprBlock(ref blk) => { // the block will close the pattern's ibox - try!(self.print_block_unclosed_indent(blk, indent_unit)); + try!(self.print_block_unclosed_indent(&**blk, + indent_unit)); } _ => { try!(self.end()); // close the ibox for the pattern - try!(self.print_expr(arm.body)); + try!(self.print_expr(&*arm.body)); } } - if !expr_is_simple_block(expr) + if !expr_is_simple_block(expr.clone()) && i < len - 1 { try!(word(&mut self.s, ",")); } @@ -1402,27 +1404,27 @@ impl<'a> State<'a> { } try!(self.bclose_(expr.span, indent_unit)); } - ast::ExprFnBlock(decl, body) => { + ast::ExprFnBlock(ref decl, ref body) => { // in do/for blocks we don't want to show an empty // argument list, but at this point we don't know which // we are inside. // // if !decl.inputs.is_empty() { - try!(self.print_fn_block_args(decl)); + try!(self.print_fn_block_args(&**decl)); try!(space(&mut self.s)); // } if !body.stmts.is_empty() || !body.expr.is_some() { - try!(self.print_block_unclosed(body)); + try!(self.print_block_unclosed(&**body)); } else { // we extract the block, so as not to create another set of boxes match body.expr.unwrap().node { - ast::ExprBlock(blk) => { - try!(self.print_block_unclosed(blk)); + ast::ExprBlock(ref blk) => { + try!(self.print_block_unclosed(&**blk)); } _ => { // this is a bare expression - try!(self.print_expr(body.expr.unwrap())); + try!(self.print_expr(&*body.expr.unwrap())); try!(self.end()); // need to close a box } } @@ -1432,25 +1434,25 @@ impl<'a> State<'a> { // empty box to satisfy the close. try!(self.ibox(0)); } - ast::ExprProc(decl, body) => { + ast::ExprProc(ref decl, ref body) => { // in do/for blocks we don't want to show an empty // argument list, but at this point we don't know which // we are inside. // // if !decl.inputs.is_empty() { - try!(self.print_proc_args(decl)); + try!(self.print_proc_args(&**decl)); try!(space(&mut self.s)); // } assert!(body.stmts.is_empty()); assert!(body.expr.is_some()); // we extract the block, so as not to create another set of boxes match body.expr.unwrap().node { - ast::ExprBlock(blk) => { - try!(self.print_block_unclosed(blk)); + ast::ExprBlock(ref blk) => { + try!(self.print_block_unclosed(&**blk)); } _ => { // this is a bare expression - try!(self.print_expr(body.expr.unwrap())); + try!(self.print_expr(&*body.expr.unwrap())); try!(self.end()); // need to close a box } } @@ -1459,28 +1461,28 @@ impl<'a> State<'a> { // empty box to satisfy the close. try!(self.ibox(0)); } - ast::ExprBlock(blk) => { + ast::ExprBlock(ref blk) => { // containing cbox, will be closed by print-block at } try!(self.cbox(indent_unit)); // head-box, will be closed by print-block after { try!(self.ibox(0u)); - try!(self.print_block(blk)); + try!(self.print_block(&**blk)); } - ast::ExprAssign(lhs, rhs) => { - try!(self.print_expr(lhs)); + ast::ExprAssign(ref lhs, ref rhs) => { + try!(self.print_expr(&**lhs)); try!(space(&mut self.s)); try!(self.word_space("=")); - try!(self.print_expr(rhs)); + try!(self.print_expr(&**rhs)); } - ast::ExprAssignOp(op, lhs, rhs) => { - try!(self.print_expr(lhs)); + ast::ExprAssignOp(op, ref lhs, ref rhs) => { + try!(self.print_expr(&**lhs)); try!(space(&mut self.s)); try!(word(&mut self.s, ast_util::binop_to_str(op))); try!(self.word_space("=")); - try!(self.print_expr(rhs)); + try!(self.print_expr(&**rhs)); } - ast::ExprField(expr, id, ref tys) => { - try!(self.print_expr(expr)); + ast::ExprField(ref expr, id, ref tys) => { + try!(self.print_expr(&**expr)); try!(word(&mut self.s, ".")); try!(self.print_ident(id)); if tys.len() > 0u { @@ -1491,10 +1493,10 @@ impl<'a> State<'a> { try!(word(&mut self.s, ">")); } } - ast::ExprIndex(expr, index) => { - try!(self.print_expr(expr)); + ast::ExprIndex(ref expr, ref index) => { + try!(self.print_expr(&**expr)); try!(word(&mut self.s, "[")); - try!(self.print_expr(index)); + try!(self.print_expr(&**index)); try!(word(&mut self.s, "]")); } ast::ExprPath(ref path) => try!(self.print_path(path, true)), @@ -1516,12 +1518,12 @@ impl<'a> State<'a> { try!(space(&mut self.s)) } } - ast::ExprRet(result) => { + ast::ExprRet(ref result) => { try!(word(&mut self.s, "return")); - match result { - Some(expr) => { + match *result { + Some(ref expr) => { try!(word(&mut self.s, " ")); - try!(self.print_expr(expr)); + try!(self.print_expr(&**expr)); } _ => () } @@ -1536,20 +1538,22 @@ impl<'a> State<'a> { try!(self.print_string(a.asm.get(), a.asm_str_style)); try!(self.word_space(":")); - try!(self.commasep(Inconsistent, a.outputs.as_slice(), |s, &(ref co, o)| { + try!(self.commasep(Inconsistent, a.outputs.as_slice(), + |s, &(ref co, ref o)| { try!(s.print_string(co.get(), ast::CookedStr)); try!(s.popen()); - try!(s.print_expr(o)); + try!(s.print_expr(&**o)); try!(s.pclose()); Ok(()) })); try!(space(&mut self.s)); try!(self.word_space(":")); - try!(self.commasep(Inconsistent, a.inputs.as_slice(), |s, &(ref co, o)| { + try!(self.commasep(Inconsistent, a.inputs.as_slice(), + |s, &(ref co, ref o)| { try!(s.print_string(co.get(), ast::CookedStr)); try!(s.popen()); - try!(s.print_expr(o)); + try!(s.print_expr(&**o)); try!(s.pclose()); Ok(()) })); @@ -1560,9 +1564,9 @@ impl<'a> State<'a> { try!(self.pclose()); } ast::ExprMac(ref m) => try!(self.print_mac(m)), - ast::ExprParen(e) => { + ast::ExprParen(ref e) => { try!(self.popen()); - try!(self.print_expr(e)); + try!(self.print_expr(&**e)); try!(self.pclose()); } } @@ -1571,12 +1575,12 @@ impl<'a> State<'a> { } pub fn print_local_decl(&mut self, loc: &ast::Local) -> IoResult<()> { - try!(self.print_pat(loc.pat)); + try!(self.print_pat(&*loc.pat)); match loc.ty.node { ast::TyInfer => Ok(()), _ => { try!(self.word_space(":")); - self.print_type(loc.ty) + self.print_type(&*loc.ty) } } } @@ -1584,25 +1588,25 @@ impl<'a> State<'a> { pub fn print_decl(&mut self, decl: &ast::Decl) -> IoResult<()> { try!(self.maybe_print_comment(decl.span.lo)); match decl.node { - ast::DeclLocal(loc) => { + ast::DeclLocal(ref loc) => { try!(self.space_if_not_bol()); try!(self.ibox(indent_unit)); try!(self.word_nbsp("let")); try!(self.ibox(indent_unit)); - try!(self.print_local_decl(loc)); + try!(self.print_local_decl(&**loc)); try!(self.end()); match loc.init { - Some(init) => { + Some(ref init) => { try!(self.nbsp()); try!(self.word_space("=")); - try!(self.print_expr(init)); + try!(self.print_expr(&**init)); } _ => {} } self.end() } - ast::DeclItem(item) => self.print_item(item) + ast::DeclItem(ref item) => self.print_item(&**item) } } @@ -1709,9 +1713,9 @@ impl<'a> State<'a> { } try!(self.print_path(path, true)); match sub { - Some(p) => { + Some(ref p) => { try!(word(&mut self.s, "@")); - try!(self.print_pat(p)); + try!(self.print_pat(&**p)); } None => () } @@ -1724,7 +1728,7 @@ impl<'a> State<'a> { if !args.is_empty() { try!(self.popen()); try!(self.commasep(Inconsistent, args.as_slice(), - |s, &p| s.print_pat(p))); + |s, p| s.print_pat(&**p))); try!(self.pclose()); } } @@ -1739,7 +1743,7 @@ impl<'a> State<'a> { try!(s.cbox(indent_unit)); try!(s.print_ident(f.ident)); try!(s.word_space(":")); - try!(s.print_pat(f.pat)); + try!(s.print_pat(&*f.pat)); s.end() }, |f| f.pat.span)); @@ -1753,46 +1757,46 @@ impl<'a> State<'a> { try!(self.popen()); try!(self.commasep(Inconsistent, elts.as_slice(), - |s, &p| s.print_pat(p))); + |s, p| s.print_pat(&**p))); if elts.len() == 1 { try!(word(&mut self.s, ",")); } try!(self.pclose()); } - ast::PatBox(inner) => { + ast::PatBox(ref inner) => { try!(word(&mut self.s, "box ")); - try!(self.print_pat(inner)); + try!(self.print_pat(&**inner)); } - ast::PatRegion(inner) => { + ast::PatRegion(ref inner) => { try!(word(&mut self.s, "&")); - try!(self.print_pat(inner)); + try!(self.print_pat(&**inner)); } - ast::PatLit(e) => try!(self.print_expr(e)), - ast::PatRange(begin, end) => { - try!(self.print_expr(begin)); + ast::PatLit(ref e) => try!(self.print_expr(&**e)), + ast::PatRange(ref begin, ref end) => { + try!(self.print_expr(&**begin)); try!(space(&mut self.s)); try!(word(&mut self.s, "..")); - try!(self.print_expr(end)); + try!(self.print_expr(&**end)); } ast::PatVec(ref before, slice, ref after) => { try!(word(&mut self.s, "[")); try!(self.commasep(Inconsistent, before.as_slice(), - |s, &p| s.print_pat(p))); - for &p in slice.iter() { + |s, p| s.print_pat(&**p))); + for p in slice.iter() { if !before.is_empty() { try!(self.word_space(",")); } - match *p { + match **p { ast::Pat { node: ast::PatWildMulti, .. } => { // this case is handled by print_pat } _ => try!(word(&mut self.s, "..")), } - try!(self.print_pat(p)); + try!(self.print_pat(&**p)); if !after.is_empty() { try!(self.word_space(",")); } } try!(self.commasep(Inconsistent, after.as_slice(), - |s, &p| s.print_pat(p))); + |s, p| s.print_pat(&**p))); try!(word(&mut self.s, "]")); } ast::PatMac(ref m) => try!(self.print_mac(m)), @@ -1888,7 +1892,7 @@ impl<'a> State<'a> { _ => { try!(self.space_if_not_bol()); try!(self.word_space("->")); - self.print_type(decl.output) + self.print_type(&*decl.output) } } } @@ -1904,7 +1908,7 @@ impl<'a> State<'a> { _ => { try!(self.space_if_not_bol()); try!(self.word_space("->")); - try!(self.print_type(decl.output)); + try!(self.print_type(&*decl.output)); } } @@ -1922,7 +1926,7 @@ impl<'a> State<'a> { _ => { try!(self.space_if_not_bol()); try!(self.word_space("->")); - try!(self.print_type(decl.output)); + try!(self.print_type(&*decl.output)); } } @@ -2014,10 +2018,10 @@ impl<'a> State<'a> { try!(s.print_ident(param.ident)); try!(s.print_bounds(&None, ¶m.bounds, false)); match param.default { - Some(default) => { + Some(ref default) => { try!(space(&mut s.s)); try!(s.word_space("=")); - s.print_type(default) + s.print_type(&**default) } _ => Ok(()) } @@ -2045,7 +2049,7 @@ impl<'a> State<'a> { try!(self.popen()); try!(self.commasep(Consistent, items.as_slice(), - |s, &i| s.print_meta_item(i))); + |s, i| s.print_meta_item(&**i))); try!(self.pclose()); } } @@ -2103,7 +2107,7 @@ impl<'a> State<'a> { ast::ViewItemUse(ref vp) => { try!(self.head("use")); - try!(self.print_view_path(*vp)); + try!(self.print_view_path(&**vp)); } } try!(word(&mut self.s, ";")); @@ -2121,13 +2125,13 @@ impl<'a> State<'a> { pub fn print_mt(&mut self, mt: &ast::MutTy) -> IoResult<()> { try!(self.print_mutability(mt.mutbl)); - self.print_type(mt.ty) + self.print_type(&*mt.ty) } pub fn print_arg(&mut self, input: &ast::Arg) -> IoResult<()> { try!(self.ibox(indent_unit)); match input.ty.node { - ast::TyInfer => try!(self.print_pat(input.pat)), + ast::TyInfer => try!(self.print_pat(&*input.pat)), _ => { match input.pat.node { ast::PatIdent(_, ref path, _) if @@ -2137,12 +2141,12 @@ impl<'a> State<'a> { // Do nothing. } _ => { - try!(self.print_pat(input.pat)); + try!(self.print_pat(&*input.pat)); try!(word(&mut self.s, ":")); try!(space(&mut self.s)); } } - try!(self.print_type(input.ty)); + try!(self.print_type(&*input.ty)); } } self.end() @@ -2229,7 +2233,7 @@ impl<'a> State<'a> { if decl.cf == ast::NoReturn { try!(self.word_nbsp("!")); } else { - try!(self.print_type(decl.output)); + try!(self.print_type(&*decl.output)); } try!(self.end()); } |
