Skip to content

Rustup to *rustc 1.10.0-nightly (764ef92ae 2016-05-19)* and bump to 0.0.69 #944

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

Merged
merged 4 commits into from
May 23, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.0.68"
version = "0.0.69"
authors = [
"Manish Goregaokar <[email protected]>",
"Andre Bogus <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!`
Expand Down
4 changes: 2 additions & 2 deletions src/blacklisted_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<Interned
}
}
PatKind::Ident(_, ref ident, ref as_pat) => {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "_");
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}
Expand All @@ -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;
}}
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.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,
Expand All @@ -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;
}
Expand All @@ -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! {
[
Expand All @@ -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
}
_ => (),
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions src/map_clone.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand All @@ -105,18 +106,18 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s
}
}

fn get_arg_name(pat: &Pat) -> Option<Ident> {
fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
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),
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P<hi
let path: &str = &path.segments
.last()
.expect("A path must have at least one segment")
.identifier
.name
.as_str();

Expand Down Expand Up @@ -512,7 +511,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P<hi
return;
}
}
// (path, fn_has_argument, methods)
// (path, fn_has_argument, methods, suffix)
let know_types: &[(&[_], _, &[_], _)] = &[(&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"),
(&paths::HASHMAP_ENTRY, false, &["or_insert"], "with"),
(&paths::OPTION,
Expand Down Expand Up @@ -811,7 +810,7 @@ fn lint_chars_next(cx: &LateContext, expr: &hir::Expr, chain: &hir::Expr, other:
let hir::ExprCall(ref fun, ref arg_char) = other.node,
arg_char.len() == 1,
let hir::ExprPath(None, ref path) = fun.node,
path.segments.len() == 1 && path.segments[0].identifier.name.as_str() == "Some"
path.segments.len() == 1 && path.segments[0].name.as_str() == "Some"
], {
let self_ty = walk_ptrs_ty(cx.tcx.expr_ty_adjusted(&args[0][0]));

Expand Down
63 changes: 38 additions & 25 deletions src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use rustc_const_eval::EvalHint::ExprTypeChecked;
use rustc_const_eval::eval_const_expr_partial;
use syntax::codemap::{Span, Spanned, ExpnFormat};
use syntax::ptr::P;
use utils::{get_item_name, match_path, snippet, get_parent_expr, span_lint};
use utils::{span_lint_and_then, walk_ptrs_ty, is_integer_literal, implements_trait};
use utils::{
get_item_name, get_parent_expr, implements_trait, is_integer_literal, match_path, snippet,
span_lint, span_lint_and_then, walk_ptrs_ty
};

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

fn check_nan(cx: &LateContext, path: &Path, span: Span) {
path.segments.last().map(|seg| {
if seg.identifier.name.as_str() == "NAN" {
if seg.name.as_str() == "NAN" {
span_lint(cx,
CMP_NAN,
span,
Expand Down Expand Up @@ -350,8 +352,8 @@ impl LateLintPass for PatternPass {
REDUNDANT_PATTERN,
pat.span,
&format!("the `{} @ _` pattern can be written as just `{}`",
ident.node.name,
ident.node.name));
ident.node,
ident.node));
}
}
}
Expand All @@ -363,15 +365,16 @@ impl LateLintPass for PatternPass {
/// **Why is this bad?** A single leading underscore is usually used to indicate that a binding
/// will not be used. Using such a binding breaks this expectation.
///
/// **Known problems:** None
/// **Known problems:** The lint does not work properly with desugaring and macro, it has been
/// allowed in the mean time.
///
/// **Example**:
/// ```
/// let _x = 0;
/// let y = _x + 1; // Here we are using `_x`, even though it has a leading underscore.
/// // We should rename `_x` to `x`
/// ```
declare_lint!(pub USED_UNDERSCORE_BINDING, Warn,
declare_lint!(pub USED_UNDERSCORE_BINDING, Allow,
"using a binding which is prefixed with an underscore");

#[derive(Copy, Clone)]
Expand All @@ -387,32 +390,42 @@ impl LateLintPass for UsedUnderscoreBinding {
#[cfg_attr(rustfmt, rustfmt_skip)]
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
if in_attributes_expansion(cx, expr) {
// Don't lint things expanded by #[derive(...)], etc
// Don't lint things expanded by #[derive(...)], etc
return;
}
let needs_lint = match expr.node {
let binding = match expr.node {
ExprPath(_, ref path) => {
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));
}
}
}
}
Expand All @@ -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| {
Expand Down
Loading