-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[check_result_unit_err
]: Disable on no_std
#9671
[check_result_unit_err
]: Disable on no_std
#9671
Conversation
This lint suggests returning a type implementing the trait `std::error::Error` for the `Result`, but this trait is not available in `no_std` crates, so it's not possible for them to fix this lint.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @giraffate (or someone else) soon. Please see the contribution instructions for more information. |
In my eyes, the lint as implemented seems to be correct, even on #![no_std]
use core::result::Result;
pub struct MyError;
pub fn ret_err() -> Result<(), MyError> {
if true { Ok(()) } else { Err(MyError) }
} In my opinion, since As an aside, it's probably worth noting that on nightly, the |
This makes sense. Is this something you'd also like to see in this PR?
So are you saying that
Thanks, I was unaware of this. |
I should probably emphasize that I'm just a bystander, not a Clippy maintainer 😅 Nonetheless, I feel that a
Technically, it already does, though perhaps the suggestion could be reworded slightly: warning: this returns a `Result<_, ()>`
--> src/lib.rs:6:1
|
6 | pub fn ret_err() -> Result<(),()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: use a custom `Error` type instead
+ = help: use a custom error type instead
= help: for further information visit https://rust-lang.github.io/rust-
clippy/master/index.html#result_unit_err
= note: `#[warn(clippy::result_unit_err)]` on by default I feel that the primary issue is that the documentation focuses on the rust-clippy/clippy_lints/src/functions/mod.rs Lines 171 to 178 in 09e4659
Ideally, this would be reworded to discuss how a custom error type, especially an |
oops :P
Agreed.
That makes a lot more sense, thanks for the clarification. I'll wait until a maintainer chimes in, but what you're suggesting makes more sense than what I had put out. Thanks! |
Thanks for the discussion!
That looks good to me. If Then, can this issue be closed? |
That's fine, we can continue this discussion on the issue. |
This lint suggests returning a type implementing the trait
std::error::Error
(doc) for theResult
, but this trait is not available inno_std
crates, so it's not possible for them to fix this lint.This is my first time working in Clippy's codebase, so I may have missed something. Please let me know and I'll fix it.
Example:
Running Clippy on a project with the following
lib.rs
:will yield the following warning:
After the fix, Clippy passes.
Please write a short comment explaining your change (or "none" for internal only changes)
changelog: [
check_result_unit_err
]: No longer warns onno_std
projects