mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
dyn type
This commit is contained in:
parent
5a56ac4b72
commit
d1eceefeb8
7 changed files with 111 additions and 1 deletions
|
@ -14,3 +14,4 @@ smol_str = { path = "../smol_str" }
|
|||
|
||||
[dev-dependencies]
|
||||
assert_eq_text = { path = "../assert_eq_text" }
|
||||
walkdir = "2.2.0"
|
||||
|
|
|
@ -55,6 +55,7 @@ Grammar(
|
|||
"enum",
|
||||
"trait",
|
||||
"impl",
|
||||
"dyn",
|
||||
"true",
|
||||
"false",
|
||||
"as",
|
||||
|
@ -134,6 +135,7 @@ Grammar(
|
|||
"FN_POINTER_TYPE",
|
||||
"FOR_TYPE",
|
||||
"IMPL_TRAIT_TYPE",
|
||||
"DYN_TRAIT_TYPE",
|
||||
|
||||
"REF_PAT",
|
||||
"BIND_PAT",
|
||||
|
|
|
@ -11,9 +11,10 @@ pub(super) fn type_(p: &mut Parser) {
|
|||
FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
|
||||
FOR_KW => for_type(p),
|
||||
IMPL_KW => impl_trait_type(p),
|
||||
DYN_KW => dyn_trait_type(p),
|
||||
_ if paths::is_path_start(p) => path_type(p),
|
||||
_ => {
|
||||
p.error("expected type");
|
||||
p.err_and_bump("expected type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +195,16 @@ fn impl_trait_type(p: &mut Parser) {
|
|||
m.complete(p, IMPL_TRAIT_TYPE);
|
||||
}
|
||||
|
||||
// test dyn_trait_type
|
||||
// type A = dyn Iterator<Item=Foo<'a>> + 'a;
|
||||
fn dyn_trait_type(p: &mut Parser) {
|
||||
assert!(p.at(DYN_KW));
|
||||
let m = p.start();
|
||||
p.bump();
|
||||
type_params::bounds_without_colon(p);
|
||||
m.complete(p, DYN_TRAIT_TYPE);
|
||||
}
|
||||
|
||||
// test path_type
|
||||
// type A = Foo;
|
||||
// type B = ::Foo;
|
||||
|
|
|
@ -62,6 +62,7 @@ pub enum SyntaxKind {
|
|||
ENUM_KW,
|
||||
TRAIT_KW,
|
||||
IMPL_KW,
|
||||
DYN_KW,
|
||||
TRUE_KW,
|
||||
FALSE_KW,
|
||||
AS_KW,
|
||||
|
@ -133,6 +134,7 @@ pub enum SyntaxKind {
|
|||
FN_POINTER_TYPE,
|
||||
FOR_TYPE,
|
||||
IMPL_TRAIT_TYPE,
|
||||
DYN_TRAIT_TYPE,
|
||||
REF_PAT,
|
||||
BIND_PAT,
|
||||
PLACEHOLDER_PAT,
|
||||
|
@ -210,6 +212,7 @@ impl SyntaxKind {
|
|||
| ENUM_KW
|
||||
| TRAIT_KW
|
||||
| IMPL_KW
|
||||
| DYN_KW
|
||||
| TRUE_KW
|
||||
| FALSE_KW
|
||||
| AS_KW
|
||||
|
@ -297,6 +300,7 @@ impl SyntaxKind {
|
|||
ENUM_KW => &SyntaxInfo { name: "ENUM_KW" },
|
||||
TRAIT_KW => &SyntaxInfo { name: "TRAIT_KW" },
|
||||
IMPL_KW => &SyntaxInfo { name: "IMPL_KW" },
|
||||
DYN_KW => &SyntaxInfo { name: "DYN_KW" },
|
||||
TRUE_KW => &SyntaxInfo { name: "TRUE_KW" },
|
||||
FALSE_KW => &SyntaxInfo { name: "FALSE_KW" },
|
||||
AS_KW => &SyntaxInfo { name: "AS_KW" },
|
||||
|
@ -368,6 +372,7 @@ impl SyntaxKind {
|
|||
FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" },
|
||||
FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" },
|
||||
IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" },
|
||||
DYN_TRAIT_TYPE => &SyntaxInfo { name: "DYN_TRAIT_TYPE" },
|
||||
REF_PAT => &SyntaxInfo { name: "REF_PAT" },
|
||||
BIND_PAT => &SyntaxInfo { name: "BIND_PAT" },
|
||||
PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" },
|
||||
|
@ -445,6 +450,7 @@ impl SyntaxKind {
|
|||
"enum" => ENUM_KW,
|
||||
"trait" => TRAIT_KW,
|
||||
"impl" => IMPL_KW,
|
||||
"dyn" => DYN_KW,
|
||||
"true" => TRUE_KW,
|
||||
"false" => FALSE_KW,
|
||||
"as" => AS_KW,
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
pub struct Cache(
|
||||
RefCell<HashMap<
|
||||
TypeId,
|
||||
Box<@ Any>,
|
||||
>>
|
||||
);
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
FILE@[0; 86)
|
||||
STRUCT@[0; 84)
|
||||
VISIBILITY@[0; 3)
|
||||
PUB_KW@[0; 3)
|
||||
WHITESPACE@[3; 4)
|
||||
STRUCT_KW@[4; 10)
|
||||
WHITESPACE@[10; 11)
|
||||
NAME@[11; 16)
|
||||
IDENT@[11; 16) "Cache"
|
||||
L_PAREN@[16; 17)
|
||||
WHITESPACE@[17; 22)
|
||||
POS_FIELD@[22; 68)
|
||||
PATH_TYPE@[22; 68)
|
||||
PATH@[22; 68)
|
||||
PATH_SEGMENT@[22; 68)
|
||||
NAME_REF@[22; 29)
|
||||
IDENT@[22; 29) "RefCell"
|
||||
TYPE_ARG_LIST@[29; 68)
|
||||
L_ANGLE@[29; 30)
|
||||
TYPE_ARG@[30; 68)
|
||||
PATH_TYPE@[30; 68)
|
||||
PATH@[30; 68)
|
||||
PATH_SEGMENT@[30; 68)
|
||||
NAME_REF@[30; 37)
|
||||
IDENT@[30; 37) "HashMap"
|
||||
TYPE_ARG_LIST@[37; 68)
|
||||
L_ANGLE@[37; 38)
|
||||
WHITESPACE@[38; 47)
|
||||
TYPE_ARG@[47; 53)
|
||||
PATH_TYPE@[47; 53)
|
||||
PATH@[47; 53)
|
||||
PATH_SEGMENT@[47; 53)
|
||||
NAME_REF@[47; 53)
|
||||
IDENT@[47; 53) "TypeId"
|
||||
COMMA@[53; 54)
|
||||
WHITESPACE@[54; 63)
|
||||
TYPE_ARG@[63; 68)
|
||||
PATH_TYPE@[63; 68)
|
||||
PATH@[63; 68)
|
||||
PATH_SEGMENT@[63; 68)
|
||||
NAME_REF@[63; 66)
|
||||
IDENT@[63; 66) "Box"
|
||||
TYPE_ARG_LIST@[66; 68)
|
||||
L_ANGLE@[66; 67)
|
||||
err: `expected type`
|
||||
TYPE_ARG@[67; 68)
|
||||
ERROR@[67; 68)
|
||||
AT@[67; 68)
|
||||
err: `expected COMMA`
|
||||
err: `expected R_ANGLE`
|
||||
err: `expected COMMA`
|
||||
err: `expected R_ANGLE`
|
||||
err: `expected COMMA`
|
||||
err: `expected R_ANGLE`
|
||||
err: `expected COMMA`
|
||||
WHITESPACE@[68; 69)
|
||||
POS_FIELD@[69; 72)
|
||||
PATH_TYPE@[69; 72)
|
||||
PATH@[69; 72)
|
||||
PATH_SEGMENT@[69; 72)
|
||||
NAME_REF@[69; 72)
|
||||
IDENT@[69; 72) "Any"
|
||||
err: `expected COMMA`
|
||||
err: `expected type`
|
||||
POS_FIELD@[72; 73)
|
||||
ERROR@[72; 73)
|
||||
R_ANGLE@[72; 73)
|
||||
COMMA@[73; 74)
|
||||
WHITESPACE@[74; 79)
|
||||
err: `expected type`
|
||||
POS_FIELD@[79; 80)
|
||||
ERROR@[79; 80)
|
||||
R_ANGLE@[79; 80)
|
||||
err: `expected COMMA`
|
||||
err: `expected type`
|
||||
POS_FIELD@[80; 81)
|
||||
ERROR@[80; 81)
|
||||
R_ANGLE@[80; 81)
|
||||
WHITESPACE@[81; 82)
|
||||
R_PAREN@[82; 83)
|
||||
SEMI@[83; 84)
|
||||
WHITESPACE@[84; 86)
|
|
@ -1,6 +1,7 @@
|
|||
extern crate libsyntax2;
|
||||
#[macro_use]
|
||||
extern crate assert_eq_text;
|
||||
extern crate walkdir;
|
||||
|
||||
use std::{
|
||||
fs,
|
||||
|
|
Loading…
Reference in a new issue