1
- use crate :: utils:: { span_help_and_lint , span_lint_and_sugg} ;
1
+ use crate :: utils:: { span_lint_and_help , span_lint_and_sugg} ;
2
2
use if_chain:: if_chain;
3
- use rustc:: lint:: { in_external_macro, EarlyContext , EarlyLintPass , LintArray , LintPass } ;
4
- use rustc:: { declare_lint_pass, declare_tool_lint} ;
3
+ use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
4
+ use rustc_ast:: * ;
5
+ use rustc_middle:: lint:: in_external_macro;
6
+ use rustc_lint:: { EarlyContext , EarlyLintPass } ;
5
7
use rustc_errors:: Applicability ;
6
- use syntax:: ast:: { BinOpKind , Expr , ExprKind , LitKind } ;
7
8
8
9
declare_clippy_lint ! {
9
10
/// **What it does:** Checks for use of `^` operator when exponentiation was intended.
@@ -33,12 +34,12 @@ impl EarlyLintPass for XorUsedAsPow {
33
34
fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & Expr ) {
34
35
if_chain ! {
35
36
if !in_external_macro( cx. sess, expr. span) ;
36
- if let ExprKind :: Binary ( op, left, right) = & expr. node ;
37
+ if let ExprKind :: Binary ( op, left, right) = & expr. kind ;
37
38
if BinOpKind :: BitXor == op. node;
38
- if let ExprKind :: Lit ( lit) = & left. node ;
39
- if let LitKind :: Int ( lhs, _) = lit. node ;
40
- if let ExprKind :: Lit ( lit) = & right. node ;
41
- if let LitKind :: Int ( rhs, _) = lit. node ;
39
+ if let ExprKind :: Lit ( lit) = & left. kind ;
40
+ if let LitKind :: Int ( lhs, _) = lit. kind ;
41
+ if let ExprKind :: Lit ( lit) = & right. kind ;
42
+ if let LitKind :: Int ( rhs, _) = lit. kind ;
42
43
then {
43
44
if lhs == 2 {
44
45
if rhs == 8 || rhs == 16 || rhs == 32 || rhs == 64 || rhs == 128 {
@@ -63,11 +64,12 @@ impl EarlyLintPass for XorUsedAsPow {
63
64
)
64
65
}
65
66
} else {
66
- span_help_and_lint (
67
+ span_lint_and_help (
67
68
cx,
68
69
XOR_USED_AS_POW ,
69
70
expr. span,
70
71
"`^` is not an exponentiation operator but appears to have been used as one" ,
72
+ None ,
71
73
"did you mean to use .pow()?"
72
74
)
73
75
}
0 commit comments