mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-03 13:37:37 +00:00
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 <erlend.tobiassen@gmail.com>
This commit is contained in:
commit
2acaa92c93
@ -29,7 +29,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
|
|||||||
DYN_KW => dyn_trait_type(p),
|
DYN_KW => 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)
|
||||||
L_ANGLE => path_type_(p, allow_bounds),
|
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);
|
p.err_recover("expected type", TYPE_RECOVERY_SET);
|
||||||
}
|
}
|
||||||
@ -243,6 +243,28 @@ pub(super) fn path_type(p: &mut Parser) {
|
|||||||
path_type_(p, true)
|
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) {
|
pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
|
||||||
assert!(paths::is_path_start(p) || p.at(L_ANGLE));
|
assert!(paths::is_path_start(p) || p.at(L_ANGLE));
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
type A = foo!();
|
||||||
|
type B = crate::foo!();
|
@ -0,0 +1,43 @@
|
|||||||
|
SOURCE_FILE@[0; 41)
|
||||||
|
TYPE_DEF@[0; 16)
|
||||||
|
TYPE_KW@[0; 4)
|
||||||
|
WHITESPACE@[4; 5)
|
||||||
|
NAME@[5; 6)
|
||||||
|
IDENT@[5; 6) "A"
|
||||||
|
WHITESPACE@[6; 7)
|
||||||
|
EQ@[7; 8)
|
||||||
|
WHITESPACE@[8; 9)
|
||||||
|
MACRO_CALL@[9; 15)
|
||||||
|
PATH@[9; 12)
|
||||||
|
PATH_SEGMENT@[9; 12)
|
||||||
|
NAME_REF@[9; 12)
|
||||||
|
IDENT@[9; 12) "foo"
|
||||||
|
EXCL@[12; 13)
|
||||||
|
TOKEN_TREE@[13; 15)
|
||||||
|
L_PAREN@[13; 14)
|
||||||
|
R_PAREN@[14; 15)
|
||||||
|
SEMI@[15; 16)
|
||||||
|
WHITESPACE@[16; 17)
|
||||||
|
TYPE_DEF@[17; 40)
|
||||||
|
TYPE_KW@[17; 21)
|
||||||
|
WHITESPACE@[21; 22)
|
||||||
|
NAME@[22; 23)
|
||||||
|
IDENT@[22; 23) "B"
|
||||||
|
WHITESPACE@[23; 24)
|
||||||
|
EQ@[24; 25)
|
||||||
|
WHITESPACE@[25; 26)
|
||||||
|
MACRO_CALL@[26; 39)
|
||||||
|
PATH@[26; 36)
|
||||||
|
PATH@[26; 31)
|
||||||
|
PATH_SEGMENT@[26; 31)
|
||||||
|
CRATE_KW@[26; 31)
|
||||||
|
COLONCOLON@[31; 33)
|
||||||
|
PATH_SEGMENT@[33; 36)
|
||||||
|
NAME_REF@[33; 36)
|
||||||
|
IDENT@[33; 36) "foo"
|
||||||
|
EXCL@[36; 37)
|
||||||
|
TOKEN_TREE@[37; 39)
|
||||||
|
L_PAREN@[37; 38)
|
||||||
|
R_PAREN@[38; 39)
|
||||||
|
SEMI@[39; 40)
|
||||||
|
WHITESPACE@[40; 41)
|
Loading…
Reference in New Issue
Block a user