From 2a5416d662724b8e8ba68aeb4069aa37e7a406d5 Mon Sep 17 00:00:00 2001 From: mcarton Date: Thu, 19 May 2016 23:14:34 +0200 Subject: [PATCH 1/4] Rustup to *1.10.0-nightly (9c6904ca1 2016-05-18)* --- README.md | 2 +- src/blacklisted_name.rs | 4 +- src/copies.rs | 2 +- src/eta_reduction.rs | 2 +- src/lib.rs | 2 +- src/loops.rs | 26 ++++---- src/map_clone.rs | 15 ++--- src/methods.rs | 3 +- src/misc.rs | 63 +++++++++++-------- src/overflow_check_conditional.rs | 4 +- src/shadow.rs | 10 +-- src/swap.rs | 2 +- src/unsafe_removed_from_name.rs | 2 +- src/unused_label.rs | 4 +- src/utils/hir.rs | 22 +++---- src/utils/mod.rs | 2 +- tests/compile-fail/used_underscore_binding.rs | 7 ++- 17 files changed, 93 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index 02b7365e8901..6843afb4ede6 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ name [unused_label](https://github.com/Manishearth/rust-clippy/wiki#unused_label) | warn | unused label [unused_lifetimes](https://github.com/Manishearth/rust-clippy/wiki#unused_lifetimes) | warn | unused lifetimes in function definitions [use_debug](https://github.com/Manishearth/rust-clippy/wiki#use_debug) | allow | use `Debug`-based formatting -[used_underscore_binding](https://github.com/Manishearth/rust-clippy/wiki#used_underscore_binding) | warn | using a binding which is prefixed with an underscore +[used_underscore_binding](https://github.com/Manishearth/rust-clippy/wiki#used_underscore_binding) | allow | using a binding which is prefixed with an underscore [useless_format](https://github.com/Manishearth/rust-clippy/wiki#useless_format) | warn | useless use of `format!` [useless_transmute](https://github.com/Manishearth/rust-clippy/wiki#useless_transmute) | warn | transmutes that have the same to and from types [useless_vec](https://github.com/Manishearth/rust-clippy/wiki#useless_vec) | warn | useless `vec!` diff --git a/src/blacklisted_name.rs b/src/blacklisted_name.rs index b515da000ee6..5cb84f62651b 100644 --- a/src/blacklisted_name.rs +++ b/src/blacklisted_name.rs @@ -35,11 +35,11 @@ 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 self.blacklist.iter().any(|s| s == &*ident.node.name.as_str()) { + if self.blacklist.iter().any(|s| s == &*ident.node.as_str()) { span_lint(cx, BLACKLISTED_NAME, pat.span, - &format!("use of a blacklisted/placeholder name `{}`", ident.node.name)); + &format!("use of a blacklisted/placeholder name `{}`", ident.node)); } } } diff --git a/src/copies.rs b/src/copies.rs index aa9f243e8c7f..4344ba461dd3 100644 --- a/src/copies.rs +++ b/src/copies.rs @@ -193,7 +193,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap { - if let Entry::Vacant(v) = map.entry(ident.node.name.as_str()) { + if let Entry::Vacant(v) = map.entry(ident.node.as_str()) { v.insert(cx.tcx.pat_ty(pat)); } if let Some(ref as_pat) = *as_pat { diff --git a/src/eta_reduction.rs b/src/eta_reduction.rs index c9a9ef85ede9..f73b6cfed2d7 100644 --- a/src/eta_reduction.rs +++ b/src/eta_reduction.rs @@ -77,7 +77,7 @@ fn check_closure(cx: &LateContext, expr: &Expr) { // If it's a proper path, it can't be a local variable return; } - if p.segments[0].identifier != ident.node { + if p.segments[0].name != ident.node { // The two idents should be the same return; } diff --git a/src/lib.rs b/src/lib.rs index d3940575659e..888abbc92c5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -411,6 +411,7 @@ pub fn plugin_registrar(reg: &mut Registry) { methods::OPTION_UNWRAP_USED, methods::RESULT_UNWRAP_USED, methods::WRONG_PUB_SELF_CONVENTION, + misc::USED_UNDERSCORE_BINDING, mut_mut::MUT_MUT, mutex_atomic::MUTEX_INTEGER, non_expressive_names::SIMILAR_NAMES, @@ -505,7 +506,6 @@ pub fn plugin_registrar(reg: &mut Registry) { misc::MODULO_ONE, misc::REDUNDANT_PATTERN, misc::TOPLEVEL_REF_ARG, - misc::USED_UNDERSCORE_BINDING, misc_early::DUPLICATE_UNDERSCORE_ARGUMENT, misc_early::REDUNDANT_CLOSURE_CALL, misc_early::UNNEEDED_FIELD_PATTERN, diff --git a/src/loops.rs b/src/loops.rs index 2384c8453037..061b8efaa64d 100644 --- a/src/loops.rs +++ b/src/loops.rs @@ -286,7 +286,7 @@ impl LateLintPass for LoopsPass { if let Some(lhs_constructor) = path.segments.last() { if method_name.node.as_str() == "next" && match_trait_method(cx, match_expr, &paths::ITERATOR) && - lhs_constructor.identifier.name.as_str() == "Some" && + lhs_constructor.name.as_str() == "Some" && !is_iterator_used_after_while_let(cx, iter_expr) { let iterator = snippet(cx, method_args[0].span, "_"); let loop_var = snippet(cx, pat_args[0].span, "_"); @@ -333,7 +333,7 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex if let PatKind::Ident(_, ref ident, _) = pat.node { let mut visitor = VarVisitor { cx: cx, - var: ident.node.name, + var: ident.node, indexed: HashMap::new(), nonindex: false, }; @@ -378,9 +378,9 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex expr.span, &format!("the loop variable `{}` is used to index `{}`. Consider using `for ({}, \ item) in {}.iter().enumerate(){}{}` or similar iterators", - ident.node.name, + ident.node, indexed, - ident.node.name, + ident.node, indexed, take, skip)); @@ -396,7 +396,7 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex expr.span, &format!("the loop variable `{}` is only used to index `{}`. \ Consider using `for item in {}` or similar iterators", - ident.node.name, + ident.node, indexed, repl)); } @@ -412,7 +412,7 @@ fn is_len_call(expr: &Expr, var: &Name) -> bool { method.node.as_str() == "len", let ExprPath(_, ref path) = len_args[0].node, path.segments.len() == 1, - &path.segments[0].identifier.name == var + &path.segments[0].name == var ], { return true; }} @@ -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.name.as_str().starts_with('_') => { + PatKind::Ident(_, ident, None) if ident.node.as_str().starts_with('_') => { let mut visitor = UsedVisitor { var: ident.node, used: false, @@ -626,14 +626,14 @@ fn pat_is_wild(pat: &PatKind, body: &Expr) -> bool { } struct UsedVisitor { - var: Ident, // var to look for + var: ast::Name, // var to look for used: bool, // has the var been used otherwise? } impl<'a> Visitor<'a> for UsedVisitor { fn visit_expr(&mut self, expr: &Expr) { if let ExprPath(None, ref path) = expr.node { - if path.segments.len() == 1 && path.segments[0].identifier == self.var { + if path.segments.len() == 1 && path.segments[0].name == self.var { self.used = true; return; } @@ -653,7 +653,7 @@ struct VarVisitor<'v, 't: 'v> { impl<'v, 't> Visitor<'v> for VarVisitor<'v, 't> { fn visit_expr(&mut self, expr: &'v Expr) { if let ExprPath(None, ref path) = expr.node { - if path.segments.len() == 1 && path.segments[0].identifier.name == self.var { + if path.segments.len() == 1 && path.segments[0].name == self.var { // we are referencing our variable! now check if it's as an index if_let_chain! { [ @@ -667,11 +667,11 @@ impl<'v, 't> Visitor<'v> for VarVisitor<'v, 't> { match def.base_def { Def::Local(..) | Def::Upvar(..) => { let extent = self.cx.tcx.region_maps.var_scope(def.base_def.var_id()); - self.indexed.insert(seqvar.segments[0].identifier.name, Some(extent)); + self.indexed.insert(seqvar.segments[0].name, Some(extent)); return; // no need to walk further } Def::Static(..) | Def::Const(..) => { - self.indexed.insert(seqvar.segments[0].identifier.name, None); + self.indexed.insert(seqvar.segments[0].name, None); return; // no need to walk further } _ => (), @@ -885,7 +885,7 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> { if let DeclLocal(ref local) = decl.node { if local.pat.id == self.var_id { if let PatKind::Ident(_, ref ident, _) = local.pat.node { - self.name = Some(ident.node.name); + self.name = Some(ident.node); self.state = if let Some(ref init) = local.init { if is_integer_literal(init, 0) { diff --git a/src/map_clone.rs b/src/map_clone.rs index d015a165457a..4ad232759cfa 100644 --- a/src/map_clone.rs +++ b/src/map_clone.rs @@ -1,5 +1,6 @@ use rustc::lint::*; use rustc::hir::*; +use syntax::ast; use utils::{is_adjusted, match_path, match_trait_method, match_type, paths, snippet, span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth}; @@ -52,7 +53,7 @@ impl LateLintPass for MapClonePass { if clone_call.node.as_str() == "clone" && clone_args.len() == 1 && match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) && - expr_eq_ident(&clone_args[0], arg_ident) + expr_eq_name(&clone_args[0], arg_ident) { span_help_and_lint(cx, MAP_CLONE, expr.span, &format!( "you seem to be using .map() to clone the contents of an {}, consider \ @@ -82,11 +83,11 @@ impl LateLintPass for MapClonePass { } } -fn expr_eq_ident(expr: &Expr, id: Ident) -> bool { +fn expr_eq_name(expr: &Expr, id: ast::Name) -> bool { match expr.node { ExprPath(None, ref path) => { let arg_segment = [PathSegment { - identifier: id, + name: id, parameters: PathParameters::none(), }]; !path.global && path.segments[..] == arg_segment @@ -105,18 +106,18 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s } } -fn get_arg_name(pat: &Pat) -> Option { +fn get_arg_name(pat: &Pat) -> Option { match pat.node { - PatKind::Ident(_, ident, None) => Some(ident.node), + PatKind::Ident(_, name, None) => Some(name.node), PatKind::Ref(ref subpat, _) => get_arg_name(subpat), _ => None, } } -fn only_derefs(cx: &LateContext, expr: &Expr, id: Ident) -> bool { +fn only_derefs(cx: &LateContext, expr: &Expr, id: ast::Name) -> bool { match expr.node { ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => only_derefs(cx, subexpr, id), - _ => expr_eq_ident(expr, id), + _ => expr_eq_name(expr, id), } } diff --git a/src/methods.rs b/src/methods.rs index ecbdb62f05ed..14bc74d467f0 100644 --- a/src/methods.rs +++ b/src/methods.rs @@ -473,7 +473,6 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P { - let ident = path.segments + let segment = path.segments .last() .expect("path should always have at least one segment") - .identifier; - ident.name.as_str().starts_with('_') && - !ident.name.as_str().starts_with("__") && - ident.name != ident.unhygienic_name && - is_used(cx, expr) // not in bang macro + .name; + if segment.as_str().starts_with('_') && + !segment.as_str().starts_with("__") && + segment != segment.unhygienize() && // not in bang macro + is_used(cx, expr) { + Some(segment.as_str()) + } else { + None + } } ExprField(_, spanned) => { let name = spanned.node.as_str(); - name.starts_with('_') && !name.starts_with("__") + if name.starts_with('_') && !name.starts_with("__") { + Some(name) + } else { + None + } } - _ => false, + _ => None, }; - if needs_lint { - span_lint(cx, - USED_UNDERSCORE_BINDING, - expr.span, - "used binding which is prefixed with an underscore. A leading underscore signals that a \ - binding will not be used."); + if let Some(binding) = binding { + if binding != "_result" { // FIXME: #944 + span_lint(cx, + USED_UNDERSCORE_BINDING, + expr.span, + &format!("used binding `{}` which is prefixed with an underscore. A leading \ + underscore signals that a binding will not be used.", binding)); + } } } } @@ -431,8 +444,8 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool { } } -/// Test whether an expression is in a macro expansion (e.g. something generated by #[derive(...)] -/// or the like) +/// Test whether an expression is in a macro expansion (e.g. something generated by +/// `#[derive(...)`] or the like). fn in_attributes_expansion(cx: &LateContext, expr: &Expr) -> bool { cx.sess().codemap().with_expn_info(expr.span.expn_id, |info_opt| { info_opt.map_or(false, |info| { diff --git a/src/overflow_check_conditional.rs b/src/overflow_check_conditional.rs index 6a8ca368fc14..34921bc2c041 100644 --- a/src/overflow_check_conditional.rs +++ b/src/overflow_check_conditional.rs @@ -31,7 +31,7 @@ impl LateLintPass for OverflowCheckConditional { let Expr_::ExprPath(_,ref path1) = ident1.node, let Expr_::ExprPath(_, ref path2) = ident2.node, let Expr_::ExprPath(_, ref path3) = second.node, - (&path1.segments[0]).identifier == (&path3.segments[0]).identifier || (&path2.segments[0]).identifier == (&path3.segments[0]).identifier, + &path1.segments[0] == &path3.segments[0] || &path2.segments[0] == &path3.segments[0], cx.tcx.expr_ty(ident1).is_integral(), cx.tcx.expr_ty(ident2).is_integral() ], { @@ -53,7 +53,7 @@ impl LateLintPass for OverflowCheckConditional { let Expr_::ExprPath(_,ref path1) = ident1.node, let Expr_::ExprPath(_, ref path2) = ident2.node, let Expr_::ExprPath(_, ref path3) = first.node, - (&path1.segments[0]).identifier == (&path3.segments[0]).identifier || (&path2.segments[0]).identifier == (&path3.segments[0]).identifier, + &path1.segments[0] == &path3.segments[0] || &path2.segments[0] == &path3.segments[0], cx.tcx.expr_ty(ident1).is_integral(), cx.tcx.expr_ty(ident2).is_integral() ], { diff --git a/src/shadow.rs b/src/shadow.rs index 4639a9439651..cf7de04cb6fc 100644 --- a/src/shadow.rs +++ b/src/shadow.rs @@ -66,7 +66,7 @@ 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 { - bindings.push((ident.node.unhygienic_name, ident.span)) + bindings.push((ident.node.unhygienize(), ident.span)) } } check_block(cx, block, &mut bindings); @@ -120,7 +120,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span, bind // TODO: match more stuff / destructuring match pat.node { PatKind::Ident(_, ref ident, ref inner) => { - let name = ident.node.unhygienic_name; + let name = ident.node.unhygienize(); if is_binding(cx, pat) { let mut new_binding = true; for tup in bindings.iter_mut() { @@ -326,7 +326,7 @@ fn is_self_shadow(name: Name, expr: &Expr) -> bool { } fn path_eq_name(name: Name, path: &Path) -> bool { - !path.global && path.segments.len() == 1 && path.segments[0].identifier.unhygienic_name == name + !path.global && path.segments.len() == 1 && path.segments[0].name.unhygienize() == name } struct ContainsSelf { @@ -335,8 +335,8 @@ struct ContainsSelf { } impl<'v> Visitor<'v> for ContainsSelf { - fn visit_ident(&mut self, _: Span, ident: Ident) { - if self.name == ident.unhygienic_name { + fn visit_name(&mut self, _: Span, name: Name) { + if self.name == name.unhygienize() { self.result = true; } } diff --git a/src/swap.rs b/src/swap.rs index 724915b9dd5c..c5572181395a 100644 --- a/src/swap.rs +++ b/src/swap.rs @@ -75,7 +75,7 @@ fn check_manual_swap(cx: &LateContext, block: &Block) { let ExprPath(None, ref rhs2) = rhs2.node, rhs2.segments.len() == 1, - tmp_name.node.name.as_str() == rhs2.segments[0].identifier.name.as_str(), + tmp_name.node.as_str() == rhs2.segments[0].name.as_str(), SpanlessEq::new(cx).ignore_fn().eq_expr(tmp_init, lhs1), SpanlessEq::new(cx).ignore_fn().eq_expr(rhs1, lhs2) ], { diff --git a/src/unsafe_removed_from_name.rs b/src/unsafe_removed_from_name.rs index 404d6d936041..3de6719c546a 100644 --- a/src/unsafe_removed_from_name.rs +++ b/src/unsafe_removed_from_name.rs @@ -41,7 +41,7 @@ impl LateLintPass for UnsafeNameRemoval { path.segments .last() .expect("use paths cannot be empty") - .identifier.name, + .name, *name, cx, &item.span ); diff --git a/src/unused_label.rs b/src/unused_label.rs index f6ff3c3d4b4e..d408f16a3711 100644 --- a/src/unused_label.rs +++ b/src/unused_label.rs @@ -65,10 +65,10 @@ impl<'v> Visitor<'v> for UnusedLabelVisitor { fn visit_expr(&mut self, expr: &hir::Expr) { match expr.node { hir::ExprBreak(Some(label)) | hir::ExprAgain(Some(label)) => { - self.labels.remove(&label.node.name.as_str()); + self.labels.remove(&label.node.as_str()); } hir::ExprLoop(_, Some(label)) | hir::ExprWhile(_, _, Some(label)) => { - self.labels.insert(label.name.as_str(), expr.span); + self.labels.insert(label.as_str(), expr.span); } _ => (), } diff --git a/src/utils/hir.rs b/src/utils/hir.rs index fe4c6d309520..0f0a7312ee4a 100644 --- a/src/utils/hir.rs +++ b/src/utils/hir.rs @@ -68,7 +68,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { match (&left.node, &right.node) { (&ExprAddrOf(l_mut, ref le), &ExprAddrOf(r_mut, ref re)) => l_mut == r_mut && self.eq_expr(le, re), - (&ExprAgain(li), &ExprAgain(ri)) => both(&li, &ri, |l, r| l.node.name.as_str() == r.node.name.as_str()), + (&ExprAgain(li), &ExprAgain(ri)) => both(&li, &ri, |l, r| l.node.as_str() == r.node.as_str()), (&ExprAssign(ref ll, ref lr), &ExprAssign(ref rl, ref rr)) => self.eq_expr(ll, rl) && self.eq_expr(lr, rr), (&ExprAssignOp(ref lo, ref ll, ref lr), &ExprAssignOp(ref ro, ref rl, ref rr)) => { lo.node == ro.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) @@ -80,7 +80,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) }) } - (&ExprBreak(li), &ExprBreak(ri)) => both(&li, &ri, |l, r| l.node.name.as_str() == r.node.name.as_str()), + (&ExprBreak(li), &ExprBreak(ri)) => both(&li, &ri, |l, r| l.node.as_str() == r.node.as_str()), (&ExprBox(ref l), &ExprBox(ref r)) => self.eq_expr(l, r), (&ExprCall(ref l_fun, ref l_args), &ExprCall(ref r_fun, ref r_args)) => { !self.ignore_fn && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args) @@ -95,7 +95,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { } (&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node, (&ExprLoop(ref lb, ref ll), &ExprLoop(ref rb, ref rl)) => { - self.eq_block(lb, rb) && both(ll, rl, |l, r| l.name.as_str() == r.name.as_str()) + self.eq_block(lb, rb) && both(ll, rl, |l, r| l.as_str() == r.as_str()) } (&ExprMatch(ref le, ref la, ref ls), &ExprMatch(ref re, ref ra, ref rs)) => { ls == rs && self.eq_expr(le, re) && @@ -124,7 +124,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { (&ExprUnary(l_op, ref le), &ExprUnary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re), (&ExprVec(ref l), &ExprVec(ref r)) => self.eq_exprs(l, r), (&ExprWhile(ref lc, ref lb, ref ll), &ExprWhile(ref rc, ref rb, ref rl)) => { - self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.name.as_str() == r.name.as_str()) + self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.as_str() == r.as_str()) } _ => false, } @@ -146,7 +146,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { self.eq_path(lp, rp) && both(la, ra, |l, r| over(l, r, |l, r| self.eq_pat(l, r))) } (&PatKind::Ident(ref lb, ref li, ref lp), &PatKind::Ident(ref rb, ref ri, ref rp)) => { - lb == rb && li.node.name.as_str() == ri.node.name.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r)) + lb == rb && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(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)) => { @@ -172,7 +172,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { left.global == right.global && over(&left.segments, &right.segments, - |l, r| l.identifier.name.as_str() == r.identifier.name.as_str() && l.parameters == r.parameters) + |l, r| l.name.as_str() == r.name.as_str() && l.parameters == r.parameters) } fn eq_qself(&self, left: &QSelf, right: &QSelf) -> bool { @@ -281,7 +281,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { let c: fn(_) -> _ = ExprAgain; c.hash(&mut self.s); if let Some(i) = i { - self.hash_name(&i.node.name); + self.hash_name(&i.node); } } ExprAssign(ref l, ref r) => { @@ -313,7 +313,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { let c: fn(_) -> _ = ExprBreak; c.hash(&mut self.s); if let Some(i) = i { - self.hash_name(&i.node.name); + self.hash_name(&i.node); } } ExprBox(ref e) => { @@ -374,7 +374,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { c.hash(&mut self.s); self.hash_block(b); if let Some(i) = *i { - self.hash_name(&i.name); + self.hash_name(&i); } } ExprMatch(ref e, ref arms, ref s) => { @@ -468,7 +468,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { self.hash_expr(cond); self.hash_block(b); if let Some(l) = l { - self.hash_name(&l.name); + self.hash_name(&l); } } } @@ -487,7 +487,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { pub fn hash_path(&mut self, p: &Path) { p.global.hash(&mut self.s); for p in &p.segments { - self.hash_name(&p.identifier.name); + self.hash_name(&p.name); } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 10bfe56e925e..3ff6167620af 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -200,7 +200,7 @@ pub fn match_trait_method(cx: &LateContext, expr: &Expr, path: &[&str]) -> bool /// match_path(path, &["std", "rt", "begin_unwind"]) /// ``` pub fn match_path(path: &Path, segments: &[&str]) -> bool { - path.segments.iter().rev().zip(segments.iter().rev()).all(|(a, b)| a.identifier.name.as_str() == *b) + path.segments.iter().rev().zip(segments.iter().rev()).all(|(a, b)| a.name.as_str() == *b) } /// Match a `Path` against a slice of segment string literals, e.g. diff --git a/tests/compile-fail/used_underscore_binding.rs b/tests/compile-fail/used_underscore_binding.rs index 6bf4324e6237..c571906c53b8 100644 --- a/tests/compile-fail/used_underscore_binding.rs +++ b/tests/compile-fail/used_underscore_binding.rs @@ -3,15 +3,16 @@ #![deny(clippy)] #![allow(blacklisted_name)] +#![deny(used_underscore_binding)] /// Test that we lint if we use a binding with a single leading underscore fn prefix_underscore(_foo: u32) -> u32 { - _foo + 1 //~ ERROR used binding which is prefixed with an underscore + _foo + 1 //~ ERROR used binding `_foo` which is prefixed with an underscore } /// Test that we lint even if the use is within a macro expansion fn in_macro(_foo: u32) { - println!("{}", _foo); //~ ERROR used binding which is prefixed with an underscore + println!("{}", _foo); //~ ERROR used binding `_foo` which is prefixed with an underscore } // Struct for testing use of fields prefixed with an underscore @@ -22,7 +23,7 @@ struct StructFieldTest { /// Test that we lint the use of a struct field which is prefixed with an underscore fn in_struct_field() { let mut s = StructFieldTest { _underscore_field: 0 }; - s._underscore_field += 1; //~ Error used binding which is prefixed with an underscore + s._underscore_field += 1; //~ Error used binding `_underscore_field` which is prefixed with an underscore } /// Test that we do not lint if the underscore is not a prefix From 6dd608e53e52d91d01677bc5f0a2eead4757e406 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 20 May 2016 19:18:32 +0200 Subject: [PATCH 2/4] Rustup to *1.10.0-nightly (764ef92ae 2016-05-19)* --- src/methods.rs | 2 +- src/vec.rs | 12 +++++++----- tests/compile-fail/methods.rs | 2 +- tests/compile-fail/mut_mut.rs | 11 ++++++----- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/methods.rs b/src/methods.rs index 14bc74d467f0..f9f557e7a9a2 100644 --- a/src/methods.rs +++ b/src/methods.rs @@ -511,7 +511,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P:` + let span = cx.sess().codemap().source_callsite(arg.span); + check_vec_macro(cx, arg, span); } } } -fn check_vec_macro(cx: &LateContext, expr: &Expr, vec: &Expr) { +fn check_vec_macro(cx: &LateContext, vec: &Expr, span: Span) { if let Some(vec_args) = unexpand_vec(cx, vec) { let snippet = match vec_args { VecArgs::Repeat(elem, len) => { @@ -69,8 +71,8 @@ fn check_vec_macro(cx: &LateContext, expr: &Expr, vec: &Expr) { } }; - span_lint_and_then(cx, USELESS_VEC, expr.span, "useless use of `vec!`", |db| { - db.span_suggestion(expr.span, "you can use a slice directly", snippet); + span_lint_and_then(cx, USELESS_VEC, span, "useless use of `vec!`", |db| { + db.span_suggestion(span, "you can use a slice directly", snippet); }); } } diff --git a/tests/compile-fail/methods.rs b/tests/compile-fail/methods.rs index 88a1e7c4cf24..9753c0213720 100644 --- a/tests/compile-fail/methods.rs +++ b/tests/compile-fail/methods.rs @@ -288,7 +288,7 @@ fn or_fun_call() { with_vec.unwrap_or(vec![]); //~^ERROR use of `unwrap_or` //~|HELP try this - //~|SUGGESTION with_vec.unwrap_or_else(|| vec![]); + // FIXME #944: ~|SUGGESTION with_vec.unwrap_or_else(|| vec![]); let without_default = Some(Foo); without_default.unwrap_or(Foo::new()); diff --git a/tests/compile-fail/mut_mut.rs b/tests/compile-fail/mut_mut.rs index 865574eaec02..8d9bceb0d0d8 100644 --- a/tests/compile-fail/mut_mut.rs +++ b/tests/compile-fail/mut_mut.rs @@ -18,6 +18,7 @@ fn less_fun(x : *mut *mut u32) { macro_rules! mut_ptr { ($p:expr) => { &mut $p } + //~^ ERROR generally you want to avoid `&mut &mut } #[deny(mut_mut)] @@ -30,12 +31,12 @@ fn main() { if fun(x) { let y : &mut &mut &mut u32 = &mut &mut &mut 2; - //~^ ERROR generally you want to avoid `&mut &mut - //~^^ ERROR generally you want to avoid `&mut &mut - //~^^^ ERROR generally you want to avoid `&mut &mut - //~^^^^ ERROR generally you want to avoid `&mut &mut + //~^ ERROR generally you want to avoid `&mut &mut + //~| ERROR generally you want to avoid `&mut &mut + //~| ERROR generally you want to avoid `&mut &mut + //~| ERROR generally you want to avoid `&mut &mut ***y + **x; } - let mut z = mut_ptr!(&mut 3u32); //~ERROR generally you want to avoid `&mut &mut + let mut z = mut_ptr!(&mut 3u32); //~ NOTE in this expansion of mut_ptr! } From ac2e175c1b9aa6ac8da7794a86f7ec4b16f669ac Mon Sep 17 00:00:00 2001 From: mcarton Date: Mon, 23 May 2016 16:34:09 +0200 Subject: [PATCH 3/4] Rustup to *1.10.0-nightly (476fe6eef 2016-05-21)* --- src/shadow.rs | 7 ++++--- tests/compile-fail/methods.rs | 6 ++---- tests/compile-fail/shadow.rs | 16 ++++++++-------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/shadow.rs b/src/shadow.rs index cf7de04cb6fc..2a0d36a80b3c 100644 --- a/src/shadow.rs +++ b/src/shadow.rs @@ -208,15 +208,16 @@ fn lint_shadow(cx: &LateContext, name: Name, span: Span, pattern_span: Span, let db = span_lint(cx, SHADOW_SAME, span, - &format!("{} is shadowed by itself in {}", + &format!("`{}` is shadowed by itself in `{}`", snippet(cx, pattern_span, "_"), snippet(cx, expr.span, ".."))); + note_orig(cx, db, SHADOW_SAME, prev_span); } else if contains_self(name, expr) { let db = span_note_and_lint(cx, SHADOW_REUSE, pattern_span, - &format!("{} is shadowed by {} which reuses the original value", + &format!("`{}` is shadowed by `{}` which reuses the original value", snippet(cx, pattern_span, "_"), snippet(cx, expr.span, "..")), expr.span, @@ -226,7 +227,7 @@ fn lint_shadow(cx: &LateContext, name: Name, span: Span, pattern_span: Span, let db = span_note_and_lint(cx, SHADOW_UNRELATED, pattern_span, - &format!("{} is shadowed by {}", + &format!("`{}` is shadowed by `{}`", snippet(cx, pattern_span, "_"), snippet(cx, expr.span, "..")), expr.span, diff --git a/tests/compile-fail/methods.rs b/tests/compile-fail/methods.rs index 9753c0213720..f6e4a9a31e05 100644 --- a/tests/compile-fail/methods.rs +++ b/tests/compile-fail/methods.rs @@ -493,10 +493,8 @@ fn single_char_pattern() { fn temporary_cstring() { use std::ffi::CString; - ( // extra parenthesis to better test spans + CString::new("foo").unwrap().as_ptr(); //~^ ERROR you are getting the inner pointer of a temporary `CString` //~| NOTE that pointer will be invalid outside this expression - CString::new("foo").unwrap() - //~^ HELP assign the `CString` to a variable to extend its lifetime - ).as_ptr(); + //~| HELP assign the `CString` to a variable to extend its lifetime } diff --git a/tests/compile-fail/shadow.rs b/tests/compile-fail/shadow.rs index 0a52a9829aef..1cfcff74a44c 100644 --- a/tests/compile-fail/shadow.rs +++ b/tests/compile-fail/shadow.rs @@ -10,15 +10,15 @@ fn first(x: (isize, isize)) -> isize { x.0 } fn main() { let mut x = 1; - let x = &mut x; //~ERROR x is shadowed by itself in &mut x - let x = { x }; //~ERROR x is shadowed by itself in { x } - let x = (&*x); //~ERROR x is shadowed by itself in &*x - let x = { *x + 1 }; //~ERROR x is shadowed by { *x + 1 } which reuses - let x = id(x); //~ERROR x is shadowed by id(x) which reuses - let x = (1, x); //~ERROR x is shadowed by (1, x) which reuses - let x = first(x); //~ERROR x is shadowed by first(x) which reuses + let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x` + let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }` + let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)` + let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses + let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses + let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses + let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses let y = 1; - let x = y; //~ERROR x is shadowed by y + let x = y; //~ERROR `x` is shadowed by `y` let o = Some(1u8); From f2eea6211c4834e8f472352bd3596a73115903b5 Mon Sep 17 00:00:00 2001 From: mcarton Date: Thu, 19 May 2016 23:15:12 +0200 Subject: [PATCH 4/4] Bump to 0.0.69 --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 017e24b10346..59b03b301c63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.69 — 2016-05-20 +* Rustup to *rustc 1.10.0-nightly (476fe6eef 2016-05-21)* +* `used_underscore_binding` has been made `Allow` temporarily + ## 0.0.68 — 2016-05-17 * Rustup to *rustc 1.10.0-nightly (cd6a40017 2016-05-16)* * New lint: [`unnecessary_operation`] diff --git a/Cargo.toml b/Cargo.toml index 49053ea1e4f0..fd0b07428c07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.68" +version = "0.0.69" authors = [ "Manish Goregaokar ", "Andre Bogus ",