mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Enable rustfix on unused_unit
tests
This commit is contained in:
parent
fbcf7eefb9
commit
7b948232ba
3 changed files with 58 additions and 11 deletions
44
tests/ui/unused_unit.fixed
Normal file
44
tests/ui/unused_unit.fixed
Normal file
|
@ -0,0 +1,44 @@
|
|||
// run-rustfix
|
||||
|
||||
// The output for humans should just highlight the whole span without showing
|
||||
// the suggested replacement, but we also want to test that suggested
|
||||
// replacement only removes one set of parentheses, rather than naïvely
|
||||
// stripping away any starting or ending parenthesis characters—hence this
|
||||
// test of the JSON error format.
|
||||
|
||||
#![feature(custom_inner_attributes)]
|
||||
#![rustfmt::skip]
|
||||
|
||||
#![deny(clippy::unused_unit)]
|
||||
|
||||
struct Unitter;
|
||||
impl Unitter {
|
||||
// try to disorient the lint with multiple unit returns and newlines
|
||||
#[allow(clippy::no_effect)]
|
||||
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G)
|
||||
where G: Fn() -> () {
|
||||
let _y: &Fn() -> () = &f;
|
||||
(); // this should not lint, as it's not in return type position
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<()> for Unitter {
|
||||
#[rustfmt::skip]
|
||||
fn into(self) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fn return_unit() { }
|
||||
|
||||
#[allow(clippy::needless_return)]
|
||||
#[allow(clippy::never_loop)]
|
||||
fn main() {
|
||||
let u = Unitter;
|
||||
assert_eq!(u.get_unit(|| {}, return_unit), u.into());
|
||||
return_unit();
|
||||
loop {
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// compile-pass
|
||||
// run-rustfix
|
||||
|
||||
// The output for humans should just highlight the whole span without showing
|
||||
// the suggested replacement, but we also want to test that suggested
|
||||
|
@ -6,14 +6,15 @@
|
|||
// stripping away any starting or ending parenthesis characters—hence this
|
||||
// test of the JSON error format.
|
||||
|
||||
#![deny(clippy::unused_unit)]
|
||||
#![allow(clippy::needless_return)]
|
||||
#![feature(custom_inner_attributes)]
|
||||
#![rustfmt::skip]
|
||||
|
||||
#![deny(clippy::unused_unit)]
|
||||
|
||||
struct Unitter;
|
||||
impl Unitter {
|
||||
// try to disorient the lint with multiple unit returns and newlines
|
||||
#[allow(clippy::no_effect)]
|
||||
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
|
||||
()
|
||||
where G: Fn() -> () {
|
||||
|
@ -31,6 +32,8 @@ impl Into<()> for Unitter {
|
|||
|
||||
fn return_unit() -> () { () }
|
||||
|
||||
#[allow(clippy::needless_return)]
|
||||
#[allow(clippy::never_loop)]
|
||||
fn main() {
|
||||
let u = Unitter;
|
||||
assert_eq!(u.get_unit(|| {}, return_unit), u.into());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: unneeded unit return type
|
||||
--> $DIR/unused_unit.rs:17:59
|
||||
--> $DIR/unused_unit.rs:18:59
|
||||
|
|
||||
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
|
||||
| ___________________________________________________________^
|
||||
|
@ -7,43 +7,43 @@ LL | | ()
|
|||
| |__________^ help: remove the `-> ()`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/unused_unit.rs:9:9
|
||||
--> $DIR/unused_unit.rs:12:9
|
||||
|
|
||||
LL | #![deny(clippy::unused_unit)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unneeded unit return type
|
||||
--> $DIR/unused_unit.rs:27:19
|
||||
--> $DIR/unused_unit.rs:28:19
|
||||
|
|
||||
LL | fn into(self) -> () {
|
||||
| ^^^^^ help: remove the `-> ()`
|
||||
|
||||
error: unneeded unit expression
|
||||
--> $DIR/unused_unit.rs:28:9
|
||||
--> $DIR/unused_unit.rs:29:9
|
||||
|
|
||||
LL | ()
|
||||
| ^^ help: remove the final `()`
|
||||
|
||||
error: unneeded unit return type
|
||||
--> $DIR/unused_unit.rs:32:18
|
||||
--> $DIR/unused_unit.rs:33:18
|
||||
|
|
||||
LL | fn return_unit() -> () { () }
|
||||
| ^^^^^ help: remove the `-> ()`
|
||||
|
||||
error: unneeded unit expression
|
||||
--> $DIR/unused_unit.rs:32:26
|
||||
--> $DIR/unused_unit.rs:33:26
|
||||
|
|
||||
LL | fn return_unit() -> () { () }
|
||||
| ^^ help: remove the final `()`
|
||||
|
||||
error: unneeded `()`
|
||||
--> $DIR/unused_unit.rs:39:14
|
||||
--> $DIR/unused_unit.rs:42:14
|
||||
|
|
||||
LL | break();
|
||||
| ^^ help: remove the `()`
|
||||
|
||||
error: unneeded `()`
|
||||
--> $DIR/unused_unit.rs:41:11
|
||||
--> $DIR/unused_unit.rs:44:11
|
||||
|
|
||||
LL | return();
|
||||
| ^^ help: remove the `()`
|
||||
|
|
Loading…
Reference in a new issue