From 7b948232ba779601e57d54c4edf1c7e15babadd6 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 7 Mar 2019 08:21:41 +0200 Subject: [PATCH] Enable rustfix on `unused_unit` tests --- tests/ui/unused_unit.fixed | 44 +++++++++++++++++++++++++++++++++++++ tests/ui/unused_unit.rs | 9 +++++--- tests/ui/unused_unit.stderr | 16 +++++++------- 3 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 tests/ui/unused_unit.fixed diff --git a/tests/ui/unused_unit.fixed b/tests/ui/unused_unit.fixed new file mode 100644 index 00000000000..64124589683 --- /dev/null +++ b/tests/ui/unused_unit.fixed @@ -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 (), 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; +} diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs index 6d6ecd105c6..8e31385b70c 100644 --- a/tests/ui/unused_unit.rs +++ b/tests/ui/unused_unit.rs @@ -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 (), 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()); diff --git a/tests/ui/unused_unit.stderr b/tests/ui/unused_unit.stderr index 92098925ac1..c33a220b98c 100644 --- a/tests/ui/unused_unit.stderr +++ b/tests/ui/unused_unit.stderr @@ -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 (), 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 `()`