@@ -4,7 +4,8 @@ use crate::{
4
4
AtomicOrderingFence , AtomicOrderingLoad , AtomicOrderingStore , ImproperCTypes ,
5
5
InvalidAtomicOrderingDiag , OnlyCastu8ToChar , OverflowingBinHex , OverflowingBinHexSign ,
6
6
OverflowingBinHexSub , OverflowingInt , OverflowingIntHelp , OverflowingLiteral ,
7
- OverflowingUInt , RangeEndpointOutOfRange , UnusedComparisons , VariantSizeDifferencesDiag ,
7
+ OverflowingUInt , RangeEndpointOutOfRange , UnusedComparisons , UseInclusiveRange ,
8
+ VariantSizeDifferencesDiag ,
8
9
} ,
9
10
} ;
10
11
use crate :: { LateContext , LateLintPass , LintContext } ;
@@ -172,16 +173,27 @@ fn lint_overflowing_range_endpoint<'tcx>(
172
173
_ => bug ! ( ) ,
173
174
} ;
174
175
176
+ let sub_sugg = if expr. span . lo ( ) == lit_span. lo ( ) {
177
+ let Ok ( start) = cx. sess ( ) . source_map ( ) . span_to_snippet ( eps[ 0 ] . span ) else { return false } ;
178
+ UseInclusiveRange :: WithoutParen {
179
+ sugg : struct_expr. span . shrink_to_lo ( ) . to ( lit_span. shrink_to_hi ( ) ) ,
180
+ start,
181
+ literal : lit_val - 1 ,
182
+ suffix,
183
+ }
184
+ } else {
185
+ UseInclusiveRange :: WithParen {
186
+ eq_sugg : expr. span . shrink_to_lo ( ) ,
187
+ lit_sugg : lit_span,
188
+ literal : lit_val - 1 ,
189
+ suffix,
190
+ }
191
+ } ;
192
+
175
193
cx. emit_spanned_lint (
176
194
OVERFLOWING_LITERALS ,
177
195
struct_expr. span ,
178
- RangeEndpointOutOfRange {
179
- ty,
180
- eq_suggestion : expr. span . shrink_to_lo ( ) ,
181
- lit_suggestion : lit_span,
182
- literal : lit_val - 1 ,
183
- suffix,
184
- } ,
196
+ RangeEndpointOutOfRange { ty, sub : sub_sugg } ,
185
197
) ;
186
198
187
199
// We've just emitted a lint, special cased for `(...)..MAX+1` ranges,
0 commit comments