Skip to content

Commit 758d854

Browse files
committed
libsyntax: De-@mut token in the parser
1 parent 425a140 commit 758d854

File tree

10 files changed

+251
-251
lines changed

10 files changed

+251
-251
lines changed

src/libsyntax/ext/asm.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
6666
asm_str_style = Some(style);
6767
}
6868
Outputs => {
69-
while *p.token != token::EOF &&
70-
*p.token != token::COLON &&
71-
*p.token != token::MOD_SEP {
69+
while p.token != token::EOF &&
70+
p.token != token::COLON &&
71+
p.token != token::MOD_SEP {
7272

7373
if outputs.len() != 0 {
7474
p.eat(&token::COMMA);
@@ -91,9 +91,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
9191
}
9292
}
9393
Inputs => {
94-
while *p.token != token::EOF &&
95-
*p.token != token::COLON &&
96-
*p.token != token::MOD_SEP {
94+
while p.token != token::EOF &&
95+
p.token != token::COLON &&
96+
p.token != token::MOD_SEP {
9797

9898
if inputs.len() != 0 {
9999
p.eat(&token::COMMA);
@@ -116,9 +116,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
116116
}
117117
Clobbers => {
118118
let mut clobs = ~[];
119-
while *p.token != token::EOF &&
120-
*p.token != token::COLON &&
121-
*p.token != token::MOD_SEP {
119+
while p.token != token::EOF &&
120+
p.token != token::COLON &&
121+
p.token != token::MOD_SEP {
122122

123123
if clobs.len() != 0 {
124124
p.eat(&token::COMMA);
@@ -142,16 +142,16 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
142142
dialect = ast::asm_intel;
143143
}
144144

145-
if *p.token == token::COMMA {
145+
if p.token == token::COMMA {
146146
p.eat(&token::COMMA);
147147
}
148148
}
149149
}
150150

151-
while *p.token == token::COLON ||
152-
*p.token == token::MOD_SEP ||
153-
*p.token == token::EOF {
154-
state = if *p.token == token::COLON {
151+
while p.token == token::COLON ||
152+
p.token == token::MOD_SEP ||
153+
p.token == token::EOF {
154+
state = if p.token == token::COLON {
155155
p.bump();
156156
match next_state(state) {
157157
Some(x) => x,
@@ -160,7 +160,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
160160
break
161161
}
162162
}
163-
} else if *p.token == token::MOD_SEP {
163+
} else if p.token == token::MOD_SEP {
164164
p.bump();
165165
let s = match next_state(state) {
166166
Some(x) => x,
@@ -176,7 +176,7 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
176176
break
177177
}
178178
}
179-
} else if *p.token == token::EOF {
179+
} else if p.token == token::EOF {
180180
continue_ = false;
181181
break;
182182
} else {

src/libsyntax/ext/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ pub fn get_exprs_from_tts(cx: &ExtCtxt,
446446
cx.cfg(),
447447
tts.to_owned());
448448
let mut es = ~[];
449-
while *p.token != token::EOF {
449+
while p.token != token::EOF {
450450
if es.len() != 0 && !p.eat(&token::COMMA) {
451451
cx.span_fatal(sp, "expected token: `,`");
452452
}

src/libsyntax/ext/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::
3232

3333
let mut cfgs = ~[];
3434
// parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)`
35-
while *p.token != token::EOF {
35+
while p.token != token::EOF {
3636
cfgs.push(p.parse_meta_item());
3737
if p.eat(&token::EOF) { break } // trailing comma is optional,.
3838
p.expect(&token::COMMA);

src/libsyntax/ext/format.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ impl<'a> Context<'a> {
6565
return (extra, None);
6666
}
6767

68-
if *p.token == token::EOF {
68+
if p.token == token::EOF {
6969
self.ecx.span_err(sp, "requires at least a format string argument");
7070
return (extra, None);
7171
}
7272
let fmtstr = p.parse_expr();
7373
let mut named = false;
74-
while *p.token != token::EOF {
74+
while p.token != token::EOF {
7575
if !p.eat(&token::COMMA) {
7676
self.ecx.span_err(sp, "expected token: `,`");
7777
return (extra, None);
7878
}
79-
if *p.token == token::EOF { break } // accept trailing commas
80-
if named || (token::is_ident(p.token) &&
79+
if p.token == token::EOF { break } // accept trailing commas
80+
if named || (token::is_ident(&p.token) &&
8181
p.look_ahead(1, |t| *t == token::EQ)) {
8282
named = true;
83-
let ident = match *p.token {
83+
let ident = match p.token {
8484
token::IDENT(i, _) => {
8585
p.bump();
8686
i

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,12 @@ pub fn parse_nt(p: &mut Parser, name: &str) -> nonterminal {
438438
"expr" => token::nt_expr(p.parse_expr()),
439439
"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
440440
// this could be handled like a token, since it is one
441-
"ident" => match *p.token {
441+
"ident" => match p.token {
442442
token::IDENT(sn,b) => { p.bump(); token::nt_ident(~sn,b) }
443-
_ => p.fatal(~"expected ident, found "
444-
+ token::to_str(get_ident_interner(), p.token))
443+
_ => {
444+
let token_str = token::to_str(get_ident_interner(), &p.token);
445+
p.fatal(~"expected ident, found " + token_str)
446+
}
445447
},
446448
"path" => {
447449
token::nt_path(~p.parse_path(LifetimeAndTypesWithoutColons).path)

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ impl ParserAnyMacro {
4040
/// allowed to be there.
4141
fn ensure_complete_parse(&self, allow_semi: bool) {
4242
let mut parser = self.parser.borrow_mut();
43-
if allow_semi && *parser.get().token == SEMI {
43+
if allow_semi && parser.get().token == SEMI {
4444
parser.get().bump()
4545
}
46-
if *parser.get().token != EOF {
46+
if parser.get().token != EOF {
4747
let token_str = parser.get().this_token_to_str();
4848
let msg = format!("macro expansion ignores token `{}` and any \
4949
following",

src/libsyntax/parse/attr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl parser_attr for Parser {
3333
loop {
3434
debug!("parse_outer_attributes: self.token={:?}",
3535
self.token);
36-
match *self.token {
36+
match self.token {
3737
token::INTERPOLATED(token::nt_attr(..)) => {
3838
attrs.push(self.parse_attribute(false));
3939
}
@@ -68,7 +68,7 @@ impl parser_attr for Parser {
6868
fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute {
6969
debug!("parse_attributes: permit_inner={:?} self.token={:?}",
7070
permit_inner, self.token);
71-
let (span, value) = match *self.token {
71+
let (span, value) = match self.token {
7272
INTERPOLATED(token::nt_attr(attr)) => {
7373
assert!(attr.node.style == ast::AttrOuter);
7474
self.bump();
@@ -89,7 +89,7 @@ impl parser_attr for Parser {
8989
token_str));
9090
}
9191
};
92-
let style = if permit_inner && *self.token == token::SEMI {
92+
let style = if permit_inner && self.token == token::SEMI {
9393
self.bump();
9494
ast::AttrInner
9595
} else {
@@ -120,7 +120,7 @@ impl parser_attr for Parser {
120120
let mut inner_attrs: ~[ast::Attribute] = ~[];
121121
let mut next_outer_attrs: ~[ast::Attribute] = ~[];
122122
loop {
123-
let attr = match *self.token {
123+
let attr = match self.token {
124124
token::INTERPOLATED(token::nt_attr(..)) => {
125125
self.parse_attribute(true)
126126
}
@@ -158,7 +158,7 @@ impl parser_attr for Parser {
158158
let lo = self.span.lo;
159159
let ident = self.parse_ident();
160160
let name = self.id_to_str(ident);
161-
match *self.token {
161+
match self.token {
162162
token::EQ => {
163163
self.bump();
164164
let lit = self.parse_lit();
@@ -196,7 +196,7 @@ impl parser_attr for Parser {
196196
}
197197

198198
fn parse_optional_meta(&mut self) -> ~[@ast::MetaItem] {
199-
match *self.token {
199+
match self.token {
200200
token::LPAREN => self.parse_meta_seq(),
201201
_ => ~[]
202202
}

src/libsyntax/parse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ mod test {
631631
}
632632
633633
fn parser_done(p: Parser){
634-
assert_eq!((*p.token).clone(), token::EOF);
634+
assert_eq!(p.token.clone(), token::EOF);
635635
}
636636
637637
#[test] fn parse_ident_pat () {

src/libsyntax/parse/obsolete.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ removed.
2020
use ast::{Expr, ExprLit, lit_nil};
2121
use codemap::{Span, respan};
2222
use parse::parser::Parser;
23-
use parse::token::Token;
2423
use parse::token;
2524

2625
use std::str;
@@ -66,7 +65,6 @@ pub trait ParserObsoleteMethods {
6665
kind: ObsoleteSyntax,
6766
kind_str: &str,
6867
desc: &str);
69-
fn token_is_obsolete_ident(&mut self, ident: &str, token: &Token) -> bool;
7068
fn is_obsolete_ident(&mut self, ident: &str) -> bool;
7169
fn eat_obsolete_ident(&mut self, ident: &str) -> bool;
7270
}
@@ -176,20 +174,15 @@ impl ParserObsoleteMethods for Parser {
176174
}
177175
}
178176

179-
fn token_is_obsolete_ident(&mut self, ident: &str, token: &Token)
180-
-> bool {
181-
match *token {
177+
fn is_obsolete_ident(&mut self, ident: &str) -> bool {
178+
match self.token {
182179
token::IDENT(sid, _) => {
183180
str::eq_slice(self.id_to_str(sid), ident)
184181
}
185182
_ => false
186183
}
187184
}
188185

189-
fn is_obsolete_ident(&mut self, ident: &str) -> bool {
190-
self.token_is_obsolete_ident(ident, self.token)
191-
}
192-
193186
fn eat_obsolete_ident(&mut self, ident: &str) -> bool {
194187
if self.is_obsolete_ident(ident) {
195188
self.bump();

0 commit comments

Comments
 (0)