//@aux-build:proc_macros.rs //@no-rustfix #![warn(clippy::unnecessary_fallible_conversions)] extern crate proc_macros; struct Foo; impl TryFrom for Foo { type Error = (); fn try_from(_: i32) -> Result { Ok(Foo) } } impl From for Foo { fn from(_: i64) -> Self { Foo } } fn main() { // `Foo` only implements `TryFrom` and not `From`, so don't lint let _: Result = 0i32.try_into(); let _: Result = i32::try_into(0i32); let _: Result = Foo::try_from(0i32); // ... it does impl From however let _: Result = 0i64.try_into(); //~^ ERROR: use of a fallible conversion when an infallible one could be used let _: Result = i64::try_into(0i64); //~^ ERROR: use of a fallible conversion when an infallible one could be used let _: Result = Foo::try_from(0i64); //~^ ERROR: use of a fallible conversion when an infallible one could be used let _: Result = 0i32.try_into(); //~^ ERROR: use of a fallible conversion when an infallible one could be used let _: Result = i32::try_into(0i32); //~^ ERROR: use of a fallible conversion when an infallible one could be used let _: Result = <_>::try_from(0i32); //~^ ERROR: use of a fallible conversion when an infallible one could be used // From a macro let _: Result = proc_macros::external!(0i32).try_into(); }