@@ -16,7 +16,7 @@ use tracing::debug;
1616
1717use super :: ty:: { AllowPlus , RecoverQPath , RecoverReturnSign } ;
1818use super :: { Parser , Restrictions , TokenType } ;
19- use crate :: errors:: PathSingleColon ;
19+ use crate :: errors:: { PathSingleColon , PathTripleColon } ;
2020use crate :: parser:: { CommaRecoveryMode , RecoverColon , RecoverComma } ;
2121use crate :: { errors, maybe_whole} ;
2222
@@ -210,7 +210,7 @@ impl<'a> Parser<'a> {
210210 let lo = self . token . span ;
211211 let mut segments = ThinVec :: new ( ) ;
212212 let mod_sep_ctxt = self . token . span . ctxt ( ) ;
213- if self . eat ( & token :: PathSep ) {
213+ if self . eat_path_sep ( ) {
214214 segments. push ( PathSegment :: path_root ( lo. shrink_to_lo ( ) . with_ctxt ( mod_sep_ctxt) ) ) ;
215215 }
216216 self . parse_path_segments ( & mut segments, style, ty_generics) ?;
@@ -246,7 +246,7 @@ impl<'a> Parser<'a> {
246246 }
247247 segments. push ( segment) ;
248248
249- if self . is_import_coupler ( ) || !self . eat ( & token :: PathSep ) {
249+ if self . is_import_coupler ( ) || !self . eat_path_sep ( ) {
250250 if style == PathStyle :: Expr
251251 && self . may_recover ( )
252252 && self . token == token:: Colon
@@ -272,6 +272,18 @@ impl<'a> Parser<'a> {
272272 }
273273 }
274274
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+
275287 pub ( super ) fn parse_path_segment (
276288 & mut self ,
277289 style : PathStyle ,
@@ -297,9 +309,7 @@ impl<'a> Parser<'a> {
297309
298310 Ok (
299311 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)
303313 {
304314 // We use `style == PathStyle::Expr` to check if this is in a recursion or not. If
305315 // 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> {
310320
311321 // Generic arguments are found - `<`, `(`, `::<` or `::(`.
312322 // First, eat `::` if it exists.
313- let _ = self . eat ( & token:: PathSep ) ;
323+ let _ = self . eat_path_sep ( ) ;
324+
314325 let lo = self . token . span ;
315326 let args = if self . eat_lt ( ) {
316327 // `<'a, T, A = U>`
0 commit comments