Unnamed repository; edit this file 'description' to name the repository.
27 files changed, 304 insertions, 569 deletions
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/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/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_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; |