From e28bd099d68ee124280eeadefe48c1f2e0ff6c17 Mon Sep 17 00:00:00 2001 From: Erlend Tobiassen Date: Fri, 25 Jan 2019 23:56:31 +0100 Subject: Support macro calls in type position --- crates/ra_syntax/src/grammar/types.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/grammar/types.rs index 21d89d83b..adc189a29 100644 --- a/crates/ra_syntax/src/grammar/types.rs +++ b/crates/ra_syntax/src/grammar/types.rs @@ -29,7 +29,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { DYN_KW => dyn_trait_type(p), // Some path types are not allowed to have bounds (no plus) L_ANGLE => path_type_(p, allow_bounds), - _ if paths::is_path_start(p) => path_type_(p, allow_bounds), + _ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds), _ => { p.err_recover("expected type", TYPE_RECOVERY_SET); } @@ -243,6 +243,28 @@ pub(super) fn path_type(p: &mut Parser) { path_type_(p, true) } +// test macro_call_type +// 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(L_ANGLE)); + let m = p.start(); + paths::type_path(p); + + let kind = if p.at(EXCL) { + items::macro_call_after_excl(p); + MACRO_CALL + } else { + PATH_TYPE + }; + + if allow_bounds && p.eat(PLUS) { + type_params::bounds_without_colon(p); + } + + m.complete(p, kind); +} + pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { assert!(paths::is_path_start(p) || p.at(L_ANGLE)); let m = p.start(); -- cgit v1.2.3