Skip to content

Commit af9fd37

Browse files
committed
internal: minimize use_tree parser tests
The code here is intentionally dense and does exactly what is written. Explaining semantic difference between Rust 2015 and 2018 doesn't help with understanding syntax. Better to just add more targeted tests.
1 parent 1d2e981 commit af9fd37

27 files changed

+304
-569
lines changed

crates/parser/src/grammar/items/use_item.rs

Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,60 @@
11
use super::*;
22

3+
// test use_item
4+
// use std::collections;
35
pub(super) fn use_(p: &mut Parser, m: Marker) {
4-
assert!(p.at(T![use]));
56
p.bump(T![use]);
67
use_tree(p, true);
78
p.expect(T![;]);
89
m.complete(p, USE);
910
}
1011

11-
/// Parse a use 'tree', such as `some::path` in `use some::path;`
12-
/// Note that this is called both by `use_item` and `use_tree_list`,
13-
/// so handles both `some::path::{inner::path}` and `inner::path` in
14-
/// `use some::path::{inner::path};`
12+
// test use_tree
13+
// use outer::tree::{inner::tree};
1514
fn use_tree(p: &mut Parser, top_level: bool) {
1615
let m = p.start();
1716
match p.current() {
18-
// Finish the use_tree for cases of e.g.
19-
// `use some::path::{self, *};` or `use *;`
20-
// This does not handle cases such as `use some::path::*`
21-
// N.B. in Rust 2015 `use *;` imports all from crate root
22-
// however in Rust 2018 `use *;` errors: ('cannot glob-import all possible crates')
23-
// FIXME: Add this error (if not out of scope)
24-
25-
// test use_star
17+
// test use_tree_star
2618
// use *;
27-
// use ::*;
28-
// use some::path::{*};
29-
// use some::path::{::*};
19+
// use std::{*};
3020
T![*] => p.bump(T![*]),
21+
// test use_tree_abs_star
22+
// use ::*;
23+
// use std::{::*};
3124
T![:] if p.at(T![::]) && p.nth(2) == T![*] => {
32-
// Parse `use ::*;`, which imports all from the crate root in Rust 2015
33-
// This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`)
34-
// but still parses and errors later: ('crate root in paths can only be used in start position')
35-
// FIXME: Add this error (if not out of scope)
36-
// In Rust 2018, it is always invalid (see above)
3725
p.bump(T![::]);
3826
p.bump(T![*]);
3927
}
40-
// Open a use tree list
41-
// Handles cases such as `use {some::path};` or `{inner::path}` in
42-
// `use some::path::{{inner::path}, other::path}`
43-
44-
// test use_tree_list
45-
// use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`)
46-
// use {path::from::root}; // Rust 2015
47-
// use ::{some::arbitrary::path}; // Rust 2015
48-
// use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting
49-
T!['{'] => {
50-
use_tree_list(p);
51-
}
28+
T!['{'] => use_tree_list(p),
5229
T![:] if p.at(T![::]) && p.nth(2) == T!['{'] => {
5330
p.bump(T![::]);
5431
use_tree_list(p);
5532
}
56-
// Parse a 'standard' path.
57-
// Also handles aliases (e.g. `use something as something_else`)
5833

59-
// test use_path
60-
// use ::crate_name; // Rust 2018 - All flavours
61-
// use crate_name; // Rust 2018 - Anchored paths
62-
// use item_in_scope_or_crate_name; // Rust 2018 - Uniform Paths
34+
// test use_tree_path
35+
// use ::std;
36+
// use std::collections;
6337
//
64-
// use self::module::Item;
65-
// use crate::Item;
66-
// use self::some::Struct;
67-
// use crate_name::some_item;
38+
// use self::m;
39+
// use super::m;
40+
// use crate::m;
6841
_ if paths::is_use_path_start(p) => {
6942
paths::use_path(p);
7043
match p.current() {
71-
T![as] => {
72-
// test use_alias
73-
// use some::path as some_name;
74-
// use some::{
75-
// other::path as some_other_name,
76-
// different::path as different_name,
77-
// yet::another::path,
78-
// running::out::of::synonyms::for_::different::*
79-
// };
80-
// use Trait as _;
81-
opt_rename(p);
82-
}
44+
// test use_tree_alias
45+
// use std as stdlib;
46+
// use Trait as _;
47+
T![as] => opt_rename(p),
8348
T![:] if p.at(T![::]) => {
8449
p.bump(T![::]);
8550
match p.current() {
86-
T![*] => {
87-
p.bump(T![*]);
88-
}
89-
// test use_tree_list_after_path
90-
// use crate::{Item};
91-
// use self::{Item};
51+
// test use_tree_path_star
52+
// use std::*;
53+
T![*] => p.bump(T![*]),
54+
// test use_tree_path_use_tree
55+
// use std::{collections};
9256
T!['{'] => use_tree_list(p),
93-
_ => {
94-
// is this unreachable?
95-
p.error("expected `{` or `*`");
96-
}
57+
_ => p.error("expected `{` or `*`"),
9758
}
9859
}
9960
_ => (),
@@ -115,6 +76,8 @@ fn use_tree(p: &mut Parser, top_level: bool) {
11576
m.complete(p, USE_TREE);
11677
}
11778

79+
// test use_tree_list
80+
// use {a, b, c};
11881
pub(crate) fn use_tree_list(p: &mut Parser) {
11982
assert!(p.at(T!['{']));
12083
let m = p.start();
Lines changed: 26 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,29 @@
1-
SOURCE_FILE@0..248
2-
USE@0..58
1+
SOURCE_FILE@0..15
2+
USE@0..14
33
44
5-
USE_TREE@4..57
6-
USE_TREE_LIST@4..57
5+
USE_TREE@4..13
6+
USE_TREE_LIST@4..13
77
8-
9-
10-
11-
12-
13-
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28-
29-
30-
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
45-
46-
47-
48-
49-
[email protected] "crate_name"
50-
51-
52-
53-
54-
[email protected] "// Rust 2018 (with a ..."
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
66-
67-
68-
69-
70-
71-
72-
73-
74-
75-
76-
77-
78-
79-
80-
[email protected] "// Rust 2015"
81-
82-
83-
84-
85-
86-
87-
88-
89-
90-
91-
92-
93-
94-
95-
96-
97-
98-
[email protected] "arbitrary"
99-
100-
101-
102-
103-
104-
105-
106-
107-
[email protected] "// Rust 2015"
108-
109-
110-
111-
112-
113-
114-
115-
116-
117-
118-
119-
120-
121-
122-
123-
124-
125-
126-
127-
128-
129-
130-
131-
132-
133-
134-
135-
136-
[email protected] "// Nonsensical but pe ..."
137-
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
use {crate::path::from::root, or::path::from::crate_name}; // Rust 2018 (with a crate named `or`)
2-
use {path::from::root}; // Rust 2015
3-
use ::{some::arbitrary::path}; // Rust 2015
4-
use ::{{{root::export}}}; // Nonsensical but perfectly legal nesting
1+
use {a, b, c};

crates/syntax/test_data/parser/inline/ok/0020_use_star.rast

Lines changed: 0 additions & 59 deletions
This file was deleted.

crates/syntax/test_data/parser/inline/ok/0020_use_star.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)