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