mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
fix: Fix parsing of dyn T in generic arg on 2015 edition
This commit is contained in:
parent
2fd06545a6
commit
a049941c1a
7 changed files with 68 additions and 3 deletions
|
@ -45,7 +45,7 @@ pub(crate) const GENERIC_ARG_FIRST: TokenSet = TokenSet::new(&[
|
|||
const GENERIC_ARG_RECOVERY_SET: TokenSet = TokenSet::new(&[T![>], T![,]]);
|
||||
|
||||
// test generic_arg
|
||||
// type T = S<i32>;
|
||||
// type T = S<i32, dyn T, fn()>;
|
||||
pub(crate) fn generic_arg(p: &mut Parser<'_>) -> bool {
|
||||
match p.current() {
|
||||
LIFETIME_IDENT if !p.nth_at(1, T![+]) => lifetime_arg(p),
|
||||
|
@ -57,6 +57,9 @@ pub(crate) fn generic_arg(p: &mut Parser<'_>) -> bool {
|
|||
// type ParenthesizedArgs = Foo<Item(T), Item::(T), Item(T): Bound, Item::(T): Bound, Item(T) = Item, Item::(T) = Item>;
|
||||
// type RTN = Foo<Item(..), Item(..), Item(..): Bound, Item(..): Bound, Item(..) = Item, Item(..) = Item>;
|
||||
|
||||
// test edition_2015_dyn_prefix_inside_generic_arg 2015
|
||||
// type A = Foo<dyn T>;
|
||||
T![ident] if !p.edition().at_least_2018() && types::is_dyn_weak(p) => type_arg(p),
|
||||
// test macro_inside_generic_arg
|
||||
// type A = Foo<syn::Token![_]>;
|
||||
k if PATH_NAME_REF_KINDS.contains(k) => {
|
||||
|
|
|
@ -58,7 +58,7 @@ fn type_with_bounds_cond(p: &mut Parser<'_>, allow_bounds: bool) {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_dyn_weak(p: &Parser<'_>) -> bool {
|
||||
pub(crate) fn is_dyn_weak(p: &Parser<'_>) -> bool {
|
||||
const WEAK_DYN_PATH_FIRST: TokenSet = TokenSet::new(&[
|
||||
IDENT,
|
||||
T![self],
|
||||
|
|
|
@ -190,6 +190,13 @@ mod ok {
|
|||
);
|
||||
}
|
||||
#[test]
|
||||
fn edition_2015_dyn_prefix_inside_generic_arg() {
|
||||
run_and_expect_no_errors_with_edition(
|
||||
"test_data/parser/inline/ok/edition_2015_dyn_prefix_inside_generic_arg.rs",
|
||||
crate::Edition::Edition2015,
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn effect_blocks() { run_and_expect_no_errors("test_data/parser/inline/ok/effect_blocks.rs"); }
|
||||
#[test]
|
||||
fn exclusive_range_pat() {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
SOURCE_FILE
|
||||
TYPE_ALIAS
|
||||
COMMENT "// 2015"
|
||||
WHITESPACE "\n"
|
||||
TYPE_KW "type"
|
||||
WHITESPACE " "
|
||||
NAME
|
||||
IDENT "A"
|
||||
WHITESPACE " "
|
||||
EQ "="
|
||||
WHITESPACE " "
|
||||
PATH_TYPE
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "Foo"
|
||||
GENERIC_ARG_LIST
|
||||
L_ANGLE "<"
|
||||
TYPE_ARG
|
||||
DYN_TRAIT_TYPE
|
||||
DYN_KW "dyn"
|
||||
WHITESPACE " "
|
||||
TYPE_BOUND_LIST
|
||||
TYPE_BOUND
|
||||
PATH_TYPE
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "T"
|
||||
R_ANGLE ">"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
|
@ -0,0 +1,2 @@
|
|||
// 2015
|
||||
type A = Foo<dyn T>;
|
|
@ -20,6 +20,27 @@ SOURCE_FILE
|
|||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "i32"
|
||||
COMMA ","
|
||||
WHITESPACE " "
|
||||
TYPE_ARG
|
||||
DYN_TRAIT_TYPE
|
||||
DYN_KW "dyn"
|
||||
WHITESPACE " "
|
||||
TYPE_BOUND_LIST
|
||||
TYPE_BOUND
|
||||
PATH_TYPE
|
||||
PATH
|
||||
PATH_SEGMENT
|
||||
NAME_REF
|
||||
IDENT "T"
|
||||
COMMA ","
|
||||
WHITESPACE " "
|
||||
TYPE_ARG
|
||||
FN_PTR_TYPE
|
||||
FN_KW "fn"
|
||||
PARAM_LIST
|
||||
L_PAREN "("
|
||||
R_PAREN ")"
|
||||
R_ANGLE ">"
|
||||
SEMICOLON ";"
|
||||
WHITESPACE "\n"
|
||||
|
|
|
@ -1 +1 @@
|
|||
type T = S<i32>;
|
||||
type T = S<i32, dyn T, fn()>;
|
||||
|
|
Loading…
Reference in a new issue