mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Allow return types for closures with lifetime binder
This commit is contained in:
parent
3c7f74de0b
commit
7c4611c7e1
4 changed files with 40 additions and 22 deletions
|
@ -1,8 +1,7 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||||
use clippy_utils::source::{position_before_rarrow, snippet_opt};
|
use clippy_utils::source::{position_before_rarrow, snippet_opt};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_ast::ast;
|
use rustc_ast::{ast, visit::FnKind, ClosureBinder};
|
||||||
use rustc_ast::visit::FnKind;
|
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
@ -43,6 +42,11 @@ impl EarlyLintPass for UnusedUnit {
|
||||||
if let ast::TyKind::Tup(ref vals) = ty.kind;
|
if let ast::TyKind::Tup(ref vals) = ty.kind;
|
||||||
if vals.is_empty() && !ty.span.from_expansion() && get_def(span) == get_def(ty.span);
|
if vals.is_empty() && !ty.span.from_expansion() && get_def(span) == get_def(ty.span);
|
||||||
then {
|
then {
|
||||||
|
// implicit types in closure signatures are forbidden when `for<...>` is present
|
||||||
|
if let FnKind::Closure(&ClosureBinder::For { .. }, ..) = kind {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lint_unneeded_unit_return(cx, ty, span);
|
lint_unneeded_unit_return(cx, ty, span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
// test of the JSON error format.
|
// test of the JSON error format.
|
||||||
|
|
||||||
#![feature(custom_inner_attributes)]
|
#![feature(custom_inner_attributes)]
|
||||||
|
#![feature(closure_lifetime_binder)]
|
||||||
#![rustfmt::skip]
|
#![rustfmt::skip]
|
||||||
|
|
||||||
#![deny(clippy::unused_unit)]
|
#![deny(clippy::unused_unit)]
|
||||||
|
@ -87,3 +88,9 @@ fn macro_expr() {
|
||||||
}
|
}
|
||||||
e!()
|
e!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod issue9748 {
|
||||||
|
fn main() {
|
||||||
|
let _ = for<'a> |_: &'a u32| -> () {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
// test of the JSON error format.
|
// test of the JSON error format.
|
||||||
|
|
||||||
#![feature(custom_inner_attributes)]
|
#![feature(custom_inner_attributes)]
|
||||||
|
#![feature(closure_lifetime_binder)]
|
||||||
#![rustfmt::skip]
|
#![rustfmt::skip]
|
||||||
|
|
||||||
#![deny(clippy::unused_unit)]
|
#![deny(clippy::unused_unit)]
|
||||||
|
@ -87,3 +88,9 @@ fn macro_expr() {
|
||||||
}
|
}
|
||||||
e!()
|
e!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod issue9748 {
|
||||||
|
fn main() {
|
||||||
|
let _ = for<'a> |_: &'a u32| -> () {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,119 +1,119 @@
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:19:58
|
--> $DIR/unused_unit.rs:20:58
|
||||||
|
|
|
|
||||||
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) -> ()
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused_unit.rs:12:9
|
--> $DIR/unused_unit.rs:13: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:19:28
|
--> $DIR/unused_unit.rs:20:28
|
||||||
|
|
|
|
||||||
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) -> ()
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:20:18
|
--> $DIR/unused_unit.rs:21:18
|
||||||
|
|
|
|
||||||
LL | where G: Fn() -> () {
|
LL | where G: Fn() -> () {
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:21:26
|
--> $DIR/unused_unit.rs:22:26
|
||||||
|
|
|
|
||||||
LL | let _y: &dyn Fn() -> () = &f;
|
LL | let _y: &dyn Fn() -> () = &f;
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:28:18
|
--> $DIR/unused_unit.rs:29:18
|
||||||
|
|
|
|
||||||
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:29:9
|
--> $DIR/unused_unit.rs:30: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:34:29
|
--> $DIR/unused_unit.rs:35:29
|
||||||
|
|
|
|
||||||
LL | fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
|
LL | fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:36:19
|
--> $DIR/unused_unit.rs:37:19
|
||||||
|
|
|
|
||||||
LL | G: FnMut() -> (),
|
LL | G: FnMut() -> (),
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:37:16
|
--> $DIR/unused_unit.rs:38:16
|
||||||
|
|
|
|
||||||
LL | H: Fn() -> ();
|
LL | H: Fn() -> ();
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:41:29
|
--> $DIR/unused_unit.rs:42:29
|
||||||
|
|
|
|
||||||
LL | fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
|
LL | fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:43:19
|
--> $DIR/unused_unit.rs:44:19
|
||||||
|
|
|
|
||||||
LL | G: FnMut() -> (),
|
LL | G: FnMut() -> (),
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:44:16
|
--> $DIR/unused_unit.rs:45:16
|
||||||
|
|
|
|
||||||
LL | H: Fn() -> () {}
|
LL | H: Fn() -> () {}
|
||||||
| ^^^^^^ help: remove the `-> ()`
|
| ^^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:47:17
|
--> $DIR/unused_unit.rs:48:17
|
||||||
|
|
|
|
||||||
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:47:26
|
--> $DIR/unused_unit.rs:48: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:57:14
|
--> $DIR/unused_unit.rs:58:14
|
||||||
|
|
|
|
||||||
LL | break();
|
LL | break();
|
||||||
| ^^ help: remove the `()`
|
| ^^ help: remove the `()`
|
||||||
|
|
||||||
error: unneeded `()`
|
error: unneeded `()`
|
||||||
--> $DIR/unused_unit.rs:59:11
|
--> $DIR/unused_unit.rs:60:11
|
||||||
|
|
|
|
||||||
LL | return();
|
LL | return();
|
||||||
| ^^ help: remove the `()`
|
| ^^ help: remove the `()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:76:10
|
--> $DIR/unused_unit.rs:77:10
|
||||||
|
|
|
|
||||||
LL | fn test()->(){}
|
LL | fn test()->(){}
|
||||||
| ^^^^ help: remove the `-> ()`
|
| ^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:79:11
|
--> $DIR/unused_unit.rs:80:11
|
||||||
|
|
|
|
||||||
LL | fn test2() ->(){}
|
LL | fn test2() ->(){}
|
||||||
| ^^^^^ help: remove the `-> ()`
|
| ^^^^^ help: remove the `-> ()`
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:82:11
|
--> $DIR/unused_unit.rs:83:11
|
||||||
|
|
|
|
||||||
LL | fn test3()-> (){}
|
LL | fn test3()-> (){}
|
||||||
| ^^^^^ help: remove the `-> ()`
|
| ^^^^^ help: remove the `-> ()`
|
||||||
|
|
Loading…
Reference in a new issue