Skip to content

Commit 5522177

Browse files
committed
Only run expensive calculations if the method name is recognized
1 parent 402a9c9 commit 5522177

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

compiler/rustc_lint/src/types.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,7 @@ impl InvalidAtomicOrdering {
14341434
fn inherent_atomic_method_call<'hir>(
14351435
cx: &LateContext<'_>,
14361436
expr: &Expr<'hir>,
1437+
recognized_names: &[Symbol], // used for fast path calculation
14371438
) -> Option<(Symbol, &'hir [Expr<'hir>])> {
14381439
const ATOMIC_TYPES: &[Symbol] = &[
14391440
sym::AtomicBool,
@@ -1453,6 +1454,7 @@ impl InvalidAtomicOrdering {
14531454
];
14541455
if_chain! {
14551456
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
1457+
if recognized_names.contains(&method_path.ident.name);
14561458
if let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
14571459
if let Some(impl_did) = cx.tcx.impl_of_method(m_def_id);
14581460
if let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def();
@@ -1494,7 +1496,7 @@ impl InvalidAtomicOrdering {
14941496
use rustc_hir::def::{DefKind, Res};
14951497
use rustc_hir::QPath;
14961498
if_chain! {
1497-
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr);
1499+
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::load, sym::store]);
14981500
if let Some((ordering_arg, invalid_ordering)) = match method {
14991501
sym::load => Some((&args[1], sym::Release)),
15001502
sym::store => Some((&args[2], sym::Acquire)),
@@ -1543,7 +1545,7 @@ impl InvalidAtomicOrdering {
15431545

15441546
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
15451547
if_chain! {
1546-
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr);
1548+
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak]);
15471549
if let Some((success_order_arg, failure_order_arg)) = match method {
15481550
sym::fetch_update => Some((&args[1], &args[2])),
15491551
sym::compare_exchange | sym::compare_exchange_weak => Some((&args[3], &args[4])),

0 commit comments

Comments
 (0)