Skip to content

Commit

Permalink
submodules: update clippy from 1b89724 to 1838bfe
Browse files Browse the repository at this point in the history
Changes:
````
Fixing typo in CONTRIBUTING.md
Fix breakage due to rust-lang/rust#57651
Run rustfmt
Fixed breakage due to rust-lang/rust#57489
Fix breakage due to rust-lang/rust#57755
Catch up with `format_args` change
Fix bad `while_let_on_iterator` suggestion.
rustup rust-lang/rust#57747
Fixing issues pointed out by dogfood tests.
Update to collect all the files then throw the error.
Adding a test for checking if test files are missing.
Remove bors.toml
add applicability to lint name suggestion
````
  • Loading branch information
matthiaskrgr committed Jan 21, 2019
1 parent eba7337 commit 96905b8
Show file tree
Hide file tree
Showing 35 changed files with 300 additions and 258 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ to lint-writing, though it does get into advanced stuff. Most lints consist of a
of this.

If you want to add a new lint or change existing ones apart from bugfixing, it's
also a good idea to give the [stability guaratees][rfc_stability] and
also a good idea to give the [stability guarantees][rfc_stability] and
[lint categories][rfc_lint_cats] sections of the [Clippy 1.0 RFC][clippy_rfc] a
quick read.

Expand Down
4 changes: 0 additions & 4 deletions bors.toml

This file was deleted.

14 changes: 9 additions & 5 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,12 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
// https://github.com/rust-lang/rust/pull/56992
CheckLintNameResult::NoLint(None) => (),
_ => {
db.span_suggestion(lint.span,
"lowercase the lint name",
name_lower);
db.span_suggestion_with_applicability(
lint.span,
"lowercase the lint name",
name_lower,
Applicability::MaybeIncorrect,
);
}
}
}
Expand Down Expand Up @@ -373,8 +376,9 @@ fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
fn is_relevant_block(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
if let Some(stmt) = block.stmts.first() {
match &stmt.node {
StmtKind::Decl(_, _) => true,
StmtKind::Expr(expr, _) | StmtKind::Semi(expr, _) => is_relevant_expr(tcx, tables, expr),
StmtKind::Local(_) => true,
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(tcx, tables, expr),
_ => false,
}
} else {
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
Expand Down
7 changes: 7 additions & 0 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use syntax::ast::{FloatTy, LitKind};
use syntax::ptr::P;
use syntax_pos::symbol::Symbol;

/// A `LitKind`-like enum to fold constant `Expr`s into.
#[derive(Debug, Clone)]
Expand All @@ -38,6 +39,8 @@ pub enum Constant {
Repeat(Box<Constant>, u64),
/// a tuple of constants
Tuple(Vec<Constant>),
/// a literal with syntax error
Err(Symbol),
}

impl PartialEq for Constant {
Expand Down Expand Up @@ -103,6 +106,9 @@ impl Hash for Constant {
c.hash(state);
l.hash(state);
},
Constant::Err(ref s) => {
s.hash(state);
},
}
}
}
Expand Down Expand Up @@ -155,6 +161,7 @@ pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
_ => bug!(),
},
LitKind::Bool(b) => Constant::Bool(b),
LitKind::Err(s) => Constant::Err(s),
}
}

Expand Down
20 changes: 9 additions & 11 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,16 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
if let Categorization::Rvalue(..) = cmt.cat {
let id = map.hir_to_node_id(cmt.hir_id);
if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(id)) {
if let StmtKind::Decl(ref decl, _) = st.node {
if let DeclKind::Local(ref loc) = decl.node {
if let Some(ref ex) = loc.init {
if let ExprKind::Box(..) = ex.node {
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
// let x = box (...)
self.set.insert(consume_pat.id);
}
// TODO Box::new
// TODO vec![]
// TODO "foo".to_owned() and friends
if let StmtKind::Local(ref loc) = st.node {
if let Some(ref ex) = loc.init {
if let ExprKind::Box(..) = ex.node {
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
// let x = box (...)
self.set.insert(consume_pat.id);
}
// TODO Box::new
// TODO vec![]
// TODO "foo".to_owned() and friends
}
}
}
Expand Down
31 changes: 13 additions & 18 deletions clippy_lints/src/eval_order_dependence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
}
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
match stmt.node {
StmtKind::Expr(ref e, _) | StmtKind::Semi(ref e, _) => DivergenceVisitor { cx }.maybe_walk_expr(e),
StmtKind::Decl(ref d, _) => {
if let DeclKind::Local(ref local) = d.node {
if let Local { init: Some(ref e), .. } = **local {
DivergenceVisitor { cx }.visit_expr(e);
}
StmtKind::Local(ref local) => {
if let Local { init: Some(ref e), .. } = **local {
DivergenceVisitor { cx }.visit_expr(e);
}
},
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => DivergenceVisitor { cx }.maybe_walk_expr(e),
StmtKind::Item(..) => {},
}
}
}
Expand Down Expand Up @@ -269,18 +268,14 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St

fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> StopEarly {
match stmt.node {
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => check_expr(vis, expr),
StmtKind::Decl(ref decl, _) => {
// If the declaration is of a local variable, check its initializer
// expression if it has one. Otherwise, keep going.
let local = match decl.node {
DeclKind::Local(ref local) => Some(local),
_ => None,
};
local
.and_then(|local| local.init.as_ref())
.map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr))
},
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => check_expr(vis, expr),
// If the declaration is of a local variable, check its initializer
// expression if it has one. Otherwise, keep going.
StmtKind::Local(ref local) => local
.init
.as_ref()
.map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr)),
_ => StopEarly::KeepGoing,
}
}

Expand Down
11 changes: 8 additions & 3 deletions clippy_lints/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
ExprKind::Call(ref fun, ref args) => {
if_chain! {
if let ExprKind::Path(ref qpath) = fun.node;
if args.len() == 3;
if let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id));
if match_def_path(cx.tcx, fun_def_id, &paths::FMT_ARGUMENTS_NEWV1FORMATTED);
let new_v1 = match_def_path(cx.tcx, fun_def_id, &paths::FMT_ARGUMENTS_NEWV1);
let new_v1_fmt = match_def_path(
cx.tcx,
fun_def_id,
&paths::FMT_ARGUMENTS_NEWV1FORMATTED
);
if new_v1 || new_v1_fmt;
if check_single_piece(&args[0]);
if let Some(format_arg) = get_single_string_arg(cx, &args[1]);
if check_unformatted(&args[2]);
if new_v1 || check_unformatted(&args[2]);
if let ExprKind::AddrOf(_, ref format_arg) = format_arg.node;
then {
let (message, sugg) = if_chain! {
Expand Down
13 changes: 6 additions & 7 deletions clippy_lints/src/let_if_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
while let Some(stmt) = it.next() {
if_chain! {
if let Some(expr) = it.peek();
if let hir::StmtKind::Decl(ref decl, _) = stmt.node;
if let hir::DeclKind::Local(ref decl) = decl.node;
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = decl.pat.node;
if let hir::StmtKind::Expr(ref if_, _) = expr.node;
if let hir::StmtKind::Local(ref local) = stmt.node;
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
if let hir::StmtKind::Expr(ref if_) = expr.node;
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;
if !used_in_expr(cx, canonical_id, cond);
if let hir::ExprKind::Block(ref then, _) = then.node;
Expand All @@ -84,15 +83,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
if let hir::ExprKind::Block(ref else_, _) = else_.node {
if let Some(default) = check_assign(cx, canonical_id, else_) {
(else_.stmts.len() > 1, default)
} else if let Some(ref default) = decl.init {
} else if let Some(ref default) = local.init {
(true, &**default)
} else {
continue;
}
} else {
continue;
}
} else if let Some(ref default) = decl.init {
} else if let Some(ref default) = local.init {
(false, &**default)
} else {
continue;
Expand Down Expand Up @@ -169,7 +168,7 @@ fn check_assign<'a, 'tcx>(
if_chain! {
if block.expr.is_none();
if let Some(expr) = block.stmts.iter().last();
if let hir::StmtKind::Semi(ref expr, _) = expr.node;
if let hir::StmtKind::Semi(ref expr) = expr.node;
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
if let hir::ExprKind::Path(ref qpath) = var.node;
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id);
Expand Down
52 changes: 28 additions & 24 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use if_chain::if_chain;
use itertools::Itertools;
use rustc::hir::def::Def;
use rustc::hir::def_id;
use rustc::hir::intravisit::{walk_block, walk_decl, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
use rustc::hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::middle::region;
Expand Down Expand Up @@ -565,6 +565,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
&& lhs_constructor.ident.name == "Some"
&& (pat_args.is_empty()
|| !is_refutable(cx, &pat_args[0])
&& !is_used_inside(cx, iter_expr, &arms[0].body)
&& !is_iterator_used_after_while_let(cx, iter_expr)
&& !is_nested(cx, expr, &method_args[0]))
{
Expand Down Expand Up @@ -596,7 +597,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}

fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
if let StmtKind::Semi(ref expr, _) = stmt.node {
if let StmtKind::Semi(ref expr) = stmt.node {
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node {
if args.len() == 1 && method.ident.name == "collect" && match_trait_method(cx, expr, &paths::ITERATOR) {
span_lint(
Expand Down Expand Up @@ -667,13 +668,7 @@ fn never_loop_block(block: &Block, main_loop_id: NodeId) -> NeverLoopResult {
fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
match stmt.node {
StmtKind::Semi(ref e, ..) | StmtKind::Expr(ref e, ..) => Some(e),
StmtKind::Decl(ref d, ..) => decl_to_expr(d),
}
}

fn decl_to_expr(decl: &Decl) -> Option<&Expr> {
match decl.node {
DeclKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
StmtKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
_ => None,
}
}
Expand Down Expand Up @@ -941,8 +936,8 @@ fn get_indexed_assignments<'a, 'tcx>(
stmts
.iter()
.map(|stmt| match stmt.node {
StmtKind::Decl(..) => None,
StmtKind::Expr(ref e, _node_id) | StmtKind::Semi(ref e, _node_id) => Some(get_assignment(cx, e, var)),
StmtKind::Local(..) | StmtKind::Item(..) => None,
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => Some(get_assignment(cx, e, var)),
})
.chain(expr.as_ref().into_iter().map(|e| Some(get_assignment(cx, &*e, var))))
.filter_map(|op| op)
Expand Down Expand Up @@ -1888,6 +1883,19 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
}
}

fn is_used_inside<'a, 'tcx: 'a>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr, container: &'tcx Expr) -> bool {
let def_id = match var_def_id(cx, expr) {
Some(id) => id,
None => return false,
};
if let Some(used_mutably) = mutated_variables(container, cx) {
if used_mutably.contains(&def_id) {
return true;
}
}
false
}

fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, iter_expr: &'tcx Expr) -> bool {
let def_id = match var_def_id(cx, iter_expr) {
Some(id) => id,
Expand Down Expand Up @@ -1962,13 +1970,9 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
if block.stmts.is_empty() {
return None;
}
if let StmtKind::Decl(ref decl, _) = block.stmts[0].node {
if let DeclKind::Local(ref local) = decl.node {
if let Some(ref expr) = local.init {
Some(expr)
} else {
None
}
if let StmtKind::Local(ref local) = block.stmts[0].node {
if let Some(ref expr) = local.init {
Some(expr)
} else {
None
}
Expand All @@ -1982,8 +1986,8 @@ fn extract_first_expr(block: &Block) -> Option<&Expr> {
match block.expr {
Some(ref expr) if block.stmts.is_empty() => Some(expr),
None if !block.stmts.is_empty() => match block.stmts[0].node {
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => Some(expr),
StmtKind::Decl(..) => None,
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => Some(expr),
StmtKind::Local(..) | StmtKind::Item(..) => None,
},
_ => None,
}
Expand Down Expand Up @@ -2081,9 +2085,9 @@ struct InitializeVisitor<'a, 'tcx: 'a> {
}

impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
fn visit_decl(&mut self, decl: &'tcx Decl) {
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
// Look for declarations of the variable
if let DeclKind::Local(ref local) = decl.node {
if let StmtKind::Local(ref local) = stmt.node {
if local.pat.id == self.var_id {
if let PatKind::Binding(_, _, ident, _) = local.pat.node {
self.name = Some(ident.name);
Expand All @@ -2100,7 +2104,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
}
}
}
walk_decl(self, decl);
walk_stmt(self, stmt);
}

fn visit_expr(&mut self, expr: &'tcx Expr) {
Expand Down Expand Up @@ -2247,7 +2251,7 @@ struct LoopNestVisitor {

impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
if stmt.node.id() == self.id {
if stmt.id == self.id {
self.nesting = LookFurther;
} else if self.nesting == Unknown {
walk_stmt(self, stmt);
Expand Down
9 changes: 5 additions & 4 deletions clippy_lints/src/map_unit_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
// If block only contains statements,
// reduce `{ X; }` to `X` or `X;`
match inner_stmt.node {
hir::StmtKind::Decl(ref d, _) => Some(d.span),
hir::StmtKind::Expr(ref e, _) => Some(e.span),
hir::StmtKind::Semi(_, _) => Some(inner_stmt.span),
hir::StmtKind::Local(ref local) => Some(local.span),
hir::StmtKind::Expr(ref e) => Some(e.span),
hir::StmtKind::Semi(..) => Some(inner_stmt.span),
hir::StmtKind::Item(..) => None,
}
},
_ => {
Expand Down Expand Up @@ -250,7 +251,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
return;
}

if let hir::StmtKind::Semi(ref expr, _) = stmt.node {
if let hir::StmtKind::Semi(ref expr) = stmt.node {
if let Some(arglists) = method_chain_args(expr, &["map"]) {
lint_map_unit_fn(cx, stmt, expr, arglists[0]);
}
Expand Down
Loading

0 comments on commit 96905b8

Please sign in to comment.