-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
What it does
Reduce simple if let statements that immediately return the unwrapped value by replacing the if let with a ?.
Lint Name
collapsible_if_let_return
Category
style
Advantage
Encourages concise code and proper use of the ? operator.
Drawbacks
None that I can think of.
Example
fn example_fn() -> Result<(), CustomError> {
if let Err(err) = run_some_process() {
return Err(err);
}
// Other function logic...
Ok(())
}
Could be written as:
fn example_fn() -> Result<(), CustomError> {
run_some_process()?;
// Other function logic...
Ok(())
}
And, if there were no other function logic, could further be reduced to:
fn example_fn() -> Result<(), CustomError> {
run_some_process()
}
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy