@@ -4,6 +4,7 @@ use clippy_utils::{is_trait_method, sym};
4
4
use rustc_hir:: { Expr , ExprKind } ;
5
5
use rustc_lint:: { LateContext , LateLintPass } ;
6
6
use rustc_session:: declare_lint_pass;
7
+ use rustc_span:: SyntaxContext ;
7
8
use std:: cmp:: Ordering :: { Equal , Greater , Less } ;
8
9
9
10
declare_clippy_lint ! {
@@ -68,8 +69,8 @@ fn min_max<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a Expr<'a>) -> Option<(MinM
68
69
. qpath_res ( qpath, path. hir_id )
69
70
. opt_def_id ( )
70
71
. and_then ( |def_id| match cx. tcx . get_diagnostic_name ( def_id) {
71
- Some ( sym:: cmp_min) => fetch_const ( cx, None , args, MinMax :: Min ) ,
72
- Some ( sym:: cmp_max) => fetch_const ( cx, None , args, MinMax :: Max ) ,
72
+ Some ( sym:: cmp_min) => fetch_const ( cx, expr . span . ctxt ( ) , None , args, MinMax :: Min ) ,
73
+ Some ( sym:: cmp_max) => fetch_const ( cx, expr . span . ctxt ( ) , None , args, MinMax :: Max ) ,
73
74
_ => None ,
74
75
} )
75
76
} else {
@@ -79,8 +80,8 @@ fn min_max<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a Expr<'a>) -> Option<(MinM
79
80
ExprKind :: MethodCall ( path, receiver, args @ [ _] , _) => {
80
81
if cx. typeck_results ( ) . expr_ty ( receiver) . is_floating_point ( ) || is_trait_method ( cx, expr, sym:: Ord ) {
81
82
match path. ident . name {
82
- sym:: max => fetch_const ( cx, Some ( receiver) , args, MinMax :: Max ) ,
83
- sym:: min => fetch_const ( cx, Some ( receiver) , args, MinMax :: Min ) ,
83
+ sym:: max => fetch_const ( cx, expr . span . ctxt ( ) , Some ( receiver) , args, MinMax :: Max ) ,
84
+ sym:: min => fetch_const ( cx, expr . span . ctxt ( ) , Some ( receiver) , args, MinMax :: Min ) ,
84
85
_ => None ,
85
86
}
86
87
} else {
@@ -93,6 +94,7 @@ fn min_max<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a Expr<'a>) -> Option<(MinM
93
94
94
95
fn fetch_const < ' a , ' tcx > (
95
96
cx : & LateContext < ' tcx > ,
97
+ ctxt : SyntaxContext ,
96
98
receiver : Option < & ' a Expr < ' a > > ,
97
99
args : & ' a [ Expr < ' a > ] ,
98
100
m : MinMax ,
@@ -104,7 +106,7 @@ fn fetch_const<'a, 'tcx>(
104
106
return None ;
105
107
}
106
108
let ecx = ConstEvalCtxt :: new ( cx) ;
107
- match ( ecx. eval_simple ( first_arg) , ecx. eval_simple ( second_arg) ) {
109
+ match ( ecx. eval_local ( first_arg, ctxt ) , ecx. eval_local ( second_arg, ctxt ) ) {
108
110
( Some ( c) , None ) => Some ( ( m, c, second_arg) ) ,
109
111
( None , Some ( c) ) => Some ( ( m, c, first_arg) ) ,
110
112
// otherwise ignore
0 commit comments