Skip to content

Commit 7b94823

Browse files
author
Michael Wright
committed
Enable rustfix on unused_unit tests
1 parent fbcf7ee commit 7b94823

File tree

3 files changed

+58
-11
lines changed

3 files changed

+58
-11
lines changed

tests/ui/unused_unit.fixed

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// run-rustfix
2+
3+
// The output for humans should just highlight the whole span without showing
4+
// the suggested replacement, but we also want to test that suggested
5+
// replacement only removes one set of parentheses, rather than naïvely
6+
// stripping away any starting or ending parenthesis characters—hence this
7+
// test of the JSON error format.
8+
9+
#![feature(custom_inner_attributes)]
10+
#![rustfmt::skip]
11+
12+
#![deny(clippy::unused_unit)]
13+
14+
struct Unitter;
15+
impl Unitter {
16+
// try to disorient the lint with multiple unit returns and newlines
17+
#[allow(clippy::no_effect)]
18+
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G)
19+
where G: Fn() -> () {
20+
let _y: &Fn() -> () = &f;
21+
(); // this should not lint, as it's not in return type position
22+
}
23+
}
24+
25+
impl Into<()> for Unitter {
26+
#[rustfmt::skip]
27+
fn into(self) {
28+
29+
}
30+
}
31+
32+
fn return_unit() { }
33+
34+
#[allow(clippy::needless_return)]
35+
#[allow(clippy::never_loop)]
36+
fn main() {
37+
let u = Unitter;
38+
assert_eq!(u.get_unit(|| {}, return_unit), u.into());
39+
return_unit();
40+
loop {
41+
break;
42+
}
43+
return;
44+
}

tests/ui/unused_unit.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
// compile-pass
1+
// run-rustfix
22

33
// The output for humans should just highlight the whole span without showing
44
// the suggested replacement, but we also want to test that suggested
55
// replacement only removes one set of parentheses, rather than naïvely
66
// stripping away any starting or ending parenthesis characters—hence this
77
// test of the JSON error format.
88

9-
#![deny(clippy::unused_unit)]
10-
#![allow(clippy::needless_return)]
119
#![feature(custom_inner_attributes)]
1210
#![rustfmt::skip]
1311

12+
#![deny(clippy::unused_unit)]
13+
1414
struct Unitter;
1515
impl Unitter {
1616
// try to disorient the lint with multiple unit returns and newlines
17+
#[allow(clippy::no_effect)]
1718
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
1819
()
1920
where G: Fn() -> () {
@@ -31,6 +32,8 @@ impl Into<()> for Unitter {
3132

3233
fn return_unit() -> () { () }
3334

35+
#[allow(clippy::needless_return)]
36+
#[allow(clippy::never_loop)]
3437
fn main() {
3538
let u = Unitter;
3639
assert_eq!(u.get_unit(|| {}, return_unit), u.into());

tests/ui/unused_unit.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
error: unneeded unit return type
2-
--> $DIR/unused_unit.rs:17:59
2+
--> $DIR/unused_unit.rs:18:59
33
|
44
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
55
| ___________________________________________________________^
66
LL | | ()
77
| |__________^ help: remove the `-> ()`
88
|
99
note: lint level defined here
10-
--> $DIR/unused_unit.rs:9:9
10+
--> $DIR/unused_unit.rs:12:9
1111
|
1212
LL | #![deny(clippy::unused_unit)]
1313
| ^^^^^^^^^^^^^^^^^^^
1414

1515
error: unneeded unit return type
16-
--> $DIR/unused_unit.rs:27:19
16+
--> $DIR/unused_unit.rs:28:19
1717
|
1818
LL | fn into(self) -> () {
1919
| ^^^^^ help: remove the `-> ()`
2020

2121
error: unneeded unit expression
22-
--> $DIR/unused_unit.rs:28:9
22+
--> $DIR/unused_unit.rs:29:9
2323
|
2424
LL | ()
2525
| ^^ help: remove the final `()`
2626

2727
error: unneeded unit return type
28-
--> $DIR/unused_unit.rs:32:18
28+
--> $DIR/unused_unit.rs:33:18
2929
|
3030
LL | fn return_unit() -> () { () }
3131
| ^^^^^ help: remove the `-> ()`
3232

3333
error: unneeded unit expression
34-
--> $DIR/unused_unit.rs:32:26
34+
--> $DIR/unused_unit.rs:33:26
3535
|
3636
LL | fn return_unit() -> () { () }
3737
| ^^ help: remove the final `()`
3838

3939
error: unneeded `()`
40-
--> $DIR/unused_unit.rs:39:14
40+
--> $DIR/unused_unit.rs:42:14
4141
|
4242
LL | break();
4343
| ^^ help: remove the `()`
4444

4545
error: unneeded `()`
46-
--> $DIR/unused_unit.rs:41:11
46+
--> $DIR/unused_unit.rs:44:11
4747
|
4848
LL | return();
4949
| ^^ help: remove the `()`

0 commit comments

Comments
 (0)