forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#6157 - rust-lang:result-unit-err, r=ebroto
New lint: result-unit-err This fixes rust-lang#1721. - [x] Followed [lint naming conventions][lint_naming] - [x] Added passing UI tests (including committed `.stderr` file) - [x] `cargo test` passes locally - [x] Executed `cargo dev update_lints` - [x] Added lint documentation - [x] Run `cargo dev fmt` [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints --- changelog: new lint: result-unit-err
- Loading branch information
Showing
10 changed files
with
189 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// edition:2018 | ||
#![warn(clippy::missing_errors_doc)] | ||
#![allow(clippy::result_unit_err)] | ||
|
||
use std::io; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#[warn(clippy::result_unit_err)] | ||
#[allow(unused)] | ||
|
||
pub fn returns_unit_error() -> Result<u32, ()> { | ||
Err(()) | ||
} | ||
|
||
fn private_unit_errors() -> Result<String, ()> { | ||
Err(()) | ||
} | ||
|
||
pub trait HasUnitError { | ||
fn get_that_error(&self) -> Result<bool, ()>; | ||
|
||
fn get_this_one_too(&self) -> Result<bool, ()> { | ||
Err(()) | ||
} | ||
} | ||
|
||
impl HasUnitError for () { | ||
fn get_that_error(&self) -> Result<bool, ()> { | ||
Ok(true) | ||
} | ||
} | ||
|
||
trait PrivateUnitError { | ||
fn no_problem(&self) -> Result<usize, ()>; | ||
} | ||
|
||
pub struct UnitErrorHolder; | ||
|
||
impl UnitErrorHolder { | ||
pub fn unit_error(&self) -> Result<usize, ()> { | ||
Ok(0) | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error: this returns a `Result<_, ()> | ||
--> $DIR/result_unit_error.rs:4:1 | ||
| | ||
LL | pub fn returns_unit_error() -> Result<u32, ()> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::result-unit-err` implied by `-D warnings` | ||
= help: use a custom Error type instead | ||
|
||
error: this returns a `Result<_, ()> | ||
--> $DIR/result_unit_error.rs:13:5 | ||
| | ||
LL | fn get_that_error(&self) -> Result<bool, ()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: use a custom Error type instead | ||
|
||
error: this returns a `Result<_, ()> | ||
--> $DIR/result_unit_error.rs:15:5 | ||
| | ||
LL | fn get_this_one_too(&self) -> Result<bool, ()> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: use a custom Error type instead | ||
|
||
error: this returns a `Result<_, ()> | ||
--> $DIR/result_unit_error.rs:33:5 | ||
| | ||
LL | pub fn unit_error(&self) -> Result<usize, ()> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: use a custom Error type instead | ||
|
||
error: aborting due to 4 previous errors | ||
|