Skip to content

Commit

Permalink
submodules: update clippy from 68ff8b1 to edd9047
Browse files Browse the repository at this point in the history
Changes:
````
Remove clippy::author attribute from trailing_zeroes test
Move author issue test to author subdir
Fix author lint
Rustup to rust-lang/rust#64813
Refactor `booleans`
Detect assignment ops in integer_arithmetic
````
  • Loading branch information
matthiaskrgr committed Sep 27, 2019
1 parent 5a97ba3 commit b5567e5
Show file tree
Hide file tree
Showing 157 changed files with 1,013 additions and 1,000 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Lit(lit) = &e.node {
if let ExprKind::Lit(lit) = &e.kind {
check_lit(cx, &lit.node, e);
}
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
return;
}
}
match &expr.node {
hir::ExprKind::Binary(op, l, r) => {
match &expr.kind {
hir::ExprKind::Binary(op, l, r) | hir::ExprKind::AssignOp(op, l, r) => {
match op.node {
hir::BinOpKind::And
| hir::BinOpKind::Or
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/assertions_on_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
let lint_assert_cb = |is_debug_assert: bool| {
if let ExprKind::Unary(_, ref lit) = e.node {
if let ExprKind::Unary(_, ref lit) = e.kind {
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit) {
if is_true {
span_help_and_lint(
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
#[allow(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
match &expr.node {
match &expr.kind {
hir::ExprKind::AssignOp(op, lhs, rhs) => {
if let hir::ExprKind::Binary(binop, l, r) = &rhs.node {
if let hir::ExprKind::Binary(binop, l, r) = &rhs.kind {
if op.node != binop.node {
return;
}
Expand All @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
}
},
hir::ExprKind::Assign(assignee, e) => {
if let hir::ExprKind::Binary(op, l, r) = &e.node {
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
#[allow(clippy::cognitive_complexity)]
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
let ty = cx.tables.expr_ty(assignee);
Expand Down
20 changes: 10 additions & 10 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
for item in items {
if_chain! {
if let NestedMetaItem::MetaItem(mi) = &item;
if let MetaItemKind::NameValue(lit) = &mi.node;
if let MetaItemKind::NameValue(lit) = &mi.kind;
if mi.check_name(sym!(since));
then {
check_semver(cx, item.span(), lit);
Expand All @@ -227,7 +227,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
if is_relevant_item(cx, item) {
check_attrs(cx, item.span, item.ident.name, &item.attrs)
}
match item.node {
match item.kind {
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(sym!(macro_use)));

Expand All @@ -242,7 +242,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
// whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items
// and `unused_imports` for `extern crate` items with `macro_use`
for lint in lint_list {
match item.node {
match item.kind {
ItemKind::Use(..) => {
if is_word(lint, sym!(unused_imports))
|| is_word(lint, sym!(deprecated))
Expand Down Expand Up @@ -355,22 +355,22 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
}

fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item) -> bool {
if let ItemKind::Fn(_, _, _, eid) = item.node {
if let ItemKind::Fn(_, _, _, eid) = item.kind {
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
} else {
true
}
}

fn is_relevant_impl(cx: &LateContext<'_, '_>, item: &ImplItem) -> bool {
match item.node {
match item.kind {
ImplItemKind::Method(_, eid) => is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value),
_ => false,
}
}

fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem) -> bool {
match item.node {
match item.kind {
TraitItemKind::Method(_, TraitMethod::Required(_)) => true,
TraitItemKind::Method(_, TraitMethod::Provided(eid)) => {
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
Expand All @@ -381,7 +381,7 @@ fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem) -> bool {

fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
if let Some(stmt) = block.stmts.first() {
match &stmt.node {
match &stmt.kind {
StmtKind::Local(_) => true,
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, tables, expr),
_ => false,
Expand All @@ -392,12 +392,12 @@ fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, bl
}

fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
match &expr.node {
match &expr.kind {
ExprKind::Block(block, _) => is_relevant_block(cx, tables, block),
ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e),
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
ExprKind::Call(path_expr, _) => {
if let ExprKind::Path(qpath) = &path_expr.node {
if let ExprKind::Path(qpath) = &path_expr.kind {
if let Some(fun_id) = tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
!match_def_path(cx, fun_id, &paths::BEGIN_PANIC)
} else {
Expand Down Expand Up @@ -464,7 +464,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
}

fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
if let LitKind::Str(is, _) = lit.node {
if let LitKind::Str(is, _) = lit.kind {
if Version::parse(&is.as_str()).is_ok() {
return;
}
Expand Down
12 changes: 6 additions & 6 deletions clippy_lints/src/bit_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Binary(cmp, left, right) = &e.node {
if let ExprKind::Binary(cmp, left, right) = &e.kind {
if cmp.node.is_comparison() {
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
check_compare(cx, left, cmp.node, cmp_opt, e.span)
Expand All @@ -121,13 +121,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
}
}
if_chain! {
if let ExprKind::Binary(op, left, right) = &e.node;
if let ExprKind::Binary(op, left, right) = &e.kind;
if BinOpKind::Eq == op.node;
if let ExprKind::Binary(op1, left1, right1) = &left.node;
if let ExprKind::Binary(op1, left1, right1) = &left.kind;
if BinOpKind::BitAnd == op1.node;
if let ExprKind::Lit(lit) = &right1.node;
if let ExprKind::Lit(lit) = &right1.kind;
if let LitKind::Int(n, _) = lit.node;
if let ExprKind::Lit(lit1) = &right.node;
if let ExprKind::Lit(lit1) = &right.kind;
if let LitKind::Int(0, _) = lit1.node;
if n.leading_zeros() == n.count_zeros();
if n > u128::from(self.verbose_bit_mask_threshold);
Expand Down Expand Up @@ -163,7 +163,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
}

fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
if let ExprKind::Binary(op, left, right) = &bit_op.node {
if let ExprKind::Binary(op, left, right) = &bit_op.kind {
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/blacklisted_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName {
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if let PatKind::Binding(.., ident, _) = pat.node {
if let PatKind::Binding(.., ident, _) = pat.kind {
if self.blacklist.contains(&ident.name.to_string()) {
span_lint(
cx,
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/block_in_if_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ struct ExVisitor<'a, 'tcx> {

impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr) {
if let ExprKind::Closure(_, _, eid, _, _) = expr.node {
if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
let body = self.cx.tcx.hir().body(eid);
let ex = &body.value;
if matches!(ex.node, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
if matches!(ex.kind, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
self.found_block = Some(ex);
return;
}
Expand All @@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
return;
}
if let Some((check, then, _)) = higher::if_block(&expr) {
if let ExprKind::Block(block, _) = &check.node {
if let ExprKind::Block(block, _) = &check.kind {
if block.rules == DefaultBlock {
if block.stmts.is_empty() {
if let Some(ex) = &block.expr {
Expand Down
26 changes: 11 additions & 15 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct Hir2Qmm<'a, 'tcx, 'v> {
impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
for a in a {
if let ExprKind::Binary(binop, lhs, rhs) = &a.node {
if let ExprKind::Binary(binop, lhs, rhs) = &a.kind {
if binop.node == op {
v = self.extract(op, &[lhs, rhs], v)?;
continue;
Expand All @@ -107,7 +107,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {

// prevent folding of `cfg!` macros and the like
if !e.span.from_expansion() {
match &e.node {
match &e.kind {
ExprKind::Unary(UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
ExprKind::Binary(binop, lhs, rhs) => match &binop.node {
BinOpKind::Or => return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)),
Expand All @@ -129,9 +129,9 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
}

if_chain! {
if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.node;
if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.kind;
if implements_ord(self.cx, e_lhs);
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.node;
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.kind;
if negate(e_binop.node) == Some(expr_binop.node);
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_lhs, expr_lhs);
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_rhs, expr_rhs);
Expand All @@ -156,7 +156,6 @@ struct SuggestContext<'a, 'tcx, 'v> {
terminals: &'v [&'v Expr],
cx: &'a LateContext<'a, 'tcx>,
output: String,
simplified: bool,
}

impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
Expand All @@ -179,7 +178,6 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
Term(n) => {
let terminal = self.terminals[n as usize];
if let Some(str) = simplify_not(self.cx, terminal) {
self.simplified = true;
self.output.push_str(&str)
} else {
self.output.push('!');
Expand Down Expand Up @@ -224,7 +222,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
}

fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
match &expr.node {
match &expr.kind {
ExprKind::Binary(binop, lhs, rhs) => {
if !implements_ord(cx, lhs) {
return None;
Expand Down Expand Up @@ -264,16 +262,14 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
}
}

// The boolean part of the return indicates whether some simplifications have been applied.
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> String {
let mut suggest_context = SuggestContext {
terminals,
cx,
output: String::new(),
simplified: false,
};
suggest_context.recurse(suggestion);
(suggest_context.output, suggest_context.simplified)
suggest_context.output
}

fn simple_negate(b: Bool) -> Bool {
Expand Down Expand Up @@ -383,7 +379,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
db.span_suggestion(
e.span,
"it would look like the following",
suggest(self.cx, suggestion, &h2q.terminals).0,
suggest(self.cx, suggestion, &h2q.terminals),
// nonminimal_bool can produce minimal but
// not human readable expressions (#3141)
Applicability::Unspecified,
Expand Down Expand Up @@ -428,7 +424,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
nonminimal_bool_lint(
improvements
.into_iter()
.map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals).0)
.map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals))
.collect(),
);
}
Expand All @@ -441,7 +437,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
if in_macro(e.span) {
return;
}
match &e.node {
match &e.kind {
ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => {
self.bool_expr(e)
},
Expand Down Expand Up @@ -471,7 +467,7 @@ struct NotSimplificationVisitor<'a, 'tcx> {

impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr) {
if let ExprKind::Unary(UnNot, inner) = &expr.node {
if let ExprKind::Unary(UnNot, inner) = &expr.kind {
if let Some(suggestion) = simplify_not(self.cx, inner) {
span_lint_and_sugg(
self.cx,
Expand Down
12 changes: 6 additions & 6 deletions clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
if_chain! {
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.node;
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.kind;
if count.ident.name == sym!(count);
if count_args.len() == 1;
if let ExprKind::MethodCall(ref filter, _, ref filter_args) = count_args[0].node;
if let ExprKind::MethodCall(ref filter, _, ref filter_args) = count_args[0].kind;
if filter.ident.name == sym!(filter);
if filter_args.len() == 2;
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].node;
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].kind;
then {
let body = cx.tcx.hir().body(body_id);
if_chain! {
if body.params.len() == 1;
if let Some(argname) = get_pat_name(&body.params[0].pat);
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.node;
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind;
if op.node == BinOpKind::Eq;
if match_type(cx,
walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])),
Expand All @@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
return;
}
let haystack = if let ExprKind::MethodCall(ref path, _, ref args) =
filter_args[0].node {
filter_args[0].kind {
let p = path.ident.name;
if (p == sym!(iter) || p == sym!(iter_mut)) && args.len() == 1 {
&args[0]
Expand Down Expand Up @@ -100,7 +100,7 @@ fn check_arg(name: Name, arg: Name, needle: &Expr) -> bool {
}

fn get_path_name(expr: &Expr) -> Option<Name> {
match expr.node {
match expr.kind {
ExprKind::Box(ref e) | ExprKind::AddrOf(_, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => get_path_name(e),
ExprKind::Block(ref b, _) => {
if b.stmts.is_empty() {
Expand Down
Loading

0 comments on commit b5567e5

Please sign in to comment.