about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2024-07-02 19:30:30 +0200
committerPhilipp Krones <hello@philkrones.com>2024-07-02 19:30:30 +0200
commit125c778d6d01824fde3fe96f765a4dd9341af036 (patch)
tree2fa02fb32b3ea218d7f3b26cff0927520488d13d
parent2da0edbdf10799f3245b08a2c7b41f3bf7890f6d (diff)
downloadrust-125c778d6d01824fde3fe96f765a4dd9341af036.tar.gz
rust-125c778d6d01824fde3fe96f765a4dd9341af036.zip
Move exported check to check_fn to exit early
-rw-r--r--clippy_lints/src/needless_pass_by_ref_mut.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/clippy_lints/src/needless_pass_by_ref_mut.rs b/clippy_lints/src/needless_pass_by_ref_mut.rs
index 13774987b8e..5ffd41d78e0 100644
--- a/clippy_lints/src/needless_pass_by_ref_mut.rs
+++ b/clippy_lints/src/needless_pass_by_ref_mut.rs
@@ -138,6 +138,10 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
             return;
         }
 
+        if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(fn_def_id) {
+            return;
+        }
+
         let hir_id = cx.tcx.local_def_id_to_hir_id(fn_def_id);
         let is_async = match kind {
             FnKind::ItemFn(.., header) => {
@@ -262,11 +266,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
             .iter()
             .filter(|(def_id, _)| !self.used_fn_def_ids.contains(def_id))
         {
-            let is_exported = cx.effective_visibilities.is_exported(*fn_def_id);
-            if self.avoid_breaking_exported_api && is_exported {
-                continue;
-            }
-
             let mut is_cfged = None;
             for input in unused {
                 // If the argument is never used mutably, we emit the warning.
@@ -286,7 +285,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
                                 format!("&{}", snippet(cx, cx.tcx.hir().span(inner_ty.ty.hir_id), "_"),),
                                 Applicability::Unspecified,
                             );
-                            if is_exported {
+                            if cx.effective_visibilities.is_exported(*fn_def_id) {
                                 diag.warn("changing this function will impact semver compatibility");
                             }
                             if *is_cfged {