1
1
use std:: cmp:: Ordering ;
2
2
3
3
use super :: UNNECESSARY_MIN_OR_MAX ;
4
- use clippy_utils:: diagnostics:: span_lint_and_sugg;
5
-
6
4
use clippy_utils:: consts:: { constant, constant_with_source, Constant , ConstantSource , FullInt } ;
5
+ use clippy_utils:: diagnostics:: span_lint_and_sugg;
7
6
use clippy_utils:: source:: snippet;
7
+ use clippy_utils:: { match_def_path, paths} ;
8
8
9
9
use rustc_errors:: Applicability ;
10
10
use rustc_hir:: Expr ;
@@ -20,28 +20,32 @@ pub(super) fn check<'tcx>(
20
20
arg : & ' tcx Expr < ' _ > ,
21
21
) {
22
22
let typeck_results = cx. typeck_results ( ) ;
23
- if let Some ( ( left, ConstantSource :: Local | ConstantSource :: CoreConstant ) ) =
24
- constant_with_source ( cx, typeck_results, recv)
25
- && let Some ( ( right, ConstantSource :: Local | ConstantSource :: CoreConstant ) ) =
26
- constant_with_source ( cx, typeck_results, arg)
23
+ if let Some ( id) = typeck_results. type_dependent_def_id ( expr. hir_id )
24
+ && ( match_def_path ( cx, id, & paths:: CORE_CMP_MIN ) || match_def_path ( cx, id, & paths:: CORE_CMP_MAX ) )
27
25
{
28
- let Some ( ord) = Constant :: partial_cmp ( cx. tcx , typeck_results. expr_ty ( recv) , & left, & right) else {
29
- return ;
30
- } ;
26
+ if let Some ( ( left, ConstantSource :: Local | ConstantSource :: CoreConstant ) ) =
27
+ constant_with_source ( cx, typeck_results, recv)
28
+ && let Some ( ( right, ConstantSource :: Local | ConstantSource :: CoreConstant ) ) =
29
+ constant_with_source ( cx, typeck_results, arg)
30
+ {
31
+ let Some ( ord) = Constant :: partial_cmp ( cx. tcx , typeck_results. expr_ty ( recv) , & left, & right) else {
32
+ return ;
33
+ } ;
31
34
32
- lint ( cx, expr, name, recv. span , arg. span , ord) ;
33
- } else if let Some ( extrema) = detect_extrema ( cx, recv) {
34
- let ord = match extrema {
35
- Extrema :: Minimum => Ordering :: Less ,
36
- Extrema :: Maximum => Ordering :: Greater ,
37
- } ;
38
- lint ( cx, expr, name, recv. span , arg. span , ord) ;
39
- } else if let Some ( extrema) = detect_extrema ( cx, arg) {
40
- let ord = match extrema {
41
- Extrema :: Minimum => Ordering :: Greater ,
42
- Extrema :: Maximum => Ordering :: Less ,
43
- } ;
44
- lint ( cx, expr, name, recv. span , arg. span , ord) ;
35
+ lint ( cx, expr, name, recv. span , arg. span , ord) ;
36
+ } else if let Some ( extrema) = detect_extrema ( cx, recv) {
37
+ let ord = match extrema {
38
+ Extrema :: Minimum => Ordering :: Less ,
39
+ Extrema :: Maximum => Ordering :: Greater ,
40
+ } ;
41
+ lint ( cx, expr, name, recv. span , arg. span , ord) ;
42
+ } else if let Some ( extrema) = detect_extrema ( cx, arg) {
43
+ let ord = match extrema {
44
+ Extrema :: Minimum => Ordering :: Greater ,
45
+ Extrema :: Maximum => Ordering :: Less ,
46
+ } ;
47
+ lint ( cx, expr, name, recv. span , arg. span , ord) ;
48
+ }
45
49
}
46
50
}
47
51
0 commit comments