Skip to content

Commit 38e0590

Browse files
committed
Auto merge of #9849 - koka831:fix/9748, r=Manishearth
Allow return types for closures with lifetime binder fix #9748 changelog: Fix [`unused_unit`] Allow return types for closures with lifetime binder
2 parents 5b0d727 + 7c4611c commit 38e0590

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

clippy_lints/src/unused_unit.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::{position_before_rarrow, snippet_opt};
33
use if_chain::if_chain;
4-
use rustc_ast::ast;
5-
use rustc_ast::visit::FnKind;
4+
use rustc_ast::{ast, visit::FnKind, ClosureBinder};
65
use rustc_errors::Applicability;
76
use rustc_lint::{EarlyContext, EarlyLintPass};
87
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -43,6 +42,11 @@ impl EarlyLintPass for UnusedUnit {
4342
if let ast::TyKind::Tup(ref vals) = ty.kind;
4443
if vals.is_empty() && !ty.span.from_expansion() && get_def(span) == get_def(ty.span);
4544
then {
45+
// implicit types in closure signatures are forbidden when `for<...>` is present
46+
if let FnKind::Closure(&ClosureBinder::For { .. }, ..) = kind {
47+
return;
48+
}
49+
4650
lint_unneeded_unit_return(cx, ty, span);
4751
}
4852
}

tests/ui/unused_unit.fixed

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// test of the JSON error format.
88

99
#![feature(custom_inner_attributes)]
10+
#![feature(closure_lifetime_binder)]
1011
#![rustfmt::skip]
1112

1213
#![deny(clippy::unused_unit)]
@@ -87,3 +88,9 @@ fn macro_expr() {
8788
}
8889
e!()
8990
}
91+
92+
mod issue9748 {
93+
fn main() {
94+
let _ = for<'a> |_: &'a u32| -> () {};
95+
}
96+
}

tests/ui/unused_unit.rs

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// test of the JSON error format.
88

99
#![feature(custom_inner_attributes)]
10+
#![feature(closure_lifetime_binder)]
1011
#![rustfmt::skip]
1112

1213
#![deny(clippy::unused_unit)]
@@ -87,3 +88,9 @@ fn macro_expr() {
8788
}
8889
e!()
8990
}
91+
92+
mod issue9748 {
93+
fn main() {
94+
let _ = for<'a> |_: &'a u32| -> () {};
95+
}
96+
}

tests/ui/unused_unit.stderr

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,119 @@
11
error: unneeded unit return type
2-
--> $DIR/unused_unit.rs:19:58
2+
--> $DIR/unused_unit.rs:20:58
33
|
44
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> ()
55
| ^^^^^^ help: remove the `-> ()`
66
|
77
note: the lint level is defined here
8-
--> $DIR/unused_unit.rs:12:9
8+
--> $DIR/unused_unit.rs:13:9
99
|
1010
LL | #![deny(clippy::unused_unit)]
1111
| ^^^^^^^^^^^^^^^^^^^
1212

1313
error: unneeded unit return type
14-
--> $DIR/unused_unit.rs:19:28
14+
--> $DIR/unused_unit.rs:20:28
1515
|
1616
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> ()
1717
| ^^^^^^ help: remove the `-> ()`
1818

1919
error: unneeded unit return type
20-
--> $DIR/unused_unit.rs:20:18
20+
--> $DIR/unused_unit.rs:21:18
2121
|
2222
LL | where G: Fn() -> () {
2323
| ^^^^^^ help: remove the `-> ()`
2424

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

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

3737
error: unneeded unit expression
38-
--> $DIR/unused_unit.rs:29:9
38+
--> $DIR/unused_unit.rs:30:9
3939
|
4040
LL | ()
4141
| ^^ help: remove the final `()`
4242

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

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

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

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

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

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

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

8585
error: unneeded unit expression
86-
--> $DIR/unused_unit.rs:47:26
86+
--> $DIR/unused_unit.rs:48:26
8787
|
8888
LL | fn return_unit() -> () { () }
8989
| ^^ help: remove the final `()`
9090

9191
error: unneeded `()`
92-
--> $DIR/unused_unit.rs:57:14
92+
--> $DIR/unused_unit.rs:58:14
9393
|
9494
LL | break();
9595
| ^^ help: remove the `()`
9696

9797
error: unneeded `()`
98-
--> $DIR/unused_unit.rs:59:11
98+
--> $DIR/unused_unit.rs:60:11
9999
|
100100
LL | return();
101101
| ^^ help: remove the `()`
102102

103103
error: unneeded unit return type
104-
--> $DIR/unused_unit.rs:76:10
104+
--> $DIR/unused_unit.rs:77:10
105105
|
106106
LL | fn test()->(){}
107107
| ^^^^ help: remove the `-> ()`
108108

109109
error: unneeded unit return type
110-
--> $DIR/unused_unit.rs:79:11
110+
--> $DIR/unused_unit.rs:80:11
111111
|
112112
LL | fn test2() ->(){}
113113
| ^^^^^ help: remove the `-> ()`
114114

115115
error: unneeded unit return type
116-
--> $DIR/unused_unit.rs:82:11
116+
--> $DIR/unused_unit.rs:83:11
117117
|
118118
LL | fn test3()-> (){}
119119
| ^^^^^ help: remove the `-> ()`

0 commit comments

Comments
 (0)