@@ -5,7 +5,7 @@ use rustc_hir::{Expr, ExprKind};
5
5
use rustc_lint:: { LateContext , LateLintPass } ;
6
6
use rustc_session:: declare_lint_pass;
7
7
use rustc_span:: sym;
8
- use std:: cmp:: Ordering ;
8
+ use std:: cmp:: Ordering :: { Equal , Greater , Less } ;
9
9
10
10
declare_clippy_lint ! {
11
11
/// ### What it does
@@ -36,26 +36,21 @@ declare_lint_pass!(MinMaxPass => [MIN_MAX]);
36
36
37
37
impl < ' tcx > LateLintPass < ' tcx > for MinMaxPass {
38
38
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
39
- if let Some ( ( outer_max, outer_c, oe) ) = min_max ( cx, expr) {
40
- if let Some ( ( inner_max, inner_c, ie) ) = min_max ( cx, oe) {
41
- if outer_max == inner_max {
42
- return ;
43
- }
44
- match (
45
- outer_max,
46
- Constant :: partial_cmp ( cx. tcx , cx. typeck_results ( ) . expr_ty ( ie) , & outer_c, & inner_c) ,
47
- ) {
48
- ( _, None ) | ( MinMax :: Max , Some ( Ordering :: Less ) ) | ( MinMax :: Min , Some ( Ordering :: Greater ) ) => ( ) ,
49
- _ => {
50
- span_lint (
51
- cx,
52
- MIN_MAX ,
53
- expr. span ,
54
- "this `min`/`max` combination leads to constant result" ,
55
- ) ;
56
- } ,
57
- }
58
- }
39
+ if let Some ( ( outer_max, outer_c, oe) ) = min_max ( cx, expr)
40
+ && let Some ( ( inner_max, inner_c, ie) ) = min_max ( cx, oe)
41
+ && outer_max != inner_max
42
+ && let Some ( ord) = Constant :: partial_cmp ( cx. tcx , cx. typeck_results ( ) . expr_ty ( ie) , & outer_c, & inner_c)
43
+ && matches ! (
44
+ ( outer_max, ord) ,
45
+ ( MinMax :: Max , Equal | Greater ) | ( MinMax :: Min , Equal | Less )
46
+ )
47
+ {
48
+ span_lint (
49
+ cx,
50
+ MIN_MAX ,
51
+ expr. span ,
52
+ "this `min`/`max` combination leads to constant result" ,
53
+ ) ;
59
54
}
60
55
}
61
56
}
0 commit comments