From d063745023441918c409a66b2607b057163b4144 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 31 Dec 2020 07:40:54 +0900 Subject: [PATCH] Add a note for `*` and `{}` usage on `use` --- compiler/rustc_parse/src/parser/item.rs | 17 ++++++++++++++++- src/test/ui/parser/import-from-path.stderr | 2 ++ src/test/ui/parser/import-from-rename.stderr | 2 ++ src/test/ui/parser/import-glob-path.stderr | 2 ++ src/test/ui/parser/import-glob-rename.stderr | 2 ++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index e49b1a54e9b12..4fcc9edb7d91b 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -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 diff --git a/src/test/ui/parser/import-from-path.stderr b/src/test/ui/parser/import-from-path.stderr index 5842037fb8050..93bdf82d0f576 100644 --- a/src/test/ui/parser/import-from-path.stderr +++ b/src/test/ui/parser/import-from-path.stderr @@ -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 diff --git a/src/test/ui/parser/import-from-rename.stderr b/src/test/ui/parser/import-from-rename.stderr index a966e9937373a..d78f6de9222cf 100644 --- a/src/test/ui/parser/import-from-rename.stderr +++ b/src/test/ui/parser/import-from-rename.stderr @@ -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 diff --git a/src/test/ui/parser/import-glob-path.stderr b/src/test/ui/parser/import-glob-path.stderr index ebca2db8305c3..a93ef255c94b2 100644 --- a/src/test/ui/parser/import-glob-path.stderr +++ b/src/test/ui/parser/import-glob-path.stderr @@ -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 diff --git a/src/test/ui/parser/import-glob-rename.stderr b/src/test/ui/parser/import-glob-rename.stderr index 2853873278251..e1a026b639e7e 100644 --- a/src/test/ui/parser/import-glob-rename.stderr +++ b/src/test/ui/parser/import-glob-rename.stderr @@ -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