@@ -174,18 +174,27 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
174
174
// (Issue #49588)
175
175
continue ;
176
176
}
177
- if let PatKind :: Binding ( _ , _, ident, None ) = fieldpat. pat . kind {
177
+ if let PatKind :: Binding ( binding_annot , _, ident, None ) = fieldpat. pat . kind {
178
178
if cx. tcx . find_field_index ( ident, & variant) ==
179
179
Some ( cx. tcx . field_index ( fieldpat. hir_id , cx. tables ) ) {
180
180
let mut err = cx. struct_span_lint ( NON_SHORTHAND_FIELD_PATTERNS ,
181
181
fieldpat. span ,
182
182
& format ! ( "the `{}:` in this pattern is redundant" , ident) ) ;
183
- let subspan = cx. tcx . sess . source_map ( ) . span_through_char ( fieldpat. span ,
184
- ':' ) ;
185
- err. span_suggestion_short (
186
- subspan,
187
- "remove this" ,
188
- ident. to_string ( ) ,
183
+ let binding = match binding_annot {
184
+ hir:: BindingAnnotation :: Unannotated => None ,
185
+ hir:: BindingAnnotation :: Mutable => Some ( "mut" ) ,
186
+ hir:: BindingAnnotation :: Ref => Some ( "ref" ) ,
187
+ hir:: BindingAnnotation :: RefMut => Some ( "ref mut" ) ,
188
+ } ;
189
+ let ident = if let Some ( binding) = binding {
190
+ format ! ( "{} {}" , binding, ident)
191
+ } else {
192
+ ident. to_string ( )
193
+ } ;
194
+ err. span_suggestion (
195
+ fieldpat. span ,
196
+ "use shorthand field pattern" ,
197
+ ident,
189
198
Applicability :: MachineApplicable
190
199
) ;
191
200
err. emit ( ) ;
0 commit comments