Skip to content

Commit

Permalink
Fix suggestion to add unneeded space in unused_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate committed Oct 27, 2020
1 parent 9c9aa2d commit dc55009
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/unused_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn is_unit_expr(expr: &ast::Expr) -> bool {
fn lint_unneeded_unit_return(cx: &EarlyContext<'_>, ty: &ast::Ty, span: Span) {
let (ret_span, appl) = if let Ok(fn_source) = cx.sess().source_map().span_to_snippet(span.with_hi(ty.span.hi())) {
fn_source
.rfind("->")
.rfind(" -> ")
.map_or((ty.span, Applicability::MaybeIncorrect), |rpos| {
(
#[allow(clippy::cast_possible_truncation)]
Expand All @@ -137,7 +137,7 @@ fn lint_unneeded_unit_return(cx: &EarlyContext<'_>, ty: &ast::Ty, span: Span) {
UNUSED_UNIT,
ret_span,
"unneeded unit return type",
"remove the `-> ()`",
"remove the ` -> ()`",
String::new(),
appl,
);
Expand Down
22 changes: 11 additions & 11 deletions tests/ui/unused_unit.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@
struct Unitter;
impl Unitter {
#[allow(clippy::no_effect)]
pub fn get_unit<F: Fn() , G>(&self, f: F, _g: G)
where G: Fn() {
let _y: &dyn Fn() = &f;
pub fn get_unit<F: Fn(), G>(&self, f: F, _g: G)
where G: Fn() {
let _y: &dyn Fn() = &f;
(); // this should not lint, as it's not in return type position
}
}

impl Into<()> for Unitter {
#[rustfmt::skip]
fn into(self) {
fn into(self) {

}
}

trait Trait {
fn redundant<F: FnOnce() , G, H>(&self, _f: F, _g: G, _h: H)
fn redundant<F: FnOnce(), G, H>(&self, _f: F, _g: G, _h: H)
where
G: FnMut() ,
H: Fn() ;
G: FnMut(),
H: Fn();
}

impl Trait for Unitter {
fn redundant<F: FnOnce() , G, H>(&self, _f: F, _g: G, _h: H)
fn redundant<F: FnOnce(), G, H>(&self, _f: F, _g: G, _h: H)
where
G: FnMut() ,
H: Fn() {}
G: FnMut(),
H: Fn() {}
}

fn return_unit() { }
fn return_unit() { }

#[allow(clippy::needless_return)]
#[allow(clippy::never_loop)]
Expand Down
48 changes: 24 additions & 24 deletions tests/ui/unused_unit.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unneeded unit return type
--> $DIR/unused_unit.rs:18:29
--> $DIR/unused_unit.rs:18:28
|
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
--> $DIR/unused_unit.rs:12:9
Expand All @@ -11,28 +11,28 @@ LL | #![deny(clippy::unused_unit)]
| ^^^^^^^^^^^^^^^^^^^

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

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

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

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

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

error: unneeded unit return type
--> $DIR/unused_unit.rs:33:30
--> $DIR/unused_unit.rs:33:29
|
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
--> $DIR/unused_unit.rs:35:20
--> $DIR/unused_unit.rs:35:19
|
LL | G: FnMut() -> (),
| ^^^^^ help: remove the `-> ()`
| ^^^^^^ help: remove the ` -> ()`

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

error: unneeded unit return type
--> $DIR/unused_unit.rs:40:30
--> $DIR/unused_unit.rs:40:29
|
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
--> $DIR/unused_unit.rs:42:20
--> $DIR/unused_unit.rs:42:19
|
LL | G: FnMut() -> (),
| ^^^^^ help: remove the `-> ()`
| ^^^^^^ help: remove the ` -> ()`

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

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

error: unneeded unit expression
--> $DIR/unused_unit.rs:46:26
Expand Down

0 comments on commit dc55009

Please sign in to comment.