about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2019-10-05 12:38:38 +0200
committerflip1995 <hello@philkrones.com>2019-10-05 12:38:38 +0200
commit3b23092b69a218f300abfd8ee629f4865486e83c (patch)
tree1eb7fcba289b749d9339829fa98599b6e137ada9
parentb7d473503b051f86c59f3256130e8ff13afe4332 (diff)
downloadrust-3b23092b69a218f300abfd8ee629f4865486e83c.tar.gz
rust-3b23092b69a218f300abfd8ee629f4865486e83c.zip
Get rid of rvalue_promotable_map method call
-rw-r--r--clippy_lints/src/methods/mod.rs15
-rw-r--r--clippy_lints/src/utils/mod.rs12
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