From 8222a1fddfe73dab5e00437efeffa7d95db0b6be Mon Sep 17 00:00:00 2001 From: Evgenii P Date: Tue, 13 Aug 2019 22:36:01 +0700 Subject: Fix is_path_start to accept T![<], fix is_path_start usages --- crates/ra_parser/src/grammar/expressions.rs | 2 +- crates/ra_parser/src/grammar/expressions/atom.rs | 2 +- crates/ra_parser/src/grammar/items.rs | 4 ++-- crates/ra_parser/src/grammar/items/use_item.rs | 2 +- crates/ra_parser/src/grammar/paths.rs | 6 +++++- crates/ra_parser/src/grammar/patterns.rs | 4 ++-- crates/ra_parser/src/grammar/type_params.rs | 2 +- crates/ra_parser/src/grammar/types.rs | 8 ++++---- 8 files changed, 17 insertions(+), 13 deletions(-) (limited to 'crates/ra_parser/src') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 9fd3a235d..aa959864a 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -549,7 +549,7 @@ fn arg_list(p: &mut Parser) { // let _ = format!(); // } 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(); paths::expr_path(p); match p.current() { diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index d98953a7e..401c738a3 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -62,7 +62,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar if let Some(m) = literal(p) { 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)); } let la = p.nth(1); diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 543af7c4b..b7da44758 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -49,7 +49,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF } Err(m) => m, }; - if paths::is_path_start(p) { + if paths::is_use_path_start(p) { match macro_call(p) { BlockLike::Block => (), BlockLike::NotBlock => { @@ -378,7 +378,7 @@ pub(crate) fn mod_item_list(p: &mut Parser) { } fn macro_call(p: &mut Parser) -> BlockLike { - assert!(paths::is_path_start(p)); + assert!(paths::is_use_path_start(p)); paths::use_path(p); macro_call_after_excl(p) } diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index c3a0b4410..c0c7d0ec6 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs @@ -65,7 +65,7 @@ fn use_tree(p: &mut Parser) { // use crate::Item; // use self::some::Struct; // use crate_name::some_item; - _ if paths::is_path_start(p) => { + _ if paths::is_use_path_start(p) => { paths::use_path(p); match p.current() { T![as] => { diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index 3537b0da1..07eb53b0c 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs @@ -4,6 +4,10 @@ pub(super) const PATH_FIRST: TokenSet = token_set![IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, L_ANGLE]; 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() { IDENT | T![self] | T![super] | T![crate] | T![::] => true, _ => false, @@ -58,7 +62,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { if first && p.eat(T![<]) { types::type_(p); if p.eat(T![as]) { - if is_path_start(p) { + if is_use_path_start(p) { types::path_type(p); } else { p.error("expected a trait"); diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 46034942a..df6000707 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -65,7 +65,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { { return Some(bind_pat(p, true)); } - if paths::is_path_start(p) { + if paths::is_use_path_start(p) { return Some(path_pat(p)); } @@ -118,7 +118,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker { // let Bar(..) = (); // } fn path_pat(p: &mut Parser) -> CompletedMarker { - assert!(paths::is_path_start(p)); + assert!(paths::is_use_path_start(p)); let m = p.start(); paths::expr_path(p); let kind = match p.current() { diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs index ef59b59d3..d739df727 100644 --- a/crates/ra_parser/src/grammar/type_params.rs +++ b/crates/ra_parser/src/grammar/type_params.rs @@ -101,7 +101,7 @@ fn type_bound(p: &mut Parser) -> bool { match p.current() { LIFETIME => p.bump(), 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); return false; diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs index 9acc00793..29d173305 100644 --- a/crates/ra_parser/src/grammar/types.rs +++ b/crates/ra_parser/src/grammar/types.rs @@ -29,7 +29,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { T![dyn ] => dyn_trait_type(p), // Some path types are not allowed to have bounds (no plus) 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); } @@ -213,7 +213,7 @@ pub(super) fn for_type(p: &mut Parser) { match p.current() { T![fn] | T![unsafe] | T![extern] => fn_pointer_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"), } m.complete(p, FOR_TYPE); @@ -252,7 +252,7 @@ pub(super) fn path_type(p: &mut Parser) { // type A = foo!(); // type B = crate::foo!(); 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(); 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) { - assert!(paths::is_path_start(p) || p.at(T![<])); + assert!(paths::is_path_start(p)); let m = p.start(); paths::type_path(p); -- cgit v1.2.3