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
This commit is contained in:
commit
0c4a81c97b
@ -971,6 +971,23 @@ impl<'a> Parser<'a> {
|
|||||||
if self.eat(&token::ModSep) {
|
if self.eat(&token::ModSep) {
|
||||||
self.parse_use_tree_glob_or_nested()?
|
self.parse_use_tree_glob_or_nested()?
|
||||||
} else {
|
} 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)
|
UseTreeKind::Simple(self.parse_rename()?, DUMMY_NODE_ID, DUMMY_NODE_ID)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
11
src/test/ui/parser/use-colon-as-mod-sep.rs
Normal file
11
src/test/ui/parser/use-colon-as-mod-sep.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Recover from using a colon as a path separator.
|
||||||
|
|
||||||
|
use std::process:Command;
|
||||||
|
//~^ ERROR expected `::`, found `:`
|
||||||
|
use std:fs::File;
|
||||||
|
//~^ ERROR expected `::`, found `:`
|
||||||
|
use std:collections:HashMap;
|
||||||
|
//~^ ERROR expected `::`, found `:`
|
||||||
|
//~| ERROR expected `::`, found `:`
|
||||||
|
|
||||||
|
fn main() { }
|
28
src/test/ui/parser/use-colon-as-mod-sep.stderr
Normal file
28
src/test/ui/parser/use-colon-as-mod-sep.stderr
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
error: expected `::`, found `:`
|
||||||
|
--> $DIR/use-colon-as-mod-sep.rs:3:17
|
||||||
|
|
|
||||||
|
LL | use std::process:Command;
|
||||||
|
| ^ help: use double colon
|
||||||
|
|
|
||||||
|
= note: import paths are delimited using `::`
|
||||||
|
|
||||||
|
error: expected `::`, found `:`
|
||||||
|
--> $DIR/use-colon-as-mod-sep.rs:5:8
|
||||||
|
|
|
||||||
|
LL | use std:fs::File;
|
||||||
|
| ^ help: use double colon
|
||||||
|
|
||||||
|
error: expected `::`, found `:`
|
||||||
|
--> $DIR/use-colon-as-mod-sep.rs:7:8
|
||||||
|
|
|
||||||
|
LL | use std:collections:HashMap;
|
||||||
|
| ^ help: use double colon
|
||||||
|
|
||||||
|
error: expected `::`, found `:`
|
||||||
|
--> $DIR/use-colon-as-mod-sep.rs:7:20
|
||||||
|
|
|
||||||
|
LL | use std:collections:HashMap;
|
||||||
|
| ^ help: use double colon
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user