@@ -2806,31 +2806,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2806
2806
&& !self . tcx . features ( ) . ref_pat_eat_one_layer_2024_structural ( ) ,
2807
2807
} ) ;
2808
2808
2809
+ let pat_kind = if let PatKind :: Binding ( user_bind_annot, _, _, _) = subpat. kind {
2810
+ info. bad_modifiers = true ;
2811
+ // If the user-provided binding modifier doesn't match the default binding mode, we'll
2812
+ // need to suggest reference patterns, which can affect other bindings.
2813
+ // For simplicity, we opt to suggest making the pattern fully explicit.
2814
+ info. suggest_eliding_modes &=
2815
+ user_bind_annot == BindingMode ( ByRef :: Yes ( def_br_mutbl) , Mutability :: Not ) ;
2816
+ "binding modifier"
2817
+ } else {
2818
+ info. bad_ref_pats = true ;
2819
+ // For simplicity, we don't try to suggest eliding reference patterns. Thus, we'll
2820
+ // suggest adding them instead, which can affect the types assigned to bindings.
2821
+ // As such, we opt to suggest making the pattern fully explicit.
2822
+ info. suggest_eliding_modes = false ;
2823
+ "reference pattern"
2824
+ } ;
2809
2825
// Only provide a detailed label if the problematic subpattern isn't from an expansion.
2810
2826
// In the case that it's from a macro, we'll add a more detailed note in the emitter.
2811
2827
let from_expansion = subpat. span . from_expansion ( ) ;
2812
2828
let primary_label = if from_expansion {
2829
+ // We can't suggest eliding modifiers within expansions.
2830
+ info. suggest_eliding_modes = false ;
2813
2831
// NB: This wording assumes the only expansions that can produce problematic reference
2814
2832
// patterns and bindings are macros. If a desugaring or AST pass is added that can do
2815
2833
// so, we may want to inspect the span's source callee or macro backtrace.
2816
2834
"occurs within macro expansion" . to_owned ( )
2817
2835
} else {
2818
- let pat_kind = if let PatKind :: Binding ( user_bind_annot, _, _, _) = subpat. kind {
2819
- info. bad_modifiers |= true ;
2820
- // If the user-provided binding modifier doesn't match the default binding mode, we'll
2821
- // need to suggest reference patterns, which can affect other bindings.
2822
- // For simplicity, we opt to suggest making the pattern fully explicit.
2823
- info. suggest_eliding_modes &=
2824
- user_bind_annot == BindingMode ( ByRef :: Yes ( def_br_mutbl) , Mutability :: Not ) ;
2825
- "binding modifier"
2826
- } else {
2827
- info. bad_ref_pats |= true ;
2828
- // For simplicity, we don't try to suggest eliding reference patterns. Thus, we'll
2829
- // suggest adding them instead, which can affect the types assigned to bindings.
2830
- // As such, we opt to suggest making the pattern fully explicit.
2831
- info. suggest_eliding_modes = false ;
2832
- "reference pattern"
2833
- } ;
2834
2836
let dbm_str = match def_br_mutbl {
2835
2837
Mutability :: Not => "ref" ,
2836
2838
Mutability :: Mut => "ref mut" ,
0 commit comments