1
1
use super :: { ForceCollect , Parser , PathStyle , TrailingToken } ;
2
- use crate :: errors:: RemoveLet ;
2
+ use crate :: errors:: {
3
+ InclusiveRangeExtraEquals , InclusiveRangeMatchArrow , InclusiveRangeNoEnd , RemoveLet ,
4
+ } ;
3
5
use crate :: { maybe_recover_from_interpolated_ty_qpath, maybe_whole} ;
4
6
use rustc_ast:: mut_visit:: { noop_visit_pat, MutVisitor } ;
5
7
use rustc_ast:: ptr:: P ;
@@ -9,7 +11,7 @@ use rustc_ast::{
9
11
PatField , PatKind , Path , QSelf , RangeEnd , RangeSyntax ,
10
12
} ;
11
13
use rustc_ast_pretty:: pprust;
12
- use rustc_errors:: { struct_span_err , Applicability , DiagnosticBuilder , ErrorGuaranteed , PResult } ;
14
+ use rustc_errors:: { Applicability , DiagnosticBuilder , ErrorGuaranteed , PResult } ;
13
15
use rustc_session:: errors:: ExprParenthesesNeeded ;
14
16
use rustc_span:: source_map:: { respan, Span , Spanned } ;
15
17
use rustc_span:: symbol:: { kw, sym, Ident } ;
@@ -782,29 +784,16 @@ impl<'a> Parser<'a> {
782
784
}
783
785
784
786
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 } ) ;
789
788
}
790
789
791
790
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 } ) ;
801
793
}
802
794
803
795
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 } ) ;
808
797
}
809
798
810
799
/// Parse a range-to pattern, `..X` or `..=X` where `X` remains to be parsed.
0 commit comments