mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Get rid of rvalue_promotable_map method call
This commit is contained in:
parent
b7d473503b
commit
3b23092b69
@ -21,7 +21,7 @@ use syntax::symbol::{sym, LocalInternedString, Symbol};
|
|||||||
use crate::utils::usage::mutated_variables;
|
use crate::utils::usage::mutated_variables;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
get_arg_name, get_parent_expr, get_trait_def_id, has_iter_method, implements_trait, in_macro, is_copy,
|
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,
|
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,
|
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,
|
span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, sugg, walk_ptrs_ty,
|
||||||
@ -1281,23 +1281,14 @@ fn lint_or_fun_call<'a, 'tcx>(
|
|||||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||||
let call_found = match &expr.kind {
|
let call_found = match &expr.kind {
|
||||||
// ignore enum and struct constructors
|
// 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,
|
hir::ExprKind::MethodCall(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if call_found {
|
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 {
|
if !self.found {
|
||||||
intravisit::walk_expr(self, expr);
|
intravisit::walk_expr(self, expr);
|
||||||
|
@ -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
|
/// 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::Call(ref fun, _) = expr.kind {
|
||||||
if let ExprKind::Path(ref qp) = fun.kind {
|
if let ExprKind::Path(ref qp) = fun.kind {
|
||||||
return matches!(
|
let res = cx.tables.qpath_res(qp, fun.hir_id);
|
||||||
cx.tables.qpath_res(qp, fun.hir_id),
|
return match res {
|
||||||
def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _)
|
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
|
false
|
||||||
|
Loading…
Reference in New Issue
Block a user