3 use utils::{span_lint_and_sugg};
5 /// **What it does:** Checks for redundnat field names 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 "using same name for field and variable ,where shorthand can 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;
42 if let ExprPath(ref qpath) = field.expr.node {
43 if let &QPath::Resolved(_, ref path) = qpath {
44 let segments = &path.segments;
46 if segments.len() == 1 {
47 let expr_name = segments[0].name;
49 if name == expr_name {
52 REDUNDANT_FIELD_NAMES,
54 "redundant field names in struct initialization",
56 "replace '{0}: {0}' with '{0}'",