@@ -2053,13 +2053,18 @@ impl<'a> Parser<'a> {
2053
2053
is_args_start ( & this. token , include_paren)
2054
2054
} ;
2055
2055
2056
- let expr_without_disambig = style == PathStyle :: Expr && check_args_start ( self , false ) ;
2057
- let parser_snapshot_before_generics = self . clone ( ) ;
2058
-
2059
- Ok ( if style == PathStyle :: Type && check_args_start ( self , true ) ||
2060
- style != PathStyle :: Mod && self . check ( & token:: ModSep )
2061
- && self . look_ahead ( 1 , |t| is_args_start ( t, true ) )
2062
- || expr_without_disambig {
2056
+ let mut parser_snapshot_before_generics = None ;
2057
+
2058
+ Ok ( if style == PathStyle :: Type && check_args_start ( self , true )
2059
+ || style != PathStyle :: Mod && self . check ( & token:: ModSep )
2060
+ && self . look_ahead ( 1 , |t| is_args_start ( t, true ) )
2061
+ || style == PathStyle :: Expr && check_args_start ( self , false ) && {
2062
+ // Check for generic arguments in an expression without a disambiguating `::`.
2063
+ // We have to save a snapshot, because it could end up being an expression
2064
+ // instead.
2065
+ parser_snapshot_before_generics = Some ( self . clone ( ) ) ;
2066
+ true
2067
+ } {
2063
2068
// Generic arguments are found - `<`, `(`, `::<` or `::(`.
2064
2069
let lo = self . span ;
2065
2070
if self . eat ( & token:: ModSep ) && style == PathStyle :: Type && enable_warning {
@@ -2078,9 +2083,9 @@ impl<'a> Parser<'a> {
2078
2083
2079
2084
match args {
2080
2085
Err ( mut err) => {
2081
- if expr_without_disambig {
2086
+ if let Some ( snapshot ) = parser_snapshot_before_generics {
2082
2087
err. cancel ( ) ;
2083
- mem:: replace ( self , parser_snapshot_before_generics ) ;
2088
+ mem:: replace ( self , snapshot ) ;
2084
2089
return Ok ( PathSegment :: from_ident ( ident) ) ;
2085
2090
}
2086
2091
return Err ( err) ;
0 commit comments