@@ -43,6 +43,7 @@ use rustc_infer::infer::TyCtxtInferExt;
4343use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
4444use rustc_middle:: hir:: map:: Map ;
4545use rustc_middle:: ty:: { self , layout:: IntegerExt , subst:: GenericArg , Ty , TyCtxt , TypeFoldable } ;
46+ use rustc_mir:: const_eval;
4647use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
4748use rustc_span:: source_map:: original_sp;
4849use rustc_span:: symbol:: { self , kw, Symbol } ;
@@ -868,11 +869,19 @@ pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
868869
869870/// Checks if an expression is constructing a tuple-like enum variant or struct
870871pub 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+
871876 if let ExprKind :: Call ( ref fun, _) = expr. kind {
872877 if let ExprKind :: Path ( ref qp) = fun. kind {
873878 let res = cx. qpath_res ( qp, fun. hir_id ) ;
874879 return match res {
875880 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+ } ,
876885 def:: Res :: Def ( _, def_id) => cx. tcx . is_promotable_const_fn ( def_id) ,
877886 _ => false ,
878887 } ;
0 commit comments