@@ -10,7 +10,7 @@ use crate::errors::{
10
10
UnexpectedParenInRangePatSugg , UnexpectedVertVertBeforeFunctionParam ,
11
11
UnexpectedVertVertInPattern ,
12
12
} ;
13
- use crate :: parser:: expr:: could_be_unclosed_char_literal;
13
+ use crate :: parser:: expr:: { could_be_unclosed_char_literal, DestructuredFloat } ;
14
14
use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_whole} ;
15
15
use rustc_ast:: mut_visit:: { noop_visit_pat, MutVisitor } ;
16
16
use rustc_ast:: ptr:: P ;
@@ -357,14 +357,27 @@ impl<'a> Parser<'a> {
357
357
return None ;
358
358
}
359
359
360
- // Check for `.hello()`, but allow `.Hello()` to be recovered as `, Hello()` in `parse_seq_to_before_tokens()`.
361
- let has_trailing_method = self . check_noexpect ( & token:: Dot )
360
+ // Returns `true` iff `token` is `x.y` float
361
+ let is_float_literal = |that : & Self , token : & Token | -> bool {
362
+ use token:: { Lit , LitKind } ;
363
+
364
+ if let token:: Literal ( Lit { kind : LitKind :: Float , symbol, suffix : None } ) = token. kind {
365
+ if let DestructuredFloat :: MiddleDot ( ..) = that. break_up_float ( symbol, token. span ) {
366
+ return true ;
367
+ }
368
+ }
369
+
370
+ false
371
+ } ;
372
+
373
+ // Check for `.hello` or `.0`
374
+ let has_dot_expr = self . check_noexpect ( & token:: Dot )
362
375
&& self . look_ahead ( 1 , |tok| {
363
- tok. ident ( )
364
- . and_then ( | ( ident , _ ) | ident . name . as_str ( ) . chars ( ) . next ( ) )
365
- . is_some_and ( char :: is_lowercase )
366
- } )
367
- && self . look_ahead ( 2 , |tok| tok . kind == token :: OpenDelim ( Delimiter :: Parenthesis ) ) ;
376
+ tok. is_ident ( )
377
+ || tok . is_integer_lit ( )
378
+ // `0.0` get lexed as a float literal
379
+ || is_float_literal ( & self , & tok )
380
+ } ) ;
368
381
369
382
// Check for operators.
370
383
// `|` is excluded as it is used in pattern alternatives and lambdas,
@@ -376,7 +389,7 @@ impl<'a> Parser<'a> {
376
389
|| ( self . token . kind == token:: OpenDelim ( Delimiter :: Bracket )
377
390
&& self . look_ahead ( 1 , |tok| tok. kind != token:: CloseDelim ( Delimiter :: Bracket ) ) ) ;
378
391
379
- if !has_trailing_method && !has_trailing_operator {
392
+ if !has_dot_expr && !has_trailing_operator {
380
393
// Nothing to recover here.
381
394
return None ;
382
395
}
@@ -412,7 +425,7 @@ impl<'a> Parser<'a> {
412
425
&& self . look_ahead ( 1 , Token :: is_range_separator) ;
413
426
414
427
// Check that `parse_expr_assoc_with` didn't eat a rhs.
415
- let is_method_call = has_trailing_method && non_assoc_span == expr. span ;
428
+ let is_method_call = false && non_assoc_span == expr. span ;
416
429
417
430
return Some ( self . dcx ( ) . emit_err ( UnexpectedExpressionInPattern {
418
431
span : expr. span ,
0 commit comments