Skip to content

Commit 4c63a21

Browse files
committed
lint: port non-shorthand pattern diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent d433c9a commit 4c63a21

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,6 @@ lint-builtin-while-true = denote infinite loops with `loop {"{"} ... {"}"}`
291291
.suggestion = use `loop`
292292
293293
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

compiler/rustc_lint/src/builtin.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,26 +256,26 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
256256
== Some(cx.tcx.field_index(fieldpat.hir_id, cx.typeck_results()))
257257
{
258258
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));
261259
let binding = match binding_annot {
262260
hir::BindingAnnotation::Unannotated => None,
263261
hir::BindingAnnotation::Mutable => Some("mut"),
264262
hir::BindingAnnotation::Ref => Some("ref"),
265263
hir::BindingAnnotation::RefMut => Some("ref mut"),
266264
};
267-
let ident = if let Some(binding) = binding {
265+
let suggested_ident = if let Some(binding) = binding {
268266
format!("{} {}", binding, ident)
269267
} else {
270268
ident.to_string()
271269
};
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();
279279
});
280280
}
281281
}

0 commit comments

Comments
 (0)