@@ -2034,13 +2034,18 @@ impl<'a> Parser<'a> {
2034
2034
is_args_start ( & this. token , include_paren)
2035
2035
} ;
2036
2036
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
+ } {
2044
2049
// Generic arguments are found - `<`, `(`, `::<` or `::(`.
2045
2050
let lo = self . span ;
2046
2051
if self . eat ( & token:: ModSep ) && style == PathStyle :: Type && enable_warning {
@@ -2059,9 +2064,9 @@ impl<'a> Parser<'a> {
2059
2064
2060
2065
match args {
2061
2066
Err ( mut err) => {
2062
- if expr_without_disambig {
2067
+ if let Some ( snapshot ) = parser_snapshot_before_generics {
2063
2068
err. cancel ( ) ;
2064
- mem:: replace ( self , parser_snapshot_before_generics ) ;
2069
+ mem:: replace ( self , snapshot ) ;
2065
2070
return Ok ( PathSegment :: from_ident ( ident) ) ;
2066
2071
}
2067
2072
return Err ( err) ;
0 commit comments