@@ -1699,32 +1699,57 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
1699
1699
let suggestion = "use `..=` for an inclusive range" ;
1700
1700
if parenthesise {
1701
1701
self . node_id = Some ( pat. id ) ;
1702
- cx. struct_span_lint ( ELLIPSIS_INCLUSIVE_RANGE_PATTERNS , pat. span , |lint| {
1703
- let end = expr_to_string ( & end) ;
1704
- let replace = match start {
1705
- Some ( start) => format ! ( "&({}..={})" , expr_to_string( & start) , end) ,
1706
- None => format ! ( "&(..={})" , end) ,
1707
- } ;
1708
- lint. build ( msg)
1709
- . span_suggestion (
1710
- pat. span ,
1711
- suggestion,
1712
- replace,
1713
- Applicability :: MachineApplicable ,
1714
- )
1715
- . emit ( ) ;
1716
- } ) ;
1702
+ let end = expr_to_string ( & end) ;
1703
+ let replace = match start {
1704
+ Some ( start) => format ! ( "&({}..={})" , expr_to_string( & start) , end) ,
1705
+ None => format ! ( "&(..={})" , end) ,
1706
+ } ;
1707
+ if cx. sess ( ) . edition ( ) >= Edition :: Edition2021 {
1708
+ let mut err =
1709
+ rustc_errors:: struct_span_err!( cx. sess, pat. span, E0783 , "{}" , msg, ) ;
1710
+ err. span_suggestion (
1711
+ pat. span ,
1712
+ suggestion,
1713
+ replace,
1714
+ Applicability :: MachineApplicable ,
1715
+ )
1716
+ . emit ( ) ;
1717
+ } else {
1718
+ cx. struct_span_lint ( ELLIPSIS_INCLUSIVE_RANGE_PATTERNS , pat. span , |lint| {
1719
+ lint. build ( msg)
1720
+ . span_suggestion (
1721
+ pat. span ,
1722
+ suggestion,
1723
+ replace,
1724
+ Applicability :: MachineApplicable ,
1725
+ )
1726
+ . emit ( ) ;
1727
+ } ) ;
1728
+ }
1717
1729
} else {
1718
- cx. struct_span_lint ( ELLIPSIS_INCLUSIVE_RANGE_PATTERNS , join, |lint| {
1719
- lint. build ( msg)
1720
- . span_suggestion_short (
1721
- join,
1722
- suggestion,
1723
- "..=" . to_owned ( ) ,
1724
- Applicability :: MachineApplicable ,
1725
- )
1726
- . emit ( ) ;
1727
- } ) ;
1730
+ let replace = "..=" . to_owned ( ) ;
1731
+ if cx. sess ( ) . edition ( ) >= Edition :: Edition2021 {
1732
+ let mut err =
1733
+ rustc_errors:: struct_span_err!( cx. sess, pat. span, E0783 , "{}" , msg, ) ;
1734
+ err. span_suggestion_short (
1735
+ join,
1736
+ suggestion,
1737
+ replace,
1738
+ Applicability :: MachineApplicable ,
1739
+ )
1740
+ . emit ( ) ;
1741
+ } else {
1742
+ cx. struct_span_lint ( ELLIPSIS_INCLUSIVE_RANGE_PATTERNS , join, |lint| {
1743
+ lint. build ( msg)
1744
+ . span_suggestion_short (
1745
+ join,
1746
+ suggestion,
1747
+ replace,
1748
+ Applicability :: MachineApplicable ,
1749
+ )
1750
+ . emit ( ) ;
1751
+ } ) ;
1752
+ }
1728
1753
} ;
1729
1754
}
1730
1755
}
0 commit comments