1 use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
2 use clippy_utils::source::snippet_opt;
3 use rustc_ast::ast::{Pat, PatKind};
4 use rustc_lint::EarlyContext;
6 use super::UNNEEDED_FIELD_PATTERN;
8 pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) {
9 if let PatKind::Struct(_, ref npat, ref pfields, _) = pat.kind {
14 .expect("A path must have at least one segment")
18 for field in pfields {
19 if let PatKind::Wild = field.pat.kind {
23 if !pfields.is_empty() && wilds == pfields.len() {
26 UNNEEDED_FIELD_PATTERN,
28 "all the struct fields are matched to a wildcard pattern, consider using `..`",
30 &format!("try with `{} {{ .. }}` instead", type_name),
35 for field in pfields {
36 if let PatKind::Wild = field.pat.kind {
41 UNNEEDED_FIELD_PATTERN,
43 "you matched a field with a wildcard pattern, consider using `..` instead",
46 let mut normal = vec![];
48 for field in pfields {
49 match field.pat.kind {
52 if let Some(n) = snippet_opt(cx, field.span) {
61 UNNEEDED_FIELD_PATTERN,
63 "you matched a field with a wildcard pattern, consider using `..` \
66 &format!("try with `{} {{ {}, .. }}`", type_name, normal[..].join(", ")),