mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
G: for type
This commit is contained in:
parent
a6f9b0414c
commit
c8910b0683
5 changed files with 45 additions and 0 deletions
|
@ -111,6 +111,7 @@ Grammar(
|
|||
"REFERENCE_TYPE",
|
||||
"PLACEHOLDER_TYPE",
|
||||
"FN_POINTER_TYPE",
|
||||
"FOR_TYPE",
|
||||
|
||||
"EXTERN_BLOCK",
|
||||
"ENUM_VARIANT",
|
||||
|
|
|
@ -9,6 +9,7 @@ pub(super) fn type_(p: &mut Parser) {
|
|||
AMPERSAND => reference_type(p),
|
||||
UNDERSCORE => placeholder_type(p),
|
||||
FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
|
||||
FOR_KW => for_type(p),
|
||||
IDENT => path_type(p),
|
||||
_ => {
|
||||
p.error("expected type");
|
||||
|
@ -166,6 +167,17 @@ fn fn_pointer_type(p: &mut Parser) {
|
|||
m.complete(p, FN_POINTER_TYPE);
|
||||
}
|
||||
|
||||
// test for_type
|
||||
// type A = for<'a> fn() -> ();
|
||||
fn for_type(p: &mut Parser) {
|
||||
assert!(p.at(FOR_KW));
|
||||
let m = p.start();
|
||||
p.bump();
|
||||
type_params::list(p);
|
||||
type_(p);
|
||||
m.complete(p, FOR_TYPE);
|
||||
}
|
||||
|
||||
fn path_type(p: &mut Parser) {
|
||||
assert!(p.at(IDENT));
|
||||
let m = p.start();
|
||||
|
|
|
@ -109,6 +109,7 @@ pub enum SyntaxKind {
|
|||
REFERENCE_TYPE,
|
||||
PLACEHOLDER_TYPE,
|
||||
FN_POINTER_TYPE,
|
||||
FOR_TYPE,
|
||||
EXTERN_BLOCK,
|
||||
ENUM_VARIANT,
|
||||
NAMED_FIELD,
|
||||
|
@ -244,6 +245,7 @@ impl SyntaxKind {
|
|||
REFERENCE_TYPE => &SyntaxInfo { name: "REFERENCE_TYPE" },
|
||||
PLACEHOLDER_TYPE => &SyntaxInfo { name: "PLACEHOLDER_TYPE" },
|
||||
FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" },
|
||||
FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" },
|
||||
EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
|
||||
ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
|
||||
NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
|
||||
|
|
1
tests/data/parser/inline/0031_for_type.rs
Normal file
1
tests/data/parser/inline/0031_for_type.rs
Normal file
|
@ -0,0 +1 @@
|
|||
type A = for<'a> fn() -> ();
|
29
tests/data/parser/inline/0031_for_type.txt
Normal file
29
tests/data/parser/inline/0031_for_type.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
FILE@[0; 29)
|
||||
TYPE_ITEM@[0; 29)
|
||||
TYPE_KW@[0; 4)
|
||||
NAME@[4; 7)
|
||||
WHITESPACE@[4; 5)
|
||||
IDENT@[5; 6) "A"
|
||||
WHITESPACE@[6; 7)
|
||||
EQ@[7; 8)
|
||||
FOR_TYPE@[8; 27)
|
||||
WHITESPACE@[8; 9)
|
||||
FOR_KW@[9; 12)
|
||||
TYPE_PARAM_LIST@[12; 17)
|
||||
L_ANGLE@[12; 13)
|
||||
LIFETIME_PARAM@[13; 15)
|
||||
LIFETIME@[13; 15) "'a"
|
||||
R_ANGLE@[15; 16)
|
||||
WHITESPACE@[16; 17)
|
||||
FN_POINTER_TYPE@[17; 27)
|
||||
FN_KW@[17; 19)
|
||||
L_PAREN@[19; 20)
|
||||
R_PAREN@[20; 21)
|
||||
WHITESPACE@[21; 22)
|
||||
THIN_ARROW@[22; 24)
|
||||
TUPLE_TYPE@[24; 27)
|
||||
WHITESPACE@[24; 25)
|
||||
L_PAREN@[25; 26)
|
||||
R_PAREN@[26; 27)
|
||||
SEMI@[27; 28)
|
||||
WHITESPACE@[28; 29)
|
Loading…
Reference in a new issue