File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Expand file tree Collapse file tree 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};
55use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
66use rustc_span:: source_map:: Spanned ;
77
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+
825declare_clippy_lint ! {
926 /// **What it does:** Checks for operations where precedence may be unclear
1027 /// and suggests to add parentheses. Currently it catches the following:
@@ -86,11 +103,16 @@ impl EarlyLintPass for Precedence {
86103 }
87104
88105 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 {
90107 if let Some ( slf) = args. first ( ) {
91108 if let ExprKind :: Lit ( ref lit) = slf. kind {
92109 match lit. kind {
93110 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+ }
94116 let mut applicability = Applicability :: MachineApplicable ;
95117 span_lint_and_sugg (
96118 cx,
Original file line number Diff line number Diff line change @@ -32,6 +32,22 @@ fn main() {
3232 let _ = -(1i32.abs());
3333 let _ = -(1f32.abs());
3434
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+
3551 let b = 3;
3652 trip!(b * 8);
3753}
Original file line number Diff line number Diff line change @@ -32,6 +32,22 @@ fn main() {
3232 let _ = -( 1i32 . abs ( ) ) ;
3333 let _ = -( 1f32 . abs ( ) ) ;
3434
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+
3551 let b = 3 ;
3652 trip ! ( b * 8 ) ;
3753}
You can’t perform that action at this time.
0 commit comments