@@ -567,20 +567,37 @@ impl<'a> Parser<'a> {
567
567
snapshot. recover_diff_marker ( ) ;
568
568
}
569
569
if self . token == token:: Colon {
570
- // if next token is following a colon, it's likely a path
571
- // and we can suggest a path separator
572
- self . bump ( ) ;
573
- if self . token . span . lo ( ) == self . prev_token . span . hi ( ) {
570
+ // if a previous and next token of the current one is
571
+ // integer literal (e.g. `1:42`), it's likely a range
572
+ // expression for Pythonistas and we can suggest so.
573
+ if self . prev_token . is_integer_lit ( )
574
+ && self . may_recover ( )
575
+ && self . look_ahead ( 1 , |token| token. is_integer_lit ( ) )
576
+ {
577
+ // FIXME(hkmatsumoto): Might be better to trigger
578
+ // this only when parsing an index expression.
574
579
err. span_suggestion_verbose (
575
- self . prev_token . span ,
576
- "maybe write a path separator here " ,
577
- ":: " ,
580
+ self . token . span ,
581
+ "you might have meant a range expression " ,
582
+ ".. " ,
578
583
Applicability :: MaybeIncorrect ,
579
584
) ;
580
- }
581
- if self . sess . unstable_features . is_nightly_build ( ) {
582
- // FIXME(Nilstrieb): Remove this again after a few months.
583
- err. note ( "type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>" ) ;
585
+ } else {
586
+ // if next token is following a colon, it's likely a path
587
+ // and we can suggest a path separator
588
+ self . bump ( ) ;
589
+ if self . token . span . lo ( ) == self . prev_token . span . hi ( ) {
590
+ err. span_suggestion_verbose (
591
+ self . prev_token . span ,
592
+ "maybe write a path separator here" ,
593
+ "::" ,
594
+ Applicability :: MaybeIncorrect ,
595
+ ) ;
596
+ }
597
+ if self . sess . unstable_features . is_nightly_build ( ) {
598
+ // FIXME(Nilstrieb): Remove this again after a few months.
599
+ err. note ( "type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>" ) ;
600
+ }
584
601
}
585
602
}
586
603
0 commit comments