From f499d365ada01a23bd046bac9b1bef7ccdb9fa8c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 30 Dec 2013 14:04:00 -0800 Subject: libsyntax: Make the parser mutable --- src/libsyntax/ext/asm.rs | 6 ++--- src/libsyntax/ext/base.rs | 6 ++--- src/libsyntax/ext/cfg.rs | 4 +++- src/libsyntax/ext/format.rs | 10 ++++---- src/libsyntax/ext/quote.rs | 14 ++++-------- src/libsyntax/ext/source_util.rs | 10 +++++--- src/libsyntax/ext/trace_macros.rs | 4 ++-- src/libsyntax/ext/tt/macro_parser.rs | 6 ++--- src/libsyntax/ext/tt/macro_rules.rs | 44 +++++++++++++++++++++++------------- 9 files changed, 59 insertions(+), 45 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index cd7953aac20..d7d8360f1e8 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -39,9 +39,9 @@ fn next_state(s: State) -> Option { pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { - let p = parse::new_parser_from_tts(cx.parse_sess(), - cx.cfg(), - tts.to_owned()); + let mut p = parse::new_parser_from_tts(cx.parse_sess(), + cx.cfg(), + tts.to_owned()); let mut asm = @""; let mut asm_str_style = None; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 7c2dad34002..a4f447874ff 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -442,9 +442,9 @@ pub fn get_single_str_from_tts(cx: &ExtCtxt, pub fn get_exprs_from_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> ~[@ast::Expr] { - let p = parse::new_parser_from_tts(cx.parse_sess(), - cx.cfg(), - tts.to_owned()); + let mut p = parse::new_parser_from_tts(cx.parse_sess(), + cx.cfg(), + tts.to_owned()); let mut es = ~[]; while *p.token != token::EOF { if es.len() != 0 && !p.eat(&token::COMMA) { diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index d9fbc33153a..f58b5eb3a92 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -26,7 +26,9 @@ use parse::token; use parse::attr::parser_attr; pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { - let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned()); + let mut p = parse::new_parser_from_tts(cx.parse_sess(), + cx.cfg(), + tts.to_owned()); let mut cfgs = ~[]; // parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)` diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 3bfab7da9b4..2d4bdd3da23 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -53,11 +53,11 @@ struct Context<'a> { impl<'a> Context<'a> { /// Parses the arguments from the given list of tokens, returning None if /// there's a parse error so we can continue parsing other format! expressions. - fn parse_args(&mut self, sp: Span, - tts: &[ast::token_tree]) -> (@ast::Expr, Option<@ast::Expr>) { - let p = rsparse::new_parser_from_tts(self.ecx.parse_sess(), - self.ecx.cfg(), - tts.to_owned()); + fn parse_args(&mut self, sp: Span, tts: &[ast::token_tree]) + -> (@ast::Expr, Option<@ast::Expr>) { + let mut p = rsparse::new_parser_from_tts(self.ecx.parse_sess(), + self.ecx.cfg(), + tts.to_owned()); // Parse the leading function expression (maybe a block, maybe a path) let extra = p.parse_expr(); if !p.eat(&token::COMMA) { diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 330d33d6fc6..5021cf968f7 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -579,21 +579,17 @@ fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) ss } -fn expand_tts(cx: &ExtCtxt, - sp: Span, - tts: &[ast::token_tree]) -> (@ast::Expr, @ast::Expr) { - +fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) + -> (@ast::Expr, @ast::Expr) { // NB: It appears that the main parser loses its mind if we consider // $foo as a tt_nonterminal during the main parse, so we have to re-parse // under quote_depth > 0. This is silly and should go away; the _guess_ is // it has to do with transition away from supporting old-style macros, so // try removing it when enough of them are gone. - let p = parse::new_parser_from_tts( - cx.parse_sess(), - cx.cfg(), - tts.to_owned() - ); + let mut p = parse::new_parser_from_tts(cx.parse_sess(), + cx.cfg(), + tts.to_owned()); *p.quote_depth += 1u; let cx_expr = p.parse_expr(); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index ccf4bf2acd6..11e7c1c8499 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -81,9 +81,13 @@ pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include!"); // The file will be added to the code map by the parser - let p = parse::new_sub_parser_from_file( - cx.parse_sess(), cx.cfg(), - &res_rel_file(cx, sp, &Path::new(file)), sp); + let mut p = + parse::new_sub_parser_from_file(cx.parse_sess(), + cx.cfg(), + &res_rel_file(cx, + sp, + &Path::new(file)), + sp); base::MRExpr(p.parse_expr()) } diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index d9b1c2bddbc..34151377d7b 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -26,7 +26,7 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt, None, tt.to_owned()); let rdr = tt_rdr as @mut reader; - let rust_parser = Parser(sess, cfg.clone(), rdr.dup()); + let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup()); if rust_parser.is_keyword(keywords::True) { cx.set_trace_macros(true); @@ -38,7 +38,7 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt, rust_parser.bump(); - let rust_parser = Parser(sess, cfg, rdr.dup()); + let mut rust_parser = Parser(sess, cfg, rdr.dup()); let result = rust_parser.parse_expr(); base::MRExpr(result) } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index a450bfeccfe..f2c695c6cd6 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -403,13 +403,13 @@ pub fn parse( } rdr.next_token(); } else /* bb_eis.len() == 1 */ { - let rust_parser = Parser(sess, cfg.clone(), rdr.dup()); + let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup()); let mut ei = bb_eis.pop(); match ei.elts[ei.idx].node { match_nonterminal(_, ref name, idx) => { ei.matches[idx].push(@matched_nonterminal( - parse_nt(&rust_parser, ident_to_str(name)))); + parse_nt(&mut rust_parser, ident_to_str(name)))); ei.idx += 1u; } _ => fail!() @@ -426,7 +426,7 @@ pub fn parse( } } -pub fn parse_nt(p: &Parser, name: &str) -> nonterminal { +pub fn parse_nt(p: &mut Parser, name: &str) -> nonterminal { match name { "item" => match p.parse_item(~[]) { Some(i) => token::nt_item(i), diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 05d402a2ba2..365c48c7c86 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -24,10 +24,11 @@ use parse::attr::parser_attr; use parse::token::{get_ident_interner, special_idents, gensym_ident, ident_to_str}; use parse::token::{FAT_ARROW, SEMI, nt_matchers, nt_tt, EOF}; use print; +use std::cell::RefCell; use util::small_vector::SmallVector; struct ParserAnyMacro { - parser: @Parser, + parser: RefCell, } impl ParserAnyMacro { @@ -38,28 +39,36 @@ impl ParserAnyMacro { /// fail!(); } )` doesn't get picked up by .parse_expr(), but it's /// allowed to be there. fn ensure_complete_parse(&self, allow_semi: bool) { - if allow_semi && *self.parser.token == SEMI { - self.parser.bump() + let mut parser = self.parser.borrow_mut(); + if allow_semi && *parser.get().token == SEMI { + parser.get().bump() } - if *self.parser.token != EOF { - let msg = format!("macro expansion ignores token `{}` and any following", - self.parser.this_token_to_str()); - self.parser.span_err(*self.parser.span, msg); + if *parser.get().token != EOF { + let token_str = parser.get().this_token_to_str(); + let msg = format!("macro expansion ignores token `{}` and any \ + following", + token_str); + let span = *parser.get().span; + parser.get().span_err(span, msg); } } } impl AnyMacro for ParserAnyMacro { fn make_expr(&self) -> @ast::Expr { - let ret = self.parser.parse_expr(); + let ret = { + let mut parser = self.parser.borrow_mut(); + parser.get().parse_expr() + }; self.ensure_complete_parse(true); ret } fn make_items(&self) -> SmallVector<@ast::item> { let mut ret = SmallVector::zero(); loop { - let attrs = self.parser.parse_outer_attributes(); - match self.parser.parse_item(attrs) { + let mut parser = self.parser.borrow_mut(); + let attrs = parser.get().parse_outer_attributes(); + match parser.get().parse_item(attrs) { Some(item) => ret.push(item), None => break } @@ -68,8 +77,11 @@ impl AnyMacro for ParserAnyMacro { ret } fn make_stmt(&self) -> @ast::Stmt { - let attrs = self.parser.parse_outer_attributes(); - let ret = self.parser.parse_stmt(attrs); + let ret = { + let mut parser = self.parser.borrow_mut(); + let attrs = parser.get().parse_outer_attributes(); + parser.get().parse_stmt(attrs) + }; self.ensure_complete_parse(true); ret } @@ -142,14 +154,14 @@ fn generic_extension(cx: &ExtCtxt, // rhs has holes ( `$id` and `$(...)` that need filled) let trncbr = new_tt_reader(s_d, Some(named_matches), rhs); - let p = @Parser(cx.parse_sess(), - cx.cfg(), - trncbr as @mut reader); + let p = Parser(cx.parse_sess(), + cx.cfg(), + trncbr as @mut reader); // Let the context choose how to interpret the result. // Weird, but useful for X-macros. return MRAny(@ParserAnyMacro { - parser: p, + parser: RefCell::new(p), } as @AnyMacro) } failure(sp, ref msg) => if sp.lo >= best_fail_spot.lo { -- cgit 1.4.1-3-g733a5 From 425a140485dc3ba70c4e30e10cd8d5fd92a458c5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 30 Dec 2013 14:40:31 -0800 Subject: libsyntax: De-`@mut` `quote_depth` in the parser --- src/libsyntax/ext/quote.rs | 2 +- src/libsyntax/ext/tt/macro_parser.rs | 4 ++-- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 5021cf968f7..0f0793e03b7 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -590,7 +590,7 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree]) let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned()); - *p.quote_depth += 1u; + p.quote_depth += 1u; let cx_expr = p.parse_expr(); if !p.eat(&token::COMMA) { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index f2c695c6cd6..a14d25305fd 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -448,9 +448,9 @@ pub fn parse_nt(p: &mut Parser, name: &str) -> nonterminal { } "attr" => token::nt_attr(@p.parse_attribute(false)), "tt" => { - *p.quote_depth += 1u; //but in theory, non-quoted tts might be useful + p.quote_depth += 1u; //but in theory, non-quoted tts might be useful let res = token::nt_tt(@p.parse_token_tree()); - *p.quote_depth -= 1u; + p.quote_depth -= 1u; res } "matchers" => token::nt_matchers(p.parse_matchers()), diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 1200c5db611..a1f770a5fde 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -175,7 +175,7 @@ pub fn parse_tts_from_source_str( name, source ); - *p.quote_depth += 1u; + p.quote_depth += 1u; // right now this is re-creating the token trees from ... token trees. maybe_aborted(p.parse_all_token_trees(),p) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2a4658854c3..806da6988d8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -315,7 +315,7 @@ pub fn Parser(sess: @mut ParseSess, buffer_end: @mut 0, tokens_consumed: @mut 0, restriction: @mut UNRESTRICTED, - quote_depth: @mut 0, + quote_depth: 0, obsolete_set: @mut HashSet::new(), mod_path_stack: @mut ~[], open_braces: @mut ~[], @@ -340,7 +340,7 @@ pub struct Parser { buffer_end: @mut int, tokens_consumed: @mut uint, restriction: @mut restriction, - quote_depth: @mut uint, // not (yet) related to the quasiquoter + quote_depth: uint, // not (yet) related to the quasiquoter reader: @mut reader, interner: @token::ident_interner, /// The set of seen errors about obsolete syntax. Used to suppress @@ -2097,7 +2097,7 @@ impl Parser { token_str)) }, /* we ought to allow different depths of unquotation */ - token::DOLLAR if *p.quote_depth > 0u => { + token::DOLLAR if p.quote_depth > 0u => { p.bump(); let sp = *p.span; -- cgit 1.4.1-3-g733a5 From 758d854436a2174c85717a64b8a90ed4041962d8 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 30 Dec 2013 15:09:41 -0800 Subject: libsyntax: De-`@mut` `token` in the parser --- src/libsyntax/ext/asm.rs | 32 +-- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/cfg.rs | 2 +- src/libsyntax/ext/format.rs | 10 +- src/libsyntax/ext/tt/macro_parser.rs | 8 +- src/libsyntax/ext/tt/macro_rules.rs | 4 +- src/libsyntax/parse/attr.rs | 12 +- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/obsolete.rs | 11 +- src/libsyntax/parse/parser.rs | 419 ++++++++++++++++++----------------- 10 files changed, 251 insertions(+), 251 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index d7d8360f1e8..c4a2f6d48bf 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -66,9 +66,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) asm_str_style = Some(style); } Outputs => { - while *p.token != token::EOF && - *p.token != token::COLON && - *p.token != token::MOD_SEP { + while p.token != token::EOF && + p.token != token::COLON && + p.token != token::MOD_SEP { if outputs.len() != 0 { p.eat(&token::COMMA); @@ -91,9 +91,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) } } Inputs => { - while *p.token != token::EOF && - *p.token != token::COLON && - *p.token != token::MOD_SEP { + while p.token != token::EOF && + p.token != token::COLON && + p.token != token::MOD_SEP { if inputs.len() != 0 { p.eat(&token::COMMA); @@ -116,9 +116,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) } Clobbers => { let mut clobs = ~[]; - while *p.token != token::EOF && - *p.token != token::COLON && - *p.token != token::MOD_SEP { + while p.token != token::EOF && + p.token != token::COLON && + p.token != token::MOD_SEP { if clobs.len() != 0 { p.eat(&token::COMMA); @@ -142,16 +142,16 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) dialect = ast::asm_intel; } - if *p.token == token::COMMA { + if p.token == token::COMMA { p.eat(&token::COMMA); } } } - while *p.token == token::COLON || - *p.token == token::MOD_SEP || - *p.token == token::EOF { - state = if *p.token == token::COLON { + while p.token == token::COLON || + p.token == token::MOD_SEP || + p.token == token::EOF { + state = if p.token == token::COLON { p.bump(); match next_state(state) { Some(x) => x, @@ -160,7 +160,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) break } } - } else if *p.token == token::MOD_SEP { + } else if p.token == token::MOD_SEP { p.bump(); let s = match next_state(state) { Some(x) => x, @@ -176,7 +176,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) break } } - } else if *p.token == token::EOF { + } else if p.token == token::EOF { continue_ = false; break; } else { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index a4f447874ff..a7a4e6416f9 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -446,7 +446,7 @@ pub fn get_exprs_from_tts(cx: &ExtCtxt, cx.cfg(), tts.to_owned()); let mut es = ~[]; - while *p.token != token::EOF { + while p.token != token::EOF { if es.len() != 0 && !p.eat(&token::COMMA) { cx.span_fatal(sp, "expected token: `,`"); } diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index f58b5eb3a92..f3f44f4fa3f 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -32,7 +32,7 @@ pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base:: let mut cfgs = ~[]; // parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)` - while *p.token != token::EOF { + while p.token != token::EOF { cfgs.push(p.parse_meta_item()); if p.eat(&token::EOF) { break } // trailing comma is optional,. p.expect(&token::COMMA); diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 2d4bdd3da23..82f9e138074 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -65,22 +65,22 @@ impl<'a> Context<'a> { return (extra, None); } - if *p.token == token::EOF { + if p.token == token::EOF { self.ecx.span_err(sp, "requires at least a format string argument"); return (extra, None); } let fmtstr = p.parse_expr(); let mut named = false; - while *p.token != token::EOF { + while p.token != token::EOF { if !p.eat(&token::COMMA) { self.ecx.span_err(sp, "expected token: `,`"); return (extra, None); } - if *p.token == token::EOF { break } // accept trailing commas - if named || (token::is_ident(p.token) && + if p.token == token::EOF { break } // accept trailing commas + if named || (token::is_ident(&p.token) && p.look_ahead(1, |t| *t == token::EQ)) { named = true; - let ident = match *p.token { + let ident = match p.token { token::IDENT(i, _) => { p.bump(); i diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index a14d25305fd..4d2923f391e 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -438,10 +438,12 @@ pub fn parse_nt(p: &mut Parser, name: &str) -> nonterminal { "expr" => token::nt_expr(p.parse_expr()), "ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)), // this could be handled like a token, since it is one - "ident" => match *p.token { + "ident" => match p.token { token::IDENT(sn,b) => { p.bump(); token::nt_ident(~sn,b) } - _ => p.fatal(~"expected ident, found " - + token::to_str(get_ident_interner(), p.token)) + _ => { + let token_str = token::to_str(get_ident_interner(), &p.token); + p.fatal(~"expected ident, found " + token_str) + } }, "path" => { token::nt_path(~p.parse_path(LifetimeAndTypesWithoutColons).path) diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 365c48c7c86..e5910678a8e 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -40,10 +40,10 @@ impl ParserAnyMacro { /// allowed to be there. fn ensure_complete_parse(&self, allow_semi: bool) { let mut parser = self.parser.borrow_mut(); - if allow_semi && *parser.get().token == SEMI { + if allow_semi && parser.get().token == SEMI { parser.get().bump() } - if *parser.get().token != EOF { + if parser.get().token != EOF { let token_str = parser.get().this_token_to_str(); let msg = format!("macro expansion ignores token `{}` and any \ following", diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index ef2322939aa..c8ebc803604 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -33,7 +33,7 @@ impl parser_attr for Parser { loop { debug!("parse_outer_attributes: self.token={:?}", self.token); - match *self.token { + match self.token { token::INTERPOLATED(token::nt_attr(..)) => { attrs.push(self.parse_attribute(false)); } @@ -68,7 +68,7 @@ impl parser_attr for Parser { fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute { debug!("parse_attributes: permit_inner={:?} self.token={:?}", permit_inner, self.token); - let (span, value) = match *self.token { + let (span, value) = match self.token { INTERPOLATED(token::nt_attr(attr)) => { assert!(attr.node.style == ast::AttrOuter); self.bump(); @@ -89,7 +89,7 @@ impl parser_attr for Parser { token_str)); } }; - let style = if permit_inner && *self.token == token::SEMI { + let style = if permit_inner && self.token == token::SEMI { self.bump(); ast::AttrInner } else { @@ -120,7 +120,7 @@ impl parser_attr for Parser { let mut inner_attrs: ~[ast::Attribute] = ~[]; let mut next_outer_attrs: ~[ast::Attribute] = ~[]; loop { - let attr = match *self.token { + let attr = match self.token { token::INTERPOLATED(token::nt_attr(..)) => { self.parse_attribute(true) } @@ -158,7 +158,7 @@ impl parser_attr for Parser { let lo = self.span.lo; let ident = self.parse_ident(); let name = self.id_to_str(ident); - match *self.token { + match self.token { token::EQ => { self.bump(); let lit = self.parse_lit(); @@ -196,7 +196,7 @@ impl parser_attr for Parser { } fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem] { - match *self.token { + match self.token { token::LPAREN => self.parse_meta_seq(), _ => ~[] } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a1f770a5fde..746e3279f19 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -631,7 +631,7 @@ mod test { } fn parser_done(p: Parser){ - assert_eq!((*p.token).clone(), token::EOF); + assert_eq!(p.token.clone(), token::EOF); } #[test] fn parse_ident_pat () { diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 199f02028a2..824420e9966 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -20,7 +20,6 @@ removed. use ast::{Expr, ExprLit, lit_nil}; use codemap::{Span, respan}; use parse::parser::Parser; -use parse::token::Token; use parse::token; use std::str; @@ -66,7 +65,6 @@ pub trait ParserObsoleteMethods { kind: ObsoleteSyntax, kind_str: &str, desc: &str); - fn token_is_obsolete_ident(&mut self, ident: &str, token: &Token) -> bool; fn is_obsolete_ident(&mut self, ident: &str) -> bool; fn eat_obsolete_ident(&mut self, ident: &str) -> bool; } @@ -176,9 +174,8 @@ impl ParserObsoleteMethods for Parser { } } - fn token_is_obsolete_ident(&mut self, ident: &str, token: &Token) - -> bool { - match *token { + fn is_obsolete_ident(&mut self, ident: &str) -> bool { + match self.token { token::IDENT(sid, _) => { str::eq_slice(self.id_to_str(sid), ident) } @@ -186,10 +183,6 @@ impl ParserObsoleteMethods for Parser { } } - fn is_obsolete_ident(&mut self, ident: &str) -> bool { - self.token_is_obsolete_ident(ident, self.token) - } - fn eat_obsolete_ident(&mut self, ident: &str) -> bool { if self.is_obsolete_ident(ident) { self.bump(); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 806da6988d8..55dcddd62c4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -143,15 +143,17 @@ macro_rules! maybe_whole_expr ( { // This horrible convolution is brought to you by // @mut, have a terrible day - let ret = match *($p).token { + let mut maybe_path = match ($p).token { + INTERPOLATED(token::nt_path(ref pt)) => Some((**pt).clone()), + _ => None, + }; + let ret = match ($p).token { INTERPOLATED(token::nt_expr(e)) => { Some(e) } - INTERPOLATED(token::nt_path(ref pt)) => { - Some($p.mk_expr( - ($p).span.lo, - ($p).span.hi, - ExprPath(/* bad */ (**pt).clone()))) + INTERPOLATED(token::nt_path(_)) => { + let pt = maybe_path.take_unwrap(); + Some($p.mk_expr(($p).span.lo, ($p).span.hi, ExprPath(pt))) } _ => None }; @@ -169,7 +171,7 @@ macro_rules! maybe_whole_expr ( macro_rules! maybe_whole ( ($p:expr, $constructor:ident) => ( { - let __found__ = match *($p).token { + let __found__ = match ($p).token { INTERPOLATED(token::$constructor(_)) => { Some(($p).bump_and_get()) } @@ -185,7 +187,7 @@ macro_rules! maybe_whole ( ); (no_clone $p:expr, $constructor:ident) => ( { - let __found__ = match *($p).token { + let __found__ = match ($p).token { INTERPOLATED(token::$constructor(_)) => { Some(($p).bump_and_get()) } @@ -201,7 +203,7 @@ macro_rules! maybe_whole ( ); (deref $p:expr, $constructor:ident) => ( { - let __found__ = match *($p).token { + let __found__ = match ($p).token { INTERPOLATED(token::$constructor(_)) => { Some(($p).bump_and_get()) } @@ -217,7 +219,7 @@ macro_rules! maybe_whole ( ); (Some $p:expr, $constructor:ident) => ( { - let __found__ = match *($p).token { + let __found__ = match ($p).token { INTERPOLATED(token::$constructor(_)) => { Some(($p).bump_and_get()) } @@ -233,7 +235,7 @@ macro_rules! maybe_whole ( ); (iovi $p:expr, $constructor:ident) => ( { - let __found__ = match *($p).token { + let __found__ = match ($p).token { INTERPOLATED(token::$constructor(_)) => { Some(($p).bump_and_get()) } @@ -249,7 +251,7 @@ macro_rules! maybe_whole ( ); (pair_empty $p:expr, $constructor:ident) => ( { - let __found__ = match *($p).token { + let __found__ = match ($p).token { INTERPOLATED(token::$constructor(_)) => { Some(($p).bump_and_get()) } @@ -301,7 +303,7 @@ pub fn Parser(sess: @mut ParseSess, interner: interner, sess: sess, cfg: cfg, - token: @mut tok0.tok, + token: tok0.tok, span: @mut span, last_span: @mut span, last_token: @mut None, @@ -328,7 +330,7 @@ pub struct Parser { sess: @mut ParseSess, cfg: CrateConfig, // the current token: - token: @mut token::Token, + token: token::Token, // the span of the current token: span: @mut Span, // the span of the prior token: @@ -360,17 +362,17 @@ fn is_plain_ident_or_underscore(t: &token::Token) -> bool { impl Parser { // convert a token to a string using self's reader - pub fn token_to_str(&mut self, token: &token::Token) -> ~str { + pub fn token_to_str(token: &token::Token) -> ~str { token::to_str(get_ident_interner(), token) } // convert the current token to a string using self's reader pub fn this_token_to_str(&mut self) -> ~str { - self.token_to_str(self.token) + Parser::token_to_str(&self.token) } pub fn unexpected_last(&mut self, t: &token::Token) -> ! { - let token_str = self.token_to_str(t); + let token_str = Parser::token_to_str(t); self.span_fatal(*self.last_span, format!("unexpected token: `{}`", token_str)); } @@ -383,10 +385,10 @@ impl Parser { // expect and consume the token t. Signal an error if // the next token is not t. pub fn expect(&mut self, t: &token::Token) { - if *self.token == *t { + if self.token == *t { self.bump(); } else { - let token_str = self.token_to_str(t); + let token_str = Parser::token_to_str(t); let this_token_str = self.this_token_to_str(); self.fatal(format!("expected `{}` but found `{}`", token_str, @@ -400,19 +402,19 @@ impl Parser { pub fn expect_one_of(&mut self, edible: &[token::Token], inedible: &[token::Token]) { - fn tokens_to_str(p: &mut Parser, tokens: &[token::Token]) -> ~str { + fn tokens_to_str(tokens: &[token::Token]) -> ~str { let mut i = tokens.iter(); // This might be a sign we need a connect method on Iterator. - let b = i.next().map_default(~"", |t| p.token_to_str(t)); - i.fold(b, |b,a| b + "`, `" + p.token_to_str(a)) + let b = i.next().map_default(~"", |t| Parser::token_to_str(t)); + i.fold(b, |b,a| b + "`, `" + Parser::token_to_str(a)) } - if edible.contains(self.token) { + if edible.contains(&self.token) { self.bump(); - } else if inedible.contains(self.token) { + } else if inedible.contains(&self.token) { // leave it in the input } else { let expected = vec::append(edible.to_owned(), inedible); - let expect = tokens_to_str(self, expected); + let expect = tokens_to_str(expected); let actual = self.this_token_to_str(); self.fatal( if expected.len() != 1 { @@ -428,7 +430,7 @@ impl Parser { // recover (without consuming any expected input token). Returns // true if and only if input was consumed for recovery. pub fn check_for_erroneous_unit_struct_expecting(&mut self, expected: &[token::Token]) -> bool { - if *self.token == token::LBRACE + if self.token == token::LBRACE && expected.iter().all(|t| *t != token::LBRACE) && self.look_ahead(1, |t| *t == token::RBRACE) { // matched; signal non-fatal error and recover. @@ -482,7 +484,7 @@ impl Parser { pub fn parse_ident(&mut self) -> ast::Ident { self.check_strict_keywords(); self.check_reserved_keywords(); - match *self.token { + match self.token { token::IDENT(i, _) => { self.bump(); i @@ -508,19 +510,19 @@ impl Parser { // consume token 'tok' if it exists. Returns true if the given // token was present, false otherwise. pub fn eat(&mut self, tok: &token::Token) -> bool { - let is_present = *self.token == *tok; + let is_present = self.token == *tok; if is_present { self.bump() } is_present } pub fn is_keyword(&mut self, kw: keywords::Keyword) -> bool { - token::is_keyword(kw, self.token) + token::is_keyword(kw, &self.token) } // if the next token is the given keyword, eat it and return // true. Otherwise, return false. pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool { - let is_kw = match *self.token { + let is_kw = match self.token { token::IDENT(sid, false) => kw.to_ident().name == sid.name, _ => false }; @@ -543,7 +545,7 @@ impl Parser { // signal an error if the given string is a strict keyword pub fn check_strict_keywords(&mut self) { - if token::is_strict_keyword(self.token) { + if token::is_strict_keyword(&self.token) { let token_str = self.this_token_to_str(); self.span_err(*self.span, format!("found `{}` in ident position", token_str)); @@ -552,7 +554,7 @@ impl Parser { // signal an error if the current token is a reserved keyword pub fn check_reserved_keywords(&mut self) { - if token::is_reserved_keyword(self.token) { + if token::is_reserved_keyword(&self.token) { let token_str = self.this_token_to_str(); self.fatal(format!("`{}` is a reserved keyword", token_str)) } @@ -561,7 +563,7 @@ impl Parser { // Expect and consume a `|`. If `||` is seen, replace it with a single // `|` and continue. If a `|` is not seen, signal an error. fn expect_or(&mut self) { - match *self.token { + match self.token { token::BINOP(token::OR) => self.bump(), token::OROR => { self.replace_token(token::BINOP(token::OR), @@ -570,7 +572,8 @@ impl Parser { } _ => { let token_str = self.this_token_to_str(); - let found_token = self.token_to_str(&token::BINOP(token::OR)); + let found_token = + Parser::token_to_str(&token::BINOP(token::OR)); self.fatal(format!("expected `{}`, found `{}`", found_token, token_str)) @@ -586,8 +589,8 @@ impl Parser { -> ~[T] { let mut first = true; let mut vector = ~[]; - while *self.token != token::BINOP(token::OR) && - *self.token != token::OROR { + while self.token != token::BINOP(token::OR) && + self.token != token::OROR { if first { first = false } else { @@ -603,7 +606,7 @@ impl Parser { // with a single > and continue. If a GT is not seen, // signal an error. pub fn expect_gt(&mut self) { - match *self.token { + match self.token { token::GT => self.bump(), token::BINOP(token::SHR) => self.replace_token( token::GT, @@ -611,7 +614,7 @@ impl Parser { self.span.hi ), _ => { - let gt_str = self.token_to_str(&token::GT); + let gt_str = Parser::token_to_str(&token::GT); let this_token_str = self.this_token_to_str(); self.fatal(format!("expected `{}`, found `{}`", gt_str, @@ -629,8 +632,8 @@ impl Parser { -> OptVec { let mut first = true; let mut v = opt_vec::Empty; - while *self.token != token::GT - && *self.token != token::BINOP(token::SHR) { + while self.token != token::GT + && self.token != token::BINOP(token::SHR) { match sep { Some(ref t) => { if first { first = false; } @@ -678,7 +681,7 @@ impl Parser { -> ~[T] { let mut first: bool = true; let mut v: ~[T] = ~[]; - while *self.token != *ket { + while self.token != *ket { match sep.sep { Some(ref t) => { if first { first = false; } @@ -686,7 +689,7 @@ impl Parser { } _ => () } - if sep.trailing_sep_allowed && *self.token == *ket { break; } + if sep.trailing_sep_allowed && self.token == *ket { break; } v.push(f(self)); } return v; @@ -729,8 +732,8 @@ impl Parser { pub fn bump(&mut self) { *self.last_span = *self.span; // Stash token for error recovery (sometimes; clone is not necessarily cheap). - *self.last_token = if is_ident_or_path(self.token) { - Some(~(*self.token).clone()) + *self.last_token = if is_ident_or_path(&self.token) { + Some(~self.token.clone()) } else { None }; @@ -749,13 +752,13 @@ impl Parser { util::replace(&mut self.buffer[buffer_start], placeholder) }; *self.span = next.sp; - *self.token = next.tok; + self.token = next.tok; *self.tokens_consumed += 1u; } // Advance the parser by one token and return the bumped token. pub fn bump_and_get(&mut self) -> token::Token { - let old_token = util::replace(self.token, token::UNDERSCORE); + let old_token = util::replace(&mut self.token, token::UNDERSCORE); self.bump(); old_token } @@ -765,7 +768,7 @@ impl Parser { next: token::Token, lo: BytePos, hi: BytePos) { - *self.token = next; + self.token = next; *self.span = mk_sp(lo, hi); } pub fn buffer_length(&mut self) -> int { @@ -812,12 +815,12 @@ impl Parser { // Is the current token one of the keywords that signals a bare function // type? pub fn token_is_bare_fn_keyword(&mut self) -> bool { - if token::is_keyword(keywords::Fn, self.token) { + if token::is_keyword(keywords::Fn, &self.token) { return true } - if token::is_keyword(keywords::Unsafe, self.token) || - token::is_keyword(keywords::Once, self.token) { + if token::is_keyword(keywords::Unsafe, &self.token) || + token::is_keyword(keywords::Once, &self.token) { return self.look_ahead(1, |t| token::is_keyword(keywords::Fn, t)) } @@ -826,16 +829,16 @@ impl Parser { // Is the current token one of the keywords that signals a closure type? pub fn token_is_closure_keyword(&mut self) -> bool { - token::is_keyword(keywords::Unsafe, self.token) || - token::is_keyword(keywords::Once, self.token) + token::is_keyword(keywords::Unsafe, &self.token) || + token::is_keyword(keywords::Once, &self.token) } // Is the current token one of the keywords that signals an old-style // closure type (with explicit sigil)? pub fn token_is_old_style_closure_keyword(&mut self) -> bool { - token::is_keyword(keywords::Unsafe, self.token) || - token::is_keyword(keywords::Once, self.token) || - token::is_keyword(keywords::Fn, self.token) + token::is_keyword(keywords::Unsafe, &self.token) || + token::is_keyword(keywords::Once, &self.token) || + token::is_keyword(keywords::Fn, &self.token) } pub fn token_is_lifetime(tok: &token::Token) -> bool { @@ -845,8 +848,8 @@ impl Parser { } } - pub fn get_lifetime(&mut self, tok: &token::Token) -> ast::Ident { - match *tok { + pub fn get_lifetime(&mut self) -> ast::Ident { + match self.token { token::LIFETIME(ref ident) => *ident, _ => self.bug("not a lifetime"), } @@ -1060,7 +1063,7 @@ impl Parser { }); let hi = p.last_span.hi; - match *p.token { + match p.token { token::SEMI => { p.bump(); debug!("parse_trait_methods(): parsing required method"); @@ -1169,9 +1172,9 @@ impl Parser { let lo = self.span.lo; - let t = if *self.token == token::LPAREN { + let t = if self.token == token::LPAREN { self.bump(); - if *self.token == token::RPAREN { + if self.token == token::RPAREN { self.bump(); ty_nil } else { @@ -1180,9 +1183,9 @@ impl Parser { // of type t let mut ts = ~[self.parse_ty(false)]; let mut one_tuple = false; - while *self.token == token::COMMA { + while self.token == token::COMMA { self.bump(); - if *self.token != token::RPAREN { + if self.token != token::RPAREN { ts.push(self.parse_ty(false)); } else { @@ -1199,19 +1202,19 @@ impl Parser { self.expect(&token::RPAREN); t } - } else if *self.token == token::AT { + } else if self.token == token::AT { // MANAGED POINTER self.bump(); self.parse_box_or_uniq_pointee(ManagedSigil) - } else if *self.token == token::TILDE { + } else if self.token == token::TILDE { // OWNED POINTER self.bump(); self.parse_box_or_uniq_pointee(OwnedSigil) - } else if *self.token == token::BINOP(token::STAR) { + } else if self.token == token::BINOP(token::STAR) { // STAR POINTER (bare pointer?) self.bump(); ty_ptr(self.parse_mt()) - } else if *self.token == token::LBRACKET { + } else if self.token == token::LBRACKET { // VECTOR self.expect(&token::LBRACKET); let t = self.parse_ty(false); @@ -1224,7 +1227,7 @@ impl Parser { }; self.expect(&token::RBRACKET); t - } else if *self.token == token::BINOP(token::AND) { + } else if self.token == token::BINOP(token::AND) { // BORROWED POINTER self.bump(); self.parse_borrowed_pointee() @@ -1233,10 +1236,10 @@ impl Parser { // BARE FUNCTION self.parse_ty_bare_fn() } else if self.token_is_closure_keyword() || - *self.token == token::BINOP(token::OR) || - *self.token == token::OROR || - *self.token == token::LT || - Parser::token_is_lifetime(self.token) { + self.token == token::BINOP(token::OR) || + self.token == token::OROR || + self.token == token::LT || + Parser::token_is_lifetime(&self.token) { // CLOSURE // // XXX(pcwalton): Eventually `token::LT` will not unambiguously @@ -1255,8 +1258,8 @@ impl Parser { ty_typeof(e) } else if self.eat_keyword(keywords::Proc) { self.parse_proc_type() - } else if *self.token == token::MOD_SEP - || is_ident_or_path(self.token) { + } else if self.token == token::MOD_SEP + || is_ident_or_path(&self.token) { // NAMED TYPE let PathAndBounds { path, @@ -1264,7 +1267,8 @@ impl Parser { } = self.parse_path(LifetimeAndTypesAndBounds); ty_path(path, bounds, ast::DUMMY_NODE_ID) } else { - self.fatal(format!("expected type, found token {:?}", *self.token)); + let msg = format!("expected type, found token {:?}", self.token); + self.fatal(msg); }; let sp = mk_sp(lo, self.last_span.hi); @@ -1276,7 +1280,7 @@ impl Parser { sigil: ast::Sigil) -> ty_ { // ~'foo fn() or ~fn() are parsed directly as obsolete fn types: - match *self.token { + match self.token { token::LIFETIME(..) => { let lifetime = self.parse_lifetime(); self.obsolete(*self.last_span, ObsoleteBoxedClosure); @@ -1317,17 +1321,17 @@ impl Parser { } pub fn is_named_argument(&mut self) -> bool { - let offset = match *self.token { + let offset = match self.token { token::BINOP(token::AND) => 1, token::ANDAND => 1, - _ if token::is_keyword(keywords::Mut, self.token) => 1, + _ if token::is_keyword(keywords::Mut, &self.token) => 1, _ => 0 }; debug!("parser is_named_argument offset:{}", offset); if offset == 0 { - is_plain_ident_or_underscore(&*self.token) + is_plain_ident_or_underscore(&self.token) && self.look_ahead(1, |t| *t == token::COLON) } else { self.look_ahead(offset, |t| is_plain_ident_or_underscore(t)) @@ -1386,7 +1390,7 @@ impl Parser { } pub fn maybe_parse_fixed_vstore(&mut self) -> Option<@ast::Expr> { - if *self.token == token::COMMA && + if self.token == token::COMMA && self.look_ahead(1, |t| *t == token::DOTDOT) { self.bump(); self.bump(); @@ -1453,7 +1457,7 @@ impl Parser { /// groups. pub fn parse_path(&mut self, mode: PathParsingMode) -> PathAndBounds { // Check for a whole path... - let found = match *self.token { + let found = match self.token { INTERPOLATED(token::nt_path(_)) => Some(self.bump_and_get()), _ => None, }; @@ -1571,7 +1575,7 @@ impl Parser { /// parses 0 or 1 lifetime pub fn parse_opt_lifetime(&mut self) -> Option { - match *self.token { + match self.token { token::LIFETIME(..) => { Some(self.parse_lifetime()) } @@ -1584,7 +1588,7 @@ impl Parser { /// Parses a single lifetime // matches lifetime = LIFETIME pub fn parse_lifetime(&mut self) -> ast::Lifetime { - match *self.token { + match self.token { token::LIFETIME(i) => { let span = *self.span; self.bump(); @@ -1614,7 +1618,7 @@ impl Parser { let mut res = opt_vec::Empty; loop { - match *self.token { + match self.token { token::LIFETIME(_) => { res.push(self.parse_lifetime()); } @@ -1623,13 +1627,15 @@ impl Parser { } } - match *self.token { + match self.token { token::COMMA => { self.bump();} token::GT => { return res; } token::BINOP(token::SHR) => { return res; } _ => { - self.fatal(format!("expected `,` or `>` after lifetime name, got: {:?}", - *self.token)); + let msg = format!("expected `,` or `>` after lifetime \ + name, got: {:?}", + self.token); + self.fatal(msg); } } } @@ -1740,12 +1746,12 @@ impl Parser { let ex: Expr_; - if *self.token == token::LPAREN { + if self.token == token::LPAREN { self.bump(); // (e) is parenthesized e // (e,) is a tuple with only one field, e let mut trailing_comma = false; - if *self.token == token::RPAREN { + if self.token == token::RPAREN { hi = self.span.hi; self.bump(); let lit = @spanned(lo, hi, lit_nil); @@ -1753,9 +1759,9 @@ impl Parser { } let mut es = ~[self.parse_expr()]; self.commit_expr(*es.last(), &[], &[token::COMMA, token::RPAREN]); - while *self.token == token::COMMA { + while self.token == token::COMMA { self.bump(); - if *self.token != token::RPAREN { + if self.token != token::RPAREN { es.push(self.parse_expr()); self.commit_expr(*es.last(), &[], &[token::COMMA, token::RPAREN]); } @@ -1772,12 +1778,12 @@ impl Parser { else { self.mk_expr(lo, hi, ExprTup(es)) } - } else if *self.token == token::LBRACE { + } else if self.token == token::LBRACE { self.bump(); let blk = self.parse_block_tail(lo, DefaultBlock); return self.mk_expr(blk.span.lo, blk.span.hi, ExprBlock(blk)); - } else if token::is_bar(&*self.token) { + } else if token::is_bar(&self.token) { return self.parse_lambda_expr(); } else if self.eat_keyword(keywords::Proc) { let decl = self.parse_proc_decl(); @@ -1804,8 +1810,8 @@ impl Parser { ExprDoBody); } else if self.eat_keyword(keywords::While) { return self.parse_while_expr(); - } else if Parser::token_is_lifetime(&*self.token) { - let lifetime = self.get_lifetime(&*self.token); + } else if Parser::token_is_lifetime(&self.token) { + let lifetime = self.get_lifetime(); self.bump(); self.expect(&token::COLON); if self.eat_keyword(keywords::For) { @@ -1819,8 +1825,8 @@ impl Parser { return self.parse_loop_expr(None); } else if self.eat_keyword(keywords::Continue) { let lo = self.span.lo; - let ex = if Parser::token_is_lifetime(&*self.token) { - let lifetime = self.get_lifetime(&*self.token); + let ex = if Parser::token_is_lifetime(&self.token) { + let lifetime = self.get_lifetime(); self.bump(); ExprAgain(Some(lifetime.name)) } else { @@ -1832,18 +1838,18 @@ impl Parser { return self.parse_match_expr(); } else if self.eat_keyword(keywords::Unsafe) { return self.parse_block_expr(lo, UnsafeBlock(ast::UserProvided)); - } else if *self.token == token::LBRACKET { + } else if self.token == token::LBRACKET { self.bump(); let mutbl = MutImmutable; - if *self.token == token::RBRACKET { + if self.token == token::RBRACKET { // Empty vector. self.bump(); ex = ExprVec(~[], mutbl); } else { // Nonempty vector. let first_expr = self.parse_expr(); - if *self.token == token::COMMA && + if self.token == token::COMMA && self.look_ahead(1, |t| *t == token::DOTDOT) { // Repeating vector syntax: [ 0, ..512 ] self.bump(); @@ -1851,7 +1857,7 @@ impl Parser { let count = self.parse_expr(); self.expect(&token::RBRACKET); ex = ExprRepeat(first_expr, count, mutbl); - } else if *self.token == token::COMMA { + } else if self.token == token::COMMA { // Vector with two or more elements. self.bump(); let remaining_exprs = self.parse_seq_to_end( @@ -1875,36 +1881,36 @@ impl Parser { self.expect(&token::RPAREN); } else if self.eat_keyword(keywords::Return) { // RETURN expression - if can_begin_expr(&*self.token) { + if can_begin_expr(&self.token) { let e = self.parse_expr(); hi = e.span.hi; ex = ExprRet(Some(e)); } else { ex = ExprRet(None); } } else if self.eat_keyword(keywords::Break) { // BREAK expression - if Parser::token_is_lifetime(&*self.token) { - let lifetime = self.get_lifetime(&*self.token); + if Parser::token_is_lifetime(&self.token) { + let lifetime = self.get_lifetime(); self.bump(); ex = ExprBreak(Some(lifetime.name)); } else { ex = ExprBreak(None); } hi = self.span.hi; - } else if *self.token == token::MOD_SEP || - is_ident(&*self.token) && !self.is_keyword(keywords::True) && + } else if self.token == token::MOD_SEP || + is_ident(&self.token) && !self.is_keyword(keywords::True) && !self.is_keyword(keywords::False) { let pth = self.parse_path(LifetimeAndTypesWithColons).path; // `!`, as an operator, is prefix, so we know this isn't that - if *self.token == token::NOT { + if self.token == token::NOT { // MACRO INVOCATION expression self.bump(); - match *self.token { + match self.token { token::LPAREN | token::LBRACE => {} _ => self.fatal("expected open delimiter") }; - let ket = token::flip_delimiter(&*self.token); + let ket = token::flip_delimiter(&self.token); self.bump(); let tts = self.parse_seq_to_end(&ket, @@ -1913,7 +1919,7 @@ impl Parser { let hi = self.span.hi; return self.mk_mac_expr(lo, hi, mac_invoc_tt(pth, tts, EMPTY_CTXT)); - } else if *self.token == token::LBRACE { + } else if self.token == token::LBRACE { // This might be a struct literal. if self.looking_at_struct_literal() { // It's a struct literal. @@ -1922,7 +1928,7 @@ impl Parser { let mut base = None; fields.push(self.parse_field()); - while *self.token != token::RBRACE { + while self.token != token::RBRACE { self.commit_expr(fields.last().expr, &[token::COMMA], &[token::RBRACE]); if self.eat(&token::DOTDOT) { @@ -1930,7 +1936,7 @@ impl Parser { break; } - if *self.token == token::RBRACE { + if self.token == token::RBRACE { // Accept an optional trailing comma. break; } @@ -1977,7 +1983,7 @@ impl Parser { loop { // expr.f if self.eat(&token::DOT) { - match *self.token { + match self.token { token::IDENT(i, _) => { hi = self.span.hi; self.bump(); @@ -1989,7 +1995,7 @@ impl Parser { }; // expr.f() method call - match *self.token { + match self.token { token::LPAREN => { let es = self.parse_unspanned_seq( &token::LPAREN, @@ -2013,7 +2019,7 @@ impl Parser { continue; } if self.expr_is_complete(e) { break; } - match *self.token { + match self.token { // expr(...) token::LPAREN => { let es = self.parse_unspanned_seq( @@ -2048,9 +2054,9 @@ impl Parser { // repetition token (+ or *). pub fn parse_sep_and_zerok(&mut self) -> (Option, bool) { fn parse_zerok(parser: &mut Parser) -> Option { - match *parser.token { + match parser.token { token::BINOP(token::STAR) | token::BINOP(token::PLUS) => { - let zerok = *parser.token == token::BINOP(token::STAR); + let zerok = parser.token == token::BINOP(token::STAR); parser.bump(); Some(zerok) }, @@ -2086,7 +2092,7 @@ impl Parser { // reaching this point. fn parse_non_delim_tt_tok(p: &mut Parser) -> token_tree { maybe_whole!(deref p, nt_tt); - match *p.token { + match p.token { token::RPAREN | token::RBRACE | token::RBRACKET => { // This is a conservative error: only report the last unclosed delimiter. The // previous unclosed delimiters could actually be closed! The parser just hasn't @@ -2101,7 +2107,7 @@ impl Parser { p.bump(); let sp = *p.span; - if *p.token == token::LPAREN { + if p.token == token::LPAREN { let seq = p.parse_seq( &token::LPAREN, &token::RPAREN, @@ -2133,7 +2139,7 @@ impl Parser { tt_tok(*p.span, p.bump_and_get()) } - match *self.token { + match self.token { token::EOF => { for sp in self.open_braces.iter() { self.span_note(*sp, "Did you mean to close this delimiter?"); @@ -2143,7 +2149,7 @@ impl Parser { self.fatal("This file contains an un-closed delimiter "); } token::LPAREN | token::LBRACE | token::LBRACKET => { - let close_delim = token::flip_delimiter(&*self.token); + let close_delim = token::flip_delimiter(&self.token); // Parse the open delimiter. (*self.open_braces).push(*self.span); @@ -2169,7 +2175,7 @@ impl Parser { // up to EOF. pub fn parse_all_token_trees(&mut self) -> ~[token_tree] { let mut tts = ~[]; - while *self.token != token::EOF { + while self.token != token::EOF { tts.push(self.parse_token_tree()); } tts @@ -2180,9 +2186,9 @@ impl Parser { // the interpolation of matchers maybe_whole!(self, nt_matchers); let name_idx = @mut 0u; - match *self.token { + match self.token { token::LBRACE | token::LPAREN | token::LBRACKET => { - let other_delimiter = token::flip_delimiter(self.token); + let other_delimiter = token::flip_delimiter(&self.token); self.bump(); self.parse_matcher_subseq_upto(name_idx, &other_delimiter) } @@ -2200,9 +2206,9 @@ impl Parser { let mut ret_val = ~[]; let mut lparens = 0u; - while *self.token != *ket || lparens > 0u { - if *self.token == token::LPAREN { lparens += 1u; } - if *self.token == token::RPAREN { lparens -= 1u; } + while self.token != *ket || lparens > 0u { + if self.token == token::LPAREN { lparens += 1u; } + if self.token == token::RPAREN { lparens -= 1u; } ret_val.push(self.parse_matcher(name_idx)); } @@ -2214,9 +2220,9 @@ impl Parser { pub fn parse_matcher(&mut self, name_idx: @mut uint) -> matcher { let lo = self.span.lo; - let m = if *self.token == token::DOLLAR { + let m = if self.token == token::DOLLAR { self.bump(); - if *self.token == token::LPAREN { + if self.token == token::LPAREN { let name_idx_lo = *name_idx; self.bump(); let ms = self.parse_matcher_subseq_upto(name_idx, @@ -2247,7 +2253,7 @@ impl Parser { let hi; let ex; - match *self.token { + match self.token { token::NOT => { self.bump(); let e = self.parse_prefix_expr(); @@ -2353,7 +2359,7 @@ impl Parser { // Prevent dynamic borrow errors later on by limiting the // scope of the borrows. { - let token: &token::Token = self.token; + let token: &token::Token = &self.token; let restriction: &restriction = self.restriction; match (token, restriction) { (&token::BINOP(token::OR), &RESTRICT_NO_BAR_OP) => return lhs, @@ -2364,7 +2370,7 @@ impl Parser { } } - let cur_opt = token_to_binop(self.token); + let cur_opt = token_to_binop(&self.token); match cur_opt { Some(cur_op) => { let cur_prec = operator_prec(cur_op); @@ -2399,7 +2405,7 @@ impl Parser { pub fn parse_assign_expr(&mut self) -> @Expr { let lo = self.span.lo; let lhs = self.parse_binops(); - match *self.token { + match self.token { token::EQ => { self.bump(); let rhs = self.parse_expr(); @@ -2455,7 +2461,7 @@ impl Parser { pub fn parse_lambda_block_expr(&mut self) -> @Expr { self.parse_lambda_expr_( |p| { - match *p.token { + match p.token { token::BINOP(token::OR) | token::OROR => { p.parse_fn_block_decl() } @@ -2613,8 +2619,8 @@ impl Parser { pub fn parse_loop_expr(&mut self, opt_ident: Option) -> @Expr { // loop headers look like 'loop {' or 'loop unsafe {' let is_loop_header = - *self.token == token::LBRACE - || (is_ident(&*self.token) + self.token == token::LBRACE + || (is_ident(&self.token) && self.look_ahead(1, |t| *t == token::LBRACE)); if is_loop_header { @@ -2632,8 +2638,8 @@ impl Parser { self.obsolete(*self.last_span, ObsoleteLoopAsContinue); let lo = self.span.lo; - let ex = if Parser::token_is_lifetime(&*self.token) { - let lifetime = self.get_lifetime(&*self.token); + let ex = if Parser::token_is_lifetime(&self.token) { + let lifetime = self.get_lifetime(); self.bump(); ExprAgain(Some(lifetime.name)) } else { @@ -2646,7 +2652,7 @@ impl Parser { // For distingishing between struct literals and blocks fn looking_at_struct_literal(&mut self) -> bool { - *self.token == token::LBRACE && + self.token == token::LBRACE && (self.look_ahead(1, |t| token::is_plain_ident(t)) && self.look_ahead(2, |t| *t == token::COLON)) } @@ -2656,7 +2662,7 @@ impl Parser { let discriminant = self.parse_expr(); self.commit_expr_expecting(discriminant, token::LBRACE); let mut arms: ~[Arm] = ~[]; - while *self.token != token::RBRACE { + while self.token != token::RBRACE { let pats = self.parse_pats(); let mut guard = None; if self.eat_keyword(keywords::If) { @@ -2667,7 +2673,7 @@ impl Parser { let require_comma = !classify::expr_is_simple_block(expr) - && *self.token != token::RBRACE; + && self.token != token::RBRACE; if require_comma { self.commit_expr(expr, &[token::COMMA], &[token::RBRACE]); @@ -2707,7 +2713,7 @@ impl Parser { // parse the RHS of a local variable declaration (e.g. '= 14;') fn parse_initializer(&mut self) -> Option<@Expr> { - if *self.token == token::EQ { + if self.token == token::EQ { self.bump(); Some(self.parse_expr()) } else { @@ -2720,7 +2726,7 @@ impl Parser { let mut pats = ~[]; loop { pats.push(self.parse_pat()); - if *self.token == token::BINOP(token::OR) { self.bump(); } + if self.token == token::BINOP(token::OR) { self.bump(); } else { return pats; } }; } @@ -2734,13 +2740,13 @@ impl Parser { let mut first = true; let mut before_slice = true; - while *self.token != token::RBRACKET { + while self.token != token::RBRACKET { if first { first = false; } else { self.expect(&token::COMMA); } let mut is_slice = false; if before_slice { - if *self.token == token::DOTDOT { + if self.token == token::DOTDOT { self.bump(); is_slice = true; before_slice = false; @@ -2748,7 +2754,7 @@ impl Parser { } if is_slice { - if *self.token == token::COMMA || *self.token == token::RBRACKET { + if self.token == token::COMMA || self.token == token::RBRACKET { slice = Some(@ast::Pat { id: ast::DUMMY_NODE_ID, node: PatWildMulti, @@ -2791,22 +2797,22 @@ impl Parser { let mut fields = ~[]; let mut etc = false; let mut first = true; - while *self.token != token::RBRACE { + while self.token != token::RBRACE { if first { first = false; } else { self.expect(&token::COMMA); // accept trailing commas - if *self.token == token::RBRACE { break } + if self.token == token::RBRACE { break } } - etc = *self.token == token::UNDERSCORE || *self.token == token::DOTDOT; - if *self.token == token::UNDERSCORE { + etc = self.token == token::UNDERSCORE || self.token == token::DOTDOT; + if self.token == token::UNDERSCORE { self.obsolete(*self.span, ObsoleteStructWildcard); } if etc { self.bump(); - if *self.token != token::RBRACE { + if self.token != token::RBRACE { let token_str = self.this_token_to_str(); self.fatal(format!("expected `\\}`, found `{}`", token_str)) @@ -2829,7 +2835,7 @@ impl Parser { let fieldpath = ast_util::ident_to_path(mk_sp(lo1, hi1), fieldname); let subpat; - if *self.token == token::COLON { + if self.token == token::COLON { match bind_type { BindByRef(..) | BindByValue(MutMutable) => { let token_str = self.this_token_to_str(); @@ -2859,7 +2865,7 @@ impl Parser { let lo = self.span.lo; let mut hi; let pat; - match *self.token { + match self.token { // parse _ token::UNDERSCORE => { self.bump(); @@ -2958,7 +2964,7 @@ impl Parser { token::LPAREN => { // parse (pat,pat,pat,...) as tuple self.bump(); - if *self.token == token::RPAREN { + if self.token == token::RPAREN { hi = self.span.hi; self.bump(); let lit = @codemap::Spanned { @@ -2969,7 +2975,7 @@ impl Parser { } else { let mut fields = ~[self.parse_pat()]; if self.look_ahead(1, |t| *t != token::RPAREN) { - while *self.token == token::COMMA { + while self.token == token::COMMA { self.bump(); fields.push(self.parse_pat()); } @@ -3003,8 +3009,7 @@ impl Parser { _ => {} } - let tok = self.token; - if !is_ident_or_path(tok) + if !is_ident_or_path(&self.token) || self.is_keyword(keywords::True) || self.is_keyword(keywords::False) { // Parse an expression pattern or exp .. exp. @@ -3013,7 +3018,7 @@ impl Parser { // preceded by unary-minus) or identifiers. let val = self.parse_literal_maybe_minus(); if self.eat(&token::DOTDOT) { - let end = if is_ident_or_path(tok) { + let end = if is_ident_or_path(&self.token) { let path = self.parse_path(LifetimeAndTypesWithColons) .path; let hi = self.span.hi; @@ -3045,7 +3050,7 @@ impl Parser { self.eat(&token::DOTDOT); let end = self.parse_expr_res(RESTRICT_NO_BAR_OP); pat = PatRange(start, end); - } else if is_plain_ident(&*self.token) && !can_be_enum_or_struct { + } else if is_plain_ident(&self.token) && !can_be_enum_or_struct { let name = self.parse_path(NoTypesAllowed).path; let sub; if self.eat(&token::AT) { @@ -3060,7 +3065,7 @@ impl Parser { // parse an enum pat let enum_path = self.parse_path(LifetimeAndTypesWithColons) .path; - match *self.token { + match self.token { token::LBRACE => { self.bump(); let (fields, etc) = @@ -3070,7 +3075,7 @@ impl Parser { } _ => { let mut args: ~[@Pat] = ~[]; - match *self.token { + match self.token { token::LPAREN => { let is_star = self.look_ahead(1, |t| { match *t { @@ -3134,7 +3139,7 @@ impl Parser { fn parse_pat_ident(&mut self, binding_mode: ast::BindingMode) -> ast::Pat_ { - if !is_plain_ident(&*self.token) { + if !is_plain_ident(&self.token) { self.span_fatal(*self.last_span, "expected identifier, found path"); } @@ -3152,7 +3157,7 @@ impl Parser { // leads to a parse error. Note that if there is no explicit // binding mode then we do not end up here, because the lookahead // will direct us over to parse_enum_variant() - if *self.token == token::LPAREN { + if self.token == token::LPAREN { self.span_fatal( *self.last_span, "expected identifier, found enum pattern"); @@ -3198,7 +3203,7 @@ impl Parser { pr: visibility, attrs: ~[Attribute]) -> struct_field { let lo = self.span.lo; - if !is_plain_ident(&*self.token) { + if !is_plain_ident(&self.token) { self.fatal("expected ident"); } let name = self.parse_ident(); @@ -3230,8 +3235,8 @@ impl Parser { self.expect_keyword(keywords::Let); let decl = self.parse_let(); return @spanned(lo, decl.span.hi, StmtDecl(decl, ast::DUMMY_NODE_ID)); - } else if is_ident(&*self.token) - && !token::is_any_keyword(self.token) + } else if is_ident(&self.token) + && !token::is_any_keyword(&self.token) && self.look_ahead(1, |t| *t == token::NOT) { // parse a macro invocation. Looks like there's serious // overlap here; if this clause doesn't catch it (and it @@ -3253,7 +3258,7 @@ impl Parser { let pth = self.parse_path(NoTypesAllowed).path; self.bump(); - let id = if *self.token == token::LPAREN { + let id = if self.token == token::LPAREN { token::special_idents::invalid // no special identifier } else { self.parse_ident() @@ -3373,11 +3378,11 @@ impl Parser { let mut attributes_box = attrs_remaining; - while (*self.token != token::RBRACE) { + while (self.token != token::RBRACE) { // parsing items even when they're not allowed lets us give // better error messages and recover more gracefully. attributes_box.push_all(self.parse_outer_attributes()); - match *self.token { + match self.token { token::SEMI => { if !attributes_box.is_empty() { self.span_err(*self.last_span, "expected item after attributes"); @@ -3399,7 +3404,7 @@ impl Parser { self.commit_stmt(stmt, &[], &[token::SEMI, token::RBRACE]); } - match *self.token { + match self.token { token::SEMI => { self.bump(); stmts.push(@codemap::Spanned { @@ -3418,7 +3423,7 @@ impl Parser { StmtMac(ref m, _) => { // statement macro; might be an expr let has_semi; - match *self.token { + match self.token { token::SEMI => { has_semi = true; } @@ -3487,7 +3492,7 @@ impl Parser { let mut result = opt_vec::Empty; loop { - match *self.token { + match self.token { token::LIFETIME(lifetime) => { if "static" == self.id_to_str(lifetime) { result.push(RegionTyParamBound); @@ -3554,10 +3559,10 @@ impl Parser { &token::RPAREN, seq_sep_trailing_disallowed(token::COMMA), |p| { - if *p.token == token::DOTDOTDOT { + if p.token == token::DOTDOTDOT { p.bump(); if allow_variadic { - if *p.token != token::RPAREN { + if p.token != token::RPAREN { p.span_fatal(*p.span, "`...` must be last in argument list for variadic function"); } @@ -3607,7 +3612,7 @@ impl Parser { } fn is_self_ident(&mut self) -> bool { - match *self.token { + match self.token { token::IDENT(id, false) => id.name == special_idents::self_.name, _ => false } @@ -3696,7 +3701,7 @@ impl Parser { // A bit of complexity and lookahead is needed here in order to be // backwards compatible. let lo = self.span.lo; - let explicit_self = match *self.token { + let explicit_self = match self.token { token::BINOP(token::AND) => { maybe_parse_borrowed_explicit_self(self) } @@ -3720,7 +3725,7 @@ impl Parser { // Possibly "*self" or "*mut self" -- not supported. Try to avoid // emitting cryptic "unexpected token" errors. self.bump(); - let mutability = if Parser::token_is_mutability(self.token) { + let mutability = if Parser::token_is_mutability(&self.token) { self.parse_mutability() } else { MutImmutable }; if self.is_self_ident() { @@ -3729,13 +3734,13 @@ impl Parser { } sty_value(mutability) } - _ if Parser::token_is_mutability(self.token) && + _ if Parser::token_is_mutability(&self.token) && self.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) => { let mutability = self.parse_mutability(); self.expect_self_ident(); sty_value(mutability) } - _ if Parser::token_is_mutability(self.token) && + _ if Parser::token_is_mutability(&self.token) && self.look_ahead(1, |t| *t == token::TILDE) && self.look_ahead(2, |t| token::is_keyword(keywords::Self, t)) => { let mutability = self.parse_mutability(); @@ -3751,7 +3756,7 @@ impl Parser { // If we parsed a self type, expect a comma before the argument list. let fn_inputs; if explicit_self != sty_static { - match *self.token { + match self.token { token::COMMA => { self.bump(); let sep = seq_sep_trailing_disallowed(token::COMMA); @@ -3918,7 +3923,7 @@ impl Parser { // Parse traits, if necessary. let traits; - if *self.token == token::COLON { + if self.token == token::COLON { self.bump(); traits = self.parse_trait_ref_list(&token::LBRACE); } else { @@ -3942,7 +3947,7 @@ impl Parser { // Special case: if the next identifier that follows is '(', don't // allow this to be parsed as a trait. - let could_be_trait = *self.token != token::LPAREN; + let could_be_trait = self.token != token::LPAREN; // Parse the trait. let mut ty = self.parse_ty(false); @@ -4021,7 +4026,7 @@ impl Parser { // It's a record-like struct. is_tuple_like = false; fields = ~[]; - while *self.token != token::RBRACE { + while self.token != token::RBRACE { fields.push(self.parse_struct_decl_field()); } if fields.len() == 0 { @@ -4029,7 +4034,7 @@ impl Parser { get_ident_interner().get(class_name.name))); } self.bump(); - } else if *self.token == token::LPAREN { + } else if self.token == token::LPAREN { // It's a tuple-like struct. is_tuple_like = true; fields = self.parse_unspanned_seq( @@ -4075,7 +4080,7 @@ impl Parser { attrs: ~[Attribute]) -> struct_field { let a_var = self.parse_name_and_ty(vis, attrs); - match *self.token { + match self.token { token::COMMA => { self.bump(); } @@ -4133,7 +4138,7 @@ impl Parser { // don't think this other loop is even necessary.... let mut first = true; - while *self.token != term { + while self.token != term { let mut attrs = self.parse_outer_attributes(); if first { attrs = attrs_remaining + attrs; @@ -4180,7 +4185,7 @@ impl Parser { fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> item_info { let id_span = *self.span; let id = self.parse_ident(); - if *self.token == token::SEMI { + if self.token == token::SEMI { self.bump(); // This mod is in an external file. Let's go get it! let (m, attrs) = self.eval_src_mod(id, outer_attrs, id_span); @@ -4356,7 +4361,7 @@ impl Parser { self.span_err(*self.last_span, "expected item after attributes"); } - assert!(*self.token == token::RBRACE); + assert!(self.token == token::RBRACE); ast::foreign_mod { abis: abis, view_items: view_items, @@ -4376,17 +4381,17 @@ impl Parser { if self.is_keyword(keywords::Mod) { must_be_named_mod = true; self.expect_keyword(keywords::Mod); - } else if *self.token != token::LBRACE { + } else if self.token != token::LBRACE { let token_str = self.this_token_to_str(); self.span_fatal(*self.span, format!("expected `\\{` or `mod` but found `{}`", token_str)) } - let (named, maybe_path, ident) = match *self.token { + let (named, maybe_path, ident) = match self.token { token::IDENT(..) => { let the_ident = self.parse_ident(); - let path = if *self.token == token::EQ { + let path = if self.token == token::EQ { self.bump(); Some(self.parse_str()) } @@ -4465,7 +4470,7 @@ impl Parser { // this should probably be renamed or refactored... fn parse_struct_def(&mut self) -> @struct_def { let mut fields: ~[struct_field] = ~[]; - while *self.token != token::RBRACE { + while self.token != token::RBRACE { fields.push(self.parse_struct_decl_field()); } self.bump(); @@ -4481,7 +4486,7 @@ impl Parser { let mut variants = ~[]; let mut all_nullary = true; let mut have_disr = false; - while *self.token != token::RBRACE { + while self.token != token::RBRACE { let variant_attrs = self.parse_outer_attributes(); let vlo = self.span.lo; @@ -4496,7 +4501,7 @@ impl Parser { // Parse a struct variant. all_nullary = false; kind = struct_variant_kind(self.parse_struct_def()); - } else if *self.token == token::LPAREN { + } else if self.token == token::LPAREN { all_nullary = false; let arg_tys = self.parse_unspanned_seq( &token::LPAREN, @@ -4564,7 +4569,7 @@ impl Parser { return None } - match *self.token { + match self.token { token::LIT_STR(s) | token::LIT_STR_RAW(s, _) => { self.bump(); @@ -4611,7 +4616,7 @@ impl Parser { attrs: ~[Attribute], macros_allowed: bool) -> item_or_view_item { - match *self.token { + match self.token { INTERPOLATED(token::nt_item(item)) => { self.bump(); let new_attrs = vec::append(attrs, item.attrs); @@ -4802,7 +4807,7 @@ impl Parser { lo : BytePos, visibility : visibility ) -> item_or_view_item { - if macros_allowed && !token::is_any_keyword(self.token) + if macros_allowed && !token::is_any_keyword(&self.token) && self.look_ahead(1, |t| *t == token::NOT) && (self.look_ahead(2, |t| is_plain_ident(t)) || self.look_ahead(2, |t| *t == token::LPAREN) @@ -4816,15 +4821,15 @@ impl Parser { // a 'special' identifier (like what `macro_rules!` uses) // is optional. We should eventually unify invoc syntax // and remove this. - let id = if is_plain_ident(&*self.token) { + let id = if is_plain_ident(&self.token) { self.parse_ident() } else { token::special_idents::invalid // no special identifier }; // eat a matched-delimiter token tree: - let tts = match *self.token { + let tts = match self.token { token::LPAREN | token::LBRACE => { - let ket = token::flip_delimiter(&*self.token); + let ket = token::flip_delimiter(&self.token); self.bump(); self.parse_seq_to_end(&ket, seq_sep_none(), @@ -4886,7 +4891,7 @@ impl Parser { fn parse_view_path(&mut self) -> @view_path { let lo = self.span.lo; - if *self.token == token::LBRACE { + if self.token == token::LBRACE { // use {foo,bar} let idents = self.parse_unspanned_seq( &token::LBRACE, &token::RBRACE, @@ -4904,12 +4909,12 @@ impl Parser { let first_ident = self.parse_ident(); let mut path = ~[first_ident]; debug!("parsed view_path: {}", self.id_to_str(first_ident)); - match *self.token { + match self.token { token::EQ => { // x = foo::bar self.bump(); path = ~[self.parse_ident()]; - while *self.token == token::MOD_SEP { + while self.token == token::MOD_SEP { self.bump(); let id = self.parse_ident(); path.push(id); @@ -4933,10 +4938,10 @@ impl Parser { token::MOD_SEP => { // foo::bar or foo::{a,b,c} or foo::* - while *self.token == token::MOD_SEP { + while self.token == token::MOD_SEP { self.bump(); - match *self.token { + match self.token { token::IDENT(i, _) => { self.bump(); path.push(i); @@ -5009,7 +5014,7 @@ impl Parser { // matches view_paths = view_path | view_path , view_paths fn parse_view_paths(&mut self) -> ~[@view_path] { let mut vp = ~[self.parse_view_path()]; - while *self.token == token::COMMA { + while self.token == token::COMMA { self.bump(); self.obsolete(*self.last_span, ObsoleteMultipleImport); vp.push(self.parse_view_path()); @@ -5114,7 +5119,7 @@ impl Parser { loop { match self.parse_foreign_item(attrs, macros_allowed) { iovi_none(returned_attrs) => { - if *self.token == token::RBRACE { + if self.token == token::RBRACE { attrs = returned_attrs; break } @@ -5164,7 +5169,7 @@ impl Parser { } pub fn parse_optional_str(&mut self) -> Option<(@str, ast::StrStyle)> { - let (s, style) = match *self.token { + let (s, style) = match self.token { token::LIT_STR(s) => (s, ast::CookedStr), token::LIT_STR_RAW(s, n) => (s, ast::RawStr(n)), _ => return None -- cgit 1.4.1-3-g733a5 From 0c6cee55eaf3871c4bb659fea9b3ada9ad1f9b2b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 30 Dec 2013 15:17:53 -0800 Subject: libsyntax: De-`@mut` `Parser::span` --- src/libsyntax/ext/format.rs | 4 +- src/libsyntax/ext/tt/macro_rules.rs | 2 +- src/libsyntax/parse/parser.rs | 100 ++++++++++++++++++------------------ 3 files changed, 54 insertions(+), 52 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 82f9e138074..8660b4c0560 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -86,13 +86,13 @@ impl<'a> Context<'a> { i } _ if named => { - self.ecx.span_err(*p.span, + self.ecx.span_err(p.span, "expected ident, positional arguments \ cannot follow named arguments"); return (extra, None); } _ => { - self.ecx.span_err(*p.span, + self.ecx.span_err(p.span, format!("expected ident for named \ argument, but found `{}`", p.this_token_to_str())); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index e5910678a8e..c9827fb54bd 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -48,7 +48,7 @@ impl ParserAnyMacro { let msg = format!("macro expansion ignores token `{}` and any \ following", token_str); - let span = *parser.get().span; + let span = parser.get().span; parser.get().span_err(span, msg); } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 55dcddd62c4..92df36da217 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -304,7 +304,7 @@ pub fn Parser(sess: @mut ParseSess, sess: sess, cfg: cfg, token: tok0.tok, - span: @mut span, + span: span, last_span: @mut span, last_token: @mut None, buffer: @mut ([ @@ -332,7 +332,7 @@ pub struct Parser { // the current token: token: token::Token, // the span of the current token: - span: @mut Span, + span: Span, // the span of the prior token: last_span: @mut Span, // the previous token or None (only stashed sometimes). @@ -434,7 +434,7 @@ impl Parser { && expected.iter().all(|t| *t != token::LBRACE) && self.look_ahead(1, |t| *t == token::RBRACE) { // matched; signal non-fatal error and recover. - self.span_err(*self.span, + self.span_err(self.span, "Unit-like struct construction is written with no trailing `{ }`"); self.eat(&token::LBRACE); self.eat(&token::RBRACE); @@ -547,7 +547,7 @@ impl Parser { pub fn check_strict_keywords(&mut self) { if token::is_strict_keyword(&self.token) { let token_str = self.this_token_to_str(); - self.span_err(*self.span, + self.span_err(self.span, format!("found `{}` in ident position", token_str)); } } @@ -566,9 +566,8 @@ impl Parser { match self.token { token::BINOP(token::OR) => self.bump(), token::OROR => { - self.replace_token(token::BINOP(token::OR), - self.span.lo + BytePos(1), - self.span.hi) + let lo = self.span.lo + BytePos(1); + self.replace_token(token::BINOP(token::OR), lo, self.span.hi) } _ => { let token_str = self.this_token_to_str(); @@ -608,11 +607,10 @@ impl Parser { pub fn expect_gt(&mut self) { match self.token { token::GT => self.bump(), - token::BINOP(token::SHR) => self.replace_token( - token::GT, - self.span.lo + BytePos(1), - self.span.hi - ), + token::BINOP(token::SHR) => { + let lo = self.span.lo + BytePos(1); + self.replace_token(token::GT, lo, self.span.hi) + } _ => { let gt_str = Parser::token_to_str(&token::GT); let this_token_str = self.this_token_to_str(); @@ -730,7 +728,7 @@ impl Parser { // advance the parser by one token pub fn bump(&mut self) { - *self.last_span = *self.span; + *self.last_span = self.span; // Stash token for error recovery (sometimes; clone is not necessarily cheap). *self.last_token = if is_ident_or_path(&self.token) { Some(~self.token.clone()) @@ -747,11 +745,11 @@ impl Parser { let placeholder = TokenAndSpan { tok: token::UNDERSCORE, - sp: *self.span, + sp: self.span, }; util::replace(&mut self.buffer[buffer_start], placeholder) }; - *self.span = next.sp; + self.span = next.sp; self.token = next.tok; *self.tokens_consumed += 1u; } @@ -769,7 +767,7 @@ impl Parser { lo: BytePos, hi: BytePos) { self.token = next; - *self.span = mk_sp(lo, hi); + self.span = mk_sp(lo, hi); } pub fn buffer_length(&mut self) -> int { if *self.buffer_start <= *self.buffer_end { @@ -787,7 +785,7 @@ impl Parser { f(&self.buffer[(*self.buffer_start + dist - 1) & 3].tok) } pub fn fatal(&mut self, m: &str) -> ! { - self.sess.span_diagnostic.span_fatal(*self.span, m) + self.sess.span_diagnostic.span_fatal(self.span, m) } pub fn span_fatal(&mut self, sp: Span, m: &str) -> ! { self.sess.span_diagnostic.span_fatal(sp, m) @@ -796,10 +794,10 @@ impl Parser { self.sess.span_diagnostic.span_note(sp, m) } pub fn bug(&mut self, m: &str) -> ! { - self.sess.span_diagnostic.span_bug(*self.span, m) + self.sess.span_diagnostic.span_bug(self.span, m) } pub fn warn(&mut self, m: &str) { - self.sess.span_diagnostic.span_warn(*self.span, m) + self.sess.span_diagnostic.span_warn(self.span, m) } pub fn span_err(&mut self, sp: Span, m: &str) { self.sess.span_diagnostic.span_err(sp, m) @@ -1047,7 +1045,7 @@ impl Parser { let attrs = p.parse_outer_attributes(); let lo = p.span.lo; - let vis_span = *p.span; + let vis_span = p.span; let vis = p.parse_visibility(); let pur = p.parse_fn_purity(); // NB: at the moment, trait methods are public by default; this @@ -1590,7 +1588,7 @@ impl Parser { pub fn parse_lifetime(&mut self) -> ast::Lifetime { match self.token { token::LIFETIME(i) => { - let span = *self.span; + let span = self.span; self.bump(); return ast::Lifetime { id: ast::DUMMY_NODE_ID, @@ -1722,7 +1720,7 @@ impl Parser { } pub fn mk_lit_u32(&mut self, i: u32) -> @Expr { - let span = self.span; + let span = &self.span; let lv_lit = @codemap::Spanned { node: lit_uint(i as u64, ty_u32), span: *span @@ -2105,7 +2103,7 @@ impl Parser { /* we ought to allow different depths of unquotation */ token::DOLLAR if p.quote_depth > 0u => { p.bump(); - let sp = *p.span; + let sp = p.span; if p.token == token::LPAREN { let seq = p.parse_seq( @@ -2136,7 +2134,7 @@ impl Parser { // turn the next token into a tt_tok: fn parse_any_tt_tok(p: &mut Parser) -> token_tree{ - tt_tok(*p.span, p.bump_and_get()) + tt_tok(p.span, p.bump_and_get()) } match self.token { @@ -2152,7 +2150,7 @@ impl Parser { let close_delim = token::flip_delimiter(&self.token); // Parse the open delimiter. - (*self.open_braces).push(*self.span); + (*self.open_braces).push(self.span); let mut result = ~[parse_any_tt_tok(self)]; let trees = @@ -2430,7 +2428,7 @@ impl Parser { self.mk_expr(lo, rhs.span.hi, assign_op) } token::DARROW => { - self.obsolete(*self.span, ObsoleteSwap); + self.obsolete(self.span, ObsoleteSwap); self.bump(); // Ignore what we get, this is an error anyway self.parse_expr(); @@ -2472,7 +2470,7 @@ impl Parser { output: P(Ty { id: ast::DUMMY_NODE_ID, node: ty_infer, - span: *p.span + span: p.span }), cf: return_val, variadic: false @@ -2758,13 +2756,13 @@ impl Parser { slice = Some(@ast::Pat { id: ast::DUMMY_NODE_ID, node: PatWildMulti, - span: *self.span, + span: self.span, }) } else { let subpat = self.parse_pat(); match subpat { @ast::Pat { id, node: PatWild, span } => { - self.obsolete(*self.span, ObsoleteVecDotDotWildcard); + self.obsolete(self.span, ObsoleteVecDotDotWildcard); slice = Some(@ast::Pat { id: id, node: PatWildMulti, @@ -2808,7 +2806,7 @@ impl Parser { etc = self.token == token::UNDERSCORE || self.token == token::DOTDOT; if self.token == token::UNDERSCORE { - self.obsolete(*self.span, ObsoleteStructWildcard); + self.obsolete(self.span, ObsoleteStructWildcard); } if etc { self.bump(); @@ -3093,7 +3091,7 @@ impl Parser { // This is a "top constructor only" pat self.bump(); if is_star { - self.obsolete(*self.span, ObsoleteEnumWildcard); + self.obsolete(self.span, ObsoleteEnumWildcard); } self.bump(); self.expect(&token::RPAREN); @@ -3193,7 +3191,7 @@ impl Parser { let local = self.parse_local(); while self.eat(&token::COMMA) { let _ = self.parse_local(); - self.obsolete(*self.span, ObsoleteMultipleLocalDecl); + self.obsolete(self.span, ObsoleteMultipleLocalDecl); } return @spanned(lo, self.last_span.hi, DeclLocal(local)); } @@ -3324,7 +3322,7 @@ impl Parser { let lo = self.span.lo; if self.eat_keyword(keywords::Unsafe) { - self.obsolete(*self.span, ObsoleteUnsafeBlock); + self.obsolete(self.span, ObsoleteUnsafeBlock); } self.expect(&token::LBRACE); @@ -3339,7 +3337,7 @@ impl Parser { let lo = self.span.lo; if self.eat_keyword(keywords::Unsafe) { - self.obsolete(*self.span, ObsoleteUnsafeBlock); + self.obsolete(self.span, ObsoleteUnsafeBlock); } self.expect(&token::LBRACE); let (inner, next) = self.parse_inner_attrs_and_next(); @@ -3497,7 +3495,7 @@ impl Parser { if "static" == self.id_to_str(lifetime) { result.push(RegionTyParamBound); } else { - self.span_err(*self.span, + self.span_err(self.span, "`'static` is the only permissible region bound here"); } self.bump(); @@ -3552,7 +3550,7 @@ impl Parser { fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool) -> (~[arg], bool) { - let sp = *self.span; + let sp = self.span; let mut args: ~[Option] = self.parse_unspanned_seq( &token::LPAREN, @@ -3563,11 +3561,11 @@ impl Parser { p.bump(); if allow_variadic { if p.token != token::RPAREN { - p.span_fatal(*p.span, + p.span_fatal(p.span, "`...` must be last in argument list for variadic function"); } } else { - p.span_fatal(*p.span, + p.span_fatal(p.span, "only foreign functions are allowed to be variadic"); } None @@ -3729,7 +3727,7 @@ impl Parser { self.parse_mutability() } else { MutImmutable }; if self.is_self_ident() { - self.span_err(*self.span, "cannot pass self by unsafe pointer"); + self.span_err(self.span, "cannot pass self by unsafe pointer"); self.bump(); } sty_value(mutability) @@ -3815,7 +3813,11 @@ impl Parser { let output = if self.eat(&token::RARROW) { self.parse_ty(false) } else { - P(Ty { id: ast::DUMMY_NODE_ID, node: ty_infer, span: *self.span }) + P(Ty { + id: ast::DUMMY_NODE_ID, + node: ty_infer, + span: self.span, + }) }; P(ast::fn_decl { @@ -3840,7 +3842,7 @@ impl Parser { P(Ty { id: ast::DUMMY_NODE_ID, node: ty_infer, - span: *self.span, + span: self.span, }) }; @@ -4087,7 +4089,7 @@ impl Parser { token::RBRACE => {} _ => { let token_str = self.this_token_to_str(); - self.span_fatal(*self.span, + self.span_fatal(self.span, format!("expected `,`, or `\\}` but found `{}`", token_str)) } @@ -4183,7 +4185,7 @@ impl Parser { // parse a `mod { ... }` or `mod ;` item fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> item_info { - let id_span = *self.span; + let id_span = self.span; let id = self.parse_ident(); if self.token == token::SEMI { self.bump(); @@ -4221,7 +4223,7 @@ impl Parser { outer_attrs: &[ast::Attribute], id_sp: Span) -> (ast::item_, ~[ast::Attribute]) { - let mut prefix = Path::new(self.sess.cm.span_to_filename(*self.span)); + let mut prefix = Path::new(self.sess.cm.span_to_filename(self.span)); prefix.pop(); let mod_path_stack = &*self.mod_path_stack; let mod_path = Path::new(".").join_many(*mod_path_stack); @@ -4383,7 +4385,7 @@ impl Parser { self.expect_keyword(keywords::Mod); } else if self.token != token::LBRACE { let token_str = self.this_token_to_str(); - self.span_fatal(*self.span, + self.span_fatal(self.span, format!("expected `\\{` or `mod` but found `{}`", token_str)) } @@ -4401,7 +4403,7 @@ impl Parser { _ => { if must_be_named_mod { let token_str = self.this_token_to_str(); - self.span_fatal(*self.span, + self.span_fatal(self.span, format!("expected foreign module name but \ found `{}`", token_str)) @@ -4435,7 +4437,7 @@ impl Parser { } if opt_abis.is_some() { - self.span_err(*self.span, "an ABI may not be specified here"); + self.span_err(self.span, "an ABI may not be specified here"); } @@ -4580,7 +4582,7 @@ impl Parser { Some(abi) => { if abis.contains(abi) { self.span_err( - *self.span, + self.span, format!("ABI `{}` appears twice", word)); } else { @@ -4590,7 +4592,7 @@ impl Parser { None => { self.span_err( - *self.span, + self.span, format!("illegal ABI: \ expected one of [{}], \ found `{}`", -- cgit 1.4.1-3-g733a5 From cc3e6ecbfd4e95c7fe37df676bc05993885fa181 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 30 Dec 2013 15:30:14 -0800 Subject: libsyntax: De-`@mut` `Parser::last_span` --- src/libsyntax/ext/asm.rs | 8 +++--- src/libsyntax/parse/parser.rs | 58 +++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 34 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index c4a2f6d48bf..0d78acadcae 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -77,10 +77,10 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) let (constraint, _str_style) = p.parse_str(); if constraint.starts_with("+") { - cx.span_unimpl(*p.last_span, + cx.span_unimpl(p.last_span, "'+' (read+write) output operand constraint modifier"); } else if !constraint.starts_with("=") { - cx.span_err(*p.last_span, "output operand constraint lacks '='"); + cx.span_err(p.last_span, "output operand constraint lacks '='"); } p.expect(&token::LPAREN); @@ -102,9 +102,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) let (constraint, _str_style) = p.parse_str(); if constraint.starts_with("=") { - cx.span_err(*p.last_span, "input operand constraint contains '='"); + cx.span_err(p.last_span, "input operand constraint contains '='"); } else if constraint.starts_with("+") { - cx.span_err(*p.last_span, "input operand constraint contains '+'"); + cx.span_err(p.last_span, "input operand constraint contains '+'"); } p.expect(&token::LPAREN); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 92df36da217..0f4cc2ae5cd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -286,9 +286,7 @@ struct ParsedItemsAndViewItems { /* ident is handled by common.rs */ -pub fn Parser(sess: @mut ParseSess, - cfg: ast::CrateConfig, - rdr: @mut reader) +pub fn Parser(sess: @mut ParseSess, cfg: ast::CrateConfig, rdr: @mut reader) -> Parser { let tok0 = rdr.next_token(); let interner = get_ident_interner(); @@ -305,7 +303,7 @@ pub fn Parser(sess: @mut ParseSess, cfg: cfg, token: tok0.tok, span: span, - last_span: @mut span, + last_span: span, last_token: @mut None, buffer: @mut ([ placeholder.clone(), @@ -334,7 +332,7 @@ pub struct Parser { // the span of the current token: span: Span, // the span of the prior token: - last_span: @mut Span, + last_span: Span, // the previous token or None (only stashed sometimes). last_token: @mut Option<~token::Token>, buffer: @mut [TokenAndSpan, ..4], @@ -373,8 +371,8 @@ impl Parser { pub fn unexpected_last(&mut self, t: &token::Token) -> ! { let token_str = Parser::token_to_str(t); - self.span_fatal(*self.last_span, format!("unexpected token: `{}`", - token_str)); + self.span_fatal(self.last_span, format!("unexpected token: `{}`", + token_str)); } pub fn unexpected(&mut self) -> ! { @@ -728,7 +726,7 @@ impl Parser { // advance the parser by one token pub fn bump(&mut self) { - *self.last_span = self.span; + self.last_span = self.span; // Stash token for error recovery (sometimes; clone is not necessarily cheap). *self.last_token = if is_ident_or_path(&self.token) { Some(~self.token.clone()) @@ -940,7 +938,7 @@ impl Parser { // Re-parse the region here. What a hack. if region.is_some() { - self.span_err(*self.last_span, + self.span_err(self.last_span, "lifetime declarations must precede \ the lifetime associated with a \ closure"); @@ -1281,13 +1279,13 @@ impl Parser { match self.token { token::LIFETIME(..) => { let lifetime = self.parse_lifetime(); - self.obsolete(*self.last_span, ObsoleteBoxedClosure); + self.obsolete(self.last_span, ObsoleteBoxedClosure); return self.parse_ty_closure(Some(sigil), Some(lifetime)); } token::IDENT(..) => { if self.token_is_old_style_closure_keyword() { - self.obsolete(*self.last_span, ObsoleteBoxedClosure); + self.obsolete(self.last_span, ObsoleteBoxedClosure); return self.parse_ty_closure(Some(sigil), None); } } @@ -1310,7 +1308,7 @@ impl Parser { let opt_lifetime = self.parse_opt_lifetime(); if self.token_is_old_style_closure_keyword() { - self.obsolete(*self.last_span, ObsoleteClosureType); + self.obsolete(self.last_span, ObsoleteClosureType); return self.parse_ty_closure(Some(BorrowedSigil), opt_lifetime); } @@ -1350,7 +1348,7 @@ impl Parser { } else { debug!("parse_arg_general ident_to_pat"); ast_util::ident_to_pat(ast::DUMMY_NODE_ID, - *self.last_span, + self.last_span, special_idents::invalid) }; @@ -1649,7 +1647,7 @@ impl Parser { if self.eat_keyword(keywords::Mut) { MutMutable } else if self.eat_keyword(keywords::Const) { - self.obsolete(*self.last_span, ObsoleteConstPointer); + self.obsolete(self.last_span, ObsoleteConstPointer); MutImmutable } else { MutImmutable @@ -2630,11 +2628,11 @@ impl Parser { } else { // This is an obsolete 'continue' expression if opt_ident.is_some() { - self.span_err(*self.last_span, + self.span_err(self.last_span, "a label may not be used with a `loop` expression"); } - self.obsolete(*self.last_span, ObsoleteLoopAsContinue); + self.obsolete(self.last_span, ObsoleteLoopAsContinue); let lo = self.span.lo; let ex = if Parser::token_is_lifetime(&self.token) { let lifetime = self.get_lifetime(); @@ -2848,7 +2846,7 @@ impl Parser { subpat = @ast::Pat { id: ast::DUMMY_NODE_ID, node: PatIdent(bind_type, fieldpath, None), - span: *self.last_span + span: self.last_span }; } fields.push(ast::FieldPat { ident: fieldname, pat: subpat }); @@ -3138,7 +3136,7 @@ impl Parser { binding_mode: ast::BindingMode) -> ast::Pat_ { if !is_plain_ident(&self.token) { - self.span_fatal(*self.last_span, + self.span_fatal(self.last_span, "expected identifier, found path"); } // why a path here, and not just an identifier? @@ -3157,7 +3155,7 @@ impl Parser { // will direct us over to parse_enum_variant() if self.token == token::LPAREN { self.span_fatal( - *self.last_span, + self.last_span, "expected identifier, found enum pattern"); } @@ -3223,7 +3221,7 @@ impl Parser { fn check_expected_item(p: &mut Parser, found_attrs: bool) { // If we have attributes then we should have an item if found_attrs { - p.span_err(*p.last_span, "expected item after attributes"); + p.span_err(p.last_span, "expected item after attributes"); } } @@ -3383,7 +3381,7 @@ impl Parser { match self.token { token::SEMI => { if !attributes_box.is_empty() { - self.span_err(*self.last_span, "expected item after attributes"); + self.span_err(self.last_span, "expected item after attributes"); attributes_box = ~[]; } self.bump(); // empty @@ -3461,7 +3459,7 @@ impl Parser { } if !attributes_box.is_empty() { - self.span_err(*self.last_span, "expected item after attributes"); + self.span_err(self.last_span, "expected item after attributes"); } let hi = self.span.hi; @@ -3709,7 +3707,7 @@ impl Parser { token::TILDE => { maybe_parse_explicit_self(|mutability| { if mutability != MutImmutable { - self.span_err(*self.last_span, + self.span_err(self.last_span, "mutability declaration not allowed here"); } sty_uniq(MutImmutable) @@ -3983,7 +3981,7 @@ impl Parser { let mut meths = ~[]; let inner_attrs = if self.eat(&token::SEMI) { - self.obsolete(*self.last_span, ObsoleteEmptyImpl); + self.obsolete(self.last_span, ObsoleteEmptyImpl); None } else { self.expect(&token::LBRACE); @@ -4166,7 +4164,7 @@ impl Parser { if first && attrs_remaining_len > 0u { // We parsed attributes for the first item but didn't find it - self.span_err(*self.last_span, "expected item after attributes"); + self.span_err(self.last_span, "expected item after attributes"); } ast::_mod { view_items: view_items, items: items } @@ -4300,7 +4298,7 @@ impl Parser { // Parse obsolete purity. let purity = self.parse_fn_purity(); if purity != impure_fn { - self.obsolete(*self.last_span, ObsoleteUnsafeExternFn); + self.obsolete(self.last_span, ObsoleteUnsafeExternFn); } let (ident, generics) = self.parse_fn_header(); @@ -4360,7 +4358,7 @@ impl Parser { foreign_items: foreign_items } = self.parse_foreign_items(first_item_attrs, true); if (! attrs_remaining.is_empty()) { - self.span_err(*self.last_span, + self.span_err(self.last_span, "expected item after attributes"); } assert!(self.token == token::RBRACE); @@ -4418,7 +4416,7 @@ impl Parser { if items_allowed && self.eat(&token::LBRACE) { // `extern mod foo { ... }` is obsolete. if named { - self.obsolete(*self.last_span, ObsoleteNamedExternModule); + self.obsolete(self.last_span, ObsoleteNamedExternModule); } let abis = opt_abis.unwrap_or(AbiSet::C()); @@ -4863,7 +4861,7 @@ impl Parser { s.push_str("priv") } s.push_char('`'); - self.span_fatal(*self.last_span, s); + self.span_fatal(self.last_span, s); } return iovi_none(attrs); } @@ -5018,7 +5016,7 @@ impl Parser { let mut vp = ~[self.parse_view_path()]; while self.token == token::COMMA { self.bump(); - self.obsolete(*self.last_span, ObsoleteMultipleImport); + self.obsolete(self.last_span, ObsoleteMultipleImport); vp.push(self.parse_view_path()); } return vp; -- cgit 1.4.1-3-g733a5