Honor avoid-breaking-exported-api in needless_pass_by_ref_mut

Until now, the lint only emitted a warning, when breaking public API. Now it
doesn't lint at all when the config value is not set to `false`, bringing it in
line with the other lints using this config value.

Also ensures that this config value is documented in the lint.
This commit is contained in:
Philipp Krones 2023-10-09 11:48:13 +02:00
parent 6e6683b15e
commit 2da0edbdf1
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
11 changed files with 85 additions and 53 deletions

View file

@ -27,7 +27,7 @@ declare_clippy_lint! {
/// Check if a `&mut` function argument is actually used mutably.
///
/// Be careful if the function is publicly reexported as it would break compatibility with
/// users of this function.
/// users of this function, when the users pass this function as an argument.
///
/// ### Why is this bad?
/// Less `mut` means less fights with the borrow checker. It can also lead to more
@ -262,8 +262,10 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
.iter()
.filter(|(def_id, _)| !self.used_fn_def_ids.contains(def_id))
{
let show_semver_warning =
self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(*fn_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 {
@ -284,7 +286,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
format!("&{}", snippet(cx, cx.tcx.hir().span(inner_ty.ty.hir_id), "_"),),
Applicability::Unspecified,
);
if show_semver_warning {
if is_exported {
diag.warn("changing this function will impact semver compatibility");
}
if *is_cfged {