@@ -2034,13 +2034,18 @@ impl<'a> Parser<'a> {
20342034 is_args_start ( & this. token , include_paren)
20352035 } ;
20362036
2037- let expr_without_disambig = style == PathStyle :: Expr && check_args_start ( self , false ) ;
2038- let parser_snapshot_before_generics = self . clone ( ) ;
2039-
2040- Ok ( if style == PathStyle :: Type && check_args_start ( self , true ) ||
2041- style != PathStyle :: Mod && self . check ( & token:: ModSep )
2042- && self . look_ahead ( 1 , |t| is_args_start ( t, true ) )
2043- || expr_without_disambig {
2037+ let mut parser_snapshot_before_generics = None ;
2038+
2039+ Ok ( if style == PathStyle :: Type && check_args_start ( self , true )
2040+ || style != PathStyle :: Mod && self . check ( & token:: ModSep )
2041+ && self . look_ahead ( 1 , |t| is_args_start ( t, true ) )
2042+ || style == PathStyle :: Expr && check_args_start ( self , false ) && {
2043+ // Check for generic arguments in an expression without a disambiguating `::`.
2044+ // We have to save a snapshot, because it could end up being an expression
2045+ // instead.
2046+ parser_snapshot_before_generics = Some ( self . clone ( ) ) ;
2047+ true
2048+ } {
20442049 // Generic arguments are found - `<`, `(`, `::<` or `::(`.
20452050 let lo = self . span ;
20462051 if self . eat ( & token:: ModSep ) && style == PathStyle :: Type && enable_warning {
@@ -2059,9 +2064,9 @@ impl<'a> Parser<'a> {
20592064
20602065 match args {
20612066 Err ( mut err) => {
2062- if expr_without_disambig {
2067+ if let Some ( snapshot ) = parser_snapshot_before_generics {
20632068 err. cancel ( ) ;
2064- mem:: replace ( self , parser_snapshot_before_generics ) ;
2069+ mem:: replace ( self , snapshot ) ;
20652070 return Ok ( PathSegment :: from_ident ( ident) ) ;
20662071 }
20672072 return Err ( err) ;
0 commit comments