From 90122542b2708a4dde36758d1ff5848764858ac0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 Mar 2019 17:47:02 +0300 Subject: allow `mut ident` patterns in trait methods closes #928 --- crates/ra_parser/src/grammar/params.rs | 3 +- .../ok/0116_trait_fn_placeholder_parameter.rs | 2 +- .../ok/0116_trait_fn_placeholder_parameter.txt | 35 +++++++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) (limited to 'crates') diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs index a70f067f9..d027578b6 100644 --- a/crates/ra_parser/src/grammar/params.rs +++ b/crates/ra_parser/src/grammar/params.rs @@ -83,9 +83,10 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { // test trait_fn_placeholder_parameter // trait Foo { - // fn bar(_: u64); + // fn bar(_: u64, mut x: i32); // } if (la0 == IDENT || la0 == UNDERSCORE) && la1 == COLON + || la0 == MUT_KW && la1 == IDENT && la2 == COLON || la0 == AMP && la1 == IDENT && la2 == COLON || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON { diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs index aede3f4fe..472cb8803 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs @@ -1,3 +1,3 @@ trait Foo { - fn bar(_: u64); + fn bar(_: u64, mut x: i32); } diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt index 248d491df..00217aef1 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt @@ -1,19 +1,19 @@ -SOURCE_FILE@[0; 34) - TRAIT_DEF@[0; 33) +SOURCE_FILE@[0; 46) + TRAIT_DEF@[0; 45) TRAIT_KW@[0; 5) WHITESPACE@[5; 6) NAME@[6; 9) IDENT@[6; 9) "Foo" WHITESPACE@[9; 10) - ITEM_LIST@[10; 33) + ITEM_LIST@[10; 45) L_CURLY@[10; 11) WHITESPACE@[11; 16) - FN_DEF@[16; 31) + FN_DEF@[16; 43) FN_KW@[16; 18) WHITESPACE@[18; 19) NAME@[19; 22) IDENT@[19; 22) "bar" - PARAM_LIST@[22; 30) + PARAM_LIST@[22; 42) L_PAREN@[22; 23) PARAM@[23; 29) PLACEHOLDER_PAT@[23; 24) @@ -25,8 +25,23 @@ SOURCE_FILE@[0; 34) PATH_SEGMENT@[26; 29) NAME_REF@[26; 29) IDENT@[26; 29) "u64" - R_PAREN@[29; 30) - SEMI@[30; 31) - WHITESPACE@[31; 32) - R_CURLY@[32; 33) - WHITESPACE@[33; 34) + COMMA@[29; 30) + WHITESPACE@[30; 31) + PARAM@[31; 41) + BIND_PAT@[31; 36) + MUT_KW@[31; 34) + WHITESPACE@[34; 35) + NAME@[35; 36) + IDENT@[35; 36) "x" + COLON@[36; 37) + WHITESPACE@[37; 38) + PATH_TYPE@[38; 41) + PATH@[38; 41) + PATH_SEGMENT@[38; 41) + NAME_REF@[38; 41) + IDENT@[38; 41) "i32" + R_PAREN@[41; 42) + SEMI@[42; 43) + WHITESPACE@[43; 44) + R_CURLY@[44; 45) + WHITESPACE@[45; 46) -- cgit v1.2.3