@@ -293,9 +293,14 @@ impl<'a, 'tcx> PatMigration<'a, 'tcx> {
293293 self . add_default_mode_label_if_needed ( ) ;
294294 // This sets the default binding mode to by-value in the user's pattern, but we'll try to
295295 // suggest removing it.
296- // TODO: if this is inside a macro expansion, we won't be able to remove it.
297296 self . push_deref ( pat_span, mutbl, PatDerefKind :: Explicit { inner_span : subpat. span } ) ;
298297
298+ // If this is inside a macro expansion, we won't be able to remove it.
299+ if pat_span. from_expansion ( ) {
300+ self . add_derefs_to_suggestion ( self . innermost_deref ) ;
301+ return ;
302+ }
303+
299304 // If the immediate subpattern is a binding, removing this reference pattern would change
300305 // its type. To avoid that, we include it and all its parents in that case.
301306 // FIXME(ref_pat_eat_one_layer_2024): This assumes ref pats can't eat the binding mode
@@ -378,8 +383,11 @@ impl<'a, 'tcx> PatMigration<'a, 'tcx> {
378383
379384 // If `mode` doesn't match the default, we'll need to specify its binding modifiers
380385 // explicitly, which in turn necessitates a by-move default binding mode.
381- // TODO: if this is inside a macro expansion, we won't be able to change it.
382- let suggest = mode != BindingMode ( self . sugg_default_mode ( ) , Mutability :: Not ) ;
386+ // Additionally, if this is inside a macro expansion, we won't be able to change it. If a
387+ // binding modifier is missing inside the expansion, there's not much we can do, but we can
388+ // avoid suggestions to elide binding modifiers that are explicit within expansions.
389+ let suggest = mode != BindingMode ( self . sugg_default_mode ( ) , Mutability :: Not )
390+ || pat_span. from_expansion ( ) && explicit_ba != BindingMode :: NONE ;
383391
384392 // Track the binding
385393 let span = if explicit_ba == BindingMode :: NONE {
0 commit comments