File tree 3 files changed +55
-1
lines changed
3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,23 @@ use rustc_lint::{EarlyContext, EarlyLintPass};
5
5
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
6
6
use rustc_span:: source_map:: Spanned ;
7
7
8
+ const ODD_FUNCTIONS_WHITELIST : [ & str ; 14 ] = [
9
+ "asin" ,
10
+ "asinh" ,
11
+ "atan" ,
12
+ "atanh" ,
13
+ "cbrt" ,
14
+ "fract" ,
15
+ "round" ,
16
+ "signum" ,
17
+ "sin" ,
18
+ "sinh" ,
19
+ "tan" ,
20
+ "tanh" ,
21
+ "to_degrees" ,
22
+ "to_radians" ,
23
+ ] ;
24
+
8
25
declare_clippy_lint ! {
9
26
/// **What it does:** Checks for operations where precedence may be unclear
10
27
/// and suggests to add parentheses. Currently it catches the following:
@@ -86,11 +103,16 @@ impl EarlyLintPass for Precedence {
86
103
}
87
104
88
105
if let ExprKind :: Unary ( UnOp :: Neg , ref rhs) = expr. kind {
89
- if let ExprKind :: MethodCall ( _ , ref args) = rhs. kind {
106
+ if let ExprKind :: MethodCall ( ref path_segment , ref args) = rhs. kind {
90
107
if let Some ( slf) = args. first ( ) {
91
108
if let ExprKind :: Lit ( ref lit) = slf. kind {
92
109
match lit. kind {
93
110
LitKind :: Int ( ..) | LitKind :: Float ( ..) => {
111
+ for & odd_function in & ODD_FUNCTIONS_WHITELIST {
112
+ if odd_function == & * path_segment. ident . name . as_str ( ) {
113
+ return ;
114
+ }
115
+ }
94
116
let mut applicability = Applicability :: MachineApplicable ;
95
117
span_lint_and_sugg (
96
118
cx,
Original file line number Diff line number Diff line change @@ -32,6 +32,22 @@ fn main() {
32
32
let _ = -(1i32.abs());
33
33
let _ = -(1f32.abs());
34
34
35
+ // Odd functions shoud not trigger an error
36
+ let _ = -1f64.asin();
37
+ let _ = -1f64.asinh();
38
+ let _ = -1f64.atan();
39
+ let _ = -1f64.atanh();
40
+ let _ = -1f64.cbrt();
41
+ let _ = -1f64.fract();
42
+ let _ = -1f64.round();
43
+ let _ = -1f64.signum();
44
+ let _ = -1f64.sin();
45
+ let _ = -1f64.sinh();
46
+ let _ = -1f64.tan();
47
+ let _ = -1f64.tanh();
48
+ let _ = -1f64.to_degrees();
49
+ let _ = -1f64.to_radians();
50
+
35
51
let b = 3;
36
52
trip!(b * 8);
37
53
}
Original file line number Diff line number Diff line change @@ -32,6 +32,22 @@ fn main() {
32
32
let _ = -( 1i32 . abs ( ) ) ;
33
33
let _ = -( 1f32 . abs ( ) ) ;
34
34
35
+ // Odd functions shoud not trigger an error
36
+ let _ = -1f64 . asin ( ) ;
37
+ let _ = -1f64 . asinh ( ) ;
38
+ let _ = -1f64 . atan ( ) ;
39
+ let _ = -1f64 . atanh ( ) ;
40
+ let _ = -1f64 . cbrt ( ) ;
41
+ let _ = -1f64 . fract ( ) ;
42
+ let _ = -1f64 . round ( ) ;
43
+ let _ = -1f64 . signum ( ) ;
44
+ let _ = -1f64 . sin ( ) ;
45
+ let _ = -1f64 . sinh ( ) ;
46
+ let _ = -1f64 . tan ( ) ;
47
+ let _ = -1f64 . tanh ( ) ;
48
+ let _ = -1f64 . to_degrees ( ) ;
49
+ let _ = -1f64 . to_radians ( ) ;
50
+
35
51
let b = 3 ;
36
52
trip ! ( b * 8 ) ;
37
53
}
You can’t perform that action at this time.
0 commit comments