2015-12-06 02:21:34 +00:00
|
|
|
//use rustc_front::hir::*;
|
|
|
|
|
|
|
|
use rustc::lint::*;
|
|
|
|
|
|
|
|
use syntax::ast::*;
|
|
|
|
|
|
|
|
use utils::span_lint;
|
|
|
|
|
2015-12-07 12:23:52 +00:00
|
|
|
declare_lint!(pub UNNEEDED_FIELD_PATTERN, Warn,
|
|
|
|
"Struct fields are bound to a wildcard instead of using `..`");
|
2015-12-06 02:21:34 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct MiscEarly;
|
|
|
|
|
|
|
|
impl LintPass for MiscEarly {
|
|
|
|
fn get_lints(&self) -> LintArray {
|
2015-12-07 12:23:52 +00:00
|
|
|
lint_array!(UNNEEDED_FIELD_PATTERN)
|
2015-12-06 02:21:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EarlyLintPass for MiscEarly {
|
|
|
|
fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) {
|
|
|
|
if let PatStruct(_, ref pfields, _) = pat.node {
|
|
|
|
let mut wilds = 0;
|
|
|
|
|
|
|
|
for field in pfields {
|
|
|
|
if field.node.pat.node == PatWild {
|
|
|
|
wilds += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !pfields.is_empty() && wilds == pfields.len() {
|
2015-12-07 12:23:52 +00:00
|
|
|
span_lint(cx, UNNEEDED_FIELD_PATTERN, pat.span,
|
2015-12-06 02:21:34 +00:00
|
|
|
"All the struct fields are matched to a wildcard pattern, \
|
|
|
|
consider using `..`.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if wilds > 0 {
|
|
|
|
for field in pfields {
|
|
|
|
if field.node.pat.node == PatWild {
|
2015-12-07 12:23:52 +00:00
|
|
|
span_lint(cx, UNNEEDED_FIELD_PATTERN, field.span,
|
2015-12-06 02:21:34 +00:00
|
|
|
"You matched a field with a wildcard pattern. \
|
|
|
|
Consider using `..` instead");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|