From c8bc6f0549f0475d6b2a7535ebb267f2b52fa957 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:28:10 +0000 Subject: [PATCH] refactor(linter): use `std::ptr::eq` (#5649) Follow-on after #5577. `!std::ptr::eq(x, y)` is more idiomatic than `std::ptr::from_ref(x) != std::ptr::from_ref(y)`. --- crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs | 2 +- crates/oxc_linter/src/rules/unicorn/prefer_event_target.rs | 2 +- crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs index 7add312bfe7a4..6ceac5604363e 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs @@ -66,7 +66,7 @@ impl Rule for NoUselessSwitchCase { let default_case = default_cases[0]; // Check if the `default` case is the last case - if std::ptr::from_ref(default_case) != std::ptr::from_ref(cases.last().unwrap()) { + if !std::ptr::eq(default_case, cases.last().unwrap()) { return; } diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_event_target.rs b/crates/oxc_linter/src/rules/unicorn/prefer_event_target.rs index 62186f822684a..6e73da3035e21 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_event_target.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_event_target.rs @@ -63,7 +63,7 @@ impl Rule for PreferEventTarget { return; }; - if std::ptr::from_ref(ident) != std::ptr::addr_of!(**callee_ident) { + if !std::ptr::eq(ident, callee_ident.as_ref()) { return; } } diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs b/crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs index 070f6a71cdefb..a77cdce54b79c 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs @@ -87,7 +87,7 @@ impl Rule for PreferRegexpTest { }; // Check if the `test` of the for statement is the same node as the call expression. - if std::ptr::addr_of!(**call_expr2) != std::ptr::from_ref(call_expr) { + if !std::ptr::eq(call_expr2.as_ref(), call_expr) { return; } } @@ -97,7 +97,7 @@ impl Rule for PreferRegexpTest { }; // Check if the `test` of the conditional expression is the same node as the call expression. - if std::ptr::addr_of!(**call_expr2) != std::ptr::from_ref(call_expr) { + if !std::ptr::eq(call_expr2.as_ref(), call_expr) { return; } }