Ignore functions annotated with #[test]
This commit is contained in:
parent
a8605269bd
commit
2cd4a9182a
@ -94,6 +94,7 @@ Suppress lints whenever the suggested change would cause breakage for other crat
|
|||||||
* [`linkedlist`](https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist)
|
* [`linkedlist`](https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist)
|
||||||
* [`rc_mutex`](https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex)
|
* [`rc_mutex`](https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex)
|
||||||
* [`unnecessary_box_returns`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns)
|
* [`unnecessary_box_returns`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns)
|
||||||
|
* [`single_call_fn`](https://rust-lang.github.io/rust-clippy/master/index.html#single_call_fn)
|
||||||
|
|
||||||
|
|
||||||
## `msrv`
|
## `msrv`
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_help;
|
use clippy_utils::diagnostics::span_lint_and_help;
|
||||||
use clippy_utils::is_from_proc_macro;
|
use clippy_utils::{is_from_proc_macro, is_in_test_function};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||||
@ -12,7 +12,7 @@ use rustc_span::Span;
|
|||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
/// Checks for functions that are only used once.
|
/// Checks for functions that are only used once. Does not lint tests.
|
||||||
///
|
///
|
||||||
/// ### Why is this bad?
|
/// ### Why is this bad?
|
||||||
/// It's usually not, splitting a function into multiple parts often improves readability and in
|
/// It's usually not, splitting a function into multiple parts often improves readability and in
|
||||||
@ -73,6 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn {
|
|||||||
if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id)
|
if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id)
|
||||||
|| in_external_macro(cx.sess(), span)
|
|| in_external_macro(cx.sess(), span)
|
||||||
|| is_from_proc_macro(cx, &(&kind, body, cx.tcx.local_def_id_to_hir_id(def_id), span))
|
|| is_from_proc_macro(cx, &(&kind, body, cx.tcx.local_def_id_to_hir_id(def_id), span))
|
||||||
|
|| is_in_test_function(cx.tcx, body.value.hir_id)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
//@aux-build:proc_macros.rs
|
//@aux-build:proc_macros.rs
|
||||||
|
//@compile-flags: --test
|
||||||
#![allow(clippy::redundant_closure_call, unused)]
|
#![allow(clippy::redundant_closure_call, unused)]
|
||||||
#![warn(clippy::single_call_fn)]
|
#![warn(clippy::single_call_fn)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
@ -64,3 +65,11 @@ fn e() {
|
|||||||
b();
|
b();
|
||||||
b();
|
b();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn k() {}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn l() {
|
||||||
|
k();
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: this function is only used once
|
error: this function is only used once
|
||||||
--> $DIR/single_call_fn.rs:33:1
|
--> $DIR/single_call_fn.rs:34:1
|
||||||
|
|
|
|
||||||
LL | / fn c() {
|
LL | / fn c() {
|
||||||
LL | | println!("really");
|
LL | | println!("really");
|
||||||
@ -9,44 +9,44 @@ LL | | }
|
|||||||
| |_^
|
| |_^
|
||||||
|
|
|
|
||||||
help: used here
|
help: used here
|
||||||
--> $DIR/single_call_fn.rs:40:5
|
--> $DIR/single_call_fn.rs:41:5
|
||||||
|
|
|
|
||||||
LL | c();
|
LL | c();
|
||||||
| ^
|
| ^
|
||||||
= note: `-D clippy::single-call-fn` implied by `-D warnings`
|
= note: `-D clippy::single-call-fn` implied by `-D warnings`
|
||||||
|
|
||||||
error: this function is only used once
|
error: this function is only used once
|
||||||
--> $DIR/single_call_fn.rs:12:1
|
--> $DIR/single_call_fn.rs:13:1
|
||||||
|
|
|
|
||||||
LL | fn i() {}
|
LL | fn i() {}
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: used here
|
help: used here
|
||||||
--> $DIR/single_call_fn.rs:17:13
|
--> $DIR/single_call_fn.rs:18:13
|
||||||
|
|
|
|
||||||
LL | let a = i;
|
LL | let a = i;
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: this function is only used once
|
error: this function is only used once
|
||||||
--> $DIR/single_call_fn.rs:43:1
|
--> $DIR/single_call_fn.rs:44:1
|
||||||
|
|
|
|
||||||
LL | fn a() {}
|
LL | fn a() {}
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: used here
|
help: used here
|
||||||
--> $DIR/single_call_fn.rs:46:5
|
--> $DIR/single_call_fn.rs:47:5
|
||||||
|
|
|
|
||||||
LL | a();
|
LL | a();
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: this function is only used once
|
error: this function is only used once
|
||||||
--> $DIR/single_call_fn.rs:13:1
|
--> $DIR/single_call_fn.rs:14:1
|
||||||
|
|
|
|
||||||
LL | fn j() {}
|
LL | fn j() {}
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: used here
|
help: used here
|
||||||
--> $DIR/single_call_fn.rs:24:9
|
--> $DIR/single_call_fn.rs:25:9
|
||||||
|
|
|
|
||||||
LL | j();
|
LL | j();
|
||||||
| ^
|
| ^
|
||||||
|
Loading…
x
Reference in New Issue
Block a user