Skip to content

WIP: rustup #1373

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 15 commits into from
Dec 17, 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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.0.104 — 2016-12-15
* Update to *rustc 1.15.0-nightly (8f02c429a 2016-12-15)*

## 0.0.103 — 2016-11-25
* Update to *rustc 1.15.0-nightly (d5814b03e 2016-11-23)*

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.103"
version = "0.0.104"
authors = [
"Manish Goregaokar <[email protected]>",
"Andre Bogus <[email protected]>",
Expand All @@ -25,7 +25,7 @@ test = false

[dependencies]
# begin automatic update
clippy_lints = { version = "0.0.103", path = "clippy_lints" }
clippy_lints = { version = "0.0.104", path = "clippy_lints" }
# end automatic update

[dev-dependencies]
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.103"
version = "0.0.104"
# end automatic update
authors = [
"Manish Goregaokar <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl LintPass for Pass {
}
}

impl LateLintPass for Pass {
fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprLit(ref lit) = e.node {
check_lit(cx, lit, e);
}
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl LintPass for Arithmetic {
}
}

impl LateLintPass for Arithmetic {
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if self.span.is_some() {
return;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ impl LateLintPass for Arithmetic {
}
}

fn check_expr_post(&mut self, _: &LateContext, expr: &hir::Expr) {
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if Some(expr.span) == self.span {
self.span = None;
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/array_indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ impl LintPass for ArrayIndexing {
}
}

impl LateLintPass for ArrayIndexing {
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
if let hir::ExprIndex(ref array, ref index) = e.node {
// Array with known size can be checked statically
let ty = cx.tcx.tables().expr_ty(array);
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl LintPass for AssignOps {
}
}

impl LateLintPass for AssignOps {
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
match expr.node {
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
span_lint_and_then(cx, ASSIGN_OPS, expr.span, "assign operation detected", |db| {
Expand Down
26 changes: 13 additions & 13 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl LintPass for AttrPass {
}
}

impl LateLintPass for AttrPass {
fn check_attribute(&mut self, cx: &LateContext, attr: &Attribute) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
if let MetaItemKind::List(ref items) = attr.value.node {
if items.is_empty() || attr.name() != "deprecated" {
return;
Expand All @@ -99,21 +99,21 @@ impl LateLintPass for AttrPass {
}
}

fn check_item(&mut self, cx: &LateContext, item: &Item) {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if is_relevant_item(cx, item) {
check_attrs(cx, item.span, &item.name, &item.attrs)
}
match item.node {
ItemExternCrate(_) |
ItemUse(_) => {
ItemUse(_, _) => {
for attr in &item.attrs {
if let MetaItemKind::List(ref lint_list) = attr.value.node {
match &*attr.name().as_str() {
"allow" | "warn" | "deny" | "forbid" => {
// whitelist `unused_imports`
for lint in lint_list {
if is_word(lint, "unused_imports") {
if let ItemUse(_) = item.node {
if let ItemUse(_, _) = item.node {
return;
}
}
Expand All @@ -138,38 +138,38 @@ impl LateLintPass for AttrPass {
}
}

fn check_impl_item(&mut self, cx: &LateContext, item: &ImplItem) {
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
if is_relevant_impl(cx, item) {
check_attrs(cx, item.span, &item.name, &item.attrs)
}
}

fn check_trait_item(&mut self, cx: &LateContext, item: &TraitItem) {
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
if is_relevant_trait(cx, item) {
check_attrs(cx, item.span, &item.name, &item.attrs)
}
}
}

fn is_relevant_item(cx: &LateContext, item: &Item) -> bool {
if let ItemFn(_, _, _, _, _, ref expr) = item.node {
is_relevant_expr(cx, expr)
if let ItemFn(_, _, _, _, _, eid) = item.node {
is_relevant_expr(cx, cx.tcx.map.expr(eid))
} else {
false
}
}

fn is_relevant_impl(cx: &LateContext, item: &ImplItem) -> bool {
match item.node {
ImplItemKind::Method(_, ref expr) => is_relevant_expr(cx, expr),
ImplItemKind::Method(_, eid) => is_relevant_expr(cx, cx.tcx.map.expr(eid)),
_ => false,
}
}

fn is_relevant_trait(cx: &LateContext, item: &TraitItem) -> bool {
match item.node {
MethodTraitItem(_, None) => true,
MethodTraitItem(_, Some(ref expr)) => is_relevant_expr(cx, expr),
MethodTraitItem(_, Some(eid)) => is_relevant_expr(cx, cx.tcx.map.expr(eid)),
_ => false,
}
}
Expand All @@ -193,8 +193,8 @@ fn is_relevant_expr(cx: &LateContext, expr: &Expr) -> bool {
ExprRet(Some(ref e)) => is_relevant_expr(cx, e),
ExprRet(None) | ExprBreak(_, None) => false,
ExprCall(ref path_expr, _) => {
if let ExprPath(..) = path_expr.node {
let fun_id = resolve_node(cx, path_expr.id).expect("function should be resolved").def_id();
if let ExprPath(ref qpath) = path_expr.node {
let fun_id = resolve_node(cx, qpath, path_expr.id).def_id();
!match_def_path(cx, fun_id, &paths::BEGIN_PANIC)
} else {
true
Expand Down
23 changes: 9 additions & 14 deletions clippy_lints/src/bit_mask.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::hir::*;
use rustc::hir::def::{Def, PathResolution};
use rustc::hir::def::Def;
use rustc::lint::*;
use rustc_const_eval::lookup_const_by_id;
use syntax::ast::LitKind;
Expand Down Expand Up @@ -79,8 +79,8 @@ impl LintPass for BitMask {
}
}

impl LateLintPass for BitMask {
fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprBinary(ref cmp, ref left, ref right) = e.node {
if cmp.node.is_comparison() {
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
Expand Down Expand Up @@ -245,18 +245,13 @@ fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option<u64> {
None
}
}
ExprPath(_, _) => {
{
// Important to let the borrow expire before the const lookup to avoid double
// borrowing.
let def_map = cx.tcx.def_map.borrow();
match def_map.get(&lit.id) {
Some(&PathResolution { base_def: Def::Const(def_id), .. }) => Some(def_id),
_ => None,
}
ExprPath(ref qpath) => {
let def = cx.tcx.tables().qpath_def(qpath, lit.id);
if let Def::Const(def_id) = def {
lookup_const_by_id(cx.tcx, def_id, None).and_then(|(l, _ty)| fetch_int_literal(cx, l))
} else {
None
}
.and_then(|def_id| lookup_const_by_id(cx.tcx, def_id, None))
.and_then(|(l, _ty)| fetch_int_literal(cx, l))
}
_ => None,
}
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/blacklisted_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl LintPass for BlackListedName {
}
}

impl LateLintPass for BlackListedName {
fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
if let PatKind::Binding(_, ref ident, _) = pat.node {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
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
23 changes: 14 additions & 9 deletions clippy_lints/src/block_in_if_condition.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::lint::{LateLintPass, LateContext, LintArray, LintPass};
use rustc::hir::*;
use rustc::hir::intravisit::{Visitor, walk_expr};
use rustc::hir::intravisit::{Visitor, walk_expr, NestedVisitorMap};
use utils::*;

/// **What it does:** Checks for `if` conditions that use blocks to contain an
Expand Down Expand Up @@ -49,28 +49,33 @@ impl LintPass for BlockInIfCondition {
}
}

struct ExVisitor<'v> {
found_block: Option<&'v Expr>,
struct ExVisitor<'a, 'tcx: 'a> {
found_block: Option<&'tcx Expr>,
cx: &'a LateContext<'a, 'tcx>,
}

impl<'v> Visitor<'v> for ExVisitor<'v> {
fn visit_expr(&mut self, expr: &'v Expr) {
if let ExprClosure(_, _, ref expr, _) = expr.node {
impl<'a, 'tcx: 'a> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr) {
if let ExprClosure(_, _, eid, _) = expr.node {
let expr = self.cx.tcx.map.expr(eid);
if matches!(expr.node, ExprBlock(_)) {
self.found_block = Some(expr);
return;
}
}
walk_expr(self, expr);
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.cx.tcx.map)
}
}

const BRACED_EXPR_MESSAGE: &'static str = "omit braces around single expression condition";
const COMPLEX_BLOCK_MESSAGE: &'static str = "in an 'if' condition, avoid complex blocks or closures with blocks; \
instead, move the block or closure higher and bind it with a 'let'";

impl LateLintPass for BlockInIfCondition {
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprIf(ref check, ref then, _) = expr.node {
if let ExprBlock(ref block) = check.node {
if block.rules == DefaultBlock {
Expand Down Expand Up @@ -105,7 +110,7 @@ impl LateLintPass for BlockInIfCondition {
}
}
} else {
let mut visitor = ExVisitor { found_block: None };
let mut visitor = ExVisitor { found_block: None, cx: cx };
walk_expr(&mut visitor, check);
if let Some(block) = visitor.found_block {
span_lint(cx, BLOCK_IN_IF_CONDITION_STMT, block.span, COMPLEX_BLOCK_MESSAGE);
Expand Down
31 changes: 18 additions & 13 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ impl LintPass for NonminimalBool {
}
}

impl LateLintPass for NonminimalBool {
fn check_item(&mut self, cx: &LateContext, item: &Item) {
NonminimalBoolVisitor(cx).visit_item(item)
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
NonminimalBoolVisitor { cx: cx }.visit_item(item)
}
}

struct NonminimalBoolVisitor<'a, 'tcx: 'a>(&'a LateContext<'a, 'tcx>);
struct NonminimalBoolVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>,
}

use quine_mc_cluskey::Bool;
struct Hir2Qmm<'a, 'tcx: 'a, 'v> {
Expand Down Expand Up @@ -308,7 +310,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
fn bool_expr(&self, e: &Expr) {
let mut h2q = Hir2Qmm {
terminals: Vec::new(),
cx: self.0,
cx: self.cx,
};
if let Ok(expr) = h2q.run(e) {

Expand Down Expand Up @@ -343,7 +345,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
continue 'simplified;
}
if stats.terminals[i] != 0 && simplified_stats.terminals[i] == 0 {
span_lint_and_then(self.0,
span_lint_and_then(self.cx,
LOGIC_BUG,
e.span,
"this boolean expression contains a logic bug",
Expand All @@ -353,7 +355,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
outer expression");
db.span_suggestion(e.span,
"it would look like the following",
suggest(self.0, suggestion, &h2q.terminals));
suggest(self.cx, suggestion, &h2q.terminals));
});
// don't also lint `NONMINIMAL_BOOL`
return;
Expand All @@ -370,29 +372,29 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
}
}
if !improvements.is_empty() {
span_lint_and_then(self.0,
span_lint_and_then(self.cx,
NONMINIMAL_BOOL,
e.span,
"this boolean expression can be simplified",
|db| {
for suggestion in &improvements {
db.span_suggestion(e.span, "try", suggest(self.0, suggestion, &h2q.terminals));
db.span_suggestion(e.span, "try", suggest(self.cx, suggestion, &h2q.terminals));
}
});
}
}
}
}

impl<'a, 'v, 'tcx> Visitor<'v> for NonminimalBoolVisitor<'a, 'tcx> {
fn visit_expr(&mut self, e: &'v Expr) {
if in_macro(self.0, e.span) {
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
fn visit_expr(&mut self, e: &'tcx Expr) {
if in_macro(self.cx, e.span) {
return;
}
match e.node {
ExprBinary(binop, _, _) if binop.node == BiOr || binop.node == BiAnd => self.bool_expr(e),
ExprUnary(UnNot, ref inner) => {
if self.0.tcx.tables.borrow().node_types[&inner.id].is_bool() {
if self.cx.tcx.tables.borrow().node_types[&inner.id].is_bool() {
self.bool_expr(e);
} else {
walk_expr(self, e);
Expand All @@ -401,4 +403,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for NonminimalBoolVisitor<'a, 'tcx> {
_ => walk_expr(self, e),
}
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.cx.tcx.map)
}
}
Loading