@@ -835,20 +835,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
835
835
self . add_rust_2024_migration_desugared_pat (
836
836
pat_info. top_info . hir_id ,
837
837
pat,
838
- ident . span ,
838
+ 't' ,
839
839
def_br_mutbl,
840
840
) ;
841
841
BindingMode ( ByRef :: No , Mutability :: Mut )
842
842
}
843
843
}
844
844
BindingMode ( ByRef :: No , mutbl) => BindingMode ( def_br, mutbl) ,
845
- BindingMode ( ByRef :: Yes ( _ ) , _) => {
845
+ BindingMode ( ByRef :: Yes ( user_br_mutbl ) , _) => {
846
846
if let ByRef :: Yes ( def_br_mutbl) = def_br {
847
847
// `ref`/`ref mut` overrides the binding mode on edition <= 2021
848
848
self . add_rust_2024_migration_desugared_pat (
849
849
pat_info. top_info . hir_id ,
850
850
pat,
851
- ident . span ,
851
+ if user_br_mutbl . is_mut ( ) { 't' } else { 'f' } ,
852
852
def_br_mutbl,
853
853
) ;
854
854
}
@@ -2387,7 +2387,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2387
2387
self . add_rust_2024_migration_desugared_pat (
2388
2388
pat_info. top_info . hir_id ,
2389
2389
pat,
2390
- inner . span ,
2390
+ if pat_mutbl . is_mut ( ) { 't' } else { '&' } ,
2391
2391
inh_mut,
2392
2392
)
2393
2393
}
@@ -2779,18 +2779,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2779
2779
& self ,
2780
2780
pat_id : HirId ,
2781
2781
subpat : & ' tcx Pat < ' tcx > ,
2782
- cutoff_span : Span ,
2782
+ final_char : char ,
2783
2783
def_br_mutbl : Mutability ,
2784
2784
) {
2785
2785
// Try to trim the span we're labeling to just the `&` or binding mode that's an issue.
2786
2786
// If the subpattern's span is is from an expansion, the emitted label will not be trimmed.
2787
- let source_map = self . tcx . sess . source_map ( ) ;
2788
- let cutoff_span = source_map
2789
- . span_extend_prev_while ( cutoff_span, |c| c. is_whitespace ( ) || c == '(' )
2790
- . unwrap_or ( cutoff_span) ;
2791
- // Ensure we use the syntax context and thus edition of `subpat.span`; this will be a hard
2792
- // error if the subpattern is of edition >= 2024.
2793
- let trimmed_span = subpat. span . until ( cutoff_span) . with_ctxt ( subpat. span . ctxt ( ) ) ;
2787
+ // Importantly, the edition of the trimmed span should be the same as `subpat.span`; this
2788
+ // will be a hard error if the subpattern is of edition >= 2024.
2789
+ let from_expansion = subpat. span . from_expansion ( ) ;
2790
+ let trimmed_span = if from_expansion {
2791
+ subpat. span
2792
+ } else {
2793
+ self . tcx . sess . source_map ( ) . span_through_char ( subpat. span , final_char)
2794
+ } ;
2794
2795
2795
2796
let mut typeck_results = self . typeck_results . borrow_mut ( ) ;
2796
2797
let mut table = typeck_results. rust_2024_migration_desugared_pats_mut ( ) ;
@@ -2824,7 +2825,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2824
2825
} ;
2825
2826
// Only provide a detailed label if the problematic subpattern isn't from an expansion.
2826
2827
// In the case that it's from a macro, we'll add a more detailed note in the emitter.
2827
- let from_expansion = subpat. span . from_expansion ( ) ;
2828
2828
let primary_label = if from_expansion {
2829
2829
// We can't suggest eliding modifiers within expansions.
2830
2830
info. suggest_eliding_modes = false ;
0 commit comments