From c0556bd8c1b5faf4d784b3a93cfb093a2cfa0587 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 18 Sep 2021 15:56:26 +0300 Subject: [PATCH] minor: improve readability --- crates/parser/src/grammar/generic_params.rs | 32 ++++++++++--------- ...rast => 0181_generic_param_attribute.rast} | 0 ...ute.rs => 0181_generic_param_attribute.rs} | 0 3 files changed, 17 insertions(+), 15 deletions(-) rename crates/syntax/test_data/parser/inline/ok/{0181_generic_param_list_param_attribute.rast => 0181_generic_param_attribute.rast} (100%) rename crates/syntax/test_data/parser/inline/ok/{0181_generic_param_list_param_attribute.rs => 0181_generic_param_attribute.rs} (100%) diff --git a/crates/parser/src/grammar/generic_params.rs b/crates/parser/src/grammar/generic_params.rs index b2ce101835..b8119f0a21 100644 --- a/crates/parser/src/grammar/generic_params.rs +++ b/crates/parser/src/grammar/generic_params.rs @@ -14,21 +14,7 @@ fn generic_param_list(p: &mut Parser) { p.bump(T![<]); while !p.at(EOF) && !p.at(T![>]) { - let m = p.start(); - - // test generic_param_list_param_attribute - // fn foo<#[lt_attr] 'a, #[t_attr] T>() {} - attributes::outer_attrs(p); - - match p.current() { - LIFETIME_IDENT => lifetime_param(p, m), - IDENT => type_param(p, m), - T![const] => const_param(p, m), - _ => { - m.abandon(p); - p.err_and_bump("expected type parameter") - } - } + generic_param(p); if !p.at(T![>]) && !p.expect(T![,]) { break; } @@ -37,6 +23,22 @@ fn generic_param_list(p: &mut Parser) { m.complete(p, GENERIC_PARAM_LIST); } +fn generic_param(p: &mut Parser) { + let m = p.start(); + // test generic_param_attribute + // fn foo<#[lt_attr] 'a, #[t_attr] T>() {} + attributes::outer_attrs(p); + match p.current() { + LIFETIME_IDENT => lifetime_param(p, m), + IDENT => type_param(p, m), + T![const] => const_param(p, m), + _ => { + m.abandon(p); + p.err_and_bump("expected type parameter") + } + } +} + // test lifetime_param // fn f<'a: 'b>() {} fn lifetime_param(p: &mut Parser, m: Marker) { diff --git a/crates/syntax/test_data/parser/inline/ok/0181_generic_param_list_param_attribute.rast b/crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rast similarity index 100% rename from crates/syntax/test_data/parser/inline/ok/0181_generic_param_list_param_attribute.rast rename to crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rast diff --git a/crates/syntax/test_data/parser/inline/ok/0181_generic_param_list_param_attribute.rs b/crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rs similarity index 100% rename from crates/syntax/test_data/parser/inline/ok/0181_generic_param_list_param_attribute.rs rename to crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rs