-
Notifications
You must be signed in to change notification settings - Fork 2k
New lint: manual_inspect #16777
Copy link
Copy link
Open
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages
Description
What it does
For the following case:
if let Some(legacy_path) = legacy_bin_path(package_root, &bin.name(), has_lib) {
warnings.push(format!(
"path `{}` was erroneously implicitly accepted for binary `{}`,\n\
please set bin.path in Cargo.toml",
legacy_path.display(),
bin.name()
));
Some(legacy_path)
} else {
None
}It is better to use Option::inspect.
Advantage
- Better readability
Drawbacks
Cannot think of so far.
Example
if let Some(legacy_path) = legacy_bin_path(package_root, &bin.name(), has_lib) {
warnings.push(format!(
"path `{}` was erroneously implicitly accepted for binary `{}`,\n\
please set bin.path in Cargo.toml",
legacy_path.display(),
bin.name()
));
Some(legacy_path)
} else {
None
}Could be written as:
legacy_bin_path(package_root, &bin.name(), has_lib)
.inspect(|legacy_path| {
warnings.push(format!(
"path `{}` was erroneously implicitly accepted for binary `{}`,\n\
please set bin.path in Cargo.toml",
legacy_path.display(),
bin.name()
));
})Comparison with existing lints
The given example will be covered by clippy::manual_map if #16775 is merged, but using Option::inspect would be better.
Additional Context
One real world example: https://docs.rs/cargo/0.64.0/src/cargo/util/toml/targets.rs.html#325
Reactions are currently unavailable
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 messages
Type
Fields
Give feedbackNo fields configured for issues without a type.