mirror of https://github.com/rust-lang/rust.git
Enable rustfix on `unused_unit` tests
This commit is contained in:
parent
fbcf7eefb9
commit
7b948232ba
|
@ -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 output for humans should just highlight the whole span without showing
|
||||||
// the suggested replacement, but we also want to test that suggested
|
// 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
|
// stripping away any starting or ending parenthesis characters—hence this
|
||||||
// test of the JSON error format.
|
// test of the JSON error format.
|
||||||
|
|
||||||
#![deny(clippy::unused_unit)]
|
|
||||||
#![allow(clippy::needless_return)]
|
|
||||||
#![feature(custom_inner_attributes)]
|
#![feature(custom_inner_attributes)]
|
||||||
#![rustfmt::skip]
|
#![rustfmt::skip]
|
||||||
|
|
||||||
|
#![deny(clippy::unused_unit)]
|
||||||
|
|
||||||
struct Unitter;
|
struct Unitter;
|
||||||
impl Unitter {
|
impl Unitter {
|
||||||
// try to disorient the lint with multiple unit returns and newlines
|
// 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) ->
|
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
|
||||||
()
|
()
|
||||||
where G: Fn() -> () {
|
where G: Fn() -> () {
|
||||||
|
@ -31,6 +32,8 @@ impl Into<()> for Unitter {
|
||||||
|
|
||||||
fn return_unit() -> () { () }
|
fn return_unit() -> () { () }
|
||||||
|
|
||||||
|
#[allow(clippy::needless_return)]
|
||||||
|
#[allow(clippy::never_loop)]
|
||||||
fn main() {
|
fn main() {
|
||||||
let u = Unitter;
|
let u = Unitter;
|
||||||
assert_eq!(u.get_unit(|| {}, return_unit), u.into());
|
assert_eq!(u.get_unit(|| {}, return_unit), u.into());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: unneeded unit return type
|
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) ->
|
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
|
||||||
| ___________________________________________________________^
|
| ___________________________________________________________^
|
||||||
|
@ -7,43 +7,43 @@ LL | | ()
|
||||||
| |__________^ help: remove the `-> ()`
|
| |__________^ help: remove the `-> ()`
|
||||||
|
|
|
|
||||||
note: lint level defined here
|
note: lint level defined here
|
||||||
--> $DIR/unused_unit.rs:9:9
|
--> $DIR/unused_unit.rs:12:9
|
||||||
|
|
|
|
||||||
LL | #![deny(clippy::unused_unit)]
|
LL | #![deny(clippy::unused_unit)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:27:19
|
--> $DIR/unused_unit.rs:28:19
|
||||||
|
|
|
|
||||||
LL | fn into(self) -> () {
|
LL | fn into(self) -> () {
|
||||||
| ^^^^^ help: remove the `-> ()`
|
| ^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit expression
|
error: unneeded unit expression
|
||||||
--> $DIR/unused_unit.rs:28:9
|
--> $DIR/unused_unit.rs:29:9
|
||||||
|
|
|
|
||||||
LL | ()
|
LL | ()
|
||||||
| ^^ help: remove the final `()`
|
| ^^ help: remove the final `()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:32:18
|
--> $DIR/unused_unit.rs:33:18
|
||||||
|
|
|
|
||||||
LL | fn return_unit() -> () { () }
|
LL | fn return_unit() -> () { () }
|
||||||
| ^^^^^ help: remove the `-> ()`
|
| ^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit expression
|
error: unneeded unit expression
|
||||||
--> $DIR/unused_unit.rs:32:26
|
--> $DIR/unused_unit.rs:33:26
|
||||||
|
|
|
|
||||||
LL | fn return_unit() -> () { () }
|
LL | fn return_unit() -> () { () }
|
||||||
| ^^ help: remove the final `()`
|
| ^^ help: remove the final `()`
|
||||||
|
|
||||||
error: unneeded `()`
|
error: unneeded `()`
|
||||||
--> $DIR/unused_unit.rs:39:14
|
--> $DIR/unused_unit.rs:42:14
|
||||||
|
|
|
|
||||||
LL | break();
|
LL | break();
|
||||||
| ^^ help: remove the `()`
|
| ^^ help: remove the `()`
|
||||||
|
|
||||||
error: unneeded `()`
|
error: unneeded `()`
|
||||||
--> $DIR/unused_unit.rs:41:11
|
--> $DIR/unused_unit.rs:44:11
|
||||||
|
|
|
|
||||||
LL | return();
|
LL | return();
|
||||||
| ^^ help: remove the `()`
|
| ^^ help: remove the `()`
|
||||||
|
|
Loading…
Reference in New Issue