@@ -43,6 +43,7 @@ use rustc_infer::infer::TyCtxtInferExt;
43
43
use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
44
44
use rustc_middle:: hir:: map:: Map ;
45
45
use rustc_middle:: ty:: { self , layout:: IntegerExt , subst:: GenericArg , Ty , TyCtxt , TypeFoldable } ;
46
+ use rustc_mir:: const_eval;
46
47
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
47
48
use rustc_span:: source_map:: original_sp;
48
49
use rustc_span:: symbol:: { self , kw, Symbol } ;
@@ -868,11 +869,19 @@ pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
868
869
869
870
/// Checks if an expression is constructing a tuple-like enum variant or struct
870
871
pub fn is_ctor_or_promotable_const_function ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
872
+ fn has_no_arguments ( cx : & LateContext < ' _ > , def_id : DefId ) -> bool {
873
+ cx. tcx . fn_sig ( def_id) . skip_binder ( ) . inputs ( ) . is_empty ( )
874
+ }
875
+
871
876
if let ExprKind :: Call ( ref fun, _) = expr. kind {
872
877
if let ExprKind :: Path ( ref qp) = fun. kind {
873
878
let res = cx. qpath_res ( qp, fun. hir_id ) ;
874
879
return match res {
875
880
def:: Res :: Def ( DefKind :: Variant | DefKind :: Ctor ( ..) , ..) => true ,
881
+ // FIXME: check the constness of the arguments, see https://github.com/rust-lang/rust-clippy/pull/5682#issuecomment-638681210
882
+ def:: Res :: Def ( DefKind :: Fn , def_id) if has_no_arguments ( cx, def_id) => {
883
+ const_eval:: is_const_fn ( cx. tcx , def_id)
884
+ } ,
876
885
def:: Res :: Def ( _, def_id) => cx. tcx . is_promotable_const_fn ( def_id) ,
877
886
_ => false ,
878
887
} ;
0 commit comments