Skip to content

Commit fec701b

Browse files
committed
Merge pull request #944 from Manishearth/rustup
Rustup to *rustc 1.10.0-nightly (764ef92 2016-05-19)* and bump to 0.0.69
2 parents 973ae82 + f2eea62 commit fec701b

23 files changed

+127
-107
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 0.0.69 — 2016-05-20
5+
* Rustup to *rustc 1.10.0-nightly (476fe6eef 2016-05-21)*
6+
* `used_underscore_binding` has been made `Allow` temporarily
7+
48
## 0.0.68 — 2016-05-17
59
* Rustup to *rustc 1.10.0-nightly (cd6a40017 2016-05-16)*
610
* New lint: [`unnecessary_operation`]

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.68"
3+
version = "0.0.69"
44
authors = [
55
"Manish Goregaokar <[email protected]>",
66
"Andre Bogus <[email protected]>",

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ name
161161
[unused_label](https://github.com/Manishearth/rust-clippy/wiki#unused_label) | warn | unused label
162162
[unused_lifetimes](https://github.com/Manishearth/rust-clippy/wiki#unused_lifetimes) | warn | unused lifetimes in function definitions
163163
[use_debug](https://github.com/Manishearth/rust-clippy/wiki#use_debug) | allow | use `Debug`-based formatting
164-
[used_underscore_binding](https://github.com/Manishearth/rust-clippy/wiki#used_underscore_binding) | warn | using a binding which is prefixed with an underscore
164+
[used_underscore_binding](https://github.com/Manishearth/rust-clippy/wiki#used_underscore_binding) | allow | using a binding which is prefixed with an underscore
165165
[useless_format](https://github.com/Manishearth/rust-clippy/wiki#useless_format) | warn | useless use of `format!`
166166
[useless_transmute](https://github.com/Manishearth/rust-clippy/wiki#useless_transmute) | warn | transmutes that have the same to and from types
167167
[useless_vec](https://github.com/Manishearth/rust-clippy/wiki#useless_vec) | warn | useless `vec!`

src/blacklisted_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ impl LintPass for BlackListedName {
3535
impl LateLintPass for BlackListedName {
3636
fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
3737
if let PatKind::Ident(_, ref ident, _) = pat.node {
38-
if self.blacklist.iter().any(|s| s == &*ident.node.name.as_str()) {
38+
if self.blacklist.iter().any(|s| s == &*ident.node.as_str()) {
3939
span_lint(cx,
4040
BLACKLISTED_NAME,
4141
pat.span,
42-
&format!("use of a blacklisted/placeholder name `{}`", ident.node.name));
42+
&format!("use of a blacklisted/placeholder name `{}`", ident.node));
4343
}
4444
}
4545
}

src/copies.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<Interned
193193
}
194194
}
195195
PatKind::Ident(_, ref ident, ref as_pat) => {
196-
if let Entry::Vacant(v) = map.entry(ident.node.name.as_str()) {
196+
if let Entry::Vacant(v) = map.entry(ident.node.as_str()) {
197197
v.insert(cx.tcx.pat_ty(pat));
198198
}
199199
if let Some(ref as_pat) = *as_pat {

src/eta_reduction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
7777
// If it's a proper path, it can't be a local variable
7878
return;
7979
}
80-
if p.segments[0].identifier != ident.node {
80+
if p.segments[0].name != ident.node {
8181
// The two idents should be the same
8282
return;
8383
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
411411
methods::OPTION_UNWRAP_USED,
412412
methods::RESULT_UNWRAP_USED,
413413
methods::WRONG_PUB_SELF_CONVENTION,
414+
misc::USED_UNDERSCORE_BINDING,
414415
mut_mut::MUT_MUT,
415416
mutex_atomic::MUTEX_INTEGER,
416417
non_expressive_names::SIMILAR_NAMES,
@@ -505,7 +506,6 @@ pub fn plugin_registrar(reg: &mut Registry) {
505506
misc::MODULO_ONE,
506507
misc::REDUNDANT_PATTERN,
507508
misc::TOPLEVEL_REF_ARG,
508-
misc::USED_UNDERSCORE_BINDING,
509509
misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
510510
misc_early::REDUNDANT_CLOSURE_CALL,
511511
misc_early::UNNEEDED_FIELD_PATTERN,

src/loops.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl LateLintPass for LoopsPass {
286286
if let Some(lhs_constructor) = path.segments.last() {
287287
if method_name.node.as_str() == "next" &&
288288
match_trait_method(cx, match_expr, &paths::ITERATOR) &&
289-
lhs_constructor.identifier.name.as_str() == "Some" &&
289+
lhs_constructor.name.as_str() == "Some" &&
290290
!is_iterator_used_after_while_let(cx, iter_expr) {
291291
let iterator = snippet(cx, method_args[0].span, "_");
292292
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
333333
if let PatKind::Ident(_, ref ident, _) = pat.node {
334334
let mut visitor = VarVisitor {
335335
cx: cx,
336-
var: ident.node.name,
336+
var: ident.node,
337337
indexed: HashMap::new(),
338338
nonindex: false,
339339
};
@@ -378,9 +378,9 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex
378378
expr.span,
379379
&format!("the loop variable `{}` is used to index `{}`. Consider using `for ({}, \
380380
item) in {}.iter().enumerate(){}{}` or similar iterators",
381-
ident.node.name,
381+
ident.node,
382382
indexed,
383-
ident.node.name,
383+
ident.node,
384384
indexed,
385385
take,
386386
skip));
@@ -396,7 +396,7 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex
396396
expr.span,
397397
&format!("the loop variable `{}` is only used to index `{}`. \
398398
Consider using `for item in {}` or similar iterators",
399-
ident.node.name,
399+
ident.node,
400400
indexed,
401401
repl));
402402
}
@@ -412,7 +412,7 @@ fn is_len_call(expr: &Expr, var: &Name) -> bool {
412412
method.node.as_str() == "len",
413413
let ExprPath(_, ref path) = len_args[0].node,
414414
path.segments.len() == 1,
415-
&path.segments[0].identifier.name == var
415+
&path.segments[0].name == var
416416
], {
417417
return true;
418418
}}
@@ -613,7 +613,7 @@ fn check_for_loop_over_map_kv(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Ex
613613
fn pat_is_wild(pat: &PatKind, body: &Expr) -> bool {
614614
match *pat {
615615
PatKind::Wild => true,
616-
PatKind::Ident(_, ident, None) if ident.node.name.as_str().starts_with('_') => {
616+
PatKind::Ident(_, ident, None) if ident.node.as_str().starts_with('_') => {
617617
let mut visitor = UsedVisitor {
618618
var: ident.node,
619619
used: false,
@@ -626,14 +626,14 @@ fn pat_is_wild(pat: &PatKind, body: &Expr) -> bool {
626626
}
627627

628628
struct UsedVisitor {
629-
var: Ident, // var to look for
629+
var: ast::Name, // var to look for
630630
used: bool, // has the var been used otherwise?
631631
}
632632

633633
impl<'a> Visitor<'a> for UsedVisitor {
634634
fn visit_expr(&mut self, expr: &Expr) {
635635
if let ExprPath(None, ref path) = expr.node {
636-
if path.segments.len() == 1 && path.segments[0].identifier == self.var {
636+
if path.segments.len() == 1 && path.segments[0].name == self.var {
637637
self.used = true;
638638
return;
639639
}
@@ -653,7 +653,7 @@ struct VarVisitor<'v, 't: 'v> {
653653
impl<'v, 't> Visitor<'v> for VarVisitor<'v, 't> {
654654
fn visit_expr(&mut self, expr: &'v Expr) {
655655
if let ExprPath(None, ref path) = expr.node {
656-
if path.segments.len() == 1 && path.segments[0].identifier.name == self.var {
656+
if path.segments.len() == 1 && path.segments[0].name == self.var {
657657
// we are referencing our variable! now check if it's as an index
658658
if_let_chain! {
659659
[
@@ -667,11 +667,11 @@ impl<'v, 't> Visitor<'v> for VarVisitor<'v, 't> {
667667
match def.base_def {
668668
Def::Local(..) | Def::Upvar(..) => {
669669
let extent = self.cx.tcx.region_maps.var_scope(def.base_def.var_id());
670-
self.indexed.insert(seqvar.segments[0].identifier.name, Some(extent));
670+
self.indexed.insert(seqvar.segments[0].name, Some(extent));
671671
return; // no need to walk further
672672
}
673673
Def::Static(..) | Def::Const(..) => {
674-
self.indexed.insert(seqvar.segments[0].identifier.name, None);
674+
self.indexed.insert(seqvar.segments[0].name, None);
675675
return; // no need to walk further
676676
}
677677
_ => (),
@@ -885,7 +885,7 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> {
885885
if let DeclLocal(ref local) = decl.node {
886886
if local.pat.id == self.var_id {
887887
if let PatKind::Ident(_, ref ident, _) = local.pat.node {
888-
self.name = Some(ident.node.name);
888+
self.name = Some(ident.node);
889889

890890
self.state = if let Some(ref init) = local.init {
891891
if is_integer_literal(init, 0) {

src/map_clone.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc::lint::*;
22
use rustc::hir::*;
3+
use syntax::ast;
34
use utils::{is_adjusted, match_path, match_trait_method, match_type, paths, snippet,
45
span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
56

@@ -52,7 +53,7 @@ impl LateLintPass for MapClonePass {
5253
if clone_call.node.as_str() == "clone" &&
5354
clone_args.len() == 1 &&
5455
match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) &&
55-
expr_eq_ident(&clone_args[0], arg_ident)
56+
expr_eq_name(&clone_args[0], arg_ident)
5657
{
5758
span_help_and_lint(cx, MAP_CLONE, expr.span, &format!(
5859
"you seem to be using .map() to clone the contents of an {}, consider \
@@ -82,11 +83,11 @@ impl LateLintPass for MapClonePass {
8283
}
8384
}
8485

85-
fn expr_eq_ident(expr: &Expr, id: Ident) -> bool {
86+
fn expr_eq_name(expr: &Expr, id: ast::Name) -> bool {
8687
match expr.node {
8788
ExprPath(None, ref path) => {
8889
let arg_segment = [PathSegment {
89-
identifier: id,
90+
name: id,
9091
parameters: PathParameters::none(),
9192
}];
9293
!path.global && path.segments[..] == arg_segment
@@ -105,18 +106,18 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s
105106
}
106107
}
107108

108-
fn get_arg_name(pat: &Pat) -> Option<Ident> {
109+
fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
109110
match pat.node {
110-
PatKind::Ident(_, ident, None) => Some(ident.node),
111+
PatKind::Ident(_, name, None) => Some(name.node),
111112
PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
112113
_ => None,
113114
}
114115
}
115116

116-
fn only_derefs(cx: &LateContext, expr: &Expr, id: Ident) -> bool {
117+
fn only_derefs(cx: &LateContext, expr: &Expr, id: ast::Name) -> bool {
117118
match expr.node {
118119
ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => only_derefs(cx, subexpr, id),
119-
_ => expr_eq_ident(expr, id),
120+
_ => expr_eq_name(expr, id),
120121
}
121122
}
122123

src/methods.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P<hi
473473
let path: &str = &path.segments
474474
.last()
475475
.expect("A path must have at least one segment")
476-
.identifier
477476
.name
478477
.as_str();
479478

@@ -512,7 +511,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P<hi
512511
return;
513512
}
514513
}
515-
// (path, fn_has_argument, methods)
514+
// (path, fn_has_argument, methods, suffix)
516515
let know_types: &[(&[_], _, &[_], _)] = &[(&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"),
517516
(&paths::HASHMAP_ENTRY, false, &["or_insert"], "with"),
518517
(&paths::OPTION,
@@ -811,7 +810,7 @@ fn lint_chars_next(cx: &LateContext, expr: &hir::Expr, chain: &hir::Expr, other:
811810
let hir::ExprCall(ref fun, ref arg_char) = other.node,
812811
arg_char.len() == 1,
813812
let hir::ExprPath(None, ref path) = fun.node,
814-
path.segments.len() == 1 && path.segments[0].identifier.name.as_str() == "Some"
813+
path.segments.len() == 1 && path.segments[0].name.as_str() == "Some"
815814
], {
816815
let self_ty = walk_ptrs_ty(cx.tcx.expr_ty_adjusted(&args[0][0]));
817816

src/misc.rs

+38-25
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ use rustc_const_eval::EvalHint::ExprTypeChecked;
88
use rustc_const_eval::eval_const_expr_partial;
99
use syntax::codemap::{Span, Spanned, ExpnFormat};
1010
use syntax::ptr::P;
11-
use utils::{get_item_name, match_path, snippet, get_parent_expr, span_lint};
12-
use utils::{span_lint_and_then, walk_ptrs_ty, is_integer_literal, implements_trait};
11+
use utils::{
12+
get_item_name, get_parent_expr, implements_trait, is_integer_literal, match_path, snippet,
13+
span_lint, span_lint_and_then, walk_ptrs_ty
14+
};
1315

1416
/// **What it does:** This lint checks for function arguments and let bindings denoted as `ref`.
1517
///
@@ -118,7 +120,7 @@ impl LateLintPass for CmpNan {
118120

119121
fn check_nan(cx: &LateContext, path: &Path, span: Span) {
120122
path.segments.last().map(|seg| {
121-
if seg.identifier.name.as_str() == "NAN" {
123+
if seg.name.as_str() == "NAN" {
122124
span_lint(cx,
123125
CMP_NAN,
124126
span,
@@ -350,8 +352,8 @@ impl LateLintPass for PatternPass {
350352
REDUNDANT_PATTERN,
351353
pat.span,
352354
&format!("the `{} @ _` pattern can be written as just `{}`",
353-
ident.node.name,
354-
ident.node.name));
355+
ident.node,
356+
ident.node));
355357
}
356358
}
357359
}
@@ -363,15 +365,16 @@ impl LateLintPass for PatternPass {
363365
/// **Why is this bad?** A single leading underscore is usually used to indicate that a binding
364366
/// will not be used. Using such a binding breaks this expectation.
365367
///
366-
/// **Known problems:** None
368+
/// **Known problems:** The lint does not work properly with desugaring and macro, it has been
369+
/// allowed in the mean time.
367370
///
368371
/// **Example**:
369372
/// ```
370373
/// let _x = 0;
371374
/// let y = _x + 1; // Here we are using `_x`, even though it has a leading underscore.
372375
/// // We should rename `_x` to `x`
373376
/// ```
374-
declare_lint!(pub USED_UNDERSCORE_BINDING, Warn,
377+
declare_lint!(pub USED_UNDERSCORE_BINDING, Allow,
375378
"using a binding which is prefixed with an underscore");
376379

377380
#[derive(Copy, Clone)]
@@ -387,32 +390,42 @@ impl LateLintPass for UsedUnderscoreBinding {
387390
#[cfg_attr(rustfmt, rustfmt_skip)]
388391
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
389392
if in_attributes_expansion(cx, expr) {
390-
// Don't lint things expanded by #[derive(...)], etc
393+
// Don't lint things expanded by #[derive(...)], etc
391394
return;
392395
}
393-
let needs_lint = match expr.node {
396+
let binding = match expr.node {
394397
ExprPath(_, ref path) => {
395-
let ident = path.segments
398+
let segment = path.segments
396399
.last()
397400
.expect("path should always have at least one segment")
398-
.identifier;
399-
ident.name.as_str().starts_with('_') &&
400-
!ident.name.as_str().starts_with("__") &&
401-
ident.name != ident.unhygienic_name &&
402-
is_used(cx, expr) // not in bang macro
401+
.name;
402+
if segment.as_str().starts_with('_') &&
403+
!segment.as_str().starts_with("__") &&
404+
segment != segment.unhygienize() && // not in bang macro
405+
is_used(cx, expr) {
406+
Some(segment.as_str())
407+
} else {
408+
None
409+
}
403410
}
404411
ExprField(_, spanned) => {
405412
let name = spanned.node.as_str();
406-
name.starts_with('_') && !name.starts_with("__")
413+
if name.starts_with('_') && !name.starts_with("__") {
414+
Some(name)
415+
} else {
416+
None
417+
}
407418
}
408-
_ => false,
419+
_ => None,
409420
};
410-
if needs_lint {
411-
span_lint(cx,
412-
USED_UNDERSCORE_BINDING,
413-
expr.span,
414-
"used binding which is prefixed with an underscore. A leading underscore signals that a \
415-
binding will not be used.");
421+
if let Some(binding) = binding {
422+
if binding != "_result" { // FIXME: #944
423+
span_lint(cx,
424+
USED_UNDERSCORE_BINDING,
425+
expr.span,
426+
&format!("used binding `{}` which is prefixed with an underscore. A leading \
427+
underscore signals that a binding will not be used.", binding));
428+
}
416429
}
417430
}
418431
}
@@ -431,8 +444,8 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool {
431444
}
432445
}
433446

434-
/// Test whether an expression is in a macro expansion (e.g. something generated by #[derive(...)]
435-
/// or the like)
447+
/// Test whether an expression is in a macro expansion (e.g. something generated by
448+
/// `#[derive(...)`] or the like).
436449
fn in_attributes_expansion(cx: &LateContext, expr: &Expr) -> bool {
437450
cx.sess().codemap().with_expn_info(expr.span.expn_id, |info_opt| {
438451
info_opt.map_or(false, |info| {

0 commit comments

Comments
 (0)