@@ -293,9 +293,14 @@ impl<'a, 'tcx> PatMigration<'a, 'tcx> {
293
293
self . add_default_mode_label_if_needed ( ) ;
294
294
// This sets the default binding mode to by-value in the user's pattern, but we'll try to
295
295
// suggest removing it.
296
- // TODO: if this is inside a macro expansion, we won't be able to remove it.
297
296
self . push_deref ( pat_span, mutbl, PatDerefKind :: Explicit { inner_span : subpat. span } ) ;
298
297
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
+
299
304
// If the immediate subpattern is a binding, removing this reference pattern would change
300
305
// its type. To avoid that, we include it and all its parents in that case.
301
306
// 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> {
378
383
379
384
// If `mode` doesn't match the default, we'll need to specify its binding modifiers
380
385
// 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 ;
383
391
384
392
// Track the binding
385
393
let span = if explicit_ba == BindingMode :: NONE {
0 commit comments