-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check on redundant _ bindings in structs
- Loading branch information
1 parent
b660bfa
commit 7211783
Showing
8 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//use rustc_front::hir::*; | ||
|
||
use rustc::lint::*; | ||
|
||
use syntax::ast::*; | ||
|
||
use utils::span_lint; | ||
|
||
declare_lint!(pub UNNEEDED_BINDING, Warn, | ||
"Type fields are bound when not necessary"); | ||
|
||
#[derive(Copy, Clone)] | ||
pub struct MiscEarly; | ||
|
||
impl LintPass for MiscEarly { | ||
fn get_lints(&self) -> LintArray { | ||
lint_array!(UNNEEDED_BINDING) | ||
} | ||
} | ||
|
||
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() { | ||
span_lint(cx, UNNEEDED_BINDING, pat.span, | ||
"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 { | ||
span_lint(cx, UNNEEDED_BINDING, field.span, | ||
"You matched a field with a wildcard pattern. \ | ||
Consider using `..` instead"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters