diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/result_unit_error.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/result_unit_error.rs')
-rw-r--r-- | src/tools/clippy/tests/ui/result_unit_error.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/result_unit_error.rs b/src/tools/clippy/tests/ui/result_unit_error.rs new file mode 100644 index 000000000..a4ec80302 --- /dev/null +++ b/src/tools/clippy/tests/ui/result_unit_error.rs @@ -0,0 +1,56 @@ +#![warn(clippy::result_unit_err)] + +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) + } +} + +// https://github.com/rust-lang/rust-clippy/issues/6546 +pub mod issue_6546 { + type ResInv<A, B> = Result<B, A>; + + pub fn should_lint() -> ResInv<(), usize> { + Ok(0) + } + + pub fn should_not_lint() -> ResInv<usize, ()> { + Ok(()) + } + + type MyRes<A, B> = Result<(A, B), Box<dyn std::error::Error>>; + + pub fn should_not_lint2(x: i32) -> MyRes<i32, ()> { + Ok((x, ())) + } +} + +fn main() {} |