aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-26 10:23:28 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-26 10:23:28 +0000
commit2acaa92c93bcd54d97221d0cede8780ff817476e (patch)
treecb92ecad2475f772d3e392d6cb43ccb84fa50acf /crates/ra_syntax/src
parent8b6dea348fa02a7ce8107a1e73917f0597f2a91d (diff)
parente28bd099d68ee124280eeadefe48c1f2e0ff6c17 (diff)
Merge #660
660: Support macro calls in type position r=matklad a=regiontog A [playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fdc6dd4ddaece92a72fa2a292b75e27c) demonstrating the syntax in question. Co-authored-by: Erlend Tobiassen <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/grammar/types.rs24
1 files changed, 23 insertions, 1 deletions
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) {
29 DYN_KW => dyn_trait_type(p), 29 DYN_KW => dyn_trait_type(p),
30 // Some path types are not allowed to have bounds (no plus) 30 // Some path types are not allowed to have bounds (no plus)
31 L_ANGLE => path_type_(p, allow_bounds), 31 L_ANGLE => path_type_(p, allow_bounds),
32 _ if paths::is_path_start(p) => path_type_(p, allow_bounds), 32 _ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds),
33 _ => { 33 _ => {
34 p.err_recover("expected type", TYPE_RECOVERY_SET); 34 p.err_recover("expected type", TYPE_RECOVERY_SET);
35 } 35 }
@@ -243,6 +243,28 @@ pub(super) fn path_type(p: &mut Parser) {
243 path_type_(p, true) 243 path_type_(p, true)
244} 244}
245 245
246// test macro_call_type
247// type A = foo!();
248// type B = crate::foo!();
249fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
250 assert!(paths::is_path_start(p) || p.at(L_ANGLE));
251 let m = p.start();
252 paths::type_path(p);
253
254 let kind = if p.at(EXCL) {
255 items::macro_call_after_excl(p);
256 MACRO_CALL
257 } else {
258 PATH_TYPE
259 };
260
261 if allow_bounds && p.eat(PLUS) {
262 type_params::bounds_without_colon(p);
263 }
264
265 m.complete(p, kind);
266}
267
246pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { 268pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
247 assert!(paths::is_path_start(p) || p.at(L_ANGLE)); 269 assert!(paths::is_path_start(p) || p.at(L_ANGLE));
248 let m = p.start(); 270 let m = p.start();