@@ -4,10 +4,10 @@ use crate::consts::{
44} ;
55use crate :: utils:: * ;
66use if_chain:: if_chain;
7- use rustc_hir:: * ;
8- use rustc_lint:: { LateContext , LateLintPass } ;
97use rustc:: ty;
108use rustc_errors:: Applicability ;
9+ use rustc_hir:: * ;
10+ use rustc_lint:: { LateContext , LateLintPass } ;
1111use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
1212use std:: f32:: consts as f32_consts;
1313use std:: f64:: consts as f64_consts;
@@ -16,11 +16,10 @@ use syntax::ast;
1616
1717declare_clippy_lint ! {
1818 /// **What it does:** Looks for floating-point expressions that
19- /// can be expressed using built-in methods to improve accuracy,
20- /// performance and/or succinctness .
19+ /// can be expressed using built-in methods to improve both
20+ /// accuracy and performance .
2121 ///
22- /// **Why is this bad?** Negatively affects accuracy, performance
23- /// and/or readability.
22+ /// **Why is this bad?** Negatively impacts accuracy and performance.
2423 ///
2524 /// **Known problems:** None
2625 ///
@@ -59,16 +58,16 @@ declare_clippy_lint! {
5958 /// let _ = a.exp_m1();
6059 /// let _ = a.powi(2);
6160 /// ```
62- pub FLOATING_POINT_IMPROVEMENTS ,
61+ pub SUBOPTIMAL_FLOPS ,
6362 nursery,
64- "looks for improvements to floating- point expressions "
63+ "usage of sub-optimal floating point operations "
6564}
6665
67- declare_lint_pass ! ( FloatingPointArithmetic => [ FLOATING_POINT_IMPROVEMENTS ] ) ;
66+ declare_lint_pass ! ( FloatingPointArithmetic => [ SUBOPTIMAL_FLOPS ] ) ;
6867
6968// Returns the specialized log method for a given base if base is constant
7069// and is one of 2, 10 and e
71- fn get_specialized_log_method ( cx : & LateContext < ' _ , ' _ > , base : & Expr ) -> Option < & ' static str > {
70+ fn get_specialized_log_method ( cx : & LateContext < ' _ , ' _ > , base : & Expr < ' _ > ) -> Option < & ' static str > {
7271 if let Some ( ( value, _) ) = constant ( cx, cx. tables , base) {
7372 if F32 ( 2.0 ) == value || F64 ( 2.0 ) == value {
7473 return Some ( "log2" ) ;
@@ -124,7 +123,7 @@ fn check_log_base(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>])
124123 if let Some ( method) = get_specialized_log_method ( cx, & args[ 1 ] ) {
125124 span_lint_and_sugg (
126125 cx,
127- FLOATING_POINT_IMPROVEMENTS ,
126+ SUBOPTIMAL_FLOPS ,
128127 expr. span ,
129128 "logarithm for bases 2, 10 and e can be computed more accurately" ,
130129 "consider using" ,
@@ -136,7 +135,7 @@ fn check_log_base(cx: &LateContext<'_, '_>, expr: &Expr<'_>, args: &[Expr<'_>])
136135
137136// TODO: Lint expressions of the form `(x + y).ln()` where y > 1 and
138137// suggest usage of `(x + (y - 1)).ln_1p()` instead
139- fn check_ln1p ( cx : & LateContext < ' _ , ' _ > , expr : & Expr , args : & HirVec < Expr > ) {
138+ fn check_ln1p ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > , args : & [ Expr < ' _ > ] ) {
140139 if_chain ! {
141140 if let ExprKind :: Binary ( op, ref lhs, ref rhs) = & args[ 0 ] . kind;
142141 if op. node == BinOpKind :: Add ;
@@ -149,7 +148,7 @@ fn check_ln1p(cx: &LateContext<'_, '_>, expr: &Expr, args: &HirVec<Expr>) {
149148
150149 span_lint_and_sugg(
151150 cx,
152- FLOATING_POINT_IMPROVEMENTS ,
151+ SUBOPTIMAL_FLOPS ,
153152 expr. span,
154153 "ln(1 + x) can be computed more accurately" ,
155154 "consider using" ,
@@ -185,7 +184,7 @@ fn get_integer_from_float_constant(value: &Constant) -> Option<i64> {
185184 }
186185}
187186
188- fn check_powf ( cx : & LateContext < ' _ , ' _ > , expr : & Expr , args : & HirVec < Expr > ) {
187+ fn check_powf ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > , args : & [ Expr < ' _ > ] ) {
189188 // Check receiver
190189 if let Some ( ( value, _) ) = constant ( cx, cx. tables , & args[ 0 ] ) {
191190 let method;
@@ -200,7 +199,7 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr, args: &HirVec<Expr>) {
200199
201200 span_lint_and_sugg (
202201 cx,
203- FLOATING_POINT_IMPROVEMENTS ,
202+ SUBOPTIMAL_FLOPS ,
204203 expr. span ,
205204 "exponent for bases 2 and e can be computed more accurately" ,
206205 "consider using" ,
@@ -223,7 +222,7 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr, args: &HirVec<Expr>) {
223222 } else if let Some ( exponent) = get_integer_from_float_constant ( & value) {
224223 span_lint_and_sugg (
225224 cx,
226- FLOATING_POINT_IMPROVEMENTS ,
225+ SUBOPTIMAL_FLOPS ,
227226 expr. span ,
228227 "exponentiation with integer powers can be computed more efficiently" ,
229228 "consider using" ,
@@ -238,7 +237,7 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr, args: &HirVec<Expr>) {
238237
239238 span_lint_and_sugg (
240239 cx,
241- FLOATING_POINT_IMPROVEMENTS ,
240+ SUBOPTIMAL_FLOPS ,
242241 expr. span ,
243242 help,
244243 "consider using" ,
@@ -250,7 +249,7 @@ fn check_powf(cx: &LateContext<'_, '_>, expr: &Expr, args: &HirVec<Expr>) {
250249
251250// TODO: Lint expressions of the form `x.exp() - y` where y > 1
252251// and suggest usage of `x.exp_m1() - (y - 1)` instead
253- fn check_expm1 ( cx : & LateContext < ' _ , ' _ > , expr : & Expr ) {
252+ fn check_expm1 ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > ) {
254253 if_chain ! {
255254 if let ExprKind :: Binary ( op, ref lhs, ref rhs) = expr. kind;
256255 if op. node == BinOpKind :: Sub ;
@@ -263,7 +262,7 @@ fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr) {
263262 then {
264263 span_lint_and_sugg(
265264 cx,
266- FLOATING_POINT_IMPROVEMENTS ,
265+ SUBOPTIMAL_FLOPS ,
267266 expr. span,
268267 "(e.pow(x) - 1) can be computed more accurately" ,
269268 "consider using" ,
@@ -278,7 +277,7 @@ fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr) {
278277}
279278
280279impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for FloatingPointArithmetic {
281- fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr ) {
280+ fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr < ' _ > ) {
282281 if let ExprKind :: MethodCall ( ref path, _, args) = & expr. kind {
283282 let recv_ty = cx. tables . expr_ty ( & args[ 0 ] ) ;
284283
0 commit comments