Fix is_path_start to accept T![<], fix is_path_start usages

This commit is contained in:
Evgenii P 2019-08-13 22:36:01 +07:00
parent f1e62501c3
commit 8222a1fddf
8 changed files with 17 additions and 13 deletions

View File

@ -549,7 +549,7 @@ fn arg_list(p: &mut Parser) {
// let _ = format!(); // let _ = format!();
// } // }
fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) { fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
assert!(paths::is_path_start(p) || p.at(T![<])); assert!(paths::is_path_start(p));
let m = p.start(); let m = p.start();
paths::expr_path(p); paths::expr_path(p);
match p.current() { match p.current() {

View File

@ -62,7 +62,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
if let Some(m) = literal(p) { if let Some(m) = literal(p) {
return Some((m, BlockLike::NotBlock)); return Some((m, BlockLike::NotBlock));
} }
if paths::is_path_start(p) || p.at(T![<]) { if paths::is_path_start(p) {
return Some(path_expr(p, r)); return Some(path_expr(p, r));
} }
let la = p.nth(1); let la = p.nth(1);

View File

@ -49,7 +49,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
} }
Err(m) => m, Err(m) => m,
}; };
if paths::is_path_start(p) { if paths::is_use_path_start(p) {
match macro_call(p) { match macro_call(p) {
BlockLike::Block => (), BlockLike::Block => (),
BlockLike::NotBlock => { BlockLike::NotBlock => {
@ -378,7 +378,7 @@ pub(crate) fn mod_item_list(p: &mut Parser) {
} }
fn macro_call(p: &mut Parser) -> BlockLike { fn macro_call(p: &mut Parser) -> BlockLike {
assert!(paths::is_path_start(p)); assert!(paths::is_use_path_start(p));
paths::use_path(p); paths::use_path(p);
macro_call_after_excl(p) macro_call_after_excl(p)
} }

View File

@ -65,7 +65,7 @@ fn use_tree(p: &mut Parser) {
// use crate::Item; // use crate::Item;
// use self::some::Struct; // use self::some::Struct;
// use crate_name::some_item; // use crate_name::some_item;
_ if paths::is_path_start(p) => { _ if paths::is_use_path_start(p) => {
paths::use_path(p); paths::use_path(p);
match p.current() { match p.current() {
T![as] => { T![as] => {

View File

@ -4,6 +4,10 @@ pub(super) const PATH_FIRST: TokenSet =
token_set![IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, L_ANGLE]; token_set![IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, L_ANGLE];
pub(super) fn is_path_start(p: &Parser) -> bool { pub(super) fn is_path_start(p: &Parser) -> bool {
is_use_path_start(p) || p.at(T![<])
}
pub(super) fn is_use_path_start(p: &Parser) -> bool {
match p.current() { match p.current() {
IDENT | T![self] | T![super] | T![crate] | T![::] => true, IDENT | T![self] | T![super] | T![crate] | T![::] => true,
_ => false, _ => false,
@ -58,7 +62,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
if first && p.eat(T![<]) { if first && p.eat(T![<]) {
types::type_(p); types::type_(p);
if p.eat(T![as]) { if p.eat(T![as]) {
if is_path_start(p) { if is_use_path_start(p) {
types::path_type(p); types::path_type(p);
} else { } else {
p.error("expected a trait"); p.error("expected a trait");

View File

@ -65,7 +65,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
{ {
return Some(bind_pat(p, true)); return Some(bind_pat(p, true));
} }
if paths::is_path_start(p) { if paths::is_use_path_start(p) {
return Some(path_pat(p)); return Some(path_pat(p));
} }
@ -118,7 +118,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker {
// let Bar(..) = (); // let Bar(..) = ();
// } // }
fn path_pat(p: &mut Parser) -> CompletedMarker { fn path_pat(p: &mut Parser) -> CompletedMarker {
assert!(paths::is_path_start(p)); assert!(paths::is_use_path_start(p));
let m = p.start(); let m = p.start();
paths::expr_path(p); paths::expr_path(p);
let kind = match p.current() { let kind = match p.current() {

View File

@ -101,7 +101,7 @@ fn type_bound(p: &mut Parser) -> bool {
match p.current() { match p.current() {
LIFETIME => p.bump(), LIFETIME => p.bump(),
T![for] => types::for_type(p), T![for] => types::for_type(p),
_ if paths::is_path_start(p) => types::path_type_(p, false), _ if paths::is_use_path_start(p) => types::path_type_(p, false),
_ => { _ => {
m.abandon(p); m.abandon(p);
return false; return false;

View File

@ -29,7 +29,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
T![dyn ] => dyn_trait_type(p), T![dyn ] => dyn_trait_type(p),
// Some path types are not allowed to have bounds (no plus) // Some path types are not allowed to have bounds (no plus)
T![<] => path_type_(p, allow_bounds), T![<] => path_type_(p, allow_bounds),
_ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds), _ if paths::is_use_path_start(p) => path_or_macro_type_(p, allow_bounds),
_ => { _ => {
p.err_recover("expected type", TYPE_RECOVERY_SET); p.err_recover("expected type", TYPE_RECOVERY_SET);
} }
@ -213,7 +213,7 @@ pub(super) fn for_type(p: &mut Parser) {
match p.current() { match p.current() {
T![fn] | T![unsafe] | T![extern] => fn_pointer_type(p), T![fn] | T![unsafe] | T![extern] => fn_pointer_type(p),
T![&] => reference_type(p), T![&] => reference_type(p),
_ if paths::is_path_start(p) || p.at(T![<]) => path_type_(p, false), _ if paths::is_path_start(p) => path_type_(p, false),
_ => p.error("expected a path"), _ => p.error("expected a path"),
} }
m.complete(p, FOR_TYPE); m.complete(p, FOR_TYPE);
@ -252,7 +252,7 @@ pub(super) fn path_type(p: &mut Parser) {
// type A = foo!(); // type A = foo!();
// type B = crate::foo!(); // type B = crate::foo!();
fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
assert!(paths::is_path_start(p) || p.at(T![<])); assert!(paths::is_path_start(p));
let m = p.start(); let m = p.start();
paths::type_path(p); paths::type_path(p);
@ -271,7 +271,7 @@ fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
} }
pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
assert!(paths::is_path_start(p) || p.at(T![<])); assert!(paths::is_path_start(p));
let m = p.start(); let m = p.start();
paths::type_path(p); paths::type_path(p);