Skip to content

Commit 0b6e7e2

Browse files
committed
Auto merge of rust-lang#12183 - y21:issue12182, r=dswij
respect `#[allow]` attributes in `single_call_fn` lint Fixes rust-lang#12182 If we delay linting to `check_crate_post`, we need to use `span_lint_hir_and_then`, since otherwise it would only respect those lint level attributes at the crate root. <sub>... maybe we can have an internal lint for this somehow?</sub> changelog: respect `#[allow]` attributes in `single_call_fn` lint
2 parents a8017ae + ad4d90b commit 0b6e7e2

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

clippy_lints/src/single_call_fn.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint_and_help;
1+
use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::{is_from_proc_macro, is_in_test_function};
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::def_id::LocalDefId;
@@ -88,16 +88,18 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn {
8888
};
8989
cx.tcx.hir().visit_all_item_likes_in_crate(&mut v);
9090

91-
for usage in self.def_id_to_usage.values() {
91+
for (&def_id, usage) in &self.def_id_to_usage {
9292
let single_call_fn_span = usage.0;
9393
if let [caller_span] = *usage.1 {
94-
span_lint_and_help(
94+
span_lint_hir_and_then(
9595
cx,
9696
SINGLE_CALL_FN,
97+
cx.tcx.local_def_id_to_hir_id(def_id),
9798
single_call_fn_span,
9899
"this function is only used once",
99-
Some(caller_span),
100-
"used here",
100+
|diag| {
101+
diag.span_help(caller_span, "used here");
102+
},
101103
);
102104
}
103105
}

tests/ui/single_call_fn.rs

+11
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ fn e() {
6969
#[test]
7070
fn k() {}
7171

72+
mod issue12182 {
73+
#[allow(clippy::single_call_fn)]
74+
fn print_foo(text: &str) {
75+
println!("{text}");
76+
}
77+
78+
fn use_print_foo() {
79+
print_foo("foo");
80+
}
81+
}
82+
7283
#[test]
7384
fn l() {
7485
k();

0 commit comments

Comments
 (0)