RS.CLIPPY.INFALLIBLE_TRY_FROM
TryFrom with infallible Error type
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: infallible_try_from. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Finds manual impls of TryFrom with infallible error types.
Why is this bad?
Infalliable conversions should be implemented via From with the blanket conversion.
Example
use std::convert::Infallible;
struct MyStruct(i16);
impl TryFrom<i16> for MyStruct {
type Error = Infallible;
fn try_from(other: i16) -> Result<Self, Infallible> {
Ok(Self(other.into()))
}
}
Use instead:
struct MyStruct(i16);
impl From<i16> for MyStruct {
fn from(other: i16) -> Self {
Self(other)
}
}