3 use utils::{span_lint_and_sugg, match_var};
5 /// **What it does:** Checks for fields in struct literals where shorthands
8 /// **Why is this bad?** If the field and variable names are the same,
9 /// the field name is redundant.
11 /// **Known problems:** None.
15 /// let bar: u8 = 123;
21 /// let foo = Foo{ bar: bar }
24 pub REDUNDANT_FIELD_NAMES,
26 "checks for fields in struct literals where shorthands could be used"
29 pub struct RedundantFieldNames;
31 impl LintPass for RedundantFieldNames {
32 fn get_lints(&self) -> LintArray {
33 lint_array!(REDUNDANT_FIELD_NAMES)
37 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantFieldNames {
38 fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
39 if let ExprStruct(_, ref fields, _) = expr.node {
41 let name = field.name.node;
43 if match_var(&field.expr, name) && !field.is_shorthand {
46 REDUNDANT_FIELD_NAMES,
48 "redundant field names in struct initialization",