Skip to content

Commit 3d8608a

Browse files
committed
Auto merge of rust-lang#80535 - JohnTitor:improve-use-diag, r=estebank
Add a note for `*` and `{}` usage on `use` Closes rust-lang#80333
2 parents 569e542 + d063745 commit 3d8608a

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

compiler/rustc_parse/src/parser/item.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,22 @@ impl<'a> Parser<'a> {
220220
let info = if self.eat_keyword(kw::Use) {
221221
// USE ITEM
222222
let tree = self.parse_use_tree()?;
223-
self.expect_semi()?;
223+
224+
// If wildcard or glob-like brace syntax doesn't have `;`,
225+
// the user may not know `*` or `{}` should be the last.
226+
if let Err(mut e) = self.expect_semi() {
227+
match tree.kind {
228+
UseTreeKind::Glob => {
229+
e.note("the wildcard token must be last on the path").emit();
230+
}
231+
UseTreeKind::Nested(..) => {
232+
e.note("glob-like brace syntax must be last on the path").emit();
233+
}
234+
_ => (),
235+
}
236+
return Err(e);
237+
}
238+
224239
(Ident::invalid(), ItemKind::Use(P(tree)))
225240
} else if self.check_fn_front_matter() {
226241
// FUNCTION ITEM

src/test/ui/parser/import-from-path.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: expected `;`, found `::`
33
|
44
LL | use foo::{bar}::baz
55
| ^^ expected `;`
6+
|
7+
= note: glob-like brace syntax must be last on the path
68

79
error: aborting due to previous error
810

src/test/ui/parser/import-from-rename.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: expected `;`, found keyword `as`
33
|
44
LL | use foo::{bar} as baz;
55
| ^^ expected `;`
6+
|
7+
= note: glob-like brace syntax must be last on the path
68

79
error: aborting due to previous error
810

src/test/ui/parser/import-glob-path.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: expected `;`, found `::`
33
|
44
LL | use foo::*::bar
55
| ^^ expected `;`
6+
|
7+
= note: the wildcard token must be last on the path
68

79
error: aborting due to previous error
810

src/test/ui/parser/import-glob-rename.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: expected `;`, found keyword `as`
33
|
44
LL | use foo::* as baz;
55
| ^^ expected `;`
6+
|
7+
= note: the wildcard token must be last on the path
68

79
error: aborting due to previous error
810

0 commit comments

Comments
 (0)