Skip to content

Commit

Permalink
Update lint to current clippy API
Browse files Browse the repository at this point in the history
  • Loading branch information
cgm616 committed Oct 22, 2020
1 parent 45413ed commit eb6c24d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&write::WRITELN_EMPTY_STRING,
&write::WRITE_LITERAL,
&write::WRITE_WITH_NEWLINE,
&xor_used_as_pow::XOR_USED_AS_POW,
&zero_div_zero::ZERO_DIVIDED_BY_ZERO,
]);
// end register lints, do not remove this comment, it’s used in `update_lints`
Expand Down Expand Up @@ -1800,6 +1801,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
LintId::of(&unwrap::PANICKING_UNWRAP),
LintId::of(&vec_resize_to_zero::VEC_RESIZE_TO_ZERO),
LintId::of(&xor_used_as_pow::XOR_USED_AS_POW),
]);

store.register_group(true, "clippy::perf", Some("clippy_perf"), vec![
Expand Down
22 changes: 12 additions & 10 deletions clippy_lints/src/xor_used_as_pow.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::utils::{span_help_and_lint, span_lint_and_sugg};
use crate::utils::{span_lint_and_help, span_lint_and_sugg};
use if_chain::if_chain;
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_ast::{BinOpKind, Expr, ExprKind, LitKind};
use rustc_errors::Applicability;
use syntax::ast::{BinOpKind, Expr, ExprKind, LitKind};
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
/// **What it does:** Checks for use of `^` operator when exponentiation was intended.
Expand Down Expand Up @@ -33,12 +34,12 @@ impl EarlyLintPass for XorUsedAsPow {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if_chain! {
if !in_external_macro(cx.sess, expr.span);
if let ExprKind::Binary(op, left, right) = &expr.node;
if let ExprKind::Binary(op, left, right) = &expr.kind;
if BinOpKind::BitXor == op.node;
if let ExprKind::Lit(lit) = &left.node;
if let LitKind::Int(lhs, _) = lit.node;
if let ExprKind::Lit(lit) = &right.node;
if let LitKind::Int(rhs, _) = lit.node;
if let ExprKind::Lit(lit) = &left.kind;
if let LitKind::Int(lhs, _) = lit.kind;
if let ExprKind::Lit(lit) = &right.kind;
if let LitKind::Int(rhs, _) = lit.kind;
then {
if lhs == 2 {
if rhs == 8 || rhs == 16 || rhs == 32 || rhs == 64 || rhs == 128 {
Expand All @@ -63,11 +64,12 @@ impl EarlyLintPass for XorUsedAsPow {
)
}
} else {
span_help_and_lint(
span_lint_and_help(
cx,
XOR_USED_AS_POW,
expr.span,
"`^` is not an exponentiation operator but appears to have been used as one",
None,
"did you mean to use .pow()?"
)
}
Expand Down

0 comments on commit eb6c24d

Please sign in to comment.