1 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
2 use rustc::ty::TyStruct;
3 use rustc::hir::{Expr, ExprStruct};
6 /// **What it does:** This lint warns on needlessly including a base struct on update when all fields are changed anyway.
8 /// **Why is this bad?** This will cost resources (because the base has to be somewhere), and make the code less readable.
10 /// **Known problems:** None.
14 /// Point { x: 1, y: 0, ..zero_point }
19 "using `Foo { ..base }` when there are no missing fields"
22 #[derive(Copy, Clone)]
25 impl LintPass for Pass {
26 fn get_lints(&self) -> LintArray {
27 lint_array!(NEEDLESS_UPDATE)
31 impl LateLintPass for Pass {
32 fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
33 if let ExprStruct(_, ref fields, Some(ref base)) = expr.node {
34 let ty = cx.tcx.expr_ty(expr);
35 if let TyStruct(def, _) = ty.sty {
36 if fields.len() == def.struct_variant().fields.len() {
40 "struct update has no effect, all the fields in the struct have already been specified");