diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 58e182d68c6..d0b07f59314 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -34,8 +34,8 @@ mod params; mod paths; mod patterns; -mod type_args; -mod type_params; +mod generic_args; +mod generic_params; mod types; use crate::{ diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs index 12e62cddbc0..29310b71bd8 100644 --- a/crates/parser/src/grammar/expressions.rs +++ b/crates/parser/src/grammar/expressions.rs @@ -486,7 +486,7 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { let m = lhs.precede(p); p.bump_any(); name_ref(p); - type_args::opt_generic_arg_list(p, true); + generic_args::opt_generic_arg_list(p, true); if p.at(T!['(']) { arg_list(p); } diff --git a/crates/parser/src/grammar/type_args.rs b/crates/parser/src/grammar/generic_args.rs similarity index 97% rename from crates/parser/src/grammar/type_args.rs rename to crates/parser/src/grammar/generic_args.rs index f09a28c443a..0ae3eea5778 100644 --- a/crates/parser/src/grammar/type_args.rs +++ b/crates/parser/src/grammar/generic_args.rs @@ -23,38 +23,6 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) { m.complete(p, GENERIC_ARG_LIST); } -pub(super) fn const_arg(p: &mut Parser) { - let m = p.start(); - // FIXME: duplicates the code below - match p.current() { - T!['{'] => { - expressions::block_expr(p); - m.complete(p, CONST_ARG); - } - k if k.is_literal() => { - expressions::literal(p); - m.complete(p, CONST_ARG); - } - T![true] | T![false] => { - expressions::literal(p); - m.complete(p, CONST_ARG); - } - T![-] => { - let lm = p.start(); - p.bump(T![-]); - expressions::literal(p); - lm.complete(p, PREFIX_EXPR); - m.complete(p, CONST_ARG); - } - _ => { - let lm = p.start(); - paths::use_path(p); - lm.complete(p, PATH_EXPR); - m.complete(p, CONST_ARG); - } - } -} - // test type_arg // type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>; fn generic_arg(p: &mut Parser) { @@ -94,7 +62,7 @@ fn generic_arg(p: &mut Parser) { } // NameRef<...>: T![:] => { - type_params::bounds(p); + generic_params::bounds(p); path_seg.abandon(p); path.abandon(p); @@ -137,3 +105,35 @@ fn generic_arg(p: &mut Parser) { } } } + +pub(super) fn const_arg(p: &mut Parser) { + let m = p.start(); + // FIXME: duplicates the code above + match p.current() { + T!['{'] => { + expressions::block_expr(p); + m.complete(p, CONST_ARG); + } + k if k.is_literal() => { + expressions::literal(p); + m.complete(p, CONST_ARG); + } + T![true] | T![false] => { + expressions::literal(p); + m.complete(p, CONST_ARG); + } + T![-] => { + let lm = p.start(); + p.bump(T![-]); + expressions::literal(p); + lm.complete(p, PREFIX_EXPR); + m.complete(p, CONST_ARG); + } + _ => { + let lm = p.start(); + paths::use_path(p); + lm.complete(p, PATH_EXPR); + m.complete(p, CONST_ARG); + } + } +} diff --git a/crates/parser/src/grammar/type_params.rs b/crates/parser/src/grammar/generic_params.rs similarity index 99% rename from crates/parser/src/grammar/type_params.rs rename to crates/parser/src/grammar/generic_params.rs index f5db4c7222f..b2ce101835d 100644 --- a/crates/parser/src/grammar/type_params.rs +++ b/crates/parser/src/grammar/generic_params.rs @@ -82,7 +82,7 @@ fn const_param(p: &mut Parser, m: Marker) { // struct B; // struct C; p.bump(T![=]); - type_args::const_arg(p); + generic_args::const_arg(p); } m.complete(p, CONST_PARAM); diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 96a2ba40129..517da6e95c4 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -284,15 +284,15 @@ fn type_alias(p: &mut Parser, m: Marker) { // test type_item_type_params // type Result = (); - type_params::opt_generic_param_list(p); + generic_params::opt_generic_param_list(p); if p.at(T![:]) { - type_params::bounds(p); + generic_params::bounds(p); } // test type_item_where_clause // type Foo where Foo: Copy = (); - type_params::opt_where_clause(p); + generic_params::opt_where_clause(p); if p.eat(T![=]) { types::type_(p); } @@ -383,7 +383,7 @@ fn fn_(p: &mut Parser, m: Marker) { name_r(p, ITEM_RECOVERY_SET); // test function_type_params // fn foo(){} - type_params::opt_generic_param_list(p); + generic_params::opt_generic_param_list(p); if p.at(T!['(']) { params::param_list_fn_def(p); @@ -397,7 +397,7 @@ fn fn_(p: &mut Parser, m: Marker) { // test function_where_clause // fn foo() where T: Copy {} - type_params::opt_where_clause(p); + generic_params::opt_where_clause(p); if p.at(T![;]) { // test fn_decl diff --git a/crates/parser/src/grammar/items/adt.rs b/crates/parser/src/grammar/items/adt.rs index e870de9de04..e4b1116958a 100644 --- a/crates/parser/src/grammar/items/adt.rs +++ b/crates/parser/src/grammar/items/adt.rs @@ -17,10 +17,10 @@ pub(super) fn union(p: &mut Parser, m: Marker) { fn struct_or_union(p: &mut Parser, m: Marker, is_struct: bool) { name_r(p, ITEM_RECOVERY_SET); - type_params::opt_generic_param_list(p); + generic_params::opt_generic_param_list(p); match p.current() { T![where] => { - type_params::opt_where_clause(p); + generic_params::opt_where_clause(p); match p.current() { T![;] => p.bump(T![;]), T!['{'] => record_field_list(p), @@ -42,7 +42,7 @@ fn struct_or_union(p: &mut Parser, m: Marker, is_struct: bool) { tuple_field_list(p); // test tuple_struct_where // struct S(T) where T: Clone; - type_params::opt_where_clause(p); + generic_params::opt_where_clause(p); p.expect(T![;]); } _ => p.error(if is_struct { "expected `;`, `{`, or `(`" } else { "expected `{`" }), @@ -53,8 +53,8 @@ fn struct_or_union(p: &mut Parser, m: Marker, is_struct: bool) { pub(super) fn enum_(p: &mut Parser, m: Marker) { p.bump(T![enum]); name_r(p, ITEM_RECOVERY_SET); - type_params::opt_generic_param_list(p); - type_params::opt_where_clause(p); + generic_params::opt_generic_param_list(p); + generic_params::opt_where_clause(p); if p.at(T!['{']) { variant_list(p); } else { diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index dd1ecf97e44..d6bb3b9b621 100644 --- a/crates/parser/src/grammar/items/traits.rs +++ b/crates/parser/src/grammar/items/traits.rs @@ -8,17 +8,17 @@ pub(super) fn trait_(p: &mut Parser, m: Marker) { // test trait_item_generic_params // trait X {} - type_params::opt_generic_param_list(p); + generic_params::opt_generic_param_list(p); if p.eat(T![=]) { // test trait_alias // trait Z = T; - type_params::bounds_without_colon(p); + generic_params::bounds_without_colon(p); // test trait_alias_where_clause // trait Z = T where U: Copy; // trait Z = where Self: T; - type_params::opt_where_clause(p); + generic_params::opt_where_clause(p); p.expect(T![;]); m.complete(p, TRAIT); return; @@ -27,12 +27,12 @@ pub(super) fn trait_(p: &mut Parser, m: Marker) { if p.at(T![:]) { // test trait_item_bounds // trait T: Hash + Clone {} - type_params::bounds(p); + generic_params::bounds(p); } // test trait_item_where_clause // trait T where Self: Copy {} - type_params::opt_where_clause(p); + generic_params::opt_where_clause(p); if p.at(T!['{']) { assoc_item_list(p); @@ -47,7 +47,7 @@ pub(super) fn trait_(p: &mut Parser, m: Marker) { pub(super) fn impl_(p: &mut Parser, m: Marker) { p.bump(T![impl]); if p.at(T![<]) && not_a_qualified_path(p) { - type_params::opt_generic_param_list(p); + generic_params::opt_generic_param_list(p); } // test impl_item_const @@ -64,7 +64,7 @@ pub(super) fn impl_(p: &mut Parser, m: Marker) { if p.eat(T![for]) { impl_type(p); } - type_params::opt_where_clause(p); + generic_params::opt_where_clause(p); if p.at(T!['{']) { assoc_item_list(p); } else { diff --git a/crates/parser/src/grammar/paths.rs b/crates/parser/src/grammar/paths.rs index c4e4f010ffb..e51dc38f973 100644 --- a/crates/parser/src/grammar/paths.rs +++ b/crates/parser/src/grammar/paths.rs @@ -117,9 +117,9 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) { params::param_list_fn_trait(p); opt_ret_type(p); } else { - type_args::opt_generic_arg_list(p, false) + generic_args::opt_generic_arg_list(p, false) } } - Mode::Expr => type_args::opt_generic_arg_list(p, true), + Mode::Expr => generic_args::opt_generic_arg_list(p, true), } } diff --git a/crates/parser/src/grammar/types.rs b/crates/parser/src/grammar/types.rs index e0b3c1bf0cb..c2aa9ffc3bd 100644 --- a/crates/parser/src/grammar/types.rs +++ b/crates/parser/src/grammar/types.rs @@ -216,7 +216,7 @@ pub(super) fn for_binder(p: &mut Parser) { assert!(p.at(T![for])); p.bump(T![for]); if p.at(T![<]) { - type_params::opt_generic_param_list(p); + generic_params::opt_generic_param_list(p); } else { p.error("expected `<`"); } @@ -254,7 +254,7 @@ fn impl_trait_type(p: &mut Parser) { assert!(p.at(T![impl])); let m = p.start(); p.bump(T![impl]); - type_params::bounds_without_colon(p); + generic_params::bounds_without_colon(p); m.complete(p, IMPL_TRAIT_TYPE); } @@ -264,7 +264,7 @@ fn dyn_trait_type(p: &mut Parser) { assert!(p.at(T![dyn])); let m = p.start(); p.bump(T![dyn]); - type_params::bounds_without_colon(p); + generic_params::bounds_without_colon(p); m.complete(p, DYN_TRAIT_TYPE); } @@ -339,7 +339,7 @@ fn opt_type_bounds_as_dyn_trait_type(p: &mut Parser, type_marker: CompletedMarke p.eat(T![+]); // Parse rest of the bounds into the TYPE_BOUND_LIST - let m = type_params::bounds_without_colon_m(p, m); + let m = generic_params::bounds_without_colon_m(p, m); // Finally precede everything with DYN_TRAIT_TYPE m.precede(p).complete(p, DYN_TRAIT_TYPE);