1803: introduce bump as a better-checked alternative to bump_any r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-09-09 22:06:25 +00:00 committed by GitHub
commit e2ebb467bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 138 additions and 132 deletions

View file

@ -93,12 +93,12 @@ pub(crate) mod fragments {
// https://doc.rust-lang.org/reference/paths.html#simple-paths // https://doc.rust-lang.org/reference/paths.html#simple-paths
// The start of an meta must be a simple path // The start of an meta must be a simple path
match p.current() { match p.current() {
IDENT | T![::] | T![super] | T![self] | T![crate] => p.bump(), IDENT | T![::] | T![super] | T![self] | T![crate] => p.bump_any(),
T![=] => { T![=] => {
p.bump(); p.bump_any();
match p.current() { match p.current() {
c if c.is_literal() => p.bump(), c if c.is_literal() => p.bump_any(),
T![true] | T![false] => p.bump(), T![true] | T![false] => p.bump_any(),
_ => {} _ => {}
} }
break; break;
@ -126,7 +126,7 @@ pub(crate) mod fragments {
while !p.at(EOF) { while !p.at(EOF) {
if p.at(T![;]) { if p.at(T![;]) {
p.bump(); p.bump(T![;]);
continue; continue;
} }
@ -179,7 +179,7 @@ fn opt_visibility(p: &mut Parser) -> bool {
match p.current() { match p.current() {
T![pub] => { T![pub] => {
let m = p.start(); let m = p.start();
p.bump(); p.bump(T![pub]);
if p.at(T!['(']) { if p.at(T!['(']) {
match p.nth(1) { match p.nth(1) {
// test crate_visibility // test crate_visibility
@ -188,13 +188,13 @@ fn opt_visibility(p: &mut Parser) -> bool {
// pub(self) struct S; // pub(self) struct S;
// pub(self) struct S; // pub(self) struct S;
T![crate] | T![self] | T![super] => { T![crate] | T![self] | T![super] => {
p.bump(); p.bump_any();
p.bump(); p.bump_any();
p.expect(T![')']); p.expect(T![')']);
} }
T![in] => { T![in] => {
p.bump(); p.bump_any();
p.bump(); p.bump_any();
paths::use_path(p); paths::use_path(p);
p.expect(T![')']); p.expect(T![')']);
} }
@ -212,7 +212,7 @@ fn opt_visibility(p: &mut Parser) -> bool {
// fn foo() { crate::foo(); } // fn foo() { crate::foo(); }
T![crate] if p.nth(1) != T![::] => { T![crate] if p.nth(1) != T![::] => {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
m.complete(p, VISIBILITY); m.complete(p, VISIBILITY);
} }
_ => return false, _ => return false,
@ -223,7 +223,7 @@ fn opt_visibility(p: &mut Parser) -> bool {
fn opt_alias(p: &mut Parser) { fn opt_alias(p: &mut Parser) {
if p.at(T![as]) { if p.at(T![as]) {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
if !p.eat(T![_]) { if !p.eat(T![_]) {
name(p); name(p);
} }
@ -234,9 +234,9 @@ fn opt_alias(p: &mut Parser) {
fn abi(p: &mut Parser) { fn abi(p: &mut Parser) {
assert!(p.at(T![extern])); assert!(p.at(T![extern]));
let abi = p.start(); let abi = p.start();
p.bump(); p.bump_any();
match p.current() { match p.current() {
STRING | RAW_STRING => p.bump(), STRING | RAW_STRING => p.bump_any(),
_ => (), _ => (),
} }
abi.complete(p, ABI); abi.complete(p, ABI);
@ -245,7 +245,7 @@ fn abi(p: &mut Parser) {
fn opt_fn_ret_type(p: &mut Parser) -> bool { fn opt_fn_ret_type(p: &mut Parser) -> bool {
if p.at(T![->]) { if p.at(T![->]) {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
types::type_(p); types::type_(p);
m.complete(p, RET_TYPE); m.complete(p, RET_TYPE);
true true
@ -257,7 +257,7 @@ fn opt_fn_ret_type(p: &mut Parser) -> bool {
fn name_r(p: &mut Parser, recovery: TokenSet) { fn name_r(p: &mut Parser, recovery: TokenSet) {
if p.at(IDENT) { if p.at(IDENT) {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
m.complete(p, NAME); m.complete(p, NAME);
} else { } else {
p.err_recover("expected a name", recovery); p.err_recover("expected a name", recovery);
@ -271,11 +271,11 @@ fn name(p: &mut Parser) {
fn name_ref(p: &mut Parser) { fn name_ref(p: &mut Parser) {
if p.at(IDENT) { if p.at(IDENT) {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
m.complete(p, NAME_REF); m.complete(p, NAME_REF);
} else if p.at(T![self]) { } else if p.at(T![self]) {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
m.complete(p, T![self]); m.complete(p, T![self]);
} else { } else {
p.err_and_bump("expected identifier"); p.err_and_bump("expected identifier");
@ -285,7 +285,7 @@ fn name_ref(p: &mut Parser) {
fn name_ref_or_index(p: &mut Parser) { fn name_ref_or_index(p: &mut Parser) {
if p.at(IDENT) || p.at(INT_NUMBER) { if p.at(IDENT) || p.at(INT_NUMBER) {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
m.complete(p, NAME_REF); m.complete(p, NAME_REF);
} else { } else {
p.err_and_bump("expected identifier"); p.err_and_bump("expected identifier");
@ -296,7 +296,7 @@ fn error_block(p: &mut Parser, message: &str) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.error(message); p.error(message);
p.bump(); p.bump_any();
expressions::expr_block_contents(p); expressions::expr_block_contents(p);
p.eat(T!['}']); p.eat(T!['}']);
m.complete(p, ERROR); m.complete(p, ERROR);

View file

@ -15,11 +15,11 @@ pub(super) fn outer_attributes(p: &mut Parser) {
fn attribute(p: &mut Parser, inner: bool) { fn attribute(p: &mut Parser, inner: bool) {
let attr = p.start(); let attr = p.start();
assert!(p.at(T![#])); assert!(p.at(T![#]));
p.bump(); p.bump_any();
if inner { if inner {
assert!(p.at(T![!])); assert!(p.at(T![!]));
p.bump(); p.bump_any();
} }
if p.at(T!['[']) { if p.at(T!['[']) {

View file

@ -46,7 +46,7 @@ pub(crate) fn block(p: &mut Parser) {
pub(crate) fn naked_block(p: &mut Parser) { pub(crate) fn naked_block(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
expr_block_contents(p); expr_block_contents(p);
p.expect(T!['}']); p.expect(T!['}']);
m.complete(p, BLOCK); m.complete(p, BLOCK);
@ -153,7 +153,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
// } // }
fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) { fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) {
assert!(p.at(T![let])); assert!(p.at(T![let]));
p.bump(); p.bump_any();
patterns::pattern(p); patterns::pattern(p);
if p.at(T![:]) { if p.at(T![:]) {
types::ascription(p); types::ascription(p);
@ -198,7 +198,7 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
// } // }
if p.at(T![;]) { if p.at(T![;]) {
p.bump(); p.bump_any();
continue; continue;
} }
@ -309,7 +309,7 @@ fn expr_bp(
} }
let m = lhs.precede(p); let m = lhs.precede(p);
match op { match op {
Op::Simple => p.bump(), Op::Simple => p.bump_any(),
Op::Composite(kind, n) => { Op::Composite(kind, n) => {
p.bump_compound(kind, n); p.bump_compound(kind, n);
} }
@ -338,7 +338,7 @@ fn lhs(
// } // }
T![&] => { T![&] => {
m = p.start(); m = p.start();
p.bump(); p.bump_any();
p.eat(T![mut]); p.eat(T![mut]);
REF_EXPR REF_EXPR
} }
@ -350,14 +350,14 @@ fn lhs(
// } // }
T![*] | T![!] | T![-] => { T![*] | T![!] | T![-] => {
m = p.start(); m = p.start();
p.bump(); p.bump_any();
PREFIX_EXPR PREFIX_EXPR
} }
// test full_range_expr // test full_range_expr
// fn foo() { xs[..]; } // fn foo() { xs[..]; }
T![..] | T![..=] => { T![..] | T![..=] => {
m = p.start(); m = p.start();
p.bump(); p.bump_any();
if p.at_ts(EXPR_FIRST) { if p.at_ts(EXPR_FIRST) {
expr_bp(p, r, 2, dollar_lvl); expr_bp(p, r, 2, dollar_lvl);
} }
@ -410,8 +410,8 @@ fn postfix_expr(
// x.0().await?.hello(); // x.0().await?.hello();
// } // }
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(); p.bump_any();
p.bump(); p.bump_any();
m.complete(p, AWAIT_EXPR) m.complete(p, AWAIT_EXPR)
} }
T![.] => field_expr(p, lhs), T![.] => field_expr(p, lhs),
@ -419,7 +419,7 @@ fn postfix_expr(
// fn foo() { let x = 1..; } // fn foo() { let x = 1..; }
T![..] | T![..=] if !EXPR_FIRST.contains(p.nth(1)) => { T![..] | T![..=] if !EXPR_FIRST.contains(p.nth(1)) => {
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(); p.bump_any();
m.complete(p, RANGE_EXPR) m.complete(p, RANGE_EXPR)
} }
T![?] => try_expr(p, lhs), T![?] => try_expr(p, lhs),
@ -453,7 +453,7 @@ fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(T!['['])); assert!(p.at(T!['[']));
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(); p.bump_any();
expr(p); expr(p);
p.expect(T![']']); p.expect(T![']']);
m.complete(p, INDEX_EXPR) m.complete(p, INDEX_EXPR)
@ -467,7 +467,7 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(T![.]) && p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth(2) == T![::])); assert!(p.at(T![.]) && p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth(2) == T![::]));
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(); p.bump_any();
name_ref(p); name_ref(p);
type_args::opt_type_arg_list(p, true); type_args::opt_type_arg_list(p, true);
if p.at(T!['(']) { if p.at(T!['(']) {
@ -493,12 +493,12 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(T![.])); assert!(p.at(T![.]));
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(); p.bump_any();
if p.at(IDENT) || p.at(INT_NUMBER) { if p.at(IDENT) || p.at(INT_NUMBER) {
name_ref_or_index(p) name_ref_or_index(p)
} else if p.at(FLOAT_NUMBER) { } else if p.at(FLOAT_NUMBER) {
// FIXME: How to recover and instead parse INT + T![.]? // FIXME: How to recover and instead parse INT + T![.]?
p.bump(); p.bump_any();
} else { } else {
p.error("expected field name or number") p.error("expected field name or number")
} }
@ -512,7 +512,7 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(T![?])); assert!(p.at(T![?]));
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(); p.bump_any();
m.complete(p, TRY_EXPR) m.complete(p, TRY_EXPR)
} }
@ -526,7 +526,7 @@ fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(T![as])); assert!(p.at(T![as]));
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(); p.bump_any();
// Use type_no_bounds(), because cast expressions are not // Use type_no_bounds(), because cast expressions are not
// allowed to have bounds. // allowed to have bounds.
types::type_no_bounds(p); types::type_no_bounds(p);
@ -536,7 +536,7 @@ fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
fn arg_list(p: &mut Parser) { fn arg_list(p: &mut Parser) {
assert!(p.at(T!['('])); assert!(p.at(T!['(']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(T![')']) && !p.at(EOF) { while !p.at(T![')']) && !p.at(EOF) {
if !p.at_ts(EXPR_FIRST) { if !p.at_ts(EXPR_FIRST) {
p.error("expected expression"); p.error("expected expression");
@ -585,7 +585,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
pub(crate) fn record_field_list(p: &mut Parser) { pub(crate) fn record_field_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(EOF) && !p.at(T!['}']) { while !p.at(EOF) && !p.at(T!['}']) {
match p.current() { match p.current() {
// test record_literal_field_with_attr // test record_literal_field_with_attr
@ -602,7 +602,7 @@ pub(crate) fn record_field_list(p: &mut Parser) {
m.complete(p, RECORD_FIELD); m.complete(p, RECORD_FIELD);
} }
T![..] => { T![..] => {
p.bump(); p.bump_any();
expr(p); expr(p);
} }
T!['{'] => error_block(p, "expected a field"), T!['{'] => error_block(p, "expected a field"),

View file

@ -31,7 +31,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
return None; return None;
} }
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
Some(m.complete(p, LITERAL)) Some(m.complete(p, LITERAL))
} }
@ -100,14 +100,14 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
} }
T![async] if la == T!['{'] || (la == T![move] && p.nth(2) == T!['{']) => { T![async] if la == T!['{'] || (la == T![move] && p.nth(2) == T!['{']) => {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
p.eat(T![move]); p.eat(T![move]);
block_expr(p, Some(m)) block_expr(p, Some(m))
} }
T![match] => match_expr(p), T![match] => match_expr(p),
T![unsafe] if la == T!['{'] => { T![unsafe] if la == T!['{'] => {
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
block_expr(p, Some(m)) block_expr(p, Some(m))
} }
T!['{'] => { T!['{'] => {
@ -179,7 +179,7 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
fn array_expr(p: &mut Parser) -> CompletedMarker { fn array_expr(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T!['['])); assert!(p.at(T!['[']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
if p.eat(T![']']) { if p.eat(T![']']) {
return m.complete(p, ARRAY_EXPR); return m.complete(p, ARRAY_EXPR);
} }
@ -261,11 +261,11 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
fn if_expr(p: &mut Parser) -> CompletedMarker { fn if_expr(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![if])); assert!(p.at(T![if]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
cond(p); cond(p);
block(p); block(p);
if p.at(T![else]) { if p.at(T![else]) {
p.bump(); p.bump_any();
if p.at(T![if]) { if p.at(T![if]) {
if_expr(p); if_expr(p);
} else { } else {
@ -284,8 +284,8 @@ fn if_expr(p: &mut Parser) -> CompletedMarker {
fn label(p: &mut Parser) { fn label(p: &mut Parser) {
assert!(p.at(LIFETIME) && p.nth(1) == T![:]); assert!(p.at(LIFETIME) && p.nth(1) == T![:]);
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
p.bump(); p.bump_any();
m.complete(p, LABEL); m.complete(p, LABEL);
} }
@ -296,7 +296,7 @@ fn label(p: &mut Parser) {
fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
assert!(p.at(T![loop])); assert!(p.at(T![loop]));
let m = m.unwrap_or_else(|| p.start()); let m = m.unwrap_or_else(|| p.start());
p.bump(); p.bump_any();
block(p); block(p);
m.complete(p, LOOP_EXPR) m.complete(p, LOOP_EXPR)
} }
@ -309,7 +309,7 @@ fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
assert!(p.at(T![while])); assert!(p.at(T![while]));
let m = m.unwrap_or_else(|| p.start()); let m = m.unwrap_or_else(|| p.start());
p.bump(); p.bump_any();
cond(p); cond(p);
block(p); block(p);
m.complete(p, WHILE_EXPR) m.complete(p, WHILE_EXPR)
@ -322,7 +322,7 @@ fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
assert!(p.at(T![for])); assert!(p.at(T![for]));
let m = m.unwrap_or_else(|| p.start()); let m = m.unwrap_or_else(|| p.start());
p.bump(); p.bump_any();
patterns::pattern(p); patterns::pattern(p);
p.expect(T![in]); p.expect(T![in]);
expr_no_struct(p); expr_no_struct(p);
@ -356,7 +356,7 @@ fn cond(p: &mut Parser) {
fn match_expr(p: &mut Parser) -> CompletedMarker { fn match_expr(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![match])); assert!(p.at(T![match]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
expr_no_struct(p); expr_no_struct(p);
if p.at(T!['{']) { if p.at(T!['{']) {
match_arm_list(p); match_arm_list(p);
@ -452,7 +452,7 @@ fn match_arm(p: &mut Parser) -> BlockLike {
fn match_guard(p: &mut Parser) -> CompletedMarker { fn match_guard(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![if])); assert!(p.at(T![if]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
expr(p); expr(p);
m.complete(p, MATCH_GUARD) m.complete(p, MATCH_GUARD)
} }
@ -478,7 +478,7 @@ pub(super) fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
fn return_expr(p: &mut Parser) -> CompletedMarker { fn return_expr(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![return])); assert!(p.at(T![return]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
if p.at_ts(EXPR_FIRST) { if p.at_ts(EXPR_FIRST) {
expr(p); expr(p);
} }
@ -495,7 +495,7 @@ fn return_expr(p: &mut Parser) -> CompletedMarker {
fn continue_expr(p: &mut Parser) -> CompletedMarker { fn continue_expr(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![continue])); assert!(p.at(T![continue]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
p.eat(LIFETIME); p.eat(LIFETIME);
m.complete(p, CONTINUE_EXPR) m.complete(p, CONTINUE_EXPR)
} }
@ -512,7 +512,7 @@ fn continue_expr(p: &mut Parser) -> CompletedMarker {
fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
assert!(p.at(T![break])); assert!(p.at(T![break]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
p.eat(LIFETIME); p.eat(LIFETIME);
// test break_ambiguity // test break_ambiguity
// fn foo(){ // fn foo(){
@ -534,7 +534,7 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
assert!(p.at(T![try])); assert!(p.at(T![try]));
let m = m.unwrap_or_else(|| p.start()); let m = m.unwrap_or_else(|| p.start());
p.bump(); p.bump_any();
block(p); block(p);
m.complete(p, TRY_EXPR) m.complete(p, TRY_EXPR)
} }
@ -548,7 +548,7 @@ fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
fn box_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { fn box_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
assert!(p.at(T![box])); assert!(p.at(T![box]));
let m = m.unwrap_or_else(|| p.start()); let m = m.unwrap_or_else(|| p.start());
p.bump(); p.bump_any();
if p.at_ts(EXPR_FIRST) { if p.at_ts(EXPR_FIRST) {
expr(p); expr(p);
} }

View file

@ -64,7 +64,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
} else if p.at(T!['}']) && !stop_on_r_curly { } else if p.at(T!['}']) && !stop_on_r_curly {
let e = p.start(); let e = p.start();
p.error("unmatched `}`"); p.error("unmatched `}`");
p.bump(); p.bump_any();
e.complete(p, ERROR); e.complete(p, ERROR);
} else if !p.at(EOF) && !p.at(T!['}']) { } else if !p.at(EOF) && !p.at(T!['}']) {
p.err_and_bump("expected an item"); p.err_and_bump("expected an item");
@ -276,9 +276,9 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
fn extern_crate_item(p: &mut Parser, m: Marker) { fn extern_crate_item(p: &mut Parser, m: Marker) {
assert!(p.at(T![extern])); assert!(p.at(T![extern]));
p.bump(); p.bump_any();
assert!(p.at(T![crate])); assert!(p.at(T![crate]));
p.bump(); p.bump_any();
name_ref(p); name_ref(p);
opt_alias(p); opt_alias(p);
p.expect(T![;]); p.expect(T![;]);
@ -288,7 +288,7 @@ fn extern_crate_item(p: &mut Parser, m: Marker) {
pub(crate) fn extern_item_list(p: &mut Parser) { pub(crate) fn extern_item_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
mod_contents(p, true); mod_contents(p, true);
p.expect(T!['}']); p.expect(T!['}']);
m.complete(p, EXTERN_ITEM_LIST); m.complete(p, EXTERN_ITEM_LIST);
@ -296,7 +296,7 @@ pub(crate) fn extern_item_list(p: &mut Parser) {
fn fn_def(p: &mut Parser, flavor: ItemFlavor) { fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
assert!(p.at(T![fn])); assert!(p.at(T![fn]));
p.bump(); p.bump_any();
name_r(p, ITEM_RECOVERY_SET); name_r(p, ITEM_RECOVERY_SET);
// test function_type_params // test function_type_params
@ -323,7 +323,7 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
// test fn_decl // test fn_decl
// trait T { fn foo(); } // trait T { fn foo(); }
if p.at(T![;]) { if p.at(T![;]) {
p.bump(); p.bump_any();
} else { } else {
expressions::block(p) expressions::block(p)
} }
@ -333,7 +333,7 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) {
// type Foo = Bar; // type Foo = Bar;
fn type_def(p: &mut Parser, m: Marker) { fn type_def(p: &mut Parser, m: Marker) {
assert!(p.at(T![type])); assert!(p.at(T![type]));
p.bump(); p.bump_any();
name(p); name(p);
@ -357,7 +357,7 @@ fn type_def(p: &mut Parser, m: Marker) {
pub(crate) fn mod_item(p: &mut Parser, m: Marker) { pub(crate) fn mod_item(p: &mut Parser, m: Marker) {
assert!(p.at(T![mod])); assert!(p.at(T![mod]));
p.bump(); p.bump_any();
name(p); name(p);
if p.at(T!['{']) { if p.at(T!['{']) {
@ -371,7 +371,7 @@ pub(crate) fn mod_item(p: &mut Parser, m: Marker) {
pub(crate) fn mod_item_list(p: &mut Parser) { pub(crate) fn mod_item_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
mod_contents(p, true); mod_contents(p, true);
p.expect(T!['}']); p.expect(T!['}']);
m.complete(p, ITEM_LIST); m.complete(p, ITEM_LIST);
@ -412,7 +412,7 @@ pub(crate) fn token_tree(p: &mut Parser) {
_ => unreachable!(), _ => unreachable!(),
}; };
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(EOF) && !p.at(closing_paren_kind) { while !p.at(EOF) && !p.at(closing_paren_kind) {
match p.current() { match p.current() {
T!['{'] | T!['('] | T!['['] => token_tree(p), T!['{'] | T!['('] | T!['['] => token_tree(p),

View file

@ -10,7 +10,7 @@ pub(super) fn const_def(p: &mut Parser, m: Marker) {
fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
assert!(p.at(kw)); assert!(p.at(kw));
p.bump(); p.bump_any();
p.eat(T![mut]); // FIXME: validator to forbid const mut p.eat(T![mut]); // FIXME: validator to forbid const mut
name(p); name(p);
types::ascription(p); types::ascription(p);

View file

@ -11,7 +11,7 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
type_params::opt_where_clause(p); type_params::opt_where_clause(p);
match p.current() { match p.current() {
T![;] => { T![;] => {
p.bump(); p.bump_any();
} }
T!['{'] => record_field_def_list(p), T!['{'] => record_field_def_list(p),
_ => { _ => {
@ -21,7 +21,7 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
} }
} }
T![;] if kind == T![struct] => { T![;] if kind == T![struct] => {
p.bump(); p.bump_any();
} }
T!['{'] => record_field_def_list(p), T!['{'] => record_field_def_list(p),
T!['('] if kind == T![struct] => { T!['('] if kind == T![struct] => {
@ -44,7 +44,7 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
pub(super) fn enum_def(p: &mut Parser, m: Marker) { pub(super) fn enum_def(p: &mut Parser, m: Marker) {
assert!(p.at(T![enum])); assert!(p.at(T![enum]));
p.bump(); p.bump_any();
name_r(p, ITEM_RECOVERY_SET); name_r(p, ITEM_RECOVERY_SET);
type_params::opt_type_param_list(p); type_params::opt_type_param_list(p);
type_params::opt_where_clause(p); type_params::opt_where_clause(p);
@ -59,7 +59,7 @@ pub(super) fn enum_def(p: &mut Parser, m: Marker) {
pub(crate) fn enum_variant_list(p: &mut Parser) { pub(crate) fn enum_variant_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(EOF) && !p.at(T!['}']) { while !p.at(EOF) && !p.at(T!['}']) {
if p.at(T!['{']) { if p.at(T!['{']) {
error_block(p, "expected enum variant"); error_block(p, "expected enum variant");
@ -73,7 +73,7 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
T!['{'] => record_field_def_list(p), T!['{'] => record_field_def_list(p),
T!['('] => tuple_field_def_list(p), T!['('] => tuple_field_def_list(p),
T![=] => { T![=] => {
p.bump(); p.bump_any();
expressions::expr(p); expressions::expr(p);
} }
_ => (), _ => (),
@ -94,7 +94,7 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
pub(crate) fn record_field_def_list(p: &mut Parser) { pub(crate) fn record_field_def_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(T!['}']) && !p.at(EOF) { while !p.at(T!['}']) && !p.at(EOF) {
if p.at(T!['{']) { if p.at(T!['{']) {
error_block(p, "expected field"); error_block(p, "expected field");

View file

@ -5,7 +5,7 @@ use super::*;
// trait X<U: Debug + Display>: Hash + Clone where U: Copy {} // trait X<U: Debug + Display>: Hash + Clone where U: Copy {}
pub(super) fn trait_def(p: &mut Parser) { pub(super) fn trait_def(p: &mut Parser) {
assert!(p.at(T![trait])); assert!(p.at(T![trait]));
p.bump(); p.bump_any();
name_r(p, ITEM_RECOVERY_SET); name_r(p, ITEM_RECOVERY_SET);
type_params::opt_type_param_list(p); type_params::opt_type_param_list(p);
if p.at(T![:]) { if p.at(T![:]) {
@ -29,7 +29,7 @@ pub(super) fn trait_def(p: &mut Parser) {
pub(crate) fn trait_item_list(p: &mut Parser) { pub(crate) fn trait_item_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(EOF) && !p.at(T!['}']) { while !p.at(EOF) && !p.at(T!['}']) {
if p.at(T!['{']) { if p.at(T!['{']) {
error_block(p, "expected an item"); error_block(p, "expected an item");
@ -45,7 +45,7 @@ pub(crate) fn trait_item_list(p: &mut Parser) {
// impl Foo {} // impl Foo {}
pub(super) fn impl_block(p: &mut Parser) { pub(super) fn impl_block(p: &mut Parser) {
assert!(p.at(T![impl])); assert!(p.at(T![impl]));
p.bump(); p.bump_any();
if choose_type_params_over_qpath(p) { if choose_type_params_over_qpath(p) {
type_params::opt_type_param_list(p); type_params::opt_type_param_list(p);
} }
@ -78,7 +78,7 @@ pub(super) fn impl_block(p: &mut Parser) {
pub(crate) fn impl_item_list(p: &mut Parser) { pub(crate) fn impl_item_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
// test impl_inner_attributes // test impl_inner_attributes
// enum F{} // enum F{}
// impl F { // impl F {

View file

@ -2,7 +2,7 @@ use super::*;
pub(super) fn use_item(p: &mut Parser, m: Marker) { pub(super) fn use_item(p: &mut Parser, m: Marker) {
assert!(p.at(T![use])); assert!(p.at(T![use]));
p.bump(); p.bump_any();
use_tree(p); use_tree(p);
p.expect(T![;]); p.expect(T![;]);
m.complete(p, USE_ITEM); m.complete(p, USE_ITEM);
@ -28,15 +28,15 @@ fn use_tree(p: &mut Parser) {
// use ::*; // use ::*;
// use some::path::{*}; // use some::path::{*};
// use some::path::{::*}; // use some::path::{::*};
(T![*], _) => p.bump(), (T![*], _) => p.bump_any(),
(T![::], T![*]) => { (T![::], T![*]) => {
// Parse `use ::*;`, which imports all from the crate root in Rust 2015 // Parse `use ::*;`, which imports all from the crate root in Rust 2015
// This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`) // This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`)
// but still parses and errors later: ('crate root in paths can only be used in start position') // but still parses and errors later: ('crate root in paths can only be used in start position')
// FIXME: Add this error (if not out of scope) // FIXME: Add this error (if not out of scope)
// In Rust 2018, it is always invalid (see above) // In Rust 2018, it is always invalid (see above)
p.bump(); p.bump_any();
p.bump(); p.bump_any();
} }
// Open a use tree list // Open a use tree list
// Handles cases such as `use {some::path};` or `{inner::path}` in // Handles cases such as `use {some::path};` or `{inner::path}` in
@ -49,7 +49,7 @@ fn use_tree(p: &mut Parser) {
// use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig // use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig
(T!['{'], _) | (T![::], T!['{']) => { (T!['{'], _) | (T![::], T!['{']) => {
if p.at(T![::]) { if p.at(T![::]) {
p.bump(); p.bump_any();
} }
use_tree_list(p); use_tree_list(p);
} }
@ -81,10 +81,10 @@ fn use_tree(p: &mut Parser) {
opt_alias(p); opt_alias(p);
} }
T![::] => { T![::] => {
p.bump(); p.bump_any();
match p.current() { match p.current() {
T![*] => { T![*] => {
p.bump(); p.bump_any();
} }
// test use_tree_list_after_path // test use_tree_list_after_path
// use crate::{Item}; // use crate::{Item};
@ -114,7 +114,7 @@ fn use_tree(p: &mut Parser) {
pub(crate) fn use_tree_list(p: &mut Parser) { pub(crate) fn use_tree_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(EOF) && !p.at(T!['}']) { while !p.at(EOF) && !p.at(T!['}']) {
use_tree(p); use_tree(p);
if !p.at(T!['}']) { if !p.at(T!['}']) {

View file

@ -39,7 +39,7 @@ fn list_(p: &mut Parser, flavor: Flavor) {
let (bra, ket) = if flavor.type_required() { (T!['('], T![')']) } else { (T![|], T![|]) }; let (bra, ket) = if flavor.type_required() { (T!['('], T![')']) } else { (T![|], T![|]) };
assert!(p.at(bra)); assert!(p.at(bra));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
if flavor.type_required() { if flavor.type_required() {
// test self_param_outer_attr // test self_param_outer_attr
// fn f(#[must_use] self) {} // fn f(#[must_use] self) {}
@ -146,7 +146,7 @@ fn opt_self_param(p: &mut Parser) {
}; };
m = p.start(); m = p.start();
for _ in 0..n_toks { for _ in 0..n_toks {
p.bump(); p.bump_any();
} }
} }
m.complete(p, SELF_PARAM); m.complete(p, SELF_PARAM);

View file

@ -44,7 +44,7 @@ fn path(p: &mut Parser, mode: Mode) {
}; };
if p.at(T![::]) && !use_tree { if p.at(T![::]) && !use_tree {
let path = qual.precede(p); let path = qual.precede(p);
p.bump(); p.bump_any();
path_segment(p, mode, false); path_segment(p, mode, false);
let path = path.complete(p, PATH); let path = path.complete(p, PATH);
qual = path; qual = path;
@ -80,7 +80,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
} }
// test crate_path // test crate_path
// use crate::foo; // use crate::foo;
T![self] | T![super] | T![crate] => p.bump(), T![self] | T![super] | T![crate] => p.bump_any(),
_ => { _ => {
p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); p.err_recover("expected identifier", items::ITEM_RECOVERY_SET);
} }

View file

@ -36,7 +36,7 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) {
// } // }
if p.at(T![...]) || p.at(T![..=]) || p.at(T![..]) { if p.at(T![...]) || p.at(T![..=]) || p.at(T![..]) {
let m = lhs.precede(p); let m = lhs.precede(p);
p.bump(); p.bump_any();
atom_pat(p, recovery_set); atom_pat(p, recovery_set);
m.complete(p, RANGE_PAT); m.complete(p, RANGE_PAT);
} }
@ -100,7 +100,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker {
assert!(is_literal_pat_start(p)); assert!(is_literal_pat_start(p));
let m = p.start(); let m = p.start();
if p.at(T![-]) { if p.at(T![-]) {
p.bump(); p.bump_any();
} }
expressions::literal(p); expressions::literal(p);
m.complete(p, LITERAL_PAT) m.complete(p, LITERAL_PAT)
@ -140,7 +140,7 @@ fn path_pat(p: &mut Parser) -> CompletedMarker {
// } // }
fn tuple_pat_fields(p: &mut Parser) { fn tuple_pat_fields(p: &mut Parser) {
assert!(p.at(T!['('])); assert!(p.at(T!['(']));
p.bump(); p.bump_any();
pat_list(p, T![')']); pat_list(p, T![')']);
p.expect(T![')']); p.expect(T![')']);
} }
@ -155,10 +155,10 @@ fn tuple_pat_fields(p: &mut Parser) {
fn record_field_pat_list(p: &mut Parser) { fn record_field_pat_list(p: &mut Parser) {
assert!(p.at(T!['{'])); assert!(p.at(T!['{']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(EOF) && !p.at(T!['}']) { while !p.at(EOF) && !p.at(T!['}']) {
match p.current() { match p.current() {
T![..] => p.bump(), T![..] => p.bump_any(),
IDENT if p.nth(1) == T![:] => record_field_pat(p), IDENT if p.nth(1) == T![:] => record_field_pat(p),
T!['{'] => error_block(p, "expected ident"), T!['{'] => error_block(p, "expected ident"),
T![box] => { T![box] => {
@ -182,7 +182,7 @@ fn record_field_pat(p: &mut Parser) {
let m = p.start(); let m = p.start();
name(p); name(p);
p.bump(); p.bump_any();
pattern(p); pattern(p);
m.complete(p, RECORD_FIELD_PAT); m.complete(p, RECORD_FIELD_PAT);
} }
@ -192,7 +192,7 @@ fn record_field_pat(p: &mut Parser) {
fn placeholder_pat(p: &mut Parser) -> CompletedMarker { fn placeholder_pat(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![_])); assert!(p.at(T![_]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
m.complete(p, PLACEHOLDER_PAT) m.complete(p, PLACEHOLDER_PAT)
} }
@ -204,7 +204,7 @@ fn placeholder_pat(p: &mut Parser) -> CompletedMarker {
fn ref_pat(p: &mut Parser) -> CompletedMarker { fn ref_pat(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![&])); assert!(p.at(T![&]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
p.eat(T![mut]); p.eat(T![mut]);
pattern(p); pattern(p);
m.complete(p, REF_PAT) m.complete(p, REF_PAT)
@ -228,7 +228,7 @@ fn tuple_pat(p: &mut Parser) -> CompletedMarker {
fn slice_pat(p: &mut Parser) -> CompletedMarker { fn slice_pat(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T!['['])); assert!(p.at(T!['[']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
pat_list(p, T![']']); pat_list(p, T![']']);
p.expect(T![']']); p.expect(T![']']);
m.complete(p, SLICE_PAT) m.complete(p, SLICE_PAT)
@ -237,7 +237,7 @@ fn slice_pat(p: &mut Parser) -> CompletedMarker {
fn pat_list(p: &mut Parser, ket: SyntaxKind) { fn pat_list(p: &mut Parser, ket: SyntaxKind) {
while !p.at(EOF) && !p.at(ket) { while !p.at(EOF) && !p.at(ket) {
match p.current() { match p.current() {
T![..] => p.bump(), T![..] => p.bump_any(),
_ => { _ => {
if !p.at_ts(PATTERN_FIRST) { if !p.at_ts(PATTERN_FIRST) {
p.error("expected a pattern"); p.error("expected a pattern");
@ -281,7 +281,7 @@ fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker {
fn box_pat(p: &mut Parser) -> CompletedMarker { fn box_pat(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![box])); assert!(p.at(T![box]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
pattern(p); pattern(p);
m.complete(p, BOX_PAT) m.complete(p, BOX_PAT)
} }

View file

@ -5,13 +5,13 @@ pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
match (colon_colon_required, p.nth(0), p.nth(1)) { match (colon_colon_required, p.nth(0), p.nth(1)) {
(_, T![::], T![<]) => { (_, T![::], T![<]) => {
m = p.start(); m = p.start();
p.bump(); p.bump_any();
p.bump(); p.bump_any();
} }
(false, T![<], T![=]) => return, (false, T![<], T![=]) => return,
(false, T![<], _) => { (false, T![<], _) => {
m = p.start(); m = p.start();
p.bump(); p.bump_any();
} }
_ => return, _ => return,
}; };
@ -32,7 +32,7 @@ fn type_arg(p: &mut Parser) {
let m = p.start(); let m = p.start();
match p.current() { match p.current() {
LIFETIME => { LIFETIME => {
p.bump(); p.bump_any();
m.complete(p, LIFETIME_ARG); m.complete(p, LIFETIME_ARG);
} }
// test associated_type_bounds // test associated_type_bounds
@ -44,7 +44,7 @@ fn type_arg(p: &mut Parser) {
} }
IDENT if p.nth(1) == T![=] => { IDENT if p.nth(1) == T![=] => {
name_ref(p); name_ref(p);
p.bump(); p.bump_any();
types::type_(p); types::type_(p);
m.complete(p, ASSOC_TYPE_ARG); m.complete(p, ASSOC_TYPE_ARG);
} }

View file

@ -10,7 +10,7 @@ pub(super) fn opt_type_param_list(p: &mut Parser) {
fn type_param_list(p: &mut Parser) { fn type_param_list(p: &mut Parser) {
assert!(p.at(T![<])); assert!(p.at(T![<]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while !p.at(EOF) && !p.at(T![>]) { while !p.at(EOF) && !p.at(T![>]) {
let m = p.start(); let m = p.start();
@ -38,7 +38,7 @@ fn type_param_list(p: &mut Parser) {
fn lifetime_param(p: &mut Parser, m: Marker) { fn lifetime_param(p: &mut Parser, m: Marker) {
assert!(p.at(LIFETIME)); assert!(p.at(LIFETIME));
p.bump(); p.bump_any();
if p.at(T![:]) { if p.at(T![:]) {
lifetime_bounds(p); lifetime_bounds(p);
} }
@ -54,7 +54,7 @@ fn type_param(p: &mut Parser, m: Marker) {
// test type_param_default // test type_param_default
// struct S<T = i32>; // struct S<T = i32>;
if p.at(T![=]) { if p.at(T![=]) {
p.bump(); p.bump_any();
types::type_(p) types::type_(p)
} }
m.complete(p, TYPE_PARAM); m.complete(p, TYPE_PARAM);
@ -64,15 +64,15 @@ fn type_param(p: &mut Parser, m: Marker) {
// struct S<T: 'a + ?Sized + (Copy)>; // struct S<T: 'a + ?Sized + (Copy)>;
pub(super) fn bounds(p: &mut Parser) { pub(super) fn bounds(p: &mut Parser) {
assert!(p.at(T![:])); assert!(p.at(T![:]));
p.bump(); p.bump_any();
bounds_without_colon(p); bounds_without_colon(p);
} }
fn lifetime_bounds(p: &mut Parser) { fn lifetime_bounds(p: &mut Parser) {
assert!(p.at(T![:])); assert!(p.at(T![:]));
p.bump(); p.bump_any();
while p.at(LIFETIME) { while p.at(LIFETIME) {
p.bump(); p.bump_any();
if !p.eat(T![+]) { if !p.eat(T![+]) {
break; break;
} }
@ -99,7 +99,7 @@ fn type_bound(p: &mut Parser) -> bool {
let has_paren = p.eat(T!['(']); let has_paren = p.eat(T!['(']);
p.eat(T![?]); p.eat(T![?]);
match p.current() { match p.current() {
LIFETIME => p.bump(), LIFETIME => p.bump_any(),
T![for] => types::for_type(p), T![for] => types::for_type(p),
_ if paths::is_use_path_start(p) => types::path_type_(p, false), _ if paths::is_use_path_start(p) => types::path_type_(p, false),
_ => { _ => {
@ -128,7 +128,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
return; return;
} }
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
while is_where_predicate(p) { while is_where_predicate(p) {
where_predicate(p); where_predicate(p);
@ -166,7 +166,7 @@ fn where_predicate(p: &mut Parser) {
let m = p.start(); let m = p.start();
match p.current() { match p.current() {
LIFETIME => { LIFETIME => {
p.bump(); p.bump_any();
if p.at(T![:]) { if p.at(T![:]) {
bounds(p); bounds(p);
} else { } else {

View file

@ -44,7 +44,7 @@ pub(super) fn ascription(p: &mut Parser) {
fn paren_or_tuple_type(p: &mut Parser) { fn paren_or_tuple_type(p: &mut Parser) {
assert!(p.at(T!['('])); assert!(p.at(T!['(']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
let mut n_types: u32 = 0; let mut n_types: u32 = 0;
let mut trailing_comma: bool = false; let mut trailing_comma: bool = false;
while !p.at(EOF) && !p.at(T![')']) { while !p.at(EOF) && !p.at(T![')']) {
@ -79,20 +79,20 @@ fn paren_or_tuple_type(p: &mut Parser) {
fn never_type(p: &mut Parser) { fn never_type(p: &mut Parser) {
assert!(p.at(T![!])); assert!(p.at(T![!]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
m.complete(p, NEVER_TYPE); m.complete(p, NEVER_TYPE);
} }
fn pointer_type(p: &mut Parser) { fn pointer_type(p: &mut Parser) {
assert!(p.at(T![*])); assert!(p.at(T![*]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
match p.current() { match p.current() {
// test pointer_type_mut // test pointer_type_mut
// type M = *mut (); // type M = *mut ();
// type C = *mut (); // type C = *mut ();
T![mut] | T![const] => p.bump(), T![mut] | T![const] => p.bump_any(),
_ => { _ => {
// test_err pointer_type_no_mutability // test_err pointer_type_no_mutability
// type T = *(); // type T = *();
@ -110,21 +110,21 @@ fn pointer_type(p: &mut Parser) {
fn array_or_slice_type(p: &mut Parser) { fn array_or_slice_type(p: &mut Parser) {
assert!(p.at(T!['['])); assert!(p.at(T!['[']));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
type_(p); type_(p);
let kind = match p.current() { let kind = match p.current() {
// test slice_type // test slice_type
// type T = [()]; // type T = [()];
T![']'] => { T![']'] => {
p.bump(); p.bump_any();
SLICE_TYPE SLICE_TYPE
} }
// test array_type // test array_type
// type T = [(); 92]; // type T = [(); 92];
T![;] => { T![;] => {
p.bump(); p.bump_any();
expressions::expr(p); expressions::expr(p);
p.expect(T![']']); p.expect(T![']']);
ARRAY_TYPE ARRAY_TYPE
@ -146,7 +146,7 @@ fn array_or_slice_type(p: &mut Parser) {
fn reference_type(p: &mut Parser) { fn reference_type(p: &mut Parser) {
assert!(p.at(T![&])); assert!(p.at(T![&]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
p.eat(LIFETIME); p.eat(LIFETIME);
p.eat(T![mut]); p.eat(T![mut]);
type_no_bounds(p); type_no_bounds(p);
@ -158,7 +158,7 @@ fn reference_type(p: &mut Parser) {
fn placeholder_type(p: &mut Parser) { fn placeholder_type(p: &mut Parser) {
assert!(p.at(T![_])); assert!(p.at(T![_]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
m.complete(p, PLACEHOLDER_TYPE); m.complete(p, PLACEHOLDER_TYPE);
} }
@ -193,7 +193,7 @@ fn fn_pointer_type(p: &mut Parser) {
pub(super) fn for_binder(p: &mut Parser) { pub(super) fn for_binder(p: &mut Parser) {
assert!(p.at(T![for])); assert!(p.at(T![for]));
p.bump(); p.bump_any();
if p.at(T![<]) { if p.at(T![<]) {
type_params::opt_type_param_list(p); type_params::opt_type_param_list(p);
} else { } else {
@ -224,7 +224,7 @@ pub(super) fn for_type(p: &mut Parser) {
fn impl_trait_type(p: &mut Parser) { fn impl_trait_type(p: &mut Parser) {
assert!(p.at(T![impl])); assert!(p.at(T![impl]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
type_params::bounds_without_colon(p); type_params::bounds_without_colon(p);
m.complete(p, IMPL_TRAIT_TYPE); m.complete(p, IMPL_TRAIT_TYPE);
} }
@ -234,7 +234,7 @@ fn impl_trait_type(p: &mut Parser) {
fn dyn_trait_type(p: &mut Parser) { fn dyn_trait_type(p: &mut Parser) {
assert!(p.at(T![dyn ])); assert!(p.at(T![dyn ]));
let m = p.start(); let m = p.start();
p.bump(); p.bump_any();
type_params::bounds_without_colon(p); type_params::bounds_without_colon(p);
m.complete(p, DYN_TRAIT_TYPE); m.complete(p, DYN_TRAIT_TYPE);
} }

View file

@ -148,7 +148,7 @@ impl<'t> Parser<'t> {
} }
/// Advances the parser by one token with composite puncts handled /// Advances the parser by one token with composite puncts handled
pub(crate) fn bump(&mut self) { pub(crate) fn bump_any(&mut self) {
let kind = self.nth(0); let kind = self.nth(0);
if kind == EOF { if kind == EOF {
return; return;
@ -170,6 +170,12 @@ impl<'t> Parser<'t> {
} }
} }
/// Advances the parser by one token, asserting that it is exactly the expected token
pub(crate) fn bump(&mut self, expected: SyntaxKind) {
debug_assert!(self.nth(0) == expected);
self.bump_any()
}
/// Advances the parser by one token, remapping its kind. /// Advances the parser by one token, remapping its kind.
/// This is useful to create contextual keywords from /// This is useful to create contextual keywords from
/// identifiers. For example, the lexer creates an `union` /// identifiers. For example, the lexer creates an `union`
@ -205,7 +211,7 @@ impl<'t> Parser<'t> {
if !self.at(kind) { if !self.at(kind) {
return false; return false;
} }
self.bump(); self.bump_any();
true true
} }
@ -231,7 +237,7 @@ impl<'t> Parser<'t> {
} else { } else {
let m = self.start(); let m = self.start();
self.error(message); self.error(message);
self.bump(); self.bump_any();
m.complete(self, ERROR); m.complete(self, ERROR);
}; };
} }