Lint for using Option::as_deref #4918
Labels
A-lint
Area: New lints
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
L-complexity
Lint: Belongs in the complexity lint group
With Rust 1.40.0,
Option::as_deref
has landed.It would be great to have a clippy lint that detects
Option::as_ref
chained byOption::map<F> where F: FnOnce(&T) -> &<T as Deref>::Target
. This would then automatically account for cases whereAsRef::as_ref
or a custom method likeString::as_str
are used.By far the most compelling case is to apply it to
Option<String>
orOption<PathBuf>
, with probably lots of code bases now containingopt.as_ref().map(String::as_str)
or similar constructs.Example in:
Example out:
There are probably more cases that could be detected, like
?
chaining ormatch
statements, but I think those will get gradually less useful to be worth the effort.Icing on the cake would be compatibility to rustfix :)
The text was updated successfully, but these errors were encountered: