Fix Return Type Syntax to include .. (i.e. method(..) and not method()) as specified in the RFC

This commit is contained in:
Chayim Refael Friedman 2024-08-26 01:45:52 +03:00
parent 7106cd3be5
commit 21e6058ab7
12 changed files with 183 additions and 16 deletions

View file

@ -102,13 +102,18 @@ fn generic_arg(p: &mut Parser<'_>) -> bool {
IDENT if p.nth_at(1, T!['(']) => {
let m = p.start();
name_ref(p);
params::param_list_fn_trait(p);
if p.at(T![:]) && !p.at(T![::]) {
// test associated_return_type_bounds
// fn foo<T: Foo<foo(): Send, bar(i32): Send, baz(i32, i32): Send>>() {}
if p.nth_at(1, T![..]) {
let rtn = p.start();
p.bump(T!['(']);
p.bump(T![..]);
p.expect(T![')']);
rtn.complete(p, RETURN_TYPE_SYNTAX);
// test return_type_syntax_assoc_type_bound
// fn foo<T: Trait<method(..): Send>>() {}
generic_params::bounds(p);
m.complete(p, ASSOC_TYPE_ARG);
} else {
params::param_list_fn_trait(p);
// test bare_dyn_types_with_paren_as_generic_args
// type A = S<Fn(i32)>;
// type A = S<Fn(i32) + Send>;

View file

@ -119,8 +119,7 @@ fn lifetime_bounds(p: &mut Parser<'_>) {
// test type_param_bounds
// struct S<T: 'a + ?Sized + (Copy) + ~const Drop>;
pub(super) fn bounds(p: &mut Parser<'_>) {
assert!(p.at(T![:]));
p.bump(T![:]);
p.expect(T![:]);
bounds_without_colon(p);
}

View file

@ -140,11 +140,24 @@ fn opt_path_type_args(p: &mut Parser<'_>, mode: Mode) {
if p.at(T![::]) && p.nth_at(2, T!['(']) {
p.bump(T![::]);
}
// test path_fn_trait_args
// type F = Box<Fn(i32) -> ()>;
if p.at(T!['(']) {
params::param_list_fn_trait(p);
opt_ret_type(p);
if p.nth_at(1, T![..]) {
// test return_type_syntax_in_path
// fn foo<T>()
// where
// T::method(..): Send,
// {}
let rtn = p.start();
p.bump(T!['(']);
p.bump(T![..]);
p.expect(T![')']);
rtn.complete(p, RETURN_TYPE_SYNTAX);
} else {
// test path_fn_trait_args
// type F = Box<Fn(i32) -> ()>;
params::param_list_fn_trait(p);
opt_ret_type(p);
}
} else {
generic_args::opt_generic_arg_list(p, false);
}

View file

@ -253,6 +253,7 @@ pub enum SyntaxKind {
RENAME,
REST_PAT,
RETURN_EXPR,
RETURN_TYPE_SYNTAX,
RET_TYPE,
SELF_PARAM,
SLICE_PAT,