Description
What it does
It would flag method calls from the standard library that actually only call another method, e.g:
.into()
-> useType::from(..)
instead.try_into()
-> useType::try_from(..)
instead.parse()
-> useType::from_str(..)
instead- etc. ... (there are probably more of these?)
Advantage
You can easily jump to the definition of the conversion code with rust-analyzer. Because if you go to definition of e.g. .into()
with rust-analyzer it will just take you to the definition of the blanket implementation:
impl<T, U> const Into<U> for T
where
U: ~const From<T>,
{
/// Calls `U::from(self)`.
///
/// That is, this conversion is whatever the implementation of
/// <code>[From]<T> for U</code> chooses to do.
#[inline]
fn into(self) -> U {
U::from(self)
}
}
which is technically correct but not very helpful since you're probably trying to get to the definition of the actual conversion code (ref rust-lang/rust-analyzer#15315) . Especially in large code bases it can be hard to manually find where a trait is implemented.
Drawbacks
It makes code more verbose and can easily lead to false positives since Clippy isn't type-aware (however implementing methods called into
or try_into
outside of the std traits is probably an anti-pattern anyway since it's confusing.)
Example
let a: Foo = b.into();
Could be written as:
let a: Foo = Foo::from(b);