about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-11-09 21:53:34 -0800
committerGitHub <noreply@github.com>2022-11-09 21:53:34 -0800
commit0c4a81c97b6309e7239eb0000bc46a5d348a2230 (patch)
tree7f4b833cca7635b5f1cb5479c388108171204375 /compiler/rustc_parse/src/parser
parente5ecf629dd0e36e0aab9c664c7a3d11d592268c9 (diff)
parentaa5a3266f408bc82dc0c1e8e9e30841c208e8228 (diff)
downloadrust-0c4a81c97b6309e7239eb0000bc46a5d348a2230.tar.gz
rust-0c4a81c97b6309e7239eb0000bc46a5d348a2230.zip
Rollup merge of #103443 - mucinoab:recover-colon-as-path-separetor, r=compiler-errors
Parser: Recover from using colon as path separator in imports

I don't know if this is the right approach, any feedback is welcome.

r? ```@compiler-errors```

Fixes #103269
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index bda301c52e9..d657a289117 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -971,6 +971,23 @@ impl<'a> Parser<'a> {
             if self.eat(&token::ModSep) {
                 self.parse_use_tree_glob_or_nested()?
             } else {
+                // Recover from using a colon as path separator.
+                while self.eat_noexpect(&token::Colon) {
+                    self.struct_span_err(self.prev_token.span, "expected `::`, found `:`")
+                        .span_suggestion_short(
+                            self.prev_token.span,
+                            "use double colon",
+                            "::",
+                            Applicability::MachineApplicable,
+                        )
+                        .note_once("import paths are delimited using `::`")
+                        .emit();
+
+                    // We parse the rest of the path and append it to the original prefix.
+                    self.parse_path_segments(&mut prefix.segments, PathStyle::Mod, None)?;
+                    prefix.span = lo.to(self.prev_token.span);
+                }
+
                 UseTreeKind::Simple(self.parse_rename()?, DUMMY_NODE_ID, DUMMY_NODE_ID)
             }
         };