From e7359068397c6fd78738c36872f4e5147a2faf85 Mon Sep 17 00:00:00 2001 From: SabrinaJewson Date: Tue, 1 Oct 2024 22:09:31 +0100 Subject: [PATCH] fix: correctly parse `use` in generic parameters --- crates/parser/src/grammar/generic_params.rs | 2 +- .../test_data/parser/err/0055_impl_use.rast | 26 +++++++++++++++++++ .../test_data/parser/err/0055_impl_use.rs | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 crates/parser/test_data/parser/err/0055_impl_use.rast create mode 100644 crates/parser/test_data/parser/err/0055_impl_use.rs diff --git a/crates/parser/src/grammar/generic_params.rs b/crates/parser/src/grammar/generic_params.rs index e0fa753fa7..ecfabca092 100644 --- a/crates/parser/src/grammar/generic_params.rs +++ b/crates/parser/src/grammar/generic_params.rs @@ -145,7 +145,7 @@ fn type_bound(p: &mut Parser<'_>) -> bool { T![for] => types::for_type(p, false), // test precise_capturing // fn captures<'a: 'a, 'b: 'b, T>() -> impl Sized + use<'b, T> {} - T![use] => { + T![use] if p.nth_at(1, T![<]) => { p.bump_any(); generic_param_list(p) } diff --git a/crates/parser/test_data/parser/err/0055_impl_use.rast b/crates/parser/test_data/parser/err/0055_impl_use.rast new file mode 100644 index 0000000000..751f007df9 --- /dev/null +++ b/crates/parser/test_data/parser/err/0055_impl_use.rast @@ -0,0 +1,26 @@ +SOURCE_FILE + IMPL + IMPL_KW "impl" + GENERIC_PARAM_LIST + L_ANGLE "<" + TYPE_PARAM + NAME + IDENT "T" + COLON ":" + WHITESPACE "\n" + TYPE_BOUND_LIST + ERROR + USE_KW "use" + WHITESPACE " " + MACRO_CALL + PATH + PATH_SEGMENT + NAME_REF + IDENT "std" + SEMICOLON ";" + WHITESPACE "\n" +error 8: expected R_ANGLE +error 8: expected type +error 11: expected `{` +error 15: expected BANG +error 15: expected `{`, `[`, `(` diff --git a/crates/parser/test_data/parser/err/0055_impl_use.rs b/crates/parser/test_data/parser/err/0055_impl_use.rs new file mode 100644 index 0000000000..571552bda8 --- /dev/null +++ b/crates/parser/test_data/parser/err/0055_impl_use.rs @@ -0,0 +1,2 @@ +impl