about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-02-24 18:32:02 -0800
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-02-25 23:37:45 -0800
commitbff22cf1665e98a1c3feb60e1c23fc30a4120934 (patch)
tree1625f6d0921cf8944742a4dc6142ed4e92b1206c /src/libsyntax
parent752befe2a6401108f27ff0141bdd73baac44c41c (diff)
downloadrust-bff22cf1665e98a1c3feb60e1c23fc30a4120934.tar.gz
rust-bff22cf1665e98a1c3feb60e1c23fc30a4120934.zip
libsyntax: add some explicit copies
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_map.rs15
-rw-r--r--src/libsyntax/ast_util.rs4
-rw-r--r--src/libsyntax/ext/pipes/parse_proto.rs56
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs2
-rw-r--r--src/libsyntax/fold.rs2
-rw-r--r--src/libsyntax/parse/common.rs4
-rw-r--r--src/libsyntax/parse/obsolete.rs2
-rw-r--r--src/libsyntax/parse/parser.rs77
8 files changed, 94 insertions, 68 deletions
diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs
index b56dfeffd7a..48fe0ca5b2d 100644
--- a/src/libsyntax/ast_map.rs
+++ b/src/libsyntax/ast_map.rs
@@ -60,8 +60,8 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: ~str, itr: @ident_interner)
                          -> ~str {
     let strs = do p.map |e| {
         match *e {
-          path_mod(s) => *itr.get(s),
-          path_name(s) => *itr.get(s)
+          path_mod(s) => copy *itr.get(s),
+          path_name(s) => copy *itr.get(s)
         }
     };
     str::connect(strs, sep)
@@ -70,7 +70,7 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: ~str, itr: @ident_interner)
 pub fn path_ident_to_str(p: path, i: ident, itr: @ident_interner) -> ~str {
     if vec::is_empty(p) {
         //FIXME /* FIXME (#2543) */ copy *i
-        *itr.get(i)
+        copy *itr.get(i)
     } else {
         fmt!("%s::%s", path_to_str(p, itr), *itr.get(i))
     }
@@ -82,8 +82,8 @@ pub fn path_to_str(p: &[path_elt], itr: @ident_interner) -> ~str {
 
 pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str {
     match pe {
-        path_mod(s) => *itr.get(s),
-        path_name(s) => *itr.get(s)
+        path_mod(s) => copy *itr.get(s),
+        path_name(s) => copy *itr.get(s)
     }
 }
 
@@ -310,7 +310,10 @@ pub fn map_item(i: @item, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) {
             for methods.each |tm| {
                 let id = ast_util::trait_method_to_ty_method(tm).id;
                 let d_id = ast_util::local_def(i.id);
-                cx.map.insert(id, node_trait_method(@*tm, d_id, item_path));
+                cx.map.insert(
+                    id,
+                    node_trait_method(@copy *tm, d_id, item_path)
+                );
             }
         }
         _ => ()
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 7bf08aaaf76..59f25024c82 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -27,7 +27,7 @@ use core::vec;
 pub pure fn path_name_i(idents: &[ident], intr: @token::ident_interner)
                      -> ~str {
     // FIXME: Bad copies (#2543 -- same for everything else that says "bad")
-    str::connect(idents.map(|i| *intr.get(*i)), ~"::")
+    str::connect(idents.map(|i| copy *intr.get(*i)), ~"::")
 }
 
 
@@ -283,7 +283,7 @@ pub fn split_trait_methods(trait_methods: &[trait_method])
     let mut reqd = ~[], provd = ~[];
     for trait_methods.each |trt_method| {
         match *trt_method {
-          required(ref tm) => reqd.push((*tm)),
+          required(ref tm) => reqd.push(copy *tm),
           provided(m) => provd.push(m)
         }
     };
diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs
index 07db67d3173..fae5b1b49af 100644
--- a/src/libsyntax/ext/pipes/parse_proto.rs
+++ b/src/libsyntax/ext/pipes/parse_proto.rs
@@ -27,10 +27,14 @@ pub impl proto_parser for parser::Parser {
     fn parse_proto(&self, id: ~str) -> protocol {
         let proto = protocol(id, *self.span);
 
-        self.parse_seq_to_before_end(token::EOF, SeqSep {
-                                        sep: None,
-                                        trailing_sep_allowed: false
-                                     }, |self| self.parse_state(proto));
+        self.parse_seq_to_before_end(
+            token::EOF,
+            SeqSep {
+                sep: None,
+                trailing_sep_allowed: false,
+            },
+            |self| self.parse_state(proto)
+        );
 
         return proto;
     }
@@ -40,9 +44,9 @@ pub impl proto_parser for parser::Parser {
         let name = *self.interner.get(id);
 
         self.expect(&token::COLON);
-        let dir = match *self.token {
-          token::IDENT(n, _) => self.interner.get(n),
-          _ => fail!()
+        let dir = match copy *self.token {
+            token::IDENT(n, _) => self.interner.get(n),
+            _ => fail!()
         };
         self.bump();
         let dir = match dir {
@@ -61,21 +65,29 @@ pub impl proto_parser for parser::Parser {
 
         // parse the messages
         self.parse_unspanned_seq(
-            token::LBRACE, token::RBRACE, SeqSep {
+            token::LBRACE,
+            token::RBRACE,
+            SeqSep {
                 sep: Some(token::COMMA),
-                trailing_sep_allowed: true
-            }, |self| self.parse_message(state));
+                trailing_sep_allowed: true,
+            },
+            |self| self.parse_message(state)
+        );
     }
 
     fn parse_message(&self, state: state) {
         let mname = *self.interner.get(self.parse_ident());
 
         let args = if *self.token == token::LPAREN {
-            self.parse_unspanned_seq(token::LPAREN,
-                                     token::RPAREN, SeqSep {
-                                        sep: Some(token::COMMA),
-                                        trailing_sep_allowed: true
-                                     }, |p| p.parse_ty(false))
+            self.parse_unspanned_seq(
+                token::LPAREN,
+                token::RPAREN,
+                SeqSep {
+                    sep: Some(token::COMMA),
+                    trailing_sep_allowed: true,
+                },
+                |p| p.parse_ty(false)
+            )
         }
         else { ~[] };
 
@@ -85,11 +97,15 @@ pub impl proto_parser for parser::Parser {
           token::IDENT(_, _) => {
             let name = *self.interner.get(self.parse_ident());
             let ntys = if *self.token == token::LT {
-                self.parse_unspanned_seq(token::LT,
-                                         token::GT, SeqSep {
-                                            sep: Some(token::COMMA),
-                                            trailing_sep_allowed: true
-                                         }, |p| p.parse_ty(false))
+                self.parse_unspanned_seq(
+                    token::LT,
+                    token::GT,
+                    SeqSep {
+                        sep: Some(token::COMMA),
+                        trailing_sep_allowed: true,
+                    },
+                    |p| p.parse_ty(false)
+                )
             }
             else { ~[] };
             Some(next_state {state: name, tys: ntys})
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index 890420edf6d..713bf9afcd0 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -424,7 +424,7 @@ pub fn parse_nt(p: Parser, name: ~str) -> nonterminal {
       ~"ident" => match *p.token {
         token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) }
         _ => p.fatal(~"expected ident, found "
-                     + token::to_str(p.reader.interner(), *p.token))
+                     + token::to_str(p.reader.interner(), copy *p.token))
       },
       ~"path" => token::nt_path(p.parse_path_with_tps(false)),
       ~"tt" => {
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index e74376afb08..d67596e100f 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -280,7 +280,7 @@ pub fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ {
         }
         item_mac(ref m) => {
             // FIXME #2888: we might actually want to do something here.
-            item_mac((*m))
+            item_mac(copy *m)
         }
     }
 }
diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs
index 91abd804fb3..78527062515 100644
--- a/src/libsyntax/parse/common.rs
+++ b/src/libsyntax/parse/common.rs
@@ -27,13 +27,13 @@ pub struct SeqSep {
     trailing_sep_allowed: bool
 }
 
-pub fn seq_sep_trailing_disallowed(t: token::Token) -> SeqSep {
+pub fn seq_sep_trailing_disallowed(+t: token::Token) -> SeqSep {
     SeqSep {
         sep: Some(t),
         trailing_sep_allowed: false,
     }
 }
-pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep {
+pub fn seq_sep_trailing_allowed(+t: token::Token) -> SeqSep {
     SeqSep {
         sep: Some(t),
         trailing_sep_allowed: true,
diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs
index 02c2fb404c2..96ed81e476e 100644
--- a/src/libsyntax/parse/obsolete.rs
+++ b/src/libsyntax/parse/obsolete.rs
@@ -198,7 +198,7 @@ pub impl Parser {
 
     fn try_parse_obsolete_priv_section() -> bool {
         if self.is_keyword(&~"priv") && self.look_ahead(1) == token::LBRACE {
-            self.obsolete(*self.span, ObsoletePrivSection);
+            self.obsolete(copy *self.span, ObsoletePrivSection);
             self.eat_keyword(&~"priv");
             self.bump();
             while *self.token != token::RBRACE {
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 7a0f248cd3d..9fe53fe50e2 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -195,11 +195,10 @@ struct ParsedItemsAndViewItems {
 /* ident is handled by common.rs */
 
 pub fn Parser(sess: @mut ParseSess,
-              cfg: ast::crate_cfg,
+              +cfg: ast::crate_cfg,
               +rdr: reader) -> Parser {
 
-    let tok0 = rdr.next_token();
-    let span0 = tok0.sp;
+    let tok0 = copy rdr.next_token();
     let interner = rdr.interner();
 
     Parser {
@@ -207,15 +206,15 @@ pub fn Parser(sess: @mut ParseSess,
         interner: interner,
         sess: sess,
         cfg: cfg,
-        token: @mut tok0.tok,
-        span: @mut span0,
-        last_span: @mut span0,
-        buffer: @mut [TokenAndSpan {tok: tok0.tok, sp: span0}, ..4],
+        token: @mut copy tok0.tok,
+        span: @mut copy tok0.sp,
+        last_span: @mut copy tok0.sp,
+        buffer: @mut [copy tok0, .. 4],
         buffer_start: @mut 0,
         buffer_end: @mut 0,
-        tokens_consumed: @mut 0u,
+        tokens_consumed: @mut 0,
         restriction: @mut UNRESTRICTED,
-        quote_depth: @mut 0u,
+        quote_depth: @mut 0,
         keywords: token::keyword_table(),
         strict_keywords: token::strict_keyword_table(),
         reserved_keywords: token::reserved_keyword_table(),
@@ -253,20 +252,20 @@ pub struct Parser {
 pub impl Parser {
     // advance the parser by one token
     fn bump() {
-        *self.last_span = *self.span;
+        *self.last_span = copy *self.span;
         let next = if *self.buffer_start == *self.buffer_end {
             self.reader.next_token()
         } else {
-            let next = self.buffer[*self.buffer_start];
+            let next = copy self.buffer[*self.buffer_start];
             *self.buffer_start = (*self.buffer_start + 1) & 3;
             next
         };
-        *self.token = next.tok;
-        *self.span = next.sp;
+        *self.token = copy next.tok;
+        *self.span = copy next.sp;
         *self.tokens_consumed += 1u;
     }
     // EFFECT: replace the current token and span with the given one
-    fn replace_token(next: token::Token, +lo: BytePos, +hi: BytePos) {
+    fn replace_token(+next: token::Token, +lo: BytePos, +hi: BytePos) {
         *self.token = next;
         *self.span = mk_sp(lo, hi);
     }
@@ -461,7 +460,7 @@ pub impl Parser {
             let hi = p.last_span.hi;
             debug!("parse_trait_methods(): trait method signature ends in \
                     `%s`",
-                   token_to_str(p.reader, *p.token));
+                   token_to_str(p.reader, copy *p.token));
             match *p.token {
               token::SEMI => {
                 p.bump();
@@ -499,8 +498,13 @@ pub impl Parser {
                 })
               }
 
-              _ => { p.fatal(~"expected `;` or `}` but found `" +
-                          token_to_str(p.reader, *p.token) + ~"`");
+              _ => {
+                    p.fatal(
+                        fmt!(
+                            "expected `;` or `}` but found `%s`",
+                            token_to_str(p.reader, copy *p.token)
+                        )
+                    );
                 }
             }
         }
@@ -649,7 +653,7 @@ pub impl Parser {
             self.parse_borrowed_pointee()
         } else if self.eat_keyword(&~"extern") {
             self.parse_ty_bare_fn()
-        } else if self.token_is_closure_keyword(&*self.token) {
+        } else if self.token_is_closure_keyword(&copy *self.token) {
             self.parse_ty_closure(None, None)
         } else if *self.token == token::MOD_SEP
             || is_ident_or_path(*self.token) {
@@ -681,7 +685,7 @@ pub impl Parser {
                     self.bump();
                     self.bump();
                     return self.parse_ty_closure(Some(sigil), Some(rname));
-                } else if self.token_is_closure_keyword(&*self.token) {
+                } else if self.token_is_closure_keyword(&copy *self.token) {
                     return self.parse_ty_closure(Some(sigil), None);
                 }
             }
@@ -716,7 +720,7 @@ pub impl Parser {
             _ => { None }
         };
 
-        if self.token_is_closure_keyword(&*self.token) {
+        if self.token_is_closure_keyword(&copy *self.token) {
             return self.parse_ty_closure(Some(BorrowedSigil), rname);
         }
 
@@ -841,9 +845,12 @@ pub impl Parser {
                 }
                 _ => {
                     self.fatal(
-                        fmt!("expected integral vector length \
-                              but found `%s`",
-                             token_to_str(self.reader, *self.token)));
+                        fmt!(
+                            "expected integral vector length \
+                            but found `%s`",
+                            token_to_str(self.reader, copy *self.token)
+                        )
+                    );
                 }
             }
         } else {
@@ -873,7 +880,7 @@ pub impl Parser {
             lit_bool(false)
         } else {
             // XXX: This is a really bad copy!
-            let tok = *self.token;
+            let tok = copy *self.token;
             self.bump();
             self.lit_from_token(tok)
         };
@@ -1063,7 +1070,7 @@ pub impl Parser {
         }
     }
 
-    fn mk_mac_expr(+lo: BytePos, +hi: BytePos, m: mac_) -> @expr {
+    fn mk_mac_expr(+lo: BytePos, +hi: BytePos, +m: mac_) -> @expr {
         @expr {
             id: self.get_id(),
             callee_id: self.get_id(),
@@ -1391,7 +1398,7 @@ pub impl Parser {
             self.bump();
             (None, zerok)
         } else {
-            let sep = *self.token;
+            let sep = copy *self.token;
             self.bump();
             if *self.token == token::BINOP(token::STAR)
                 || *self.token == token::BINOP(token::PLUS) {
@@ -1416,7 +1423,7 @@ pub impl Parser {
                 p.fatal(
                     fmt!(
                         "incorrect close delimiter: `%s`",
-                        token_to_str(p.reader, *p.token)
+                        token_to_str(p.reader, copy *p.token)
                     )
                 );
               }
@@ -1912,7 +1919,7 @@ pub impl Parser {
         // labeled loop headers look like 'loop foo: {'
         let is_labeled_loop_header =
             is_ident(*self.token)
-            && !self.is_any_keyword(&*self.token)
+            && !self.is_any_keyword(&copy *self.token)
             && self.look_ahead(1) == token::COLON;
 
         if is_loop_header || is_labeled_loop_header {
@@ -2143,7 +2150,7 @@ pub impl Parser {
         let lo = self.span.lo;
         let mut hi = self.span.hi;
         let mut pat;
-        match *self.token {
+        match copy *self.token {
           token::UNDERSCORE => { self.bump(); pat = pat_wild; }
           token::AT => {
             self.bump();
@@ -2446,7 +2453,7 @@ pub impl Parser {
             let decl = self.parse_let();
             return @spanned(lo, decl.span.hi, stmt_decl(decl, self.get_id()));
         } else if is_ident(*self.token)
-            && !self.is_any_keyword(&*self.token)
+            && !self.is_any_keyword(&copy *self.token)
             && self.look_ahead(1) == token::NOT {
 
             check_expected_item(self, first_item_attrs);
@@ -2540,7 +2547,7 @@ pub impl Parser {
 
         let lo = self.span.lo;
         if self.eat_keyword(&~"unsafe") {
-            self.obsolete(*self.span, ObsoleteUnsafeBlock);
+            self.obsolete(copy *self.span, ObsoleteUnsafeBlock);
         }
         self.expect(&token::LBRACE);
         let (inner, next) =
@@ -3049,7 +3056,7 @@ pub impl Parser {
             ty = self.parse_ty(false);
             opt_trait_ref
         } else if self.eat(&token::COLON) {
-            self.obsolete(*self.span, ObsoleteImplSyntax);
+            self.obsolete(copy *self.span, ObsoleteImplSyntax);
             Some(self.parse_trait_ref())
         } else {
             None
@@ -3116,7 +3123,7 @@ pub impl Parser {
         self.parse_region_param();
         let ty_params = self.parse_ty_params();
         if self.eat(&token::COLON) {
-            self.obsolete(*self.span, ObsoleteClassTraits);
+            self.obsolete(copy *self.span, ObsoleteClassTraits);
             let _ = self.parse_trait_ref_list(token::LBRACE);
         }
 
@@ -3948,7 +3955,7 @@ pub impl Parser {
                 vis: visibility,
                 span: mk_sp(lo, self.last_span.hi)
             });
-        } else if macros_allowed && !self.is_any_keyword(&*self.token)
+        } else if macros_allowed && !self.is_any_keyword(&copy *self.token)
                 && self.look_ahead(1) == token::NOT
                 && (is_plain_ident(self.look_ahead(2))
                     || self.look_ahead(2) == token::LPAREN
@@ -4121,7 +4128,7 @@ pub impl Parser {
     fn is_view_item() -> bool {
         let tok, next_tok;
         if !self.is_keyword(&~"pub") && !self.is_keyword(&~"priv") {
-            tok = *self.token;
+            tok = copy *self.token;
             next_tok = self.look_ahead(1);
         } else {
             tok = self.look_ahead(1);