diff options
| author | Steven Joruk <steven@joruk.com> | 2022-03-11 19:22:49 +0000 |
|---|---|---|
| committer | Steven Joruk <steven@joruk.com> | 2022-03-11 19:51:35 +0000 |
| commit | 972f50da2dc5b9015382b2908b41df7d1b52beb3 (patch) | |
| tree | 6e28a5f5953b1b70f300d3bfd53939060351ccde | |
| parent | 224a255c5a7c75efb5567fc38b3772c5dbb094c4 (diff) | |
| download | rust-972f50da2dc5b9015382b2908b41df7d1b52beb3.tar.gz rust-972f50da2dc5b9015382b2908b41df7d1b52beb3.zip | |
fix: Stop wrapping ConstParam's default values in ConstArg
This was causing ConstParam::default_val to always return None for block
expressions.
CONST_ARG@24..29
BLOCK_EXPR@24..29
...
| -rw-r--r-- | crates/parser/src/grammar/generic_args.rs | 22 | ||||
| -rw-r--r-- | crates/parser/src/grammar/generic_params.rs | 7 | ||||
| -rw-r--r-- | crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rast | 57 | ||||
| -rw-r--r-- | crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rs | 2 | ||||
| -rw-r--r-- | crates/parser/test_data/parser/inline/ok/0199_const_param_default_expression.rast | 34 | ||||
| -rw-r--r-- | crates/parser/test_data/parser/inline/ok/0199_const_param_default_expression.rs | 1 | ||||
| -rw-r--r-- | crates/parser/test_data/parser/inline/ok/0200_const_param_default_literal.rast (renamed from crates/parser/test_data/parser/inline/ok/0165_const_param_defaults.rast) | 9 | ||||
| -rw-r--r-- | crates/parser/test_data/parser/inline/ok/0200_const_param_default_literal.rs (renamed from crates/parser/test_data/parser/inline/ok/0165_const_param_defaults.rs) | 0 |
8 files changed, 82 insertions, 50 deletions
diff --git a/crates/parser/src/grammar/generic_args.rs b/crates/parser/src/grammar/generic_args.rs index 1148c6c35c5..bba312009b9 100644 --- a/crates/parser/src/grammar/generic_args.rs +++ b/crates/parser/src/grammar/generic_args.rs @@ -72,28 +72,24 @@ fn lifetime_arg(p: &mut Parser) { m.complete(p, LIFETIME_ARG); } -// test const_arg -// type T = S<92>; -pub(super) fn const_arg(p: &mut Parser) { - let m = p.start(); +pub(super) fn const_arg_content(p: &mut Parser) { + // The tests in here are really for `const_arg`, which wraps the content + // CONST_ARG. match p.current() { // test const_arg_block // type T = S<{90 + 2}>; T!['{'] => { expressions::block_expr(p); - m.complete(p, CONST_ARG); } // test const_arg_literal // type T = S<"hello", 0xdeadbeef>; k if k.is_literal() => { expressions::literal(p); - m.complete(p, CONST_ARG); } // test const_arg_bool_literal // type T = S<true>; T![true] | T![false] => { expressions::literal(p); - m.complete(p, CONST_ARG); } // test const_arg_negative_number // type T = S<-92>; @@ -102,19 +98,25 @@ pub(super) fn const_arg(p: &mut Parser) { p.bump(T![-]); expressions::literal(p); lm.complete(p, PREFIX_EXPR); - m.complete(p, CONST_ARG); } // test const_arg_path - // struct S<const N: u32 = u32::MAX>; + // type T = S<u32::MAX>; _ => { let lm = p.start(); paths::use_path(p); lm.complete(p, PATH_EXPR); - m.complete(p, CONST_ARG); } } } +// test const_arg +// type T = S<92>; +pub(super) fn const_arg(p: &mut Parser) { + let m = p.start(); + const_arg_content(p); + m.complete(p, CONST_ARG); +} + fn type_arg(p: &mut Parser) { let m = p.start(); types::type_(p); diff --git a/crates/parser/src/grammar/generic_params.rs b/crates/parser/src/grammar/generic_params.rs index 1009c67ffa1..1c5af92b874 100644 --- a/crates/parser/src/grammar/generic_params.rs +++ b/crates/parser/src/grammar/generic_params.rs @@ -79,10 +79,13 @@ fn const_param(p: &mut Parser, m: Marker) { } if p.at(T![=]) { - // test const_param_defaults + // test const_param_default_literal // struct A<const N: i32 = -1>; p.bump(T![=]); - generic_args::const_arg(p); + + // test const_param_default_expression + // struct A<const N: i32 = { 1 }>; + generic_args::const_arg_content(p); } m.complete(p, CONST_PARAM); diff --git a/crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rast b/crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rast index 440dfb06a38..62ddefa5a8d 100644 --- a/crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rast +++ b/crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rast @@ -1,37 +1,30 @@ SOURCE_FILE - STRUCT - STRUCT_KW "struct" + TYPE_ALIAS + TYPE_KW "type" WHITESPACE " " NAME - IDENT "S" - GENERIC_PARAM_LIST - L_ANGLE "<" - CONST_PARAM - CONST_KW "const" - WHITESPACE " " - NAME - IDENT "N" - COLON ":" - WHITESPACE " " - PATH_TYPE - PATH - PATH_SEGMENT - NAME_REF - IDENT "u32" - WHITESPACE " " - EQ "=" - WHITESPACE " " - CONST_ARG - PATH_EXPR - PATH - PATH - PATH_SEGMENT - NAME_REF - IDENT "u32" - COLON2 "::" - PATH_SEGMENT - NAME_REF - IDENT "MAX" - R_ANGLE ">" + IDENT "T" + WHITESPACE " " + EQ "=" + WHITESPACE " " + PATH_TYPE + PATH + PATH_SEGMENT + NAME_REF + IDENT "S" + GENERIC_ARG_LIST + L_ANGLE "<" + TYPE_ARG + PATH_TYPE + PATH + PATH + PATH_SEGMENT + NAME_REF + IDENT "u32" + COLON2 "::" + PATH_SEGMENT + NAME_REF + IDENT "MAX" + R_ANGLE ">" SEMICOLON ";" WHITESPACE "\n" diff --git a/crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rs b/crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rs index ee075f3e50f..1383d0d6d56 100644 --- a/crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rs +++ b/crates/parser/test_data/parser/inline/ok/0188_const_arg_path.rs @@ -1 +1 @@ -struct S<const N: u32 = u32::MAX>; +type T = S<u32::MAX>; diff --git a/crates/parser/test_data/parser/inline/ok/0199_const_param_default_expression.rast b/crates/parser/test_data/parser/inline/ok/0199_const_param_default_expression.rast new file mode 100644 index 00000000000..0607ff54fbb --- /dev/null +++ b/crates/parser/test_data/parser/inline/ok/0199_const_param_default_expression.rast @@ -0,0 +1,34 @@ +SOURCE_FILE + STRUCT + STRUCT_KW "struct" + WHITESPACE " " + NAME + IDENT "A" + GENERIC_PARAM_LIST + L_ANGLE "<" + CONST_PARAM + CONST_KW "const" + WHITESPACE " " + NAME + IDENT "N" + COLON ":" + WHITESPACE " " + PATH_TYPE + PATH + PATH_SEGMENT + NAME_REF + IDENT "i32" + WHITESPACE " " + EQ "=" + WHITESPACE " " + BLOCK_EXPR + STMT_LIST + L_CURLY "{" + WHITESPACE " " + LITERAL + INT_NUMBER "1" + WHITESPACE " " + R_CURLY "}" + R_ANGLE ">" + SEMICOLON ";" + WHITESPACE "\n" diff --git a/crates/parser/test_data/parser/inline/ok/0199_const_param_default_expression.rs b/crates/parser/test_data/parser/inline/ok/0199_const_param_default_expression.rs new file mode 100644 index 00000000000..551bde0b008 --- /dev/null +++ b/crates/parser/test_data/parser/inline/ok/0199_const_param_default_expression.rs @@ -0,0 +1 @@ +struct A<const N: i32 = { 1 }>; diff --git a/crates/parser/test_data/parser/inline/ok/0165_const_param_defaults.rast b/crates/parser/test_data/parser/inline/ok/0200_const_param_default_literal.rast index 6de10353bf0..8e52313651c 100644 --- a/crates/parser/test_data/parser/inline/ok/0165_const_param_defaults.rast +++ b/crates/parser/test_data/parser/inline/ok/0200_const_param_default_literal.rast @@ -21,11 +21,10 @@ SOURCE_FILE WHITESPACE " " EQ "=" WHITESPACE " " - CONST_ARG - PREFIX_EXPR - MINUS "-" - LITERAL - INT_NUMBER "1" + PREFIX_EXPR + MINUS "-" + LITERAL + INT_NUMBER "1" R_ANGLE ">" SEMICOLON ";" WHITESPACE "\n" diff --git a/crates/parser/test_data/parser/inline/ok/0165_const_param_defaults.rs b/crates/parser/test_data/parser/inline/ok/0200_const_param_default_literal.rs index 879ecffa75d..879ecffa75d 100644 --- a/crates/parser/test_data/parser/inline/ok/0165_const_param_defaults.rs +++ b/crates/parser/test_data/parser/inline/ok/0200_const_param_default_literal.rs |
