Skip to content

Commit dc55009

Browse files
committed
Fix suggestion to add unneeded space in unused_unit
1 parent 9c9aa2d commit dc55009

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

clippy_lints/src/unused_unit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn is_unit_expr(expr: &ast::Expr) -> bool {
121121
fn lint_unneeded_unit_return(cx: &EarlyContext<'_>, ty: &ast::Ty, span: Span) {
122122
let (ret_span, appl) = if let Ok(fn_source) = cx.sess().source_map().span_to_snippet(span.with_hi(ty.span.hi())) {
123123
fn_source
124-
.rfind("->")
124+
.rfind(" -> ")
125125
.map_or((ty.span, Applicability::MaybeIncorrect), |rpos| {
126126
(
127127
#[allow(clippy::cast_possible_truncation)]
@@ -137,7 +137,7 @@ fn lint_unneeded_unit_return(cx: &EarlyContext<'_>, ty: &ast::Ty, span: Span) {
137137
UNUSED_UNIT,
138138
ret_span,
139139
"unneeded unit return type",
140-
"remove the `-> ()`",
140+
"remove the ` -> ()`",
141141
String::new(),
142142
appl,
143143
);

tests/ui/unused_unit.fixed

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@
1515
struct Unitter;
1616
impl Unitter {
1717
#[allow(clippy::no_effect)]
18-
pub fn get_unit<F: Fn() , G>(&self, f: F, _g: G)
19-
where G: Fn() {
20-
let _y: &dyn Fn() = &f;
18+
pub fn get_unit<F: Fn(), G>(&self, f: F, _g: G)
19+
where G: Fn() {
20+
let _y: &dyn Fn() = &f;
2121
(); // this should not lint, as it's not in return type position
2222
}
2323
}
2424

2525
impl Into<()> for Unitter {
2626
#[rustfmt::skip]
27-
fn into(self) {
27+
fn into(self) {
2828

2929
}
3030
}
3131

3232
trait Trait {
33-
fn redundant<F: FnOnce() , G, H>(&self, _f: F, _g: G, _h: H)
33+
fn redundant<F: FnOnce(), G, H>(&self, _f: F, _g: G, _h: H)
3434
where
35-
G: FnMut() ,
36-
H: Fn() ;
35+
G: FnMut(),
36+
H: Fn();
3737
}
3838

3939
impl Trait for Unitter {
40-
fn redundant<F: FnOnce() , G, H>(&self, _f: F, _g: G, _h: H)
40+
fn redundant<F: FnOnce(), G, H>(&self, _f: F, _g: G, _h: H)
4141
where
42-
G: FnMut() ,
43-
H: Fn() {}
42+
G: FnMut(),
43+
H: Fn() {}
4444
}
4545

46-
fn return_unit() { }
46+
fn return_unit() { }
4747

4848
#[allow(clippy::needless_return)]
4949
#[allow(clippy::never_loop)]

tests/ui/unused_unit.stderr

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

1313
error: unneeded unit return type
14-
--> $DIR/unused_unit.rs:19:19
14+
--> $DIR/unused_unit.rs:19:18
1515
|
1616
LL | where G: Fn() -> () {
17-
| ^^^^^ help: remove the `-> ()`
17+
| ^^^^^^ help: remove the ` -> ()`
1818

1919
error: unneeded unit return type
20-
--> $DIR/unused_unit.rs:18:59
20+
--> $DIR/unused_unit.rs:18:58
2121
|
2222
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> ()
23-
| ^^^^^ help: remove the `-> ()`
23+
| ^^^^^^ help: remove the ` -> ()`
2424

2525
error: unneeded unit return type
26-
--> $DIR/unused_unit.rs:20:27
26+
--> $DIR/unused_unit.rs:20:26
2727
|
2828
LL | let _y: &dyn Fn() -> () = &f;
29-
| ^^^^^ help: remove the `-> ()`
29+
| ^^^^^^ help: remove the ` -> ()`
3030

3131
error: unneeded unit return type
32-
--> $DIR/unused_unit.rs:27:19
32+
--> $DIR/unused_unit.rs:27:18
3333
|
3434
LL | fn into(self) -> () {
35-
| ^^^^^ help: remove the `-> ()`
35+
| ^^^^^^ help: remove the ` -> ()`
3636

3737
error: unneeded unit expression
3838
--> $DIR/unused_unit.rs:28:9
@@ -41,46 +41,46 @@ LL | ()
4141
| ^^ help: remove the final `()`
4242

4343
error: unneeded unit return type
44-
--> $DIR/unused_unit.rs:33:30
44+
--> $DIR/unused_unit.rs:33:29
4545
|
4646
LL | fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
47-
| ^^^^^ help: remove the `-> ()`
47+
| ^^^^^^ help: remove the ` -> ()`
4848

4949
error: unneeded unit return type
50-
--> $DIR/unused_unit.rs:35:20
50+
--> $DIR/unused_unit.rs:35:19
5151
|
5252
LL | G: FnMut() -> (),
53-
| ^^^^^ help: remove the `-> ()`
53+
| ^^^^^^ help: remove the ` -> ()`
5454

5555
error: unneeded unit return type
56-
--> $DIR/unused_unit.rs:36:17
56+
--> $DIR/unused_unit.rs:36:16
5757
|
5858
LL | H: Fn() -> ();
59-
| ^^^^^ help: remove the `-> ()`
59+
| ^^^^^^ help: remove the ` -> ()`
6060

6161
error: unneeded unit return type
62-
--> $DIR/unused_unit.rs:40:30
62+
--> $DIR/unused_unit.rs:40:29
6363
|
6464
LL | fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
65-
| ^^^^^ help: remove the `-> ()`
65+
| ^^^^^^ help: remove the ` -> ()`
6666

6767
error: unneeded unit return type
68-
--> $DIR/unused_unit.rs:42:20
68+
--> $DIR/unused_unit.rs:42:19
6969
|
7070
LL | G: FnMut() -> (),
71-
| ^^^^^ help: remove the `-> ()`
71+
| ^^^^^^ help: remove the ` -> ()`
7272

7373
error: unneeded unit return type
74-
--> $DIR/unused_unit.rs:43:17
74+
--> $DIR/unused_unit.rs:43:16
7575
|
7676
LL | H: Fn() -> () {}
77-
| ^^^^^ help: remove the `-> ()`
77+
| ^^^^^^ help: remove the ` -> ()`
7878

7979
error: unneeded unit return type
80-
--> $DIR/unused_unit.rs:46:18
80+
--> $DIR/unused_unit.rs:46:17
8181
|
8282
LL | fn return_unit() -> () { () }
83-
| ^^^^^ help: remove the `-> ()`
83+
| ^^^^^^ help: remove the ` -> ()`
8484

8585
error: unneeded unit expression
8686
--> $DIR/unused_unit.rs:46:26

0 commit comments

Comments
 (0)