Skip to content

Commit 125c778

Browse files
committed
Move exported check to check_fn to exit early
1 parent 2da0edb commit 125c778

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

clippy_lints/src/needless_pass_by_ref_mut.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
138138
return;
139139
}
140140

141+
if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(fn_def_id) {
142+
return;
143+
}
144+
141145
let hir_id = cx.tcx.local_def_id_to_hir_id(fn_def_id);
142146
let is_async = match kind {
143147
FnKind::ItemFn(.., header) => {
@@ -262,11 +266,6 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
262266
.iter()
263267
.filter(|(def_id, _)| !self.used_fn_def_ids.contains(def_id))
264268
{
265-
let is_exported = cx.effective_visibilities.is_exported(*fn_def_id);
266-
if self.avoid_breaking_exported_api && is_exported {
267-
continue;
268-
}
269-
270269
let mut is_cfged = None;
271270
for input in unused {
272271
// If the argument is never used mutably, we emit the warning.
@@ -286,7 +285,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
286285
format!("&{}", snippet(cx, cx.tcx.hir().span(inner_ty.ty.hir_id), "_"),),
287286
Applicability::Unspecified,
288287
);
289-
if is_exported {
288+
if cx.effective_visibilities.is_exported(*fn_def_id) {
290289
diag.warn("changing this function will impact semver compatibility");
291290
}
292291
if *is_cfged {

0 commit comments

Comments
 (0)