-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
A-lintArea: New lintsArea: New lints
Description
What it does
fn foo() -> Result<i32, Error> {
Ok(42)
}Suggested clippy lint: "Needless use of Result (function never returns Err). Consider changing the return type to i32 ."
(Unsure if it should be "needless" or "unnecessary", see #2845)
Categories (optional)
clippy::complexity (code that does something simple but in a complex way)
The use of this lint would most often come up after refactoring some code, when a function that used to have a ? in it no longer thus, and so now never returns an error.
Removing unnecessary uses of Result makes your code cleaner and clearer.
Drawbacks
Sometimes the user wants to return a Result because they plan on adding a failure condition later.
Example
fn foo() -> Result<i32, Error> {
Ok(42)
}Could be written as:
fn foo() -> i32 {
42
}Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints