Skip to content

Add test for needless_return lint #6606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/ui/needless_return.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ mod issue6501 {
};
let _ = || {};
}

struct Foo;
#[allow(clippy::unnecessary_lazy_evaluations)]
fn bar(res: Result<Foo, u8>) -> Foo {
res.unwrap_or_else(|_| Foo)
}
}

fn main() {
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/needless_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ mod issue6501 {
};
let _ = || return;
}

struct Foo;
#[allow(clippy::unnecessary_lazy_evaluations)]
fn bar(res: Result<Foo, u8>) -> Foo {
res.unwrap_or_else(|_| return Foo)
}
}

fn main() {
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/needless_return.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,11 @@ error: unneeded `return` statement
LL | let _ = || return;
| ^^^^^^ help: replace `return` with an empty block: `{}`

error: aborting due to 17 previous errors
error: unneeded `return` statement
--> $DIR/needless_return.rs:119:32
|
LL | res.unwrap_or_else(|_| return Foo)
| ^^^^^^^^^^ help: remove `return`: `Foo`

error: aborting due to 18 previous errors