File tree 3 files changed +56
-0
lines changed
compiler/rustc_parse/src/parser
3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -971,6 +971,23 @@ impl<'a> Parser<'a> {
971
971
if self . eat ( & token:: ModSep ) {
972
972
self . parse_use_tree_glob_or_nested ( ) ?
973
973
} else {
974
+ // Recover from using a colon as path separator.
975
+ while self . eat_noexpect ( & token:: Colon ) {
976
+ self . struct_span_err ( self . prev_token . span , "expected `::`, found `:`" )
977
+ . span_suggestion_short (
978
+ self . prev_token . span ,
979
+ "use double colon" ,
980
+ "::" ,
981
+ Applicability :: MachineApplicable ,
982
+ )
983
+ . note_once ( "import paths are delimited using `::`" )
984
+ . emit ( ) ;
985
+
986
+ // We parse the rest of the path and append it to the original prefix.
987
+ self . parse_path_segments ( & mut prefix. segments , PathStyle :: Mod , None ) ?;
988
+ prefix. span = lo. to ( self . prev_token . span ) ;
989
+ }
990
+
974
991
UseTreeKind :: Simple ( self . parse_rename ( ) ?, DUMMY_NODE_ID , DUMMY_NODE_ID )
975
992
}
976
993
} ;
Original file line number Diff line number Diff line change
1
+ // Recover from using a colon as a path separator.
2
+
3
+ use std:: process: Command ;
4
+ //~^ ERROR expected `::`, found `:`
5
+ use std: fs:: File ;
6
+ //~^ ERROR expected `::`, found `:`
7
+ use std: collections: HashMap ;
8
+ //~^ ERROR expected `::`, found `:`
9
+ //~| ERROR expected `::`, found `:`
10
+
11
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: expected `::`, found `:`
2
+ --> $DIR/use-colon-as-mod-sep.rs:3:17
3
+ |
4
+ LL | use std::process:Command;
5
+ | ^ help: use double colon
6
+ |
7
+ = note: import paths are delimited using `::`
8
+
9
+ error: expected `::`, found `:`
10
+ --> $DIR/use-colon-as-mod-sep.rs:5:8
11
+ |
12
+ LL | use std:fs::File;
13
+ | ^ help: use double colon
14
+
15
+ error: expected `::`, found `:`
16
+ --> $DIR/use-colon-as-mod-sep.rs:7:8
17
+ |
18
+ LL | use std:collections:HashMap;
19
+ | ^ help: use double colon
20
+
21
+ error: expected `::`, found `:`
22
+ --> $DIR/use-colon-as-mod-sep.rs:7:20
23
+ |
24
+ LL | use std:collections:HashMap;
25
+ | ^ help: use double colon
26
+
27
+ error: aborting due to 4 previous errors
28
+
You can’t perform that action at this time.
0 commit comments