Unnamed repository; edit this file 'description' to name the repository.
Merge #10276
10276: internal: parser cleanup r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
46 files changed, 555 insertions, 759 deletions
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 58e182d68c..d0b07f5931 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -34,8 +34,8 @@ mod items; 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 12e62cddbc..29310b71bd 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 index f09a28c443..cd75d20a42 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) { @@ -83,7 +51,7 @@ fn generic_arg(p: &mut Parser) { path_ty.abandon(p); m.complete(p, ASSOC_TYPE_ARG); } - T![:] if p.nth(1) == T![:] => { + T![:] if p.at(T![::]) => { // NameRef::, this is a path type path_seg.complete(p, PATH_SEGMENT); let qual = path.complete(p, PATH); @@ -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 index a7a0109fd1..b8119f0a21 100644 --- a/crates/parser/src/grammar/type_params.rs +++ b/crates/parser/src/grammar/generic_params.rs @@ -1,34 +1,20 @@ use super::*; pub(super) fn opt_generic_param_list(p: &mut Parser) { - if !p.at(T![<]) { - return; + if p.at(T![<]) { + generic_param_list(p); } - generic_param_list(p); } +// test generic_param_list +// fn f<T: Clone>() {} fn generic_param_list(p: &mut Parser) { assert!(p.at(T![<])); let m = p.start(); p.bump(T![<]); while !p.at(EOF) && !p.at(T![>]) { - let m = p.start(); - - // test generic_lifetime_type_attribute - // fn foo<#[derive(Lifetime)] 'a, #[derive(Type)] T>(_: &'a 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,24 @@ 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) { assert!(p.at(LIFETIME_IDENT)); lifetime(p); @@ -46,15 +50,17 @@ fn lifetime_param(p: &mut Parser, m: Marker) { m.complete(p, LIFETIME_PARAM); } +// test type_param +// fn f<T: Clone>() {} fn type_param(p: &mut Parser, m: Marker) { assert!(p.at(IDENT)); name(p); if p.at(T![:]) { bounds(p); } - // test type_param_default - // struct S<T = i32>; if p.at(T![=]) { + // test type_param_default + // struct S<T = i32>; p.bump(T![=]); types::type_(p) } @@ -64,7 +70,6 @@ fn type_param(p: &mut Parser, m: Marker) { // test const_param // struct S<const N: u32>; fn const_param(p: &mut Parser, m: Marker) { - assert!(p.at(T![const])); p.bump(T![const]); name(p); if p.at(T![:]) { @@ -73,26 +78,18 @@ fn const_param(p: &mut Parser, m: Marker) { p.error("missing type for const parameter"); } - // test const_param_defaults - // struct A<const N: i32 = -1>; - // struct B<const N: i32 = {}>; - // struct C<const N: i32 = some::CONST>; if p.at(T![=]) { + // test const_param_defaults + // struct A<const N: i32 = -1>; + // struct B<const N: i32 = {}>; + // struct C<const N: i32 = some::CONST>; p.bump(T![=]); - type_args::const_arg(p); + generic_args::const_arg(p); } m.complete(p, CONST_PARAM); } -// test type_param_bounds -// struct S<T: 'a + ?Sized + (Copy)>; -pub(super) fn bounds(p: &mut Parser) { - assert!(p.at(T![:])); - p.bump(T![:]); - bounds_without_colon(p); -} - fn lifetime_bounds(p: &mut Parser) { assert!(p.at(T![:])); p.bump(T![:]); @@ -104,21 +101,28 @@ fn lifetime_bounds(p: &mut Parser) { } } +// test type_param_bounds +// struct S<T: 'a + ?Sized + (Copy)>; +pub(super) fn bounds(p: &mut Parser) { + assert!(p.at(T![:])); + p.bump(T![:]); + bounds_without_colon(p); +} + +pub(super) fn bounds_without_colon(p: &mut Parser) { + let m = p.start(); + bounds_without_colon_m(p, m); +} + pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> CompletedMarker { while type_bound(p) { if !p.eat(T![+]) { break; } } - marker.complete(p, TYPE_BOUND_LIST) } -pub(super) fn bounds_without_colon(p: &mut Parser) { - let m = p.start(); - bounds_without_colon_m(p, m); -} - fn type_bound(p: &mut Parser) -> bool { let m = p.start(); let has_paren = p.eat(T!['(']); @@ -160,8 +164,9 @@ pub(super) fn opt_where_clause(p: &mut Parser) { let comma = p.eat(T![,]); - if is_where_clause_end(p) { - break; + match p.current() { + T!['{'] | T![;] | T![=] => break, + _ => (), } if !comma { @@ -170,20 +175,16 @@ pub(super) fn opt_where_clause(p: &mut Parser) { } m.complete(p, WHERE_CLAUSE); -} -fn is_where_predicate(p: &mut Parser) -> bool { - match p.current() { - LIFETIME_IDENT => true, - T![impl] => false, - token => types::TYPE_FIRST.contains(token), + fn is_where_predicate(p: &mut Parser) -> bool { + match p.current() { + LIFETIME_IDENT => true, + T![impl] => false, + token => types::TYPE_FIRST.contains(token), + } } } -fn is_where_clause_end(p: &mut Parser) -> bool { - matches!(p.current(), T!['{'] | T![;] | T![=]) -} - fn where_predicate(p: &mut Parser) { let m = p.start(); match p.current() { @@ -199,12 +200,12 @@ fn where_predicate(p: &mut Parser) { p.error("expected lifetime or type"); } _ => { - // test where_pred_for - // fn for_trait<F>() - // where - // for<'a> F: Fn(&'a str) - // { } if p.at(T![for]) { + // test where_pred_for + // fn for_trait<F>() + // where + // for<'a> F: Fn(&'a str) + // { } types::for_binder(p); } diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 13d9f9e1ab..517da6e95c 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -19,7 +19,7 @@ use super::*; // struct S; pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { attributes::inner_attrs(p); - while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) { + while !p.at(EOF) && !(p.at(T!['}']) && stop_on_r_curly) { item_or_macro(p, stop_on_r_curly) } } @@ -284,15 +284,15 @@ fn type_alias(p: &mut Parser, m: Marker) { // test type_item_type_params // type Result<T> = (); - 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<T: Clone + Copy>(){} - 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<T>() 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 e870de9de0..e4b1116958 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>(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 dd1ecf97e4..d6bb3b9b62 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<U: Debug + Display> {} - type_params::opt_generic_param_list(p); + generic_params::opt_generic_param_list(p); if p.eat(T![=]) { // test trait_alias // trait Z<U> = T<U>; - type_params::bounds_without_colon(p); + generic_params::bounds_without_colon(p); // test trait_alias_where_clause // trait Z<U> = T<U> where U: Copy; // trait Z<U> = where Self: T<U>; - 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/items/use_item.rs b/crates/parser/src/grammar/items/use_item.rs index 2339d0c69c..ffb147b1fd 100644 --- a/crates/parser/src/grammar/items/use_item.rs +++ b/crates/parser/src/grammar/items/use_item.rs @@ -1,99 +1,60 @@ use super::*; +// test use_item +// use std::collections; pub(super) fn use_(p: &mut Parser, m: Marker) { - assert!(p.at(T![use])); p.bump(T![use]); use_tree(p, true); p.expect(T![;]); m.complete(p, USE); } -/// Parse a use 'tree', such as `some::path` in `use some::path;` -/// Note that this is called both by `use_item` and `use_tree_list`, -/// so handles both `some::path::{inner::path}` and `inner::path` in -/// `use some::path::{inner::path};` +// test use_tree +// use outer::tree::{inner::tree}; fn use_tree(p: &mut Parser, top_level: bool) { let m = p.start(); match p.current() { - // Finish the use_tree for cases of e.g. - // `use some::path::{self, *};` or `use *;` - // This does not handle cases such as `use some::path::*` - // N.B. in Rust 2015 `use *;` imports all from crate root - // however in Rust 2018 `use *;` errors: ('cannot glob-import all possible crates') - // FIXME: Add this error (if not out of scope) - - // test use_star + // test use_tree_star // use *; - // use ::*; - // use some::path::{*}; - // use some::path::{::*}; + // use std::{*}; T![*] => p.bump(T![*]), + // test use_tree_abs_star + // use ::*; + // use std::{::*}; T![:] if p.at(T![::]) && p.nth(2) == T![*] => { - // Parse `use ::*;`, which imports all from the crate root in Rust 2015 - // This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`) - // but still parses and errors later: ('crate root in paths can only be used in start position') - // FIXME: Add this error (if not out of scope) - // In Rust 2018, it is always invalid (see above) p.bump(T![::]); p.bump(T![*]); } - // Open a use tree list - // Handles cases such as `use {some::path};` or `{inner::path}` in - // `use some::path::{{inner::path}, other::path}` - - // test use_tree_list - // use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`) - // use {path::from::root}; // Rust 2015 - // use ::{some::arbitrary::path}; // Rust 2015 - // use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting - T!['{'] => { - use_tree_list(p); - } + T!['{'] => use_tree_list(p), T![:] if p.at(T![::]) && p.nth(2) == T!['{'] => { p.bump(T![::]); use_tree_list(p); } - // Parse a 'standard' path. - // Also handles aliases (e.g. `use something as something_else`) - // test use_path - // use ::crate_name; // Rust 2018 - All flavours - // use crate_name; // Rust 2018 - Anchored paths - // use item_in_scope_or_crate_name; // Rust 2018 - Uniform Paths + // test use_tree_path + // use ::std; + // use std::collections; // - // use self::module::Item; - // use crate::Item; - // use self::some::Struct; - // use crate_name::some_item; + // use self::m; + // use super::m; + // use crate::m; _ if paths::is_use_path_start(p) => { paths::use_path(p); match p.current() { - T![as] => { - // test use_alias - // use some::path as some_name; - // use some::{ - // other::path as some_other_name, - // different::path as different_name, - // yet::another::path, - // running::out::of::synonyms::for_::different::* - // }; - // use Trait as _; - opt_rename(p); - } + // test use_tree_alias + // use std as stdlib; + // use Trait as _; + T![as] => opt_rename(p), T![:] if p.at(T![::]) => { p.bump(T![::]); match p.current() { - T![*] => { - p.bump(T![*]); - } - // test use_tree_list_after_path - // use crate::{Item}; - // use self::{Item}; + // test use_tree_path_star + // use std::*; + T![*] => p.bump(T![*]), + // test use_tree_path_use_tree + // use std::{collections}; T!['{'] => use_tree_list(p), - _ => { - // is this unreachable? - p.error("expected `{` or `*`"); - } + _ => p.error("expected `{` or `*`"), } } _ => (), @@ -115,6 +76,8 @@ fn use_tree(p: &mut Parser, top_level: bool) { m.complete(p, USE_TREE); } +// test use_tree_list +// use {a, b, c}; pub(crate) fn use_tree_list(p: &mut Parser) { assert!(p.at(T!['{'])); let m = p.start(); diff --git a/crates/parser/src/grammar/paths.rs b/crates/parser/src/grammar/paths.rs index c4e4f010ff..e51dc38f97 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 e0b3c1bf0c..c2aa9ffc3b 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); diff --git a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast index 970826739f..9bee074b7b 100644 --- a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast +++ b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast @@ -1,137 +1,29 @@ [email protected] "use" - [email protected] "crate" - [email protected] "::" - [email protected] "path" - [email protected] "::" - [email protected] "from" - [email protected] "::" - [email protected] "root" - [email protected] "," - [email protected] " " - [email protected] "or" - [email protected] "::" - [email protected] "path" - [email protected] "::" - [email protected] "from" - [email protected] "::" - [email protected] "crate_name" - [email protected] "}" - [email protected] ";" - [email protected] " " - [email protected] "// Rust 2018 (with a ..." - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "{" - [email protected] "path" - [email protected] "::" - [email protected] "from" - [email protected] "::" - [email protected] "root" - [email protected] "}" - [email protected] ";" - [email protected] " " - [email protected] "// Rust 2015" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "::" - [email protected] "{" - [email protected] "some" - [email protected] "::" - [email protected] "arbitrary" - [email protected] "::" - [email protected] "path" - [email protected] "}" - [email protected] ";" - [email protected] " " - [email protected] "// Rust 2015" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "::" - [email protected] "{" - [email protected] "{" - [email protected] "{" - [email protected] "root" - [email protected] "::" - [email protected] "export" - [email protected] "}" - [email protected] "}" - [email protected] "}" - [email protected] ";" - [email protected] " " - [email protected] "// Nonsensical but pe ..." - [email protected] "\n" + [email protected] "a" + [email protected] "," + [email protected] " " + [email protected] "b" + [email protected] "," + [email protected] " " + [email protected] "c" + [email protected] "}" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs index 02af4b446e..6fa175f542 100644 --- a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs +++ b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rs @@ -1,4 +1 @@ -use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`) -use {path::from::root}; // Rust 2015 -use ::{some::arbitrary::path}; // Rust 2015 -use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting +use {a, b, c}; diff --git a/crates/syntax/test_data/parser/inline/ok/0020_use_star.rast b/crates/syntax/test_data/parser/inline/ok/0020_use_star.rast deleted file mode 100644 index b3623c4455..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0020_use_star.rast +++ /dev/null @@ -1,59 +0,0 @@ - [email protected] "use" - [email protected] " " - [email protected] "*" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "::" - [email protected] "*" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "some" - [email protected] "::" - [email protected] "path" - [email protected] "::" - [email protected] "{" - [email protected] "*" - [email protected] "}" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "some" - [email protected] "::" - [email protected] "path" - [email protected] "::" - [email protected] "{" - [email protected] "::" - [email protected] "*" - [email protected] "}" - [email protected] ";" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0020_use_star.rs b/crates/syntax/test_data/parser/inline/ok/0020_use_star.rs deleted file mode 100644 index 6f15769a8c..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0020_use_star.rs +++ /dev/null @@ -1,4 +0,0 @@ -use *; -use ::*; -use some::path::{*}; -use some::path::{::*}; diff --git a/crates/syntax/test_data/parser/inline/ok/0043_use_alias.rast b/crates/syntax/test_data/parser/inline/ok/0043_use_alias.rast deleted file mode 100644 index 60b517230e..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0043_use_alias.rast +++ /dev/null @@ -1,138 +0,0 @@ - [email protected] "use" - [email protected] " " - [email protected] "some" - [email protected] "::" - [email protected] "path" - [email protected] " " - [email protected] "as" - [email protected] " " - [email protected] "some_name" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "some" - [email protected] "::" - [email protected] "{" - [email protected] "\n " - [email protected] "other" - [email protected] "::" - [email protected] "path" - [email protected] " " - [email protected] "as" - [email protected] " " - [email protected] "some_other_name" - [email protected] "," - [email protected] "\n " - [email protected] "different" - [email protected] "::" - [email protected] "path" - [email protected] " " - [email protected] "as" - [email protected] " " - [email protected] "different_name" - [email protected] "," - [email protected] "\n " - [email protected] "yet" - [email protected] "::" - [email protected] "another" - [email protected] "::" - [email protected] "path" - [email protected] "," - [email protected] "\n " - [email protected] "running" - [email protected] "::" - [email protected] "out" - [email protected] "::" - [email protected] "of" - [email protected] "::" - [email protected] "synonyms" - [email protected] "::" - [email protected] "for_" - [email protected] "::" - [email protected] "different" - [email protected] "::" - [email protected] "*" - [email protected] "\n" - [email protected] "}" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "Trait" - [email protected] " " - [email protected] "as" - [email protected] " " - [email protected] "_" - [email protected] ";" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0043_use_alias.rs b/crates/syntax/test_data/parser/inline/ok/0043_use_alias.rs deleted file mode 100644 index 9be50f8770..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0043_use_alias.rs +++ /dev/null @@ -1,8 +0,0 @@ -use some::path as some_name; -use some::{ - other::path as some_other_name, - different::path as different_name, - yet::another::path, - running::out::of::synonyms::for_::different::* -}; -use Trait as _; diff --git a/crates/syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rast b/crates/syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rast deleted file mode 100644 index 192a9cca68..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rast +++ /dev/null @@ -1,39 +0,0 @@ - [email protected] "use" - [email protected] " " - [email protected] "crate" - [email protected] "::" - [email protected] "{" - [email protected] "Item" - [email protected] "}" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "self" - [email protected] "::" - [email protected] "{" - [email protected] "Item" - [email protected] "}" - [email protected] ";" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rs b/crates/syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rs deleted file mode 100644 index c0a3d634e5..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0069_use_tree_list_after_path.rs +++ /dev/null @@ -1,2 +0,0 @@ -use crate::{Item}; -use self::{Item}; diff --git a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast b/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast deleted file mode 100644 index ac51eb91d2..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast +++ /dev/null @@ -1,108 +0,0 @@ - [email protected] "use" - [email protected] " " - [email protected] "::" - [email protected] "crate_name" - [email protected] ";" - [email protected] " " - [email protected] "// Rust 2018 - All fl ..." - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "crate_name" - [email protected] ";" - [email protected] " " - [email protected] "// Rust 2018 - Anchor ..." - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "item_in_scope_or_crat ..." - [email protected] ";" - [email protected] " " - [email protected] "// Rust 2018 - Unifor ..." - [email protected] "\n\n" - [email protected] "use" - [email protected] " " - [email protected] "self" - [email protected] "::" - [email protected] "module" - [email protected] "::" - [email protected] "Item" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "crate" - [email protected] "::" - [email protected] "Item" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "self" - [email protected] "::" - [email protected] "some" - [email protected] "::" - [email protected] "Struct" - [email protected] ";" - [email protected] "\n" - [email protected] "use" - [email protected] " " - [email protected] "crate_name" - [email protected] "::" - [email protected] "some_item" - [email protected] ";" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rs b/crates/syntax/test_data/parser/inline/ok/0110_use_path.rs deleted file mode 100644 index 1e436a6bc2..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rs +++ /dev/null @@ -1,8 +0,0 @@ -use ::crate_name; // Rust 2018 - All flavours -use crate_name; // Rust 2018 - Anchored paths -use item_in_scope_or_crate_name; // Rust 2018 - Uniform Paths - -use self::module::Item; -use crate::Item; -use self::some::Struct; -use crate_name::some_item; diff --git a/crates/syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rast b/crates/syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rast deleted file mode 100644 index 5682bd28c5..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rast +++ /dev/null @@ -1,69 +0,0 @@ - [email protected] "fn" - [email protected] " " - [email protected] "foo" - [email protected] "<" - [email protected] "#" - [email protected] "[" - [email protected] "derive" - [email protected] "(" - [email protected] "Lifetime" - [email protected] ")" - [email protected] "]" - [email protected] " " - [email protected] "'a" - [email protected] "," - [email protected] " " - [email protected] "#" - [email protected] "[" - [email protected] "derive" - [email protected] "(" - [email protected] "Type" - [email protected] ")" - [email protected] "]" - [email protected] " " - [email protected] "T" - [email protected] ">" - [email protected] "(" - [email protected] "_" - [email protected] ":" - [email protected] " " - [email protected] "&" - [email protected] "'a" - [email protected] " " - [email protected] "T" - [email protected] ")" - [email protected] " " - [email protected] "{" - [email protected] "\n" - [email protected] "}" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rs b/crates/syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rs deleted file mode 100644 index e8fdf741fb..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0122_generic_lifetime_type_attribute.rs +++ /dev/null @@ -1,2 +0,0 @@ -fn foo<#[derive(Lifetime)] 'a, #[derive(Type)] T>(_: &'a T) { -} diff --git a/crates/syntax/test_data/parser/inline/ok/0174_use_tree_star.rast b/crates/syntax/test_data/parser/inline/ok/0174_use_tree_star.rast new file mode 100644 index 0000000000..b9c6a3bed8 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0174_use_tree_star.rast @@ -0,0 +1,24 @@ + [email protected] "use" + [email protected] " " + [email protected] "*" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "std" + [email protected] "::" + [email protected] "{" + [email protected] "*" + [email protected] "}" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0174_use_tree_star.rs b/crates/syntax/test_data/parser/inline/ok/0174_use_tree_star.rs new file mode 100644 index 0000000000..b8c613440d --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0174_use_tree_star.rs @@ -0,0 +1,2 @@ +use *; +use std::{*}; diff --git a/crates/syntax/test_data/parser/inline/ok/0176_use_tree_alias.rast b/crates/syntax/test_data/parser/inline/ok/0176_use_tree_alias.rast new file mode 100644 index 0000000000..210ff1f981 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0176_use_tree_alias.rast @@ -0,0 +1,32 @@ + [email protected] "use" + [email protected] " " + [email protected] "std" + [email protected] " " + [email protected] "as" + [email protected] " " + [email protected] "stdlib" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "Trait" + [email protected] " " + [email protected] "as" + [email protected] " " + [email protected] "_" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0176_use_tree_alias.rs b/crates/syntax/test_data/parser/inline/ok/0176_use_tree_alias.rs new file mode 100644 index 0000000000..19a6906a26 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0176_use_tree_alias.rs @@ -0,0 +1,2 @@ +use std as stdlib; +use Trait as _; diff --git a/crates/syntax/test_data/parser/inline/ok/0177_use_tree.rast b/crates/syntax/test_data/parser/inline/ok/0177_use_tree.rast new file mode 100644 index 0000000000..978d2963e8 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_use_tree.rast @@ -0,0 +1,30 @@ + [email protected] "use" + [email protected] " " + [email protected] "outer" + [email protected] "::" + [email protected] "tree" + [email protected] "::" + [email protected] "{" + [email protected] "inner" + [email protected] "::" + [email protected] "tree" + [email protected] "}" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0177_use_tree.rs b/crates/syntax/test_data/parser/inline/ok/0177_use_tree.rs new file mode 100644 index 0000000000..3cc3943482 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_use_tree.rs @@ -0,0 +1 @@ +use outer::tree::{inner::tree}; diff --git a/crates/syntax/test_data/parser/inline/ok/0177_use_tree_path.rast b/crates/syntax/test_data/parser/inline/ok/0177_use_tree_path.rast new file mode 100644 index 0000000000..24086b5a1d --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_use_tree_path.rast @@ -0,0 +1,72 @@ + [email protected] "use" + [email protected] " " + [email protected] "::" + [email protected] "std" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "std" + [email protected] "::" + [email protected] "collections" + [email protected] ";" + [email protected] "\n\n" + [email protected] "use" + [email protected] " " + [email protected] "self" + [email protected] "::" + [email protected] "m" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "super" + [email protected] "::" + [email protected] "m" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "crate" + [email protected] "::" + [email protected] "m" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0177_use_tree_path.rs b/crates/syntax/test_data/parser/inline/ok/0177_use_tree_path.rs new file mode 100644 index 0000000000..5b22f88523 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_use_tree_path.rs @@ -0,0 +1,6 @@ +use ::std; +use std::collections; + +use self::m; +use super::m; +use crate::m; diff --git a/crates/syntax/test_data/parser/inline/ok/0178_use_tree_path_use_tree.rast b/crates/syntax/test_data/parser/inline/ok/0178_use_tree_path_use_tree.rast new file mode 100644 index 0000000000..620a792306 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0178_use_tree_path_use_tree.rast @@ -0,0 +1,20 @@ + [email protected] "use" + [email protected] " " + [email protected] "std" + [email protected] "::" + [email protected] "{" + [email protected] "collections" + [email protected] "}" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0178_use_tree_path_use_tree.rs b/crates/syntax/test_data/parser/inline/ok/0178_use_tree_path_use_tree.rs new file mode 100644 index 0000000000..c3086f51a2 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0178_use_tree_path_use_tree.rs @@ -0,0 +1 @@ +use std::{collections}; diff --git a/crates/syntax/test_data/parser/inline/ok/0179_use_tree_abs_star.rast b/crates/syntax/test_data/parser/inline/ok/0179_use_tree_abs_star.rast new file mode 100644 index 0000000000..4b132f2ded --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0179_use_tree_abs_star.rast @@ -0,0 +1,26 @@ + [email protected] "use" + [email protected] " " + [email protected] "::" + [email protected] "*" + [email protected] ";" + [email protected] "\n" + [email protected] "use" + [email protected] " " + [email protected] "std" + [email protected] "::" + [email protected] "{" + [email protected] "::" + [email protected] "*" + [email protected] "}" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0179_use_tree_abs_star.rs b/crates/syntax/test_data/parser/inline/ok/0179_use_tree_abs_star.rs new file mode 100644 index 0000000000..caae0ba026 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0179_use_tree_abs_star.rs @@ -0,0 +1,2 @@ +use ::*; +use std::{::*}; diff --git a/crates/syntax/test_data/parser/inline/ok/0180_use_tree_path_star.rast b/crates/syntax/test_data/parser/inline/ok/0180_use_tree_path_star.rast new file mode 100644 index 0000000000..93384d6ed7 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0180_use_tree_path_star.rast @@ -0,0 +1,13 @@ + [email protected] "use" + [email protected] " " + [email protected] "std" + [email protected] "::" + [email protected] "*" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0180_use_tree_path_star.rs b/crates/syntax/test_data/parser/inline/ok/0180_use_tree_path_star.rs new file mode 100644 index 0000000000..dd601cffe5 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0180_use_tree_path_star.rs @@ -0,0 +1 @@ +use std::*; diff --git a/crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rast b/crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rast new file mode 100644 index 0000000000..475c236766 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rast @@ -0,0 +1,45 @@ + [email protected] "fn" + [email protected] " " + [email protected] "foo" + [email protected] "<" + [email protected] "#" + [email protected] "[" + [email protected] "lt_attr" + [email protected] "]" + [email protected] " " + [email protected] "'a" + [email protected] "," + [email protected] " " + [email protected] "#" + [email protected] "[" + [email protected] "t_attr" + [email protected] "]" + [email protected] " " + [email protected] "T" + [email protected] ">" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rs b/crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rs new file mode 100644 index 0000000000..0509f81da7 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0181_generic_param_attribute.rs @@ -0,0 +1 @@ +fn foo<#[lt_attr] 'a, #[t_attr] T>() {} diff --git a/crates/syntax/test_data/parser/inline/ok/0181_use_item.rast b/crates/syntax/test_data/parser/inline/ok/0181_use_item.rast new file mode 100644 index 0000000000..3952fcf09e --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0181_use_item.rast @@ -0,0 +1,16 @@ + [email protected] "use" + [email protected] " " + [email protected] "std" + [email protected] "::" + [email protected] "collections" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0181_use_item.rs b/crates/syntax/test_data/parser/inline/ok/0181_use_item.rs new file mode 100644 index 0000000000..48ac87b14a --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0181_use_item.rs @@ -0,0 +1 @@ +use std::collections; diff --git a/crates/syntax/test_data/parser/inline/ok/0182_lifetime_param.rast b/crates/syntax/test_data/parser/inline/ok/0182_lifetime_param.rast new file mode 100644 index 0000000000..0eb7361ce4 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0182_lifetime_param.rast @@ -0,0 +1,24 @@ + [email protected] "fn" + [email protected] " " + [email protected] "f" + [email protected] "<" + [email protected] "'a" + [email protected] ":" + [email protected] " " + [email protected] "'b" + [email protected] ">" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0182_lifetime_param.rs b/crates/syntax/test_data/parser/inline/ok/0182_lifetime_param.rs new file mode 100644 index 0000000000..2bb38ece8c --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0182_lifetime_param.rs @@ -0,0 +1 @@ +fn f<'a: 'b>() {} diff --git a/crates/syntax/test_data/parser/inline/ok/0183_type_param.rast b/crates/syntax/test_data/parser/inline/ok/0183_type_param.rast new file mode 100644 index 0000000000..9d8ab493e0 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0183_type_param.rast @@ -0,0 +1,29 @@ + [email protected] "fn" + [email protected] " " + [email protected] "f" + [email protected] "<" + [email protected] "T" + [email protected] ":" + [email protected] " " + [email protected] "Clone" + [email protected] ">" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0183_type_param.rs b/crates/syntax/test_data/parser/inline/ok/0183_type_param.rs new file mode 100644 index 0000000000..b250bc6bf0 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0183_type_param.rs @@ -0,0 +1 @@ +fn f<T: Clone>() {} diff --git a/crates/syntax/test_data/parser/inline/ok/0184_generic_param_list.rast b/crates/syntax/test_data/parser/inline/ok/0184_generic_param_list.rast new file mode 100644 index 0000000000..9d8ab493e0 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0184_generic_param_list.rast @@ -0,0 +1,29 @@ + [email protected] "fn" + [email protected] " " + [email protected] "f" + [email protected] "<" + [email protected] "T" + [email protected] ":" + [email protected] " " + [email protected] "Clone" + [email protected] ">" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0184_generic_param_list.rs b/crates/syntax/test_data/parser/inline/ok/0184_generic_param_list.rs new file mode 100644 index 0000000000..b250bc6bf0 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0184_generic_param_list.rs @@ -0,0 +1 @@ +fn f<T: Clone>() {} |