Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect #[allow] attributes in single_call_fn lint #12183

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions clippy_lints/src/single_call_fn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::diagnostics::span_lint_hir_and_then;
use clippy_utils::{is_from_proc_macro, is_in_test_function};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LocalDefId;
Expand Down Expand Up @@ -88,16 +88,18 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn {
};
cx.tcx.hir().visit_all_item_likes_in_crate(&mut v);

for usage in self.def_id_to_usage.values() {
for (&def_id, usage) in &self.def_id_to_usage {
let single_call_fn_span = usage.0;
if let [caller_span] = *usage.1 {
span_lint_and_help(
span_lint_hir_and_then(
cx,
SINGLE_CALL_FN,
cx.tcx.local_def_id_to_hir_id(def_id),
single_call_fn_span,
"this function is only used once",
Some(caller_span),
"used here",
|diag| {
diag.span_help(caller_span, "used here");
},
);
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/single_call_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ fn e() {
#[test]
fn k() {}

mod issue12182 {
#[allow(clippy::single_call_fn)]
fn print_foo(text: &str) {
println!("{text}");
}

fn use_print_foo() {
print_foo("foo");
}
}

#[test]
fn l() {
k();
Expand Down