From 3b23092b69a218f300abfd8ee629f4865486e83c Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 5 Oct 2019 12:38:38 +0200 Subject: [PATCH] Get rid of rvalue_promotable_map method call --- clippy_lints/src/methods/mod.rs | 15 +++------------ clippy_lints/src/utils/mod.rs | 12 +++++++----- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index be233c6e69a..526cb6ca610 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -21,7 +21,7 @@ use syntax::symbol::{sym, LocalInternedString, Symbol}; use crate::utils::usage::mutated_variables; use crate::utils::{ get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro, is_copy, - is_ctor_function, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path, + is_ctor_or_promotable_const_function, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path, match_qpath, match_trait_method, match_type, match_var, method_calls, method_chain_args, paths, remove_blocks, return_ty, same_tys, single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, sugg, walk_ptrs_ty, @@ -1281,22 +1281,13 @@ fn lint_or_fun_call<'a, 'tcx>( fn visit_expr(&mut self, expr: &'tcx hir::Expr) { let call_found = match &expr.kind { // ignore enum and struct constructors - hir::ExprKind::Call(..) => !is_ctor_function(self.cx, expr), + hir::ExprKind::Call(..) => !is_ctor_or_promotable_const_function(self.cx, expr), hir::ExprKind::MethodCall(..) => true, _ => false, }; if call_found { - // don't lint for constant values - let owner_def = self.cx.tcx.hir().get_parent_did(expr.hir_id); - let promotable = self - .cx - .tcx - .rvalue_promotable_map(owner_def) - .contains(&expr.hir_id.local_id); - if !promotable { - self.found |= true; - } + self.found |= true; } if !self.found { diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 27dad6322d8..9aca35c91cf 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -803,13 +803,15 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { } /// Checks if an expression is constructing a tuple-like enum variant or struct -pub fn is_ctor_function(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { +pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { if let ExprKind::Call(ref fun, _) = expr.kind { if let ExprKind::Path(ref qp) = fun.kind { - return matches!( - cx.tables.qpath_res(qp, fun.hir_id), - def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) - ); + let res = cx.tables.qpath_res(qp, fun.hir_id); + return match res { + def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => true, + def::Res::Def(_, def_id) => cx.tcx.is_promotable_const_fn(def_id), + _ => false, + } } } false