@@ -277,7 +277,7 @@ impl EarlyLintPass for Return {
|
|||||||
if_chain! {
|
if_chain! {
|
||||||
if let Some(ref stmt) = block.stmts.last();
|
if let Some(ref stmt) = block.stmts.last();
|
||||||
if let ast::StmtKind::Expr(ref expr) = stmt.node;
|
if let ast::StmtKind::Expr(ref expr) = stmt.node;
|
||||||
if is_unit_expr(expr) && !expr.span.from_expansion();
|
if is_unit_expr(expr) && !stmt.span.from_expansion();
|
||||||
then {
|
then {
|
||||||
let sp = expr.span;
|
let sp = expr.span;
|
||||||
span_lint_and_then(cx, UNUSED_UNIT, sp, "unneeded unit expression", |db| {
|
span_lint_and_then(cx, UNUSED_UNIT, sp, "unneeded unit expression", |db| {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#![rustfmt::skip]
|
#![rustfmt::skip]
|
||||||
|
|
||||||
#![deny(clippy::unused_unit)]
|
#![deny(clippy::unused_unit)]
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
struct Unitter;
|
struct Unitter;
|
||||||
impl Unitter {
|
impl Unitter {
|
||||||
@@ -42,3 +43,16 @@ fn main() {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust-clippy/issues/4076
|
||||||
|
fn foo() {
|
||||||
|
macro_rules! foo {
|
||||||
|
(recv($r:expr) -> $res:pat => $body:expr) => {
|
||||||
|
$body
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foo! {
|
||||||
|
recv(rx) -> _x => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#![rustfmt::skip]
|
#![rustfmt::skip]
|
||||||
|
|
||||||
#![deny(clippy::unused_unit)]
|
#![deny(clippy::unused_unit)]
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
struct Unitter;
|
struct Unitter;
|
||||||
impl Unitter {
|
impl Unitter {
|
||||||
@@ -43,3 +44,16 @@ fn main() {
|
|||||||
}
|
}
|
||||||
return();
|
return();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust-clippy/issues/4076
|
||||||
|
fn foo() {
|
||||||
|
macro_rules! foo {
|
||||||
|
(recv($r:expr) -> $res:pat => $body:expr) => {
|
||||||
|
$body
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foo! {
|
||||||
|
recv(rx) -> _x => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:18:59
|
--> $DIR/unused_unit.rs:19: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) ->
|
||||||
| ___________________________________________________________^
|
| ___________________________________________________________^
|
||||||
@@ -13,37 +13,37 @@ LL | #![deny(clippy::unused_unit)]
|
|||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unneeded unit return type
|
error: unneeded unit return type
|
||||||
--> $DIR/unused_unit.rs:28:19
|
--> $DIR/unused_unit.rs:29: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: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:33:18
|
--> $DIR/unused_unit.rs:34: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:33:26
|
--> $DIR/unused_unit.rs:34: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:42:14
|
--> $DIR/unused_unit.rs:43:14
|
||||||
|
|
|
|
||||||
LL | break();
|
LL | break();
|
||||||
| ^^ help: remove the `()`
|
| ^^ help: remove the `()`
|
||||||
|
|
||||||
error: unneeded `()`
|
error: unneeded `()`
|
||||||
--> $DIR/unused_unit.rs:44:11
|
--> $DIR/unused_unit.rs:45:11
|
||||||
|
|
|
|
||||||
LL | return();
|
LL | return();
|
||||||
| ^^ help: remove the `()`
|
| ^^ help: remove the `()`
|
||||||
|
|||||||
Reference in New Issue
Block a user