diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-06-27 17:41:35 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-07-17 14:56:42 -0700 |
| commit | b4e674f6e662bc80f2e7a5a1a9834f2152f08d32 (patch) | |
| tree | 1b567620d7ea1641fa58338b8f6e5c68bb324248 /src/libsyntax/parse | |
| parent | 8c082658bed1877d5741f7badceb8efc3015598d (diff) | |
| download | rust-b4e674f6e662bc80f2e7a5a1a9834f2152f08d32.tar.gz rust-b4e674f6e662bc80f2e7a5a1a9834f2152f08d32.zip | |
librustc: Add a lint mode for unnecessary `copy` and remove a bunch of them.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 65 |
4 files changed, 41 insertions, 55 deletions
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 4a872832952..22e0a150a19 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -94,7 +94,7 @@ fn dup_string_reader(r: @mut StringReader) -> @mut StringReader { curr: r.curr, filemap: r.filemap, peek_tok: copy r.peek_tok, - peek_span: copy r.peek_span + peek_span: r.peek_span } } @@ -103,20 +103,20 @@ impl reader for StringReader { // return the next token. EFFECT: advances the string_reader. fn next_token(@mut self) -> TokenAndSpan { let ret_val = TokenAndSpan { - tok: copy self.peek_tok, - sp: copy self.peek_span, + tok: /*bad*/copy self.peek_tok, + sp: self.peek_span, }; string_advance_token(self); ret_val } fn fatal(@mut self, m: ~str) -> ! { - self.span_diagnostic.span_fatal(copy self.peek_span, m) + self.span_diagnostic.span_fatal(self.peek_span, m) } fn span_diag(@mut self) -> @span_handler { self.span_diagnostic } fn peek(@mut self) -> TokenAndSpan { TokenAndSpan { - tok: copy self.peek_tok, - sp: copy self.peek_span, + tok: /*bad*/copy self.peek_tok, + sp: self.peek_span, } } fn dup(@mut self) -> @reader { dup_string_reader(self) as @reader } @@ -126,13 +126,13 @@ impl reader for TtReader { fn is_eof(@mut self) -> bool { self.cur_tok == token::EOF } fn next_token(@mut self) -> TokenAndSpan { tt_next_token(self) } fn fatal(@mut self, m: ~str) -> ! { - self.sp_diag.span_fatal(copy self.cur_span, m); + self.sp_diag.span_fatal(self.cur_span, m); } fn span_diag(@mut self) -> @span_handler { self.sp_diag } fn peek(@mut self) -> TokenAndSpan { TokenAndSpan { tok: copy self.cur_tok, - sp: copy self.cur_span, + sp: self.cur_span, } } fn dup(@mut self) -> @reader { dup_tt_reader(self) as @reader } @@ -144,7 +144,7 @@ fn string_advance_token(r: @mut StringReader) { match (consume_whitespace_and_comments(r)) { Some(comment) => { r.peek_tok = copy comment.tok; - r.peek_span = copy comment.sp; + r.peek_span = comment.sp; }, None => { if is_eof(r) { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 40f1964bc9c..84cc49192ed 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -307,7 +307,7 @@ pub fn filemap_to_tts(sess: @mut ParseSess, filemap: @FileMap) // it appears to me that the cfg doesn't matter here... indeed, // parsing tt's probably shouldn't require a parser at all. let cfg = ~[]; - let srdr = lexer::new_string_reader(copy sess.span_diagnostic, filemap); + let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap); let p1 = Parser(sess, cfg, srdr as @reader); p1.parse_all_token_trees() } @@ -316,11 +316,7 @@ pub fn filemap_to_tts(sess: @mut ParseSess, filemap: @FileMap) pub fn tts_to_parser(sess: @mut ParseSess, tts: ~[ast::token_tree], cfg: ast::crate_cfg) -> Parser { - let trdr = lexer::new_tt_reader( - copy sess.span_diagnostic, - None, - tts - ); + let trdr = lexer::new_tt_reader(sess.span_diagnostic, None, tts); Parser(sess, cfg, trdr as @reader) } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index fff4c125af6..01ed6531273 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -329,8 +329,9 @@ impl ParserObsoleteMethods for Parser { pub fn try_parse_obsolete_priv_section(&self, attrs: &[attribute]) -> bool { - if self.is_keyword(keywords::Priv) && self.look_ahead(1) == token::LBRACE { - self.obsolete(copy *self.span, ObsoletePrivSection); + if self.is_keyword(keywords::Priv) && self.look_ahead(1) == + token::LBRACE { + self.obsolete(*self.span, ObsoletePrivSection); self.eat_keyword(keywords::Priv); self.bump(); while *self.token != token::RBRACE { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9e9071d6b8c..497000a6cbf 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -236,8 +236,8 @@ pub fn Parser(sess: @mut ParseSess, sess: sess, cfg: cfg, token: @mut copy tok0.tok, - span: @mut copy tok0.sp, - last_span: @mut copy tok0.sp, + span: @mut tok0.sp, + last_span: @mut tok0.sp, buffer: @mut ([copy tok0, .. 4]), buffer_start: @mut 0, buffer_end: @mut 0, @@ -530,7 +530,7 @@ impl Parser { // advance the parser by one token pub fn bump(&self) { - *self.last_span = copy *self.span; + *self.last_span = *self.span; let next = if *self.buffer_start == *self.buffer_end { self.reader.next_token() } else { @@ -538,8 +538,8 @@ impl Parser { *self.buffer_start = (*self.buffer_start + 1) & 3; next }; - *self.token = copy next.tok; - *self.span = copy next.sp; + *self.token = /*bad*/copy next.tok; + *self.span = next.sp; *self.tokens_consumed += 1u; } // EFFECT: replace the current token and span with the given one @@ -565,7 +565,7 @@ impl Parser { return copy self.buffer[(*self.buffer_start + dist - 1) & 3].tok; } pub fn fatal(&self, m: &str) -> ! { - self.sess.span_diagnostic.span_fatal(*copy self.span, m) + self.sess.span_diagnostic.span_fatal(*self.span, m) } pub fn span_fatal(&self, sp: span, m: &str) -> ! { self.sess.span_diagnostic.span_fatal(sp, m) @@ -574,10 +574,10 @@ impl Parser { self.sess.span_diagnostic.span_note(sp, m) } pub fn bug(&self, m: &str) -> ! { - self.sess.span_diagnostic.span_bug(*copy self.span, m) + self.sess.span_diagnostic.span_bug(*self.span, m) } pub fn warn(&self, m: &str) { - self.sess.span_diagnostic.span_warn(*copy self.span, m) + self.sess.span_diagnostic.span_warn(*self.span, m) } pub fn span_err(&self, sp: span, m: &str) { self.sess.span_diagnostic.span_err(sp, m) @@ -608,7 +608,7 @@ impl Parser { pub fn get_lifetime(&self, tok: &token::Token) -> ast::ident { match *tok { - token::LIFETIME(ref ident) => copy *ident, + token::LIFETIME(ref ident) => *ident, _ => self.bug("not a lifetime"), } } @@ -1259,7 +1259,7 @@ impl Parser { self.obsolete(*self.last_span, ObsoleteLifetimeNotation); match *self.token { token::IDENT(sid, _) => { - let span = copy self.span; + let span = self.span; self.bump(); Some(ast::Lifetime { id: self.get_id(), @@ -1347,7 +1347,7 @@ impl Parser { pub fn parse_lifetime(&self) -> ast::Lifetime { match *self.token { token::LIFETIME(i) => { - let span = copy self.span; + let span = self.span; self.bump(); return ast::Lifetime { id: self.get_id(), @@ -1358,7 +1358,7 @@ impl Parser { // Also accept the (obsolete) syntax `foo/` token::IDENT(i, _) => { - let span = copy self.span; + let span = self.span; self.bump(); self.expect(&token::BINOP(token::SLASH)); self.obsolete(*self.last_span, ObsoleteLifetimeNotation); @@ -2981,7 +2981,7 @@ impl Parser { let lo = self.span.lo; if self.eat_keyword(keywords::Unsafe) { - self.obsolete(copy *self.span, ObsoleteUnsafeBlock); + self.obsolete(*self.span, ObsoleteUnsafeBlock); } self.expect(&token::LBRACE); @@ -2996,7 +2996,7 @@ impl Parser { let lo = self.span.lo; if self.eat_keyword(keywords::Unsafe) { - self.obsolete(copy *self.span, ObsoleteUnsafeBlock); + self.obsolete(*self.span, ObsoleteUnsafeBlock); } self.expect(&token::LBRACE); let (inner, next) = self.parse_inner_attrs_and_next(); @@ -3581,7 +3581,7 @@ impl Parser { ty = self.parse_ty(false); opt_trait_ref } else if self.eat(&token::COLON) { - self.obsolete(copy *self.span, ObsoleteImplSyntax); + self.obsolete(*self.span, ObsoleteImplSyntax); Some(self.parse_trait_ref()) } else { None @@ -3626,7 +3626,7 @@ impl Parser { self.parse_region_param(); let generics = self.parse_generics(); if self.eat(&token::COLON) { - self.obsolete(copy *self.span, ObsoleteClassTraits); + self.obsolete(*self.span, ObsoleteClassTraits); let _ = self.parse_trait_ref_list(&token::LBRACE); } @@ -3710,7 +3710,7 @@ impl Parser { let a_var = self.parse_name_and_ty(vis, attrs); match *self.token { token::SEMI => { - self.obsolete(copy *self.span, ObsoleteFieldTerminator); + self.obsolete(*self.span, ObsoleteFieldTerminator); self.bump(); } token::COMMA => { @@ -3718,13 +3718,9 @@ impl Parser { } token::RBRACE => {} _ => { - self.span_fatal( - copy *self.span, - fmt!( - "expected `,`, or '}' but found `%s`", - self.this_token_to_str() - ) - ); + self.span_fatal(*self.span, + fmt!("expected `,`, or '}' but found `%s`", + self.this_token_to_str())); } } a_var @@ -4043,26 +4039,19 @@ impl Parser { must_be_named_mod = true; self.expect_keyword(keywords::Mod); } else if *self.token != token::LBRACE { - self.span_fatal( - copy *self.span, - fmt!( - "expected `{` or `mod` but found `%s`", - self.this_token_to_str() - ) - ); + self.span_fatal(*self.span, + fmt!("expected `{` or `mod` but found `%s`", + self.this_token_to_str())); } let (sort, ident) = match *self.token { token::IDENT(*) => (ast::named, self.parse_ident()), _ => { if must_be_named_mod { - self.span_fatal( - copy *self.span, - fmt!( - "expected foreign module name but found `%s`", - self.this_token_to_str() - ) - ); + self.span_fatal(*self.span, + fmt!("expected foreign module name but \ + found `%s`", + self.this_token_to_str())); } (ast::anonymous, |
