@@ -4,12 +4,11 @@ use crate::consts::{
4
4
} ;
5
5
use crate :: utils:: * ;
6
6
use if_chain:: if_chain;
7
- use rustc:: declare_lint_pass;
8
- use rustc:: hir:: * ;
9
- use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
7
+ use rustc_hir:: * ;
8
+ use rustc_lint:: { LateContext , LateLintPass } ;
10
9
use rustc:: ty;
11
10
use rustc_errors:: Applicability ;
12
- use rustc_session:: declare_tool_lint;
11
+ use rustc_session:: { declare_lint_pass , declare_tool_lint} ;
13
12
use std:: f32:: consts as f32_consts;
14
13
use std:: f64:: consts as f64_consts;
15
14
use sugg:: Sugg ;
@@ -278,84 +277,6 @@ fn check_expm1(cx: &LateContext<'_, '_>, expr: &Expr) {
278
277
}
279
278
}
280
279
281
- // Checks whether two expressions evaluate to the same value
282
- fn are_exprs_equivalent ( cx : & LateContext < ' _ , ' _ > , left : & Expr , right : & Expr ) -> bool {
283
- // Checks whether the values are constant and equal
284
- if_chain ! {
285
- if let Some ( ( left_value, _) ) = constant( cx, cx. tables, left) ;
286
- if let Some ( ( right_value, _) ) = constant( cx, cx. tables, right) ;
287
- if left_value == right_value;
288
- then {
289
- return true ;
290
- }
291
- }
292
-
293
- // Checks whether the expressions resolve to the same variable
294
- if_chain ! {
295
- if let ExprKind :: Path ( ref left_qpath) = left. kind;
296
- if let QPath :: Resolved ( _, ref left_path) = * left_qpath;
297
- if left_path. segments. len( ) == 1 ;
298
- if let def:: Res :: Local ( left_local_id) = qpath_res( cx, left_qpath, left. hir_id) ;
299
- if let ExprKind :: Path ( ref right_qpath) = right. kind;
300
- if let QPath :: Resolved ( _, ref right_path) = * right_qpath;
301
- if right_path. segments. len( ) == 1 ;
302
- if let def:: Res :: Local ( right_local_id) = qpath_res( cx, right_qpath, right. hir_id) ;
303
- if left_local_id == right_local_id;
304
- then {
305
- return true ;
306
- }
307
- }
308
-
309
- false
310
- }
311
-
312
- fn check_log_division ( cx : & LateContext < ' _ , ' _ > , expr : & Expr ) {
313
- let log_methods = [ "log" , "log2" , "log10" , "ln" ] ;
314
-
315
- if_chain ! {
316
- if let ExprKind :: Binary ( op, ref lhs, ref rhs) = expr. kind;
317
- if op. node == BinOpKind :: Div ;
318
- if cx. tables. expr_ty( lhs) . is_floating_point( ) ;
319
- if let ExprKind :: MethodCall ( left_path, _, left_args) = & lhs. kind;
320
- if cx. tables. expr_ty( & left_args[ 0 ] ) . is_floating_point( ) ;
321
- if let ExprKind :: MethodCall ( right_path, _, right_args) = & rhs. kind;
322
- if cx. tables. expr_ty( & right_args[ 0 ] ) . is_floating_point( ) ;
323
- let left_method = left_path. ident. name. as_str( ) ;
324
- if left_method == right_path. ident. name. as_str( ) ;
325
- if log_methods. iter( ) . any( |& method| left_method == method) ;
326
- then {
327
- let left_recv = & left_args[ 0 ] ;
328
- let right_recv = & right_args[ 0 ] ;
329
-
330
- // Return early when bases are not equal
331
- if left_method == "log" && !are_exprs_equivalent( cx, & left_args[ 1 ] , & right_args[ 1 ] ) {
332
- return ;
333
- }
334
-
335
- // Reduce the expression further for bases 2, 10 and e
336
- let suggestion = if let Some ( method) = get_specialized_log_method( cx, right_recv) {
337
- format!( "{}.{}()" , Sugg :: hir( cx, left_recv, ".." ) , method)
338
- } else {
339
- format!(
340
- "{}.log({})" ,
341
- Sugg :: hir( cx, left_recv, ".." ) ,
342
- Sugg :: hir( cx, right_recv, ".." )
343
- )
344
- } ;
345
-
346
- span_lint_and_sugg(
347
- cx,
348
- FLOATING_POINT_IMPROVEMENTS ,
349
- expr. span,
350
- "x.log(b) / y.log(b) can be reduced to x.log(y)" ,
351
- "consider using" ,
352
- suggestion,
353
- Applicability :: MachineApplicable ,
354
- ) ;
355
- }
356
- }
357
- }
358
-
359
280
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for FloatingPointArithmetic {
360
281
fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr ) {
361
282
if let ExprKind :: MethodCall ( ref path, _, args) = & expr. kind {
@@ -371,7 +292,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatingPointArithmetic {
371
292
}
372
293
} else {
373
294
check_expm1 ( cx, expr) ;
374
- check_log_division ( cx, expr) ;
375
295
}
376
296
}
377
297
}
0 commit comments