@@ -2806,31 +2806,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28062806 && !self . tcx . features ( ) . ref_pat_eat_one_layer_2024_structural ( ) ,
28072807 } ) ;
28082808
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+ } ;
28092825 // Only provide a detailed label if the problematic subpattern isn't from an expansion.
28102826 // In the case that it's from a macro, we'll add a more detailed note in the emitter.
28112827 let from_expansion = subpat. span . from_expansion ( ) ;
28122828 let primary_label = if from_expansion {
2829+ // We can't suggest eliding modifiers within expansions.
2830+ info. suggest_eliding_modes = false ;
28132831 // NB: This wording assumes the only expansions that can produce problematic reference
28142832 // patterns and bindings are macros. If a desugaring or AST pass is added that can do
28152833 // so, we may want to inspect the span's source callee or macro backtrace.
28162834 "occurs within macro expansion" . to_owned ( )
28172835 } 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- } ;
28342836 let dbm_str = match def_br_mutbl {
28352837 Mutability :: Not => "ref" ,
28362838 Mutability :: Mut => "ref mut" ,
0 commit comments