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),
+ token::NtIdent(ref e, _) => ident_to_string(**e),
token::NtTT(ref e) => tt_to_string(&**e),
token::NtArm(ref e) => arm_to_string(&*e),
token::NtImplItem(ref e) => impl_item_to_string(&**e),
to_string(|s| s.print_path(p, false, 0))
}
-pub fn ident_to_string(id: &ast::Ident) -> String {
- to_string(|s| s.print_ident(*id))
+pub fn ident_to_string(id: ast::Ident) -> String {
+ to_string(|s| s.print_ident(id))
}
pub fn fun_to_string(decl: &ast::FnDecl,
self.end()
}
+ fn commasep_iter<'it, T: 'it, F, I>(&mut self, b: Breaks, elts: I, mut op: F) -> io::Result<()>
+ where F: FnMut(&mut Self, &T) -> io::Result<()>,
+ I: Iterator<Item=&'it T>,
+ {
+ try!(self.rbox(0, b));
+ let mut first = true;
+ for elt in elts {
+ if first { first = false; } else { try!(self.word_space(",")); }
+ try!(op(self, elt));
+ }
+ self.end()
+ }
fn next_lit(&mut self, pos: BytePos) -> Option<comments::Literal> {
let mut cur_lit = self.cur_cmnt_and_lit().cur_lit;
let mut count = 0;
for attr in attrs {
match attr.node.style {
- ast::AttrInner => {
+ ast::AttrStyle::Inner => {
try!(self.print_attribute(attr));
count += 1;
}
let mut count = 0;
for attr in attrs {
match attr.node.style {
- ast::AttrOuter => {
+ ast::AttrStyle::Outer => {
try!(self.print_attribute(attr));
count += 1;
}
word(self.writer(), &attr.value_str().unwrap())
} else {
match attr.node.style {
- ast::AttrInner => try!(word(self.writer(), "#![")),
- ast::AttrOuter => try!(word(self.writer(), "#[")),
+ ast::AttrStyle::Inner => try!(word(self.writer(), "#![")),
+ ast::AttrStyle::Outer => try!(word(self.writer(), "#[")),
}
try!(self.print_meta_item(&*attr.meta()));
word(self.writer(), "]")
}
ast::ItemStruct(ref struct_def, ref generics) => {
try!(self.head(&visibility_qualified(item.vis,"struct")));
- try!(self.print_struct(&**struct_def, generics, item.ident, item.span));
+ try!(self.print_struct(&struct_def, generics, item.ident, item.span, true));
}
ast::ItemDefaultImpl(unsafety, ref trait_ref) => {
}
pub fn print_struct(&mut self,
- struct_def: &ast::StructDef,
+ struct_def: &ast::VariantData,
generics: &ast::Generics,
ident: ast::Ident,
- span: codemap::Span) -> io::Result<()> {
+ span: codemap::Span,
+ print_finalizer: bool) -> io::Result<()> {
try!(self.print_ident(ident));
try!(self.print_generics(generics));
- if ast_util::struct_def_is_tuple_like(struct_def) {
- if !struct_def.fields.is_empty() {
+ if !struct_def.is_struct() {
+ if struct_def.is_tuple() {
try!(self.popen());
- try!(self.commasep(
- Inconsistent, &struct_def.fields,
+ try!(self.commasep_iter(
+ Inconsistent, struct_def.fields(),
|s, field| {
match field.node.kind {
ast::NamedField(..) => panic!("unexpected named field"),
try!(self.pclose());
}
try!(self.print_where_clause(&generics.where_clause));
- try!(word(&mut self.s, ";"));
+ if print_finalizer {
+ try!(word(&mut self.s, ";"));
+ }
try!(self.end());
self.end() // close the outer-box
} else {
try!(self.bopen());
try!(self.hardbreak_if_not_bol());
- for field in &struct_def.fields {
+ for field in struct_def.fields() {
match field.node.kind {
ast::UnnamedField(..) => panic!("unexpected unnamed field"),
ast::NamedField(ident, visibility) => {
}
pub fn print_variant(&mut self, v: &ast::Variant) -> io::Result<()> {
- match v.node.kind {
- ast::TupleVariantKind(ref args) => {
- try!(self.print_ident(v.node.name));
- if !args.is_empty() {
- try!(self.popen());
- try!(self.commasep(Consistent,
- &args[..],
- |s, arg| s.print_type(&*arg.ty)));
- try!(self.pclose());
- }
- }
- 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.head(""));
+ let generics = ast_util::empty_generics();
+ try!(self.print_struct(&v.node.data, &generics, v.node.name, v.span, false));
match v.node.disr_expr {
Some(ref d) => {
try!(space(&mut self.s));
try!(space(&mut self.s));
try!(self.print_block(&**blk));
}
- ast::ExprMatch(ref expr, ref arms, _) => {
+ ast::ExprMatch(ref expr, ref arms) => {
try!(self.cbox(indent_unit));
try!(self.ibox(4));
try!(self.word_nbsp("match"));
ast::ViewPathSimple(ident, ref path) => {
try!(self.print_path(path, false, 0));
- // FIXME(#6993) can't compare identifiers directly here
if path.segments.last().unwrap().identifier.name !=
ident.name {
try!(space(&mut self.s));
use ast_util;
use codemap;
use parse::token;
+ use ptr::P;
#[test]
fn test_fun_to_string() {
name: ident,
attrs: Vec::new(),
// making this up as I go.... ?
- kind: ast::TupleVariantKind(Vec::new()),
- id: 0,
+ data: P(ast::VariantData::Unit(ast::DUMMY_NODE_ID)),
disr_expr: None,
});