Skip to content

Commit 3b23092

Browse files
committed
Get rid of rvalue_promotable_map method call
1 parent b7d4735 commit 3b23092

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

clippy_lints/src/methods/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use syntax::symbol::{sym, LocalInternedString, Symbol};
2121
use crate::utils::usage::mutated_variables;
2222
use crate::utils::{
2323
get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro, is_copy,
24-
is_ctor_function, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path,
24+
is_ctor_or_promotable_const_function, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment, match_def_path,
2525
match_qpath, match_trait_method, match_type, match_var, method_calls, method_chain_args, paths, remove_blocks,
2626
return_ty, same_tys, single_segment_path, snippet, snippet_with_applicability, snippet_with_macro_callsite,
2727
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>(
12811281
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
12821282
let call_found = match &expr.kind {
12831283
// ignore enum and struct constructors
1284-
hir::ExprKind::Call(..) => !is_ctor_function(self.cx, expr),
1284+
hir::ExprKind::Call(..) => !is_ctor_or_promotable_const_function(self.cx, expr),
12851285
hir::ExprKind::MethodCall(..) => true,
12861286
_ => false,
12871287
};
12881288

12891289
if call_found {
1290-
// don't lint for constant values
1291-
let owner_def = self.cx.tcx.hir().get_parent_did(expr.hir_id);
1292-
let promotable = self
1293-
.cx
1294-
.tcx
1295-
.rvalue_promotable_map(owner_def)
1296-
.contains(&expr.hir_id.local_id);
1297-
if !promotable {
1298-
self.found |= true;
1299-
}
1290+
self.found |= true;
13001291
}
13011292

13021293
if !self.found {

clippy_lints/src/utils/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,15 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
803803
}
804804

805805
/// Checks if an expression is constructing a tuple-like enum variant or struct
806-
pub fn is_ctor_function(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
806+
pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
807807
if let ExprKind::Call(ref fun, _) = expr.kind {
808808
if let ExprKind::Path(ref qp) = fun.kind {
809-
return matches!(
810-
cx.tables.qpath_res(qp, fun.hir_id),
811-
def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _)
812-
);
809+
let res = cx.tables.qpath_res(qp, fun.hir_id);
810+
return match res {
811+
def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => true,
812+
def::Res::Def(_, def_id) => cx.tcx.is_promotable_const_fn(def_id),
813+
_ => false,
814+
}
813815
}
814816
}
815817
false

0 commit comments

Comments
 (0)