about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-02-26 06:35:36 -0800
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-02-26 20:48:11 -0800
commit4ae91e2961ac7be50a346a6b0d724601878a9cd0 (patch)
tree90cb8dd7634d786c2ff6c7253dc1dc742c4f925e /src/libsyntax/parse
parent8d239a256d39eb2527ddd40e34d14a2e1801fb61 (diff)
downloadrust-4ae91e2961ac7be50a346a6b0d724601878a9cd0.tar.gz
rust-4ae91e2961ac7be50a346a6b0d724601878a9cd0.zip
libsyntax: add explicit copies
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/attr.rs12
-rw-r--r--src/libsyntax/parse/comments.rs10
-rw-r--r--src/libsyntax/parse/mod.rs21
-rw-r--r--src/libsyntax/parse/parser.rs105
-rw-r--r--src/libsyntax/parse/token.rs14
5 files changed, 101 insertions, 61 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs
index 56e350db47b..a52a9f3ba5e 100644
--- a/src/libsyntax/parse/attr.rs
+++ b/src/libsyntax/parse/attr.rs
@@ -46,7 +46,10 @@ impl parser_attr for Parser {
               }
               token::DOC_COMMENT(s) => {
                 let attr = ::attr::mk_sugared_doc_attr(
-                        *self.id_to_str(s), self.span.lo, self.span.hi);
+                    copy *self.id_to_str(s),
+                    self.span.lo,
+                    self.span.hi
+                );
                 if attr.node.style != ast::attr_outer {
                   self.fatal(~"expected outer comment");
                 }
@@ -113,7 +116,10 @@ impl parser_attr for Parser {
               }
               token::DOC_COMMENT(s) => {
                 let attr = ::attr::mk_sugared_doc_attr(
-                        *self.id_to_str(s), self.span.lo, self.span.hi);
+                    copy *self.id_to_str(s),
+                    self.span.lo,
+                    self.span.hi
+                );
                 self.bump();
                 if attr.node.style == ast::attr_inner {
                   inner_attrs += ~[attr];
@@ -151,7 +157,7 @@ impl parser_attr for Parser {
     }
 
     fn parse_meta_seq() -> ~[@ast::meta_item] {
-        self.parse_seq(
+        copy self.parse_seq(
             &token::LPAREN,
             &token::RPAREN,
             seq_sep_trailing_disallowed(token::COMMA),
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs
index 4960563db88..714ae9a0fd5 100644
--- a/src/libsyntax/parse/comments.rs
+++ b/src/libsyntax/parse/comments.rs
@@ -221,7 +221,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str],
         if col < len {
             s1 = str::slice(s, col, len);
         } else { s1 = ~""; }
-    } else { s1 = s; }
+    } else { s1 = /*bad*/ copy s; }
     log(debug, ~"pushing line: " + s1);
     lines.push(s1);
 }
@@ -321,7 +321,7 @@ pub struct lit {
 }
 
 pub fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
-                                    path: ~str,
+                                    +path: ~str,
                                     srdr: io::Reader) -> (~[cmnt], ~[lit]) {
     let src = @str::from_bytes(srdr.read_whole_stream());
     let itr = parse::token::mk_fake_ident_interner();
@@ -356,10 +356,10 @@ pub fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
         let TokenAndSpan {tok: tok, sp: sp} = rdr.peek();
         if token::is_lit(&tok) {
             let s = get_str_from(rdr, bstart);
-            literals.push(lit {lit: s, pos: sp.lo});
-            log(debug, ~"tok lit: " + s);
+            literals.push(lit {lit: /*bad*/ copy s, pos: sp.lo});
+            debug!("tok lit: %s", s);
         } else {
-            log(debug, ~"tok: " + token::to_str(rdr.interner, &tok));
+            debug!("tok: %s", token::to_str(rdr.interner, &tok));
         }
         first_read = false;
     }
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 5fa61159385..cf5cb847018 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -92,7 +92,7 @@ pub fn parse_crate_from_source_str(name: ~str,
                                    source: @~str,
                                    cfg: ast::crate_cfg,
                                    sess: @mut ParseSess) -> @ast::crate {
-    let p = new_parser_from_source_str(sess, cfg, name,
+    let p = new_parser_from_source_str(sess, cfg, /*bad*/ copy name,
                                        codemap::FssNone, source);
     let r = p.parse_crate_mod(cfg);
     p.abort_if_errors();
@@ -103,7 +103,7 @@ pub fn parse_expr_from_source_str(name: ~str,
                                   source: @~str,
                                   cfg: ast::crate_cfg,
                                   sess: @mut ParseSess) -> @ast::expr {
-    let p = new_parser_from_source_str(sess, cfg, name,
+    let p = new_parser_from_source_str(sess, cfg, /*bad*/ copy name,
                                        codemap::FssNone, source);
     let r = p.parse_expr();
     p.abort_if_errors();
@@ -116,7 +116,7 @@ pub fn parse_item_from_source_str(name: ~str,
                                   +attrs: ~[ast::attribute],
                                   sess: @mut ParseSess)
                                -> Option<@ast::item> {
-    let p = new_parser_from_source_str(sess, cfg, name,
+    let p = new_parser_from_source_str(sess, cfg, /*bad*/ copy name,
                                        codemap::FssNone, source);
     let r = p.parse_item(attrs);
     p.abort_if_errors();
@@ -128,7 +128,7 @@ pub fn parse_stmt_from_source_str(name: ~str,
                                   cfg: ast::crate_cfg,
                                   +attrs: ~[ast::attribute],
                                   sess: @mut ParseSess) -> @ast::stmt {
-    let p = new_parser_from_source_str(sess, cfg, name,
+    let p = new_parser_from_source_str(sess, cfg, /*bad*/ copy name,
                                        codemap::FssNone, source);
     let r = p.parse_stmt(attrs);
     p.abort_if_errors();
@@ -139,7 +139,7 @@ pub fn parse_tts_from_source_str(name: ~str,
                                  source: @~str,
                                  cfg: ast::crate_cfg,
                                  sess: @mut ParseSess) -> ~[ast::token_tree] {
-    let p = new_parser_from_source_str(sess, cfg, name,
+    let p = new_parser_from_source_str(sess, cfg, /*bad*/ copy name,
                                        codemap::FssNone, source);
     *p.quote_depth += 1u;
     let r = p.parse_all_token_trees();
@@ -153,8 +153,13 @@ pub fn parse_from_source_str<T>(f: fn (p: Parser) -> T,
                             sess: @mut ParseSess)
     -> T
 {
-    let p = new_parser_from_source_str(sess, cfg, name, ss,
-                                       source);
+    let p = new_parser_from_source_str(
+        sess,
+        cfg,
+        /*bad*/ copy name,
+        /*bad*/ copy ss,
+        source
+    );
     let r = f(p);
     if !p.reader.is_eof() {
         p.reader.fatal(~"expected end-of-string");
@@ -226,7 +231,7 @@ pub fn new_sub_parser_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg,
 }
 
 pub fn new_parser_from_tts(sess: @mut ParseSess, cfg: ast::crate_cfg,
-                       tts: ~[ast::token_tree]) -> Parser {
+                           +tts: ~[ast::token_tree]) -> Parser {
     let trdr = lexer::new_tt_reader(copy sess.span_diagnostic, sess.interner,
                                     None, tts);
     return Parser(sess, cfg, trdr as reader)
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 694e8387958..2c7947090c2 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -147,16 +147,25 @@ macro_rules! maybe_whole_expr (
 )
 
 macro_rules! maybe_whole (
-    ($p:expr, $constructor:ident) => ( match *$p.token {
-      INTERPOLATED(token::$constructor(x)) => { $p.bump(); return x; }
+    ($p:expr, $constructor:ident) => ( match copy *$p.token {
+      INTERPOLATED(token::$constructor(x)) => {
+        $p.bump();
+        return x;
+      }
       _ => ()
     }) ;
-    (deref $p:expr, $constructor:ident) => ( match *$p.token {
-      INTERPOLATED(token::$constructor(x)) => { $p.bump(); return *x; }
+    (deref $p:expr, $constructor:ident) => ( match copy *$p.token {
+      INTERPOLATED(token::$constructor(x)) => {
+        $p.bump();
+        return copy *x;
+      }
       _ => ()
     }) ;
-    (Some $p:expr, $constructor:ident) => ( match *$p.token {
-      INTERPOLATED(token::$constructor(x)) => { $p.bump(); return Some(x); }
+    (Some $p:expr, $constructor:ident) => ( match copy *$p.token {
+      INTERPOLATED(token::$constructor(x)) => {
+        $p.bump();
+        return Some(x);
+      }
       _ => ()
     }) ;
     (iovi $p:expr, $constructor:ident) => ( match *$p.token {
@@ -166,9 +175,10 @@ macro_rules! maybe_whole (
       }
       _ => ()
     }) ;
-    (pair_empty $p:expr, $constructor:ident) => ( match *$p.token {
+    (pair_empty $p:expr, $constructor:ident) => ( match copy *$p.token {
       INTERPOLATED(token::$constructor(x)) => {
-        $p.bump(); return (~[], x);
+        $p.bump();
+        return (~[], x);
       }
       _ => ()
     })
@@ -612,8 +622,11 @@ pub impl Parser {
                         one_tuple = true;
                     }
                 }
-                let t = if ts.len() == 1 && !one_tuple { ts[0].node }
-                else { ty_tup(ts) };
+                let t = if ts.len() == 1 && !one_tuple {
+                    copy ts[0].node
+                } else {
+                    ty_tup(ts)
+                };
                 self.expect(&token::RPAREN);
                 t
             }
@@ -972,7 +985,7 @@ pub impl Parser {
         @ast::path { span: mk_sp(lo, hi),
                      rp: rp,
                      types: tps,
-                     .. *path }
+                     .. copy *path }
     }
 
     fn parse_opt_lifetime() -> Option<ast::Lifetime> {
@@ -1440,7 +1453,12 @@ pub impl Parser {
                         |p| p.parse_token_tree()
                     );
                     let (s, z) = p.parse_sep_and_zerok();
-                    tt_seq(mk_sp(sp.lo ,p.span.hi), seq.node, s, z)
+                    tt_seq(
+                        mk_sp(sp.lo ,p.span.hi),
+                        /*bad*/ copy seq.node,
+                        s,
+                        z
+                    )
                 } else {
                     tt_nonterminal(sp, p.parse_ident())
                 }
@@ -1453,7 +1471,7 @@ pub impl Parser {
 
         // turn the next token into a tt_tok:
         fn parse_any_tt_tok(p: &Parser) -> token_tree{
-            let res = tt_tok(*p.span, *p.token);
+            let res = tt_tok(*p.span, copy *p.token);
             p.bump();
             res
         }
@@ -1562,7 +1580,7 @@ pub impl Parser {
                 m
             }
         } else {
-            let m = match_tok(*self.token);
+            let m = match_tok(copy *self.token);
             self.bump();
             m
         };
@@ -1665,7 +1683,7 @@ pub impl Parser {
     fn parse_more_binops(lhs: @expr, min_prec: uint) ->
         @expr {
         if self.expr_is_complete(lhs) { return lhs; }
-        let peeked = *self.token;
+        let peeked = copy *self.token;
         if peeked == token::BINOP(token::OR) &&
             (*self.restriction == RESTRICT_NO_BAR_OP ||
              *self.restriction == RESTRICT_NO_BAR_OR_DOUBLEBAR_OP) {
@@ -1859,7 +1877,7 @@ pub impl Parser {
         // Turn on the restriction to stop at | or || so we can parse
         // them as the lambda arguments
         let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
-        match e.node {
+        match /*bad*/ copy e.node {
             expr_call(f, args, NoSugar) => {
                 let block = self.parse_lambda_block_expr();
                 let last_arg = self.mk_expr(block.span.lo, block.span.hi,
@@ -2441,7 +2459,7 @@ pub impl Parser {
     fn parse_stmt(+first_item_attrs: ~[attribute]) -> @stmt {
         maybe_whole!(self, nt_stmt);
 
-        fn check_expected_item(p: &Parser, current_attrs: ~[attribute]) {
+        fn check_expected_item(p: &Parser, current_attrs: &[attribute]) {
             // If we have attributes then we should have an item
             if !current_attrs.is_empty() {
                 p.fatal(~"expected item after attrs");
@@ -2497,7 +2515,7 @@ pub impl Parser {
             let item_attrs = vec::append(first_item_attrs,
                                          self.parse_outer_attributes());
 
-            match self.parse_item_or_view_item(item_attrs,
+            match self.parse_item_or_view_item(/*bad*/ copy item_attrs,
                                                true, false, false) {
               iovi_item(i) => {
                 let mut hi = i.span.hi;
@@ -2614,7 +2632,7 @@ pub impl Parser {
                                     self.bump();
                                     stmts.push(@codemap::spanned {
                                         node: stmt_semi(e, stmt_id),
-                                        .. *stmt});
+                                        .. copy *stmt});
                                 }
                                 token::RBRACE => {
                                     expr = Some(e);
@@ -2640,8 +2658,8 @@ pub impl Parser {
                                 token::SEMI => {
                                     self.bump();
                                     stmts.push(@codemap::spanned {
-                                        node: stmt_mac((*m), true),
-                                        .. *stmt});
+                                        node: stmt_mac(copy *m, true),
+                                        .. copy *stmt});
                                 }
                                 token::RBRACE => {
                                     // if a block ends in `m!(arg)` without
@@ -2649,7 +2667,7 @@ pub impl Parser {
                                     expr = Some(
                                         self.mk_mac_expr(stmt.span.lo,
                                                          stmt.span.hi,
-                                                         (*m).node));
+                                                         copy m.node));
                                 }
                                 _ => { stmts.push(stmt); }
                             }
@@ -2990,6 +3008,7 @@ pub impl Parser {
         let self_ty = if is_static { static_sty} else { self_ty };
 
         let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
+        let hi = body.span.hi;
         let attrs = vec::append(attrs, inner_attrs);
         @ast::method {
             ident: ident,
@@ -3000,7 +3019,7 @@ pub impl Parser {
             decl: decl,
             body: body,
             id: self.get_id(),
-            span: mk_sp(lo, body.span.hi),
+            span: mk_sp(lo, hi),
             self_id: self.get_id(),
             vis: visa,
         }
@@ -3161,7 +3180,7 @@ pub impl Parser {
                                                           declared here");
                         }
                         None => {
-                          the_dtor = Some(((*blk), (*attrs), s));
+                          the_dtor = Some((copy *blk, copy *attrs, s));
                         }
                       }
                   }
@@ -3205,7 +3224,7 @@ pub impl Parser {
         }
 
         let actual_dtor = do the_dtor.map |dtor| {
-            let (d_body, d_attrs, d_s) = *dtor;
+            let (d_body, d_attrs, d_s) = copy *dtor;
             codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(),
                                                      attrs: d_attrs,
                                                      self_id: self.get_id(),
@@ -3257,7 +3276,7 @@ pub impl Parser {
         a_var
     }
 
-    fn parse_dtor(attrs: ~[attribute]) -> class_contents {
+    fn parse_dtor(+attrs: ~[attribute]) -> class_contents {
         let lo = self.last_span.lo;
         let body = self.parse_block();
         dtor_decl(body, attrs, mk_sp(lo, self.last_span.hi))
@@ -3323,12 +3342,17 @@ pub impl Parser {
         while *self.token != term {
             let mut attrs = self.parse_outer_attributes();
             if first {
-                attrs = vec::append(attrs_remaining, attrs);
+                attrs = vec::append(/*bad*/ copy attrs_remaining, attrs);
                 first = false;
             }
             debug!("parse_mod_items: parse_item_or_view_item(attrs=%?)",
                    attrs);
-            match self.parse_item_or_view_item(attrs, true, false, true) {
+            match self.parse_item_or_view_item(
+                /*bad*/ copy attrs,
+                true,
+                false,
+                true
+            ) {
               iovi_item(item) => items.push(item),
               iovi_view_item(view_item) => {
                 self.span_fatal(view_item.span, ~"view items must be \
@@ -3456,7 +3480,7 @@ pub impl Parser {
                                     outer_attrs, id_sp)
     }
 
-    fn eval_src_mod_from_path(prefix: Path, path: Path,
+    fn eval_src_mod_from_path(prefix: Path, +path: Path,
                               outer_attrs: ~[ast::attribute],
                               id_sp: span
                              ) -> (ast::item_, ~[ast::attribute]) {
@@ -3471,12 +3495,15 @@ pub impl Parser {
             new_sub_parser_from_file(self.sess, self.cfg,
                                      &full_path, id_sp);
         let (inner, next) = p0.parse_inner_attrs_and_next();
-        let mod_attrs = vec::append(outer_attrs, inner);
+        let mod_attrs = vec::append(
+            /*bad*/ copy outer_attrs,
+            inner
+        );
         let first_item_outer_attrs = next;
         let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
         return (ast::item_mod(m0), mod_attrs);
 
-        fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str {
+        fn cdir_path_opt(+default: ~str, attrs: ~[ast::attribute]) -> ~str {
             match ::attr::first_attr_value_str_by_name(attrs, ~"path") {
                 Some(d) => copy *d,
                 None => default
@@ -3631,8 +3658,9 @@ pub impl Parser {
             self.expect(&token::RBRACE);
 
             return iovi_item(self.mk_item(lo, self.last_span.hi, ident,
-                                     item_foreign_mod(m), visibility,
-                                     maybe_append(attrs, Some(inner))));
+                                          item_foreign_mod(m), visibility,
+                                          maybe_append(/*bad*/ copy attrs,
+                                                       Some(inner))));
         }
 
         match abi_opt {
@@ -3648,7 +3676,7 @@ pub impl Parser {
         self.expect(&token::SEMI);
         iovi_view_item(@ast::view_item {
             node: view_item_extern_mod(ident, metadata, self.get_id()),
-            attrs: attrs,
+            attrs: copy attrs,
             vis: visibility,
             span: mk_sp(lo, self.last_span.hi)
         })
@@ -3691,7 +3719,7 @@ pub impl Parser {
                                               declared here");
                         }
                         None => {
-                            the_dtor = Some(((*blk), (*attrs), s));
+                            the_dtor = Some((copy *blk, copy *attrs, s));
                         }
                     }
                 }
@@ -3704,7 +3732,7 @@ pub impl Parser {
         }
         self.bump();
         let mut actual_dtor = do the_dtor.map |dtor| {
-            let (d_body, d_attrs, d_s) = *dtor;
+            let (d_body, d_attrs, d_s) = copy *dtor;
             codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(),
                                                      attrs: d_attrs,
                                                      self_id: self.get_id(),
@@ -4216,7 +4244,8 @@ pub impl Parser {
 
         let mut (view_items, items, foreign_items) = (~[], ~[], ~[]);
         loop {
-            match self.parse_item_or_view_item(attrs, items_allowed,
+            match self.parse_item_or_view_item(/*bad*/ copy attrs,
+                                               items_allowed,
                                                foreign_items_allowed,
                                                macros_allowed) {
                 iovi_none =>
@@ -4265,7 +4294,7 @@ pub impl Parser {
         @spanned(lo, self.span.lo,
                  ast::crate_ { module: m,
                                attrs: inner,
-                               config: self.cfg })
+                               config: copy self.cfg })
     }
 
     fn parse_str() -> @~str {
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 2b9df61120e..8b063314c9b 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -179,14 +179,14 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
       }
       LIT_INT_UNSUFFIXED(i) => { i.to_str() }
       LIT_FLOAT(s, t) => {
-        let mut body = *in.get(s);
+        let mut body = copy *in.get(s);
         if body.ends_with(~".") {
             body = body + ~"0";  // `10.f` is not a float literal
         }
         body + ast_util::float_ty_to_str(t)
       }
       LIT_FLOAT_UNSUFFIXED(s) => {
-        let mut body = *in.get(s);
+        let mut body = copy *in.get(s);
         if body.ends_with(~".") {
             body = body + ~"0";  // `10.f` is not a float literal
         }
@@ -195,12 +195,12 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
       LIT_STR(s) => { ~"\"" + str::escape_default(*in.get(s)) + ~"\"" }
 
       /* Name components */
-      IDENT(s, _) => *in.get(s),
+      IDENT(s, _) => copy *in.get(s),
       LIFETIME(s) => fmt!("'%s", *in.get(s)),
       UNDERSCORE => ~"_",
 
       /* Other */
-      DOC_COMMENT(s) => *in.get(s),
+      DOC_COMMENT(s) => copy *in.get(s),
       EOF => ~"<eof>",
       INTERPOLATED(ref nt) => {
         match nt {
@@ -476,7 +476,7 @@ pub fn temporary_keyword_table() -> HashMap<~str, ()> {
         ~"self", ~"static",
     ];
     for keys.each |word| {
-        words.insert(*word, ());
+        words.insert(copy *word, ());
     }
     words
 }
@@ -503,7 +503,7 @@ pub fn strict_keyword_table() -> HashMap<~str, ()> {
         ~"while"
     ];
     for keys.each |word| {
-        words.insert(*word, ());
+        words.insert(copy *word, ());
     }
     words
 }
@@ -514,7 +514,7 @@ pub fn reserved_keyword_table() -> HashMap<~str, ()> {
         ~"be"
     ];
     for keys.each |word| {
-        words.insert(*word, ());
+        words.insert(copy *word, ());
     }
     words
 }