11use super :: { ForceCollect , Parser , PathStyle , TrailingToken } ;
2- use crate :: errors:: RemoveLet ;
2+ use crate :: errors:: {
3+ InclusiveRangeExtraEquals , InclusiveRangeMatchArrow , InclusiveRangeNoEnd , RemoveLet ,
4+ } ;
35use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_whole} ;
46use rustc_ast:: mut_visit:: { noop_visit_pat, MutVisitor } ;
57use rustc_ast:: ptr:: P ;
@@ -9,7 +11,7 @@ use rustc_ast::{
911 PatField , PatKind , Path , QSelf , RangeEnd , RangeSyntax ,
1012} ;
1113use rustc_ast_pretty:: pprust;
12- use rustc_errors:: { struct_span_err , Applicability , DiagnosticBuilder , ErrorGuaranteed , PResult } ;
14+ use rustc_errors:: { Applicability , DiagnosticBuilder , ErrorGuaranteed , PResult } ;
1315use rustc_session:: errors:: ExprParenthesesNeeded ;
1416use rustc_span:: source_map:: { respan, Span , Spanned } ;
1517use rustc_span:: symbol:: { kw, sym, Ident } ;
@@ -782,29 +784,16 @@ impl<'a> Parser<'a> {
782784 }
783785
784786 fn error_inclusive_range_with_extra_equals ( & self , span : Span ) {
785- self . struct_span_err ( span, "unexpected `=` after inclusive range" )
786- . span_suggestion_short ( span, "use `..=` instead" , "..=" , Applicability :: MaybeIncorrect )
787- . note ( "inclusive ranges end with a single equals sign (`..=`)" )
788- . emit ( ) ;
787+ self . sess . emit_err ( InclusiveRangeExtraEquals { span } ) ;
789788 }
790789
791790 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 ( ) ;
791+ let after_pat = span. with_hi ( span. hi ( ) - rustc_span:: BytePos ( 1 ) ) . shrink_to_hi ( ) ;
792+ self . sess . emit_err ( InclusiveRangeMatchArrow { span, after_pat } ) ;
801793 }
802794
803795 fn error_inclusive_range_with_no_end ( & self , span : Span ) {
804- struct_span_err ! ( self . sess. span_diagnostic, span, E0586 , "inclusive range with no end" )
805- . span_suggestion_short ( span, "use `..` instead" , ".." , Applicability :: MachineApplicable )
806- . note ( "inclusive ranges must be bounded at the end (`..=b` or `a..=b`)" )
807- . emit ( ) ;
796+ self . sess . emit_err ( InclusiveRangeNoEnd { span } ) ;
808797 }
809798
810799 /// Parse a range-to pattern, `..X` or `..=X` where `X` remains to be parsed.
0 commit comments