@@ -647,7 +647,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
647
647
) ,
648
648
) ,
649
649
match & args[ ..] {
650
- [ ] => ( base. span. shrink_to_hi( ) . with_hi( deref. span. hi( ) ) , ")" . to_string( ) ) ,
650
+ [ ] => (
651
+ self . tcx. adjust_span( base. span) . shrink_to_hi( ) . with_hi( deref. span. hi( ) ) ,
652
+ ")" . to_string( ) ,
653
+ ) ,
651
654
[ first, ..] => ( base. span. between( first. span) , ", " . to_string( ) ) ,
652
655
} ,
653
656
]
@@ -771,8 +774,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
771
774
"use `?` to coerce and return an appropriate `Err`, and wrap the resulting value \
772
775
in `Ok` so the expression remains of type `Result`",
773
776
vec ! [
774
- ( expr. span. shrink_to_lo( ) , "Ok(" . to_string( ) ) ,
775
- ( expr. span. shrink_to_hi( ) , "?)" . to_string( ) ) ,
777
+ ( self . tcx . adjust_span ( expr. span) . shrink_to_lo( ) , "Ok(" . to_string( ) ) ,
778
+ ( self . tcx . adjust_span ( expr. span) . shrink_to_hi( ) , "?)" . to_string( ) ) ,
776
779
] ,
777
780
Applicability :: MaybeIncorrect ,
778
781
) ;
@@ -843,8 +846,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
843
846
} else {
844
847
return false ;
845
848
} ;
846
- if let Some ( indent) =
847
- self . tcx . sess . source_map ( ) . indentation_before ( span. shrink_to_lo ( ) )
849
+ if let Some ( indent) = self
850
+ . tcx
851
+ . sess
852
+ . source_map ( )
853
+ . indentation_before ( self . tcx . adjust_span ( span) . shrink_to_lo ( ) )
848
854
{
849
855
// Add a semicolon, except after `}`.
850
856
let semicolon =
@@ -853,7 +859,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
853
859
_ => ";" ,
854
860
} ;
855
861
err. span_suggestions (
856
- span. shrink_to_hi ( ) ,
862
+ self . tcx . adjust_span ( span) . shrink_to_hi ( ) ,
857
863
"try adding an expression at the end of the block" ,
858
864
return_suggestions
859
865
. into_iter ( )
@@ -931,8 +937,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
931
937
}
932
938
933
939
vec ! [
934
- ( expr. span. shrink_to_lo( ) , format!( "{prefix}{variant}{open}" ) ) ,
935
- ( expr. span. shrink_to_hi( ) , close. to_owned( ) ) ,
940
+ (
941
+ self . tcx. adjust_span( expr. span) . shrink_to_lo( ) ,
942
+ format!( "{prefix}{variant}{open}" ) ,
943
+ ) ,
944
+ ( self . tcx. adjust_span( expr. span) . shrink_to_hi( ) , close. to_owned( ) ) ,
936
945
]
937
946
} ;
938
947
@@ -1016,8 +1025,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1016
1025
err. multipart_suggestion (
1017
1026
format ! ( "consider calling `{s}::new`" ) ,
1018
1027
vec ! [
1019
- ( expr. span. shrink_to_lo( ) , format!( "{path}::new(" ) ) ,
1020
- ( expr. span. shrink_to_hi( ) , format!( "){unwrap}" ) ) ,
1028
+ ( self . tcx . adjust_span ( expr. span) . shrink_to_lo( ) , format!( "{path}::new(" ) ) ,
1029
+ ( self . tcx . adjust_span ( expr. span) . shrink_to_hi( ) , format!( "){unwrap}" ) ) ,
1021
1030
] ,
1022
1031
Applicability :: MaybeIncorrect ,
1023
1032
) ;
@@ -1271,7 +1280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1271
1280
&& replace_prefix ( & src, "\" " , "b\" " ) . is_some ( )
1272
1281
{
1273
1282
return Some ( (
1274
- sp . shrink_to_lo ( ) ,
1283
+ self . tcx . adjust_span ( sp ) . shrink_to_lo ( ) ,
1275
1284
"consider adding a leading `b`" . to_string ( ) ,
1276
1285
"b" . to_string ( ) ,
1277
1286
Applicability :: MachineApplicable ,
@@ -1468,7 +1477,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1468
1477
_ if sp == expr. span => {
1469
1478
if let Some ( mut steps) = self . deref_steps ( checked_ty, expected) {
1470
1479
let mut expr = expr. peel_blocks ( ) ;
1471
- let mut prefix_span = expr. span . shrink_to_lo ( ) ;
1480
+ let mut prefix_span = self . tcx . adjust_span ( expr. span ) . shrink_to_lo ( ) ;
1472
1481
let mut remove = String :: new ( ) ;
1473
1482
1474
1483
// Try peeling off any existing `&` and `&mut` to reach our target type
@@ -1539,7 +1548,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1539
1548
return None ;
1540
1549
} else if let Some ( expr) = self . maybe_get_block_expr ( expr) {
1541
1550
// prefix should be empty here..
1542
- ( expr. span . shrink_to_lo ( ) , "*" . to_string ( ) )
1551
+ ( self . tcx . adjust_span ( expr. span ) . shrink_to_lo ( ) , "*" . to_string ( ) )
1543
1552
} else {
1544
1553
( prefix_span, format ! ( "{}{}" , prefix, "*" . repeat( steps) ) )
1545
1554
} ;
@@ -1596,7 +1605,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1596
1605
// `expr` is a literal field for a struct, only suggest if appropriate
1597
1606
if field. is_shorthand {
1598
1607
// This is a field literal
1599
- sugg. push ( ( field. ident . span . shrink_to_lo ( ) , format ! ( "{}: " , field. ident) ) ) ;
1608
+ sugg. push ( (
1609
+ self . tcx . adjust_span ( field. ident . span ) . shrink_to_lo ( ) ,
1610
+ format ! ( "{}: " , field. ident) ,
1611
+ ) ) ;
1600
1612
} else {
1601
1613
// Likely a field was meant, but this field wasn't found. Do not suggest anything.
1602
1614
return false ;
@@ -1652,16 +1664,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1652
1664
) ;
1653
1665
1654
1666
let close_paren = if expr. precedence ( ) . order ( ) < PREC_POSTFIX {
1655
- sugg. push ( ( expr. span . shrink_to_lo ( ) , "(" . to_string ( ) ) ) ;
1667
+ sugg. push ( ( self . tcx . adjust_span ( expr. span ) . shrink_to_lo ( ) , "(" . to_string ( ) ) ) ;
1656
1668
")"
1657
1669
} else {
1658
1670
""
1659
1671
} ;
1660
1672
1661
1673
let mut cast_suggestion = sugg. clone ( ) ;
1662
- cast_suggestion. push ( ( expr. span . shrink_to_hi ( ) , format ! ( "{close_paren} as {expected_ty}" ) ) ) ;
1674
+ cast_suggestion. push ( (
1675
+ self . tcx . adjust_span ( expr. span ) . shrink_to_hi ( ) ,
1676
+ format ! ( "{close_paren} as {expected_ty}" ) ,
1677
+ ) ) ;
1663
1678
let mut into_suggestion = sugg. clone ( ) ;
1664
- into_suggestion. push ( ( expr. span . shrink_to_hi ( ) , format ! ( "{close_paren}.into()" ) ) ) ;
1679
+ into_suggestion. push ( (
1680
+ self . tcx . adjust_span ( expr. span ) . shrink_to_hi ( ) ,
1681
+ format ! ( "{close_paren}.into()" ) ,
1682
+ ) ) ;
1665
1683
let mut suffix_suggestion = sugg. clone ( ) ;
1666
1684
suffix_suggestion. push ( (
1667
1685
if matches ! (
@@ -1715,15 +1733,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1715
1733
"you can convert `{lhs_src}` from `{expected_ty}` to `{checked_ty}`, matching the type of `{src}`" ,
1716
1734
) ;
1717
1735
let suggestion = vec ! [
1718
- ( lhs_expr. span. shrink_to_lo( ) , format!( "{checked_ty}::from(" ) ) ,
1719
- ( lhs_expr. span. shrink_to_hi( ) , ")" . to_string( ) ) ,
1736
+ (
1737
+ self . tcx. adjust_span( lhs_expr. span) . shrink_to_lo( ) ,
1738
+ format!( "{checked_ty}::from(" ) ,
1739
+ ) ,
1740
+ ( self . tcx. adjust_span( lhs_expr. span) . shrink_to_hi( ) , ")" . to_string( ) ) ,
1720
1741
] ;
1721
1742
( msg, suggestion)
1722
1743
} else {
1723
1744
let msg = format ! ( "{msg} and panic if the converted value doesn't fit" ) ;
1724
1745
let mut suggestion = sugg. clone ( ) ;
1725
1746
suggestion. push ( (
1726
- expr. span . shrink_to_hi ( ) ,
1747
+ self . tcx . adjust_span ( expr. span ) . shrink_to_hi ( ) ,
1727
1748
format ! ( "{close_paren}.try_into().unwrap()" ) ,
1728
1749
) ) ;
1729
1750
( msg, suggestion)
0 commit comments