@@ -4,6 +4,7 @@ use clippy_utils::{is_trait_method, sym};
44use rustc_hir:: { Expr , ExprKind } ;
55use rustc_lint:: { LateContext , LateLintPass } ;
66use rustc_session:: declare_lint_pass;
7+ use rustc_span:: SyntaxContext ;
78use std:: cmp:: Ordering :: { Equal , Greater , Less } ;
89
910declare_clippy_lint ! {
@@ -68,8 +69,8 @@ fn min_max<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a Expr<'a>) -> Option<(MinM
6869 . qpath_res ( qpath, path. hir_id )
6970 . opt_def_id ( )
7071 . 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 ) ,
7374 _ => None ,
7475 } )
7576 } else {
@@ -79,8 +80,8 @@ fn min_max<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a Expr<'a>) -> Option<(MinM
7980 ExprKind :: MethodCall ( path, receiver, args @ [ _] , _) => {
8081 if cx. typeck_results ( ) . expr_ty ( receiver) . is_floating_point ( ) || is_trait_method ( cx, expr, sym:: Ord ) {
8182 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 ) ,
8485 _ => None ,
8586 }
8687 } else {
@@ -93,6 +94,7 @@ fn min_max<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a Expr<'a>) -> Option<(MinM
9394
9495fn fetch_const < ' a , ' tcx > (
9596 cx : & LateContext < ' tcx > ,
97+ ctxt : SyntaxContext ,
9698 receiver : Option < & ' a Expr < ' a > > ,
9799 args : & ' a [ Expr < ' a > ] ,
98100 m : MinMax ,
@@ -104,7 +106,7 @@ fn fetch_const<'a, 'tcx>(
104106 return None ;
105107 }
106108 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 ) ) {
108110 ( Some ( c) , None ) => Some ( ( m, c, second_arg) ) ,
109111 ( None , Some ( c) ) => Some ( ( m, c, first_arg) ) ,
110112 // otherwise ignore
0 commit comments