mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
impl trait type
This commit is contained in:
parent
643d235035
commit
1af8eb9c08
@ -118,6 +118,7 @@ Grammar(
|
|||||||
"PLACEHOLDER_TYPE",
|
"PLACEHOLDER_TYPE",
|
||||||
"FN_POINTER_TYPE",
|
"FN_POINTER_TYPE",
|
||||||
"FOR_TYPE",
|
"FOR_TYPE",
|
||||||
|
"IMPL_TRAIT_TYPE",
|
||||||
|
|
||||||
"REF_PAT",
|
"REF_PAT",
|
||||||
"BIND_PAT",
|
"BIND_PAT",
|
||||||
|
@ -57,6 +57,10 @@ pub(super) fn list(p: &mut Parser) {
|
|||||||
pub(super) fn bounds(p: &mut Parser) {
|
pub(super) fn bounds(p: &mut Parser) {
|
||||||
assert!(p.at(COLON));
|
assert!(p.at(COLON));
|
||||||
p.bump();
|
p.bump();
|
||||||
|
bounds_without_colon(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn bounds_without_colon(p: &mut Parser) {
|
||||||
loop {
|
loop {
|
||||||
let has_paren = p.eat(L_PAREN);
|
let has_paren = p.eat(L_PAREN);
|
||||||
p.eat(QUESTION);
|
p.eat(QUESTION);
|
||||||
@ -79,6 +83,7 @@ pub(super) fn bounds(p: &mut Parser) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub(super) fn where_clause(p: &mut Parser) {
|
pub(super) fn where_clause(p: &mut Parser) {
|
||||||
if p.at(WHERE_KW) {
|
if p.at(WHERE_KW) {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
|
@ -10,6 +10,7 @@ pub(super) fn type_(p: &mut Parser) {
|
|||||||
UNDERSCORE => placeholder_type(p),
|
UNDERSCORE => placeholder_type(p),
|
||||||
FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
|
FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
|
||||||
FOR_KW => for_type(p),
|
FOR_KW => for_type(p),
|
||||||
|
IMPL_KW => impl_trait_type(p),
|
||||||
_ if paths::is_path_start(p) => path_type(p),
|
_ if paths::is_path_start(p) => path_type(p),
|
||||||
_ => {
|
_ => {
|
||||||
p.error("expected type");
|
p.error("expected type");
|
||||||
@ -183,6 +184,16 @@ fn for_type(p: &mut Parser) {
|
|||||||
m.complete(p, FOR_TYPE);
|
m.complete(p, FOR_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test impl_trait_type
|
||||||
|
// type A = impl Iterator<Item=Foo<'a>> + 'a;
|
||||||
|
fn impl_trait_type(p: &mut Parser) {
|
||||||
|
assert!(p.at(IMPL_KW));
|
||||||
|
let m = p.start();
|
||||||
|
p.bump();
|
||||||
|
type_params::bounds_without_colon(p);
|
||||||
|
m.complete(p, IMPL_TRAIT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
// test path_type
|
// test path_type
|
||||||
// type A = Foo;
|
// type A = Foo;
|
||||||
// type B = ::Foo;
|
// type B = ::Foo;
|
||||||
|
@ -111,6 +111,7 @@ pub enum SyntaxKind {
|
|||||||
PLACEHOLDER_TYPE,
|
PLACEHOLDER_TYPE,
|
||||||
FN_POINTER_TYPE,
|
FN_POINTER_TYPE,
|
||||||
FOR_TYPE,
|
FOR_TYPE,
|
||||||
|
IMPL_TRAIT_TYPE,
|
||||||
REF_PAT,
|
REF_PAT,
|
||||||
BIND_PAT,
|
BIND_PAT,
|
||||||
PLACEHOLDER_PAT,
|
PLACEHOLDER_PAT,
|
||||||
@ -271,6 +272,7 @@ impl SyntaxKind {
|
|||||||
PLACEHOLDER_TYPE => &SyntaxInfo { name: "PLACEHOLDER_TYPE" },
|
PLACEHOLDER_TYPE => &SyntaxInfo { name: "PLACEHOLDER_TYPE" },
|
||||||
FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" },
|
FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" },
|
||||||
FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" },
|
FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" },
|
||||||
|
IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" },
|
||||||
REF_PAT => &SyntaxInfo { name: "REF_PAT" },
|
REF_PAT => &SyntaxInfo { name: "REF_PAT" },
|
||||||
BIND_PAT => &SyntaxInfo { name: "BIND_PAT" },
|
BIND_PAT => &SyntaxInfo { name: "BIND_PAT" },
|
||||||
PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" },
|
PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" },
|
||||||
|
1
tests/data/parser/inline/0063_impl_trait_type.rs
Normal file
1
tests/data/parser/inline/0063_impl_trait_type.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
type A = impl Iterator<Item=Foo<'a>> + 'a;
|
39
tests/data/parser/inline/0063_impl_trait_type.txt
Normal file
39
tests/data/parser/inline/0063_impl_trait_type.txt
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
FILE@[0; 43)
|
||||||
|
TYPE_ITEM@[0; 43)
|
||||||
|
TYPE_KW@[0; 4)
|
||||||
|
NAME@[4; 7)
|
||||||
|
WHITESPACE@[4; 5)
|
||||||
|
IDENT@[5; 6) "A"
|
||||||
|
WHITESPACE@[6; 7)
|
||||||
|
EQ@[7; 8)
|
||||||
|
IMPL_TRAIT_TYPE@[8; 41)
|
||||||
|
WHITESPACE@[8; 9)
|
||||||
|
IMPL_KW@[9; 13)
|
||||||
|
PATH@[13; 37)
|
||||||
|
PATH_SEGMENT@[13; 37)
|
||||||
|
NAME_REF@[13; 22)
|
||||||
|
WHITESPACE@[13; 14)
|
||||||
|
IDENT@[14; 22) "Iterator"
|
||||||
|
TYPE_ARG_LIST@[22; 37)
|
||||||
|
L_ANGLE@[22; 23)
|
||||||
|
ASSOC_TYPE_ARG@[23; 35)
|
||||||
|
NAME_REF@[23; 27)
|
||||||
|
IDENT@[23; 27) "Item"
|
||||||
|
EQ@[27; 28)
|
||||||
|
PATH_TYPE@[28; 35)
|
||||||
|
PATH@[28; 35)
|
||||||
|
PATH_SEGMENT@[28; 35)
|
||||||
|
NAME_REF@[28; 31)
|
||||||
|
IDENT@[28; 31) "Foo"
|
||||||
|
TYPE_ARG_LIST@[31; 35)
|
||||||
|
L_ANGLE@[31; 32)
|
||||||
|
LIFETIME_ARG@[32; 34)
|
||||||
|
LIFETIME@[32; 34) "'a"
|
||||||
|
R_ANGLE@[34; 35)
|
||||||
|
R_ANGLE@[35; 36)
|
||||||
|
WHITESPACE@[36; 37)
|
||||||
|
PLUS@[37; 38)
|
||||||
|
WHITESPACE@[38; 39)
|
||||||
|
LIFETIME@[39; 41) "'a"
|
||||||
|
SEMI@[41; 42)
|
||||||
|
WHITESPACE@[42; 43)
|
Loading…
Reference in New Issue
Block a user