Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s/PatKind::Ident/PatKind::Binding/g #970

Merged
merged 7 commits into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.0.71 — TBD
## 0.0.71 — 2016-05-31
* Rustup to *rustc 1.10.0-nightly (7bddce693 2016-05-27)*
* New lint: [`useless_let_if_seq`]

## 0.0.70 — 2016-05-28
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.0.70"
version = "0.0.71"
authors = [
"Manish Goregaokar <manishsmail@gmail.com>",
"Andre Bogus <bogusandre@gmail.com>",
Expand Down Expand Up @@ -30,7 +30,7 @@ toml = "0.1"
unicode-normalization = "0.1"
quine-mc_cluskey = "0.2.2"
# begin automatic update
clippy_lints = { version = "0.0.70", path = "clippy_lints" }
clippy_lints = { version = "0.0.71", path = "clippy_lints" }
# end automatic update
rustc-serialize = "0.3"

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "clippy_lints"
# begin automatic update
version = "0.0.70"
version = "0.0.71"
# end automatic update
authors = [
"Manish Goregaokar <manishsmail@gmail.com>",
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/blacklisted_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl LintPass for BlackListedName {

impl LateLintPass for BlackListedName {
fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
if let PatKind::Ident(_, ref ident, _) = pat.node {
if let PatKind::Binding(_, ref ident, _) = pat.node {
if self.blacklist.iter().any(|s| s == &*ident.node.as_str()) {
span_lint(cx,
BLACKLISTED_NAME,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
(BiDiv, Constant::Int(l), Some(Constant::Int(r))) => (l / r).ok().map(Constant::Int),
(BiRem, Constant::Int(l), Some(Constant::Int(r))) => (l % r).ok().map(Constant::Int),
(BiAnd, Constant::Bool(false), _) => Some(Constant::Bool(false)),
(BiAnd, Constant::Bool(true), Some(r)) => Some(r),
(BiOr, Constant::Bool(true), _) => Some(Constant::Bool(true)),
(BiAnd, Constant::Bool(true), Some(r)) |
(BiOr, Constant::Bool(false), Some(r)) => Some(r),
(BiBitXor, Constant::Bool(l), Some(Constant::Bool(r))) => Some(Constant::Bool(l ^ r)),
(BiBitXor, Constant::Int(l), Some(Constant::Int(r))) => (l ^ r).ok().map(Constant::Int),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<Interned
bindings_impl(cx, pat, map);
}
}
PatKind::Ident(_, ref ident, ref as_pat) => {
PatKind::Binding(_, ref ident, ref as_pat) => {
if let Entry::Vacant(v) = map.entry(ident.node.as_str()) {
v.insert(cx.tcx.pat_ty(pat));
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
_ => (),
}
for (ref a1, ref a2) in decl.inputs.iter().zip(args) {
if let PatKind::Ident(_, ident, _) = a1.pat.node {
if let PatKind::Binding(_, ident, _) = a1.pat.node {
// XXXManishearth Should I be checking the binding mode here?
if let ExprPath(None, ref p) = a2.node {
if p.segments.len() != 1 {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/let_if_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl LateLintPass for LetIfSeq {
let Some(expr) = it.peek(),
let hir::StmtDecl(ref decl, _) = stmt.node,
let hir::DeclLocal(ref decl) = decl.node,
let hir::PatKind::Ident(mode, ref name, None) = decl.pat.node,
let hir::PatKind::Binding(mode, ref name, None) = decl.pat.node,
let Some(def) = cx.tcx.def_map.borrow().get(&decl.pat.id),
let hir::StmtExpr(ref if_, _) = expr.node,
let hir::ExprIf(ref cond, ref then, ref else_) = if_.node,
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fn check_for_loop(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &E
fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &Expr) {
if let Some(UnsugaredRange { start: Some(ref start), ref end, .. }) = unsugar_range(arg) {
// the var must be a single name
if let PatKind::Ident(_, ref ident, _) = pat.node {
if let PatKind::Binding(_, ref ident, _) = pat.node {
let mut visitor = VarVisitor {
cx: cx,
var: ident.node,
Expand Down Expand Up @@ -613,7 +613,7 @@ fn check_for_loop_over_map_kv(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Ex
fn pat_is_wild(pat: &PatKind, body: &Expr) -> bool {
match *pat {
PatKind::Wild => true,
PatKind::Ident(_, ident, None) if ident.node.as_str().starts_with('_') => {
PatKind::Binding(_, ident, None) if ident.node.as_str().starts_with('_') => {
let mut visitor = UsedVisitor {
var: ident.node,
used: false,
Expand Down Expand Up @@ -884,7 +884,7 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> {
// Look for declarations of the variable
if let DeclLocal(ref local) = decl.node {
if local.pat.id == self.var_id {
if let PatKind::Ident(_, ref ident, _) = local.pat.node {
if let PatKind::Binding(_, ref ident, _) = local.pat.node {
self.name = Some(ident.node);

self.state = if let Some(ref init) = local.init {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s

fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
match pat.node {
PatKind::Ident(_, name, None) => Some(name.node),
PatKind::Binding(_, name, None) => Some(name.node),
PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
_ => None,
}
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr:
}
path.to_string()
}
PatKind::Ident(BindByValue(MutImmutable), ident, None) => ident.node.to_string(),
PatKind::Binding(BindByValue(MutImmutable), ident, None) => ident.node.to_string(),
PatKind::Path(ref path) => path.to_string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Binding really necessary here? My understanding was that variant were now resolved (and we only care about some known paths).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but I'm tired now and have to get up early tomorrow.

_ => return,
};

Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl LateLintPass for TopLevelRefPass {
return;
}
for ref arg in &decl.inputs {
if let PatKind::Ident(BindByRef(_), _, _) = arg.pat.node {
if let PatKind::Binding(BindByRef(_), _, _) = arg.pat.node {
span_lint(cx,
TOPLEVEL_REF_ARG,
arg.pat.span,
Expand All @@ -58,7 +58,7 @@ impl LateLintPass for TopLevelRefPass {
[
let StmtDecl(ref d, _) = s.node,
let DeclLocal(ref l) = d.node,
let PatKind::Ident(BindByRef(_), i, None) = l.pat.node,
let PatKind::Binding(BindByRef(_), i, None) = l.pat.node,
let Some(ref init) = l.init
], {
let tyopt = if let Some(ref ty) = l.ty {
Expand Down Expand Up @@ -346,7 +346,7 @@ impl LintPass for PatternPass {

impl LateLintPass for PatternPass {
fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
if let PatKind::Ident(_, ref ident, Some(ref right)) = pat.node {
if let PatKind::Binding(_, ref ident, Some(ref right)) = pat.node {
if right.node == PatKind::Wild {
span_lint(cx,
REDUNDANT_PATTERN,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl LateLintPass for ShadowPass {
fn check_fn(cx: &LateContext, decl: &FnDecl, block: &Block) {
let mut bindings = Vec::new();
for arg in &decl.inputs {
if let PatKind::Ident(_, ident, _) = arg.pat.node {
if let PatKind::Binding(_, ident, _) = arg.pat.node {
bindings.push((ident.node.unhygienize(), ident.span))
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ fn is_binding(cx: &LateContext, pat: &Pat) -> bool {
fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span, bindings: &mut Vec<(Name, Span)>) {
// TODO: match more stuff / destructuring
match pat.node {
PatKind::Ident(_, ref ident, ref inner) => {
PatKind::Binding(_, ref ident, ref inner) => {
let name = ident.node.unhygienize();
if is_binding(cx, pat) {
let mut new_binding = true;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
let StmtDecl(ref tmp, _) = w[0].node,
let DeclLocal(ref tmp) = tmp.node,
let Some(ref tmp_init) = tmp.init,
let PatKind::Ident(_, ref tmp_name, None) = tmp.pat.node,
let PatKind::Binding(_, ref tmp_name, None) = tmp.pat.node,

// foo() = bar();
let StmtSemi(ref first, _) = w[1].node,
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/utils/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
(&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => {
self.eq_path(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
}
(&PatKind::Ident(ref lb, ref li, ref lp), &PatKind::Ident(ref rb, ref ri, ref rp)) => {
(&PatKind::Binding(ref lb, ref li, ref lp), &PatKind::Binding(ref rb, ref ri, ref rp)) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might also want to add PatKind::Path here and add some tests for it. Something like:

if let None = Some(42) {
} else if let None = Some(42) {
}

See rust-lang/rust#31685.

lb == rb && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
}
(&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_path(l, r),
(&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r),
(&PatKind::QPath(ref ls, ref lp), &PatKind::QPath(ref rs, ref rp)) => {
self.eq_qself(ls, rs) && self.eq_path(lp, rp)
Expand Down
5 changes: 5 additions & 0 deletions tests/compile-fail/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ fn if_same_then_else() -> Result<&'static str, ()> {

let _ = match Some(42) {
Some(_) => 24,
None => 24, //~ERROR this `match` has identical arm bodies
};

let _ = match Some(42) {
Some(foo) => 24,
None => 24,
};

Expand Down
6 changes: 6 additions & 0 deletions tests/compile-fail/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ fn overlapping() {
11 ... 50 => println!("0 ... 10"),
_ => (),
}

if let None = Some(42) {
// nothing
} else if let None = Some(42) {
// another nothing :-)
}
}

fn main() {
Expand Down