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 <erlend.tobiassen@gmail.com>
This commit is contained in:
bors[bot] 2019-01-26 10:23:28 +00:00
commit 2acaa92c93
3 changed files with 68 additions and 1 deletions

View file

@ -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();