@@ -16,7 +16,7 @@ use tracing::debug;
16
16
17
17
use super :: ty:: { AllowPlus , RecoverQPath , RecoverReturnSign } ;
18
18
use super :: { Parser , Restrictions , TokenType } ;
19
- use crate :: errors:: PathSingleColon ;
19
+ use crate :: errors:: { PathSingleColon , PathTripleColon } ;
20
20
use crate :: parser:: { CommaRecoveryMode , RecoverColon , RecoverComma } ;
21
21
use crate :: { errors, maybe_whole} ;
22
22
@@ -210,7 +210,7 @@ impl<'a> Parser<'a> {
210
210
let lo = self . token . span ;
211
211
let mut segments = ThinVec :: new ( ) ;
212
212
let mod_sep_ctxt = self . token . span . ctxt ( ) ;
213
- if self . eat ( & token :: PathSep ) {
213
+ if self . eat_path_sep ( ) {
214
214
segments. push ( PathSegment :: path_root ( lo. shrink_to_lo ( ) . with_ctxt ( mod_sep_ctxt) ) ) ;
215
215
}
216
216
self . parse_path_segments ( & mut segments, style, ty_generics) ?;
@@ -246,7 +246,7 @@ impl<'a> Parser<'a> {
246
246
}
247
247
segments. push ( segment) ;
248
248
249
- if self . is_import_coupler ( ) || !self . eat ( & token :: PathSep ) {
249
+ if self . is_import_coupler ( ) || !self . eat_path_sep ( ) {
250
250
if style == PathStyle :: Expr
251
251
&& self . may_recover ( )
252
252
&& self . token == token:: Colon
@@ -272,6 +272,18 @@ impl<'a> Parser<'a> {
272
272
}
273
273
}
274
274
275
+ /// Eat `::` or, potentially, `:::`.
276
+ #[ must_use]
277
+ pub ( super ) fn eat_path_sep ( & mut self ) -> bool {
278
+ let result = self . eat ( & token:: PathSep ) ;
279
+ if result && self . may_recover ( ) {
280
+ if self . eat_noexpect ( & token:: Colon ) {
281
+ self . dcx ( ) . emit_err ( PathTripleColon { span : self . prev_token . span } ) ;
282
+ }
283
+ }
284
+ result
285
+ }
286
+
275
287
pub ( super ) fn parse_path_segment (
276
288
& mut self ,
277
289
style : PathStyle ,
@@ -297,9 +309,7 @@ impl<'a> Parser<'a> {
297
309
298
310
Ok (
299
311
if style == PathStyle :: Type && check_args_start ( self )
300
- || style != PathStyle :: Mod
301
- && self . check ( & token:: PathSep )
302
- && self . look_ahead ( 1 , |t| is_args_start ( t) )
312
+ || style != PathStyle :: Mod && self . check_path_sep_and_look_ahead ( is_args_start)
303
313
{
304
314
// We use `style == PathStyle::Expr` to check if this is in a recursion or not. If
305
315
// it isn't, then we reset the unmatched angle bracket count as we're about to start
@@ -310,7 +320,8 @@ impl<'a> Parser<'a> {
310
320
311
321
// Generic arguments are found - `<`, `(`, `::<` or `::(`.
312
322
// First, eat `::` if it exists.
313
- let _ = self . eat ( & token:: PathSep ) ;
323
+ let _ = self . eat_path_sep ( ) ;
324
+
314
325
let lo = self . token . span ;
315
326
let args = if self . eat_lt ( ) {
316
327
// `<'a, T, A = U>`
0 commit comments