@@ -835,20 +835,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
835835 self . add_rust_2024_migration_desugared_pat (
836836 pat_info. top_info . hir_id ,
837837 pat,
838- ident . span ,
838+ 't' ,
839839 def_br_mutbl,
840840 ) ;
841841 BindingMode ( ByRef :: No , Mutability :: Mut )
842842 }
843843 }
844844 BindingMode ( ByRef :: No , mutbl) => BindingMode ( def_br, mutbl) ,
845- BindingMode ( ByRef :: Yes ( _ ) , _) => {
845+ BindingMode ( ByRef :: Yes ( user_br_mutbl ) , _) => {
846846 if let ByRef :: Yes ( def_br_mutbl) = def_br {
847847 // `ref`/`ref mut` overrides the binding mode on edition <= 2021
848848 self . add_rust_2024_migration_desugared_pat (
849849 pat_info. top_info . hir_id ,
850850 pat,
851- ident . span ,
851+ if user_br_mutbl . is_mut ( ) { 't' } else { 'f' } ,
852852 def_br_mutbl,
853853 ) ;
854854 }
@@ -2387,7 +2387,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23872387 self . add_rust_2024_migration_desugared_pat (
23882388 pat_info. top_info . hir_id ,
23892389 pat,
2390- inner . span ,
2390+ if pat_mutbl . is_mut ( ) { 't' } else { '&' } ,
23912391 inh_mut,
23922392 )
23932393 }
@@ -2779,18 +2779,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27792779 & self ,
27802780 pat_id : HirId ,
27812781 subpat : & ' tcx Pat < ' tcx > ,
2782- cutoff_span : Span ,
2782+ final_char : char ,
27832783 def_br_mutbl : Mutability ,
27842784 ) {
27852785 // Try to trim the span we're labeling to just the `&` or binding mode that's an issue.
27862786 // 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+ } ;
27942795
27952796 let mut typeck_results = self . typeck_results . borrow_mut ( ) ;
27962797 let mut table = typeck_results. rust_2024_migration_desugared_pats_mut ( ) ;
@@ -2824,7 +2825,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28242825 } ;
28252826 // Only provide a detailed label if the problematic subpattern isn't from an expansion.
28262827 // 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 ( ) ;
28282828 let primary_label = if from_expansion {
28292829 // We can't suggest eliding modifiers within expansions.
28302830 info. suggest_eliding_modes = false ;
0 commit comments