diff options
| author | y21 <30553356+y21@users.noreply.github.com> | 2024-01-21 14:54:01 +0100 |
|---|---|---|
| committer | y21 <30553356+y21@users.noreply.github.com> | 2024-01-21 15:16:29 +0100 |
| commit | ad4d90b4a95887834ac93339ff388ed58cc8840d (patch) | |
| tree | d5993145e168f8ae6904a145ef437600d0879290 | |
| parent | 64d08a8b1dffb70a238c8ecb587c859d66517961 (diff) | |
| download | rust-ad4d90b4a95887834ac93339ff388ed58cc8840d.tar.gz rust-ad4d90b4a95887834ac93339ff388ed58cc8840d.zip | |
respect `#[allow]` attribute in `single_call_fn` lint
| -rw-r--r-- | clippy_lints/src/single_call_fn.rs | 12 | ||||
| -rw-r--r-- | tests/ui/single_call_fn.rs | 11 |
2 files changed, 18 insertions, 5 deletions
diff --git a/clippy_lints/src/single_call_fn.rs b/clippy_lints/src/single_call_fn.rs index 8e181c3ccc7..03877420774 100644 --- a/clippy_lints/src/single_call_fn.rs +++ b/clippy_lints/src/single_call_fn.rs @@ -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"); + }, ); } } diff --git a/tests/ui/single_call_fn.rs b/tests/ui/single_call_fn.rs index 3cc8061647d..c20214feccc 100644 --- a/tests/ui/single_call_fn.rs +++ b/tests/ui/single_call_fn.rs @@ -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(); |
