add test for closures
This commit is contained in:
parent
07dbcbda12
commit
a8605269bd
4 changed files with 63 additions and 22 deletions
|
|
@ -1,5 +1,5 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![allow(unused)]
|
||||
#![allow(clippy::redundant_closure_call, unused)]
|
||||
#![warn(clippy::single_call_fn)]
|
||||
#![no_main]
|
||||
|
||||
|
|
@ -9,6 +9,23 @@ extern crate proc_macros;
|
|||
// Do not lint since it's public
|
||||
pub fn f() {}
|
||||
|
||||
fn i() {}
|
||||
fn j() {}
|
||||
|
||||
fn h() {
|
||||
// Linted
|
||||
let a = i;
|
||||
// Do not lint closures
|
||||
let a = (|| {
|
||||
// Not linted
|
||||
a();
|
||||
// Imo, it's reasonable to lint this as the function is still only being used once. Just in
|
||||
// a closure.
|
||||
j();
|
||||
});
|
||||
a();
|
||||
}
|
||||
|
||||
fn g() {
|
||||
f();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,5 @@
|
|||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:26:1
|
||||
|
|
||||
LL | fn a() {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:29:5
|
||||
|
|
||||
LL | a();
|
||||
| ^
|
||||
= note: `-D clippy::single-call-fn` implied by `-D warnings`
|
||||
|
||||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:16:1
|
||||
--> $DIR/single_call_fn.rs:33:1
|
||||
|
|
||||
LL | / fn c() {
|
||||
LL | | println!("really");
|
||||
|
|
@ -22,10 +9,47 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:23:5
|
||||
--> $DIR/single_call_fn.rs:40:5
|
||||
|
|
||||
LL | c();
|
||||
| ^
|
||||
= note: `-D clippy::single-call-fn` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:12:1
|
||||
|
|
||||
LL | fn i() {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:17:13
|
||||
|
|
||||
LL | let a = i;
|
||||
| ^
|
||||
|
||||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:43:1
|
||||
|
|
||||
LL | fn a() {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:46:5
|
||||
|
|
||||
LL | a();
|
||||
| ^
|
||||
|
||||
error: this function is only used once
|
||||
--> $DIR/single_call_fn.rs:13:1
|
||||
|
|
||||
LL | fn j() {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: used here
|
||||
--> $DIR/single_call_fn.rs:24:9
|
||||
|
|
||||
LL | j();
|
||||
| ^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue