]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs
Auto merge of #8630 - Jarcho:forget_non_drop, r=Manishearth
[rust.git] / clippy_lints / src / matches / rest_pat_in_fully_bound_struct.rs
1 use clippy_utils::diagnostics::span_lint_and_help;
2 use rustc_hir::{Pat, PatKind, QPath};
3 use rustc_lint::LateContext;
4 use rustc_middle::ty;
5
6 use super::REST_PAT_IN_FULLY_BOUND_STRUCTS;
7
8 pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) {
9     if_chain! {
10         if !pat.span.from_expansion();
11         if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind;
12         if let Some(def_id) = path.res.opt_def_id();
13         let ty = cx.tcx.type_of(def_id);
14         if let ty::Adt(def, _) = ty.kind();
15         if def.is_struct() || def.is_union();
16         if fields.len() == def.non_enum_variant().fields.len();
17
18         then {
19             span_lint_and_help(
20                 cx,
21                 REST_PAT_IN_FULLY_BOUND_STRUCTS,
22                 pat.span,
23                 "unnecessary use of `..` pattern in struct binding. All fields were already bound",
24                 None,
25                 "consider removing `..` from this binding",
26             );
27         }
28     }
29 }