Skip to content

Add a note for * and {} usage on use #80535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,22 @@ impl<'a> Parser<'a> {
let info = if self.eat_keyword(kw::Use) {
// USE ITEM
let tree = self.parse_use_tree()?;
self.expect_semi()?;

// If wildcard or glob-like brace syntax doesn't have `;`,
// the user may not know `*` or `{}` should be the last.
if let Err(mut e) = self.expect_semi() {
match tree.kind {
UseTreeKind::Glob => {
e.note("the wildcard token must be last on the path").emit();
}
UseTreeKind::Nested(..) => {
e.note("glob-like brace syntax must be last on the path").emit();
}
_ => (),
}
return Err(e);
}

(Ident::invalid(), ItemKind::Use(P(tree)))
} else if self.check_fn_front_matter() {
// FUNCTION ITEM
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/parser/import-from-path.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error: expected `;`, found `::`
|
LL | use foo::{bar}::baz
| ^^ expected `;`
|
= note: glob-like brace syntax must be last on the path

error: aborting due to previous error

2 changes: 2 additions & 0 deletions src/test/ui/parser/import-from-rename.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error: expected `;`, found keyword `as`
|
LL | use foo::{bar} as baz;
| ^^ expected `;`
|
= note: glob-like brace syntax must be last on the path

error: aborting due to previous error

2 changes: 2 additions & 0 deletions src/test/ui/parser/import-glob-path.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error: expected `;`, found `::`
|
LL | use foo::*::bar
| ^^ expected `;`
|
= note: the wildcard token must be last on the path

error: aborting due to previous error

2 changes: 2 additions & 0 deletions src/test/ui/parser/import-glob-rename.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error: expected `;`, found keyword `as`
|
LL | use foo::* as baz;
| ^^ expected `;`
|
= note: the wildcard token must be last on the path

error: aborting due to previous error