@@ -746,32 +746,38 @@ impl<'a> Parser<'a> {
746746 // Parsing e.g. `X..`.
747747 if let RangeEnd :: Included ( _) = re. node {
748748 // FIXME(Centril): Consider semantic errors instead in `ast_validation`.
749- self . inclusive_range_with_incorrect_end ( re . span ) ;
749+ self . inclusive_range_with_incorrect_end ( ) ;
750750 }
751751 None
752752 } ;
753753 Ok ( PatKind :: Range ( Some ( begin) , end, re) )
754754 }
755755
756- pub ( super ) fn inclusive_range_with_incorrect_end ( & mut self , span : Span ) {
756+ pub ( super ) fn inclusive_range_with_incorrect_end ( & mut self ) {
757757 let tok = & self . token ;
758-
758+ let span = self . prev_token . span ;
759759 // If the user typed "..==" instead of "..=", we want to give them
760760 // a specific error message telling them to use "..=".
761+ // If they typed "..=>", suggest they use ".. =>".
761762 // Otherwise, we assume that they meant to type a half open exclusive
762763 // range and give them an error telling them to do that instead.
763- if matches ! ( tok. kind, token:: Eq ) && tok. span . lo ( ) == span. hi ( ) {
764- let span_with_eq = span. to ( tok. span ) ;
764+ let no_space = tok. span . lo ( ) == span. hi ( ) ;
765+ match tok. kind {
766+ token:: Eq if no_space => {
767+ let span_with_eq = span. to ( tok. span ) ;
765768
766- // Ensure the user doesn't receive unhelpful unexpected token errors
767- self . bump ( ) ;
768- if self . is_pat_range_end_start ( 0 ) {
769- let _ = self . parse_pat_range_end ( ) . map_err ( |e| e. cancel ( ) ) ;
770- }
769+ // Ensure the user doesn't receive unhelpful unexpected token errors
770+ self . bump ( ) ;
771+ if self . is_pat_range_end_start ( 0 ) {
772+ let _ = self . parse_pat_range_end ( ) . map_err ( |e| e. cancel ( ) ) ;
773+ }
771774
772- self . error_inclusive_range_with_extra_equals ( span_with_eq) ;
773- } else {
774- self . error_inclusive_range_with_no_end ( span) ;
775+ self . error_inclusive_range_with_extra_equals ( span_with_eq) ;
776+ }
777+ token:: Gt if no_space => {
778+ self . error_inclusive_range_match_arrow ( span) ;
779+ }
780+ _ => self . error_inclusive_range_with_no_end ( span) ,
775781 }
776782 }
777783
@@ -782,6 +788,18 @@ impl<'a> Parser<'a> {
782788 . emit ( ) ;
783789 }
784790
791+ fn error_inclusive_range_match_arrow ( & self , span : Span ) {
792+ let without_eq = span. with_hi ( span. hi ( ) - rustc_span:: BytePos ( 1 ) ) ;
793+ self . struct_span_err ( span, "unexpected `=>` after open range" )
794+ . span_suggestion_verbose (
795+ without_eq. shrink_to_hi ( ) ,
796+ "add a space between the pattern and `=>`" ,
797+ " " ,
798+ Applicability :: MachineApplicable ,
799+ )
800+ . emit ( ) ;
801+ }
802+
785803 fn error_inclusive_range_with_no_end ( & self , span : Span ) {
786804 struct_span_err ! ( self . sess. span_diagnostic, span, E0586 , "inclusive range with no end" )
787805 . span_suggestion_short ( span, "use `..` instead" , ".." , Applicability :: MachineApplicable )
0 commit comments