@@ -647,7 +647,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
647647 ) ,
648648 ) ,
649649 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+ ) ,
651654 [ first, ..] => ( base. span. between( first. span) , ", " . to_string( ) ) ,
652655 } ,
653656 ]
@@ -771,8 +774,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
771774 "use `?` to coerce and return an appropriate `Err`, and wrap the resulting value \
772775 in `Ok` so the expression remains of type `Result`",
773776 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( ) ) ,
776779 ] ,
777780 Applicability :: MaybeIncorrect ,
778781 ) ;
@@ -843,8 +846,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
843846 } else {
844847 return false ;
845848 } ;
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 ( ) )
848854 {
849855 // Add a semicolon, except after `}`.
850856 let semicolon =
@@ -853,7 +859,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
853859 _ => ";" ,
854860 } ;
855861 err. span_suggestions (
856- span. shrink_to_hi ( ) ,
862+ self . tcx . adjust_span ( span) . shrink_to_hi ( ) ,
857863 "try adding an expression at the end of the block" ,
858864 return_suggestions
859865 . into_iter ( )
@@ -931,8 +937,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
931937 }
932938
933939 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( ) ) ,
936945 ]
937946 } ;
938947
@@ -1016,8 +1025,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10161025 err. multipart_suggestion (
10171026 format ! ( "consider calling `{s}::new`" ) ,
10181027 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}" ) ) ,
10211030 ] ,
10221031 Applicability :: MaybeIncorrect ,
10231032 ) ;
@@ -1271,7 +1280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12711280 && replace_prefix ( & src, "\" " , "b\" " ) . is_some ( )
12721281 {
12731282 return Some ( (
1274- sp . shrink_to_lo ( ) ,
1283+ self . tcx . adjust_span ( sp ) . shrink_to_lo ( ) ,
12751284 "consider adding a leading `b`" . to_string ( ) ,
12761285 "b" . to_string ( ) ,
12771286 Applicability :: MachineApplicable ,
@@ -1468,7 +1477,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14681477 _ if sp == expr. span => {
14691478 if let Some ( mut steps) = self . deref_steps ( checked_ty, expected) {
14701479 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 ( ) ;
14721481 let mut remove = String :: new ( ) ;
14731482
14741483 // Try peeling off any existing `&` and `&mut` to reach our target type
@@ -1539,7 +1548,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15391548 return None ;
15401549 } else if let Some ( expr) = self . maybe_get_block_expr ( expr) {
15411550 // 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 ( ) )
15431552 } else {
15441553 ( prefix_span, format ! ( "{}{}" , prefix, "*" . repeat( steps) ) )
15451554 } ;
@@ -1596,7 +1605,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15961605 // `expr` is a literal field for a struct, only suggest if appropriate
15971606 if field. is_shorthand {
15981607 // 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+ ) ) ;
16001612 } else {
16011613 // Likely a field was meant, but this field wasn't found. Do not suggest anything.
16021614 return false ;
@@ -1652,16 +1664,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16521664 ) ;
16531665
16541666 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 ( ) ) ) ;
16561668 ")"
16571669 } else {
16581670 ""
16591671 } ;
16601672
16611673 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+ ) ) ;
16631678 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+ ) ) ;
16651683 let mut suffix_suggestion = sugg. clone ( ) ;
16661684 suffix_suggestion. push ( (
16671685 if matches ! (
@@ -1715,15 +1733,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17151733 "you can convert `{lhs_src}` from `{expected_ty}` to `{checked_ty}`, matching the type of `{src}`" ,
17161734 ) ;
17171735 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( ) ) ,
17201741 ] ;
17211742 ( msg, suggestion)
17221743 } else {
17231744 let msg = format ! ( "{msg} and panic if the converted value doesn't fit" ) ;
17241745 let mut suggestion = sugg. clone ( ) ;
17251746 suggestion. push ( (
1726- expr. span . shrink_to_hi ( ) ,
1747+ self . tcx . adjust_span ( expr. span ) . shrink_to_hi ( ) ,
17271748 format ! ( "{close_paren}.try_into().unwrap()" ) ,
17281749 ) ) ;
17291750 ( msg, suggestion)
0 commit comments