File tree Expand file tree Collapse file tree 2 files changed +13
-10
lines changed
rustc_error_messages/locales/en-US Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -291,3 +291,6 @@ lint-builtin-while-true = denote infinite loops with `loop {"{"} ... {"}"}`
291
291
.suggestion = use `loop`
292
292
293
293
lint-builtin-box-pointers = type uses owned (Box type) pointers: { $ty }
294
+
295
+ lint-builtin-non-shorthand-field-patterns = the `{ $ident } :` in this pattern is redundant
296
+ .suggestion = use shorthand field pattern
Original file line number Diff line number Diff line change @@ -256,26 +256,26 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
256
256
== Some ( cx. tcx . field_index ( fieldpat. hir_id , cx. typeck_results ( ) ) )
257
257
{
258
258
cx. struct_span_lint ( NON_SHORTHAND_FIELD_PATTERNS , fieldpat. span , |lint| {
259
- let mut err = lint
260
- . build ( & format ! ( "the `{}:` in this pattern is redundant" , ident) ) ;
261
259
let binding = match binding_annot {
262
260
hir:: BindingAnnotation :: Unannotated => None ,
263
261
hir:: BindingAnnotation :: Mutable => Some ( "mut" ) ,
264
262
hir:: BindingAnnotation :: Ref => Some ( "ref" ) ,
265
263
hir:: BindingAnnotation :: RefMut => Some ( "ref mut" ) ,
266
264
} ;
267
- let ident = if let Some ( binding) = binding {
265
+ let suggested_ident = if let Some ( binding) = binding {
268
266
format ! ( "{} {}" , binding, ident)
269
267
} else {
270
268
ident. to_string ( )
271
269
} ;
272
- err. span_suggestion (
273
- fieldpat. span ,
274
- "use shorthand field pattern" ,
275
- ident,
276
- Applicability :: MachineApplicable ,
277
- ) ;
278
- err. emit ( ) ;
270
+ lint. build ( fluent:: lint:: builtin_non_shorthand_field_patterns)
271
+ . set_arg ( "ident" , ident. clone ( ) )
272
+ . span_suggestion (
273
+ fieldpat. span ,
274
+ fluent:: lint:: suggestion,
275
+ suggested_ident,
276
+ Applicability :: MachineApplicable ,
277
+ )
278
+ . emit ( ) ;
279
279
} ) ;
280
280
}
281
281
}
You can’t perform that action at this time.
0 commit comments