]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/ext/deriving/show.rs
auto merge of #13704 : edwardw/rust/doc-hidden, r=alexcrichton
[rust.git] / src / libsyntax / ext / deriving / show.rs
index 4b9925c8d9f3e9a4875d623dac5ba4afe34bc500..b9725361538d1fbc9500d63f640b07711ab9cab1 100644 (file)
 use ext::base::ExtCtxt;
 use ext::build::AstBuilder;
 use ext::deriving::generic::*;
-
 use parse::token;
 
 use collections::HashMap;
+use std::strbuf::StrBuf;
 
 pub fn expand_deriving_show(cx: &mut ExtCtxt,
                             span: Span,
@@ -26,27 +26,29 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
                             item: @Item,
                             push: |@Item|) {
     // &mut ::std::fmt::Formatter
-    let fmtr = Ptr(~Literal(Path::new(~["std", "fmt", "Formatter"])),
+    let fmtr = Ptr(~Literal(Path::new(vec!("std", "fmt", "Formatter"))),
                    Borrowed(None, ast::MutMutable));
 
     let trait_def = TraitDef {
         span: span,
-        attributes: ~[],
-        path: Path::new(~["std", "fmt", "Show"]),
-        additional_bounds: ~[],
+        attributes: Vec::new(),
+        path: Path::new(vec!("std", "fmt", "Show")),
+        additional_bounds: Vec::new(),
         generics: LifetimeBounds::empty(),
-        methods: ~[
+        methods: vec!(
             MethodDef {
                 name: "fmt",
                 generics: LifetimeBounds::empty(),
                 explicit_self: borrowed_explicit_self(),
-                args: ~[fmtr],
-                ret_ty: Literal(Path::new(~["std", "fmt", "Result"])),
-                inline: false,
+                args: vec!(fmtr),
+                ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
+                attributes: Vec::new(),
                 const_nonmatching: false,
-                combine_substructure: show_substructure
+                combine_substructure: combine_substructure(|a, b, c| {
+                    show_substructure(a, b, c)
+                })
             }
-        ]
+        )
     };
     trait_def.expand(cx, mitem, item, push)
 }
@@ -68,9 +70,9 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
         }
     };
 
-    let mut format_string = token::get_ident(name).get().to_owned();
+    let mut format_string = StrBuf::from_str(token::get_ident(name).get());
     // the internal fields we're actually formatting
-    let mut exprs = ~[];
+    let mut exprs = Vec::new();
 
     // Getting harder... making the format string:
     match *substr.fields {
@@ -79,7 +81,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
         EnumMatching(_, _, ref fields) if fields.len() == 0 => {}
 
         Struct(ref fields) | EnumMatching(_, _, ref fields) => {
-            if fields[0].name.is_none() {
+            if fields.get(0).name.is_none() {
                 // tuple struct/"normal" variant
 
                 format_string.push_str("(");
@@ -124,17 +126,17 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
     let formatter = substr.nonself_args[0];
     let buf = cx.expr_field_access(span, formatter, cx.ident_of("buf"));
 
-    let std_write = ~[cx.ident_of("std"), cx.ident_of("fmt"), cx.ident_of("write")];
+    let std_write = vec!(cx.ident_of("std"), cx.ident_of("fmt"), cx.ident_of("write"));
     let args = cx.ident_of("__args");
-    let write_call = cx.expr_call_global(span, std_write, ~[buf, cx.expr_ident(span, args)]);
-    let format_closure = cx.lambda_expr(span, ~[args], write_call);
+    let write_call = cx.expr_call_global(span, std_write, vec!(buf, cx.expr_ident(span, args)));
+    let format_closure = cx.lambda_expr(span, vec!(args), write_call);
 
-    let s = token::intern_and_get_ident(format_string);
+    let s = token::intern_and_get_ident(format_string.as_slice());
     let format_string = cx.expr_str(span, s);
 
     // phew, not our responsibility any more!
     format::expand_preparsed_format_args(cx, span,
                                          format_closure,
-                                         format_string, exprs, ~[],
+                                         format_string, exprs, Vec::new(),
                                          HashMap::new())
 }