1 use crate::utils::span_lint;
2 use rustc::hir::{Expr, ExprKind};
3 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5 use rustc::{declare_lint_pass, declare_tool_lint};
8 /// **What it does:** Checks for needlessly including a base struct on update
9 /// when all fields are changed anyway.
11 /// **Why is this bad?** This will cost resources (because the base has to be
12 /// somewhere), and make the code less readable.
14 /// **Known problems:** None.
26 "using `Foo { ..base }` when there are no missing fields"
29 declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]);
31 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate {
32 fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
33 if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.node {
34 let ty = cx.tables.expr_ty(expr);
35 if let ty::Adt(def, _) = ty.sty {
36 if fields.len() == def.non_enum_variant().fields.len() {
41 "struct update has no effect, all the fields in the struct have already been specified",