@@ -358,7 +358,7 @@ impl<'a> Parser<'a> {
358358 err : & mut DiagnosticBuilder < ' _ > ,
359359 maybe_expected_semicolon : bool ,
360360 ) {
361- if let Some ( ( sp, likely_path) ) = self . last_type_ascription {
361+ if let Some ( ( sp, likely_path) ) = self . last_type_ascription . take ( ) {
362362 let sm = self . sess . source_map ( ) ;
363363 let next_pos = sm. lookup_char_pos ( self . token . span . lo ( ) ) ;
364364 let op_pos = sm. lookup_char_pos ( sp. hi ( ) ) ;
@@ -395,7 +395,6 @@ impl<'a> Parser<'a> {
395395 err. note ( "for more information, see \
396396 https://github.com/rust-lang/rust/issues/23416") ;
397397 }
398- self . last_type_ascription = None ;
399398 }
400399 }
401400
@@ -1083,8 +1082,15 @@ impl<'a> Parser<'a> {
10831082 }
10841083
10851084 pub ( super ) fn could_ascription_be_path ( & self , node : & ast:: ExprKind ) -> bool {
1086- self . token . is_ident ( ) &&
1087- if let ast:: ExprKind :: Path ( ..) = node { true } else { false } &&
1085+ ( self . token == token:: Lt && // `foo:<bar`, likely a typoed turbofish.
1086+ self . look_ahead ( 1 , |t| t. is_ident ( ) && !t. is_reserved_ident ( ) )
1087+ ) ||
1088+ self . token . is_ident ( ) &&
1089+ match node {
1090+ // `foo::` → `foo:` or `foo.bar::` → `foo.bar:`
1091+ ast:: ExprKind :: Path ( ..) | ast:: ExprKind :: Field ( ..) => true ,
1092+ _ => false ,
1093+ } &&
10881094 !self . token . is_reserved_ident ( ) && // v `foo:bar(baz)`
10891095 self . look_ahead ( 1 , |t| t == & token:: OpenDelim ( token:: Paren ) ) ||
10901096 self . look_ahead ( 1 , |t| t == & token:: Lt ) && // `foo:bar<baz`
0 commit comments