@@ -4,7 +4,8 @@ use crate::{
44 AtomicOrderingFence , AtomicOrderingLoad , AtomicOrderingStore , ImproperCTypes ,
55 InvalidAtomicOrderingDiag , OnlyCastu8ToChar , OverflowingBinHex , OverflowingBinHexSign ,
66 OverflowingBinHexSub , OverflowingInt , OverflowingIntHelp , OverflowingLiteral ,
7- OverflowingUInt , RangeEndpointOutOfRange , UnusedComparisons , VariantSizeDifferencesDiag ,
7+ OverflowingUInt , RangeEndpointOutOfRange , UnusedComparisons , UseInclusiveRange ,
8+ VariantSizeDifferencesDiag ,
89 } ,
910} ;
1011use crate :: { LateContext , LateLintPass , LintContext } ;
@@ -172,16 +173,27 @@ fn lint_overflowing_range_endpoint<'tcx>(
172173 _ => bug ! ( ) ,
173174 } ;
174175
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+
175193 cx. emit_spanned_lint (
176194 OVERFLOWING_LITERALS ,
177195 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 } ,
185197 ) ;
186198
187199 // We've just emitted a lint, special cased for `(...)..MAX+1` ranges,
0 commit comments