mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 17:07:17 +00:00
Auto merge of #12183 - y21:issue12182, r=dswij
respect `#[allow]` attributes in `single_call_fn` lint Fixes #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
This commit is contained in:
commit
0b6e7e2acf
2 changed files with 18 additions and 5 deletions
|
@ -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;
|
||||
|
@ -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");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue