From a37873d7fb5903f1545b913a14f4aaa0306822a6 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Mon, 1 Dec 2025 16:41:39 +0100 Subject: [PATCH] add a coretest checking `TryInto`/`TryFrom` impls --- library/coretests/tests/convert.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/library/coretests/tests/convert.rs b/library/coretests/tests/convert.rs index f1048f4cf09c..1eb7468e56ea 100644 --- a/library/coretests/tests/convert.rs +++ b/library/coretests/tests/convert.rs @@ -14,3 +14,20 @@ const fn into(x: Vec) -> Vec { const BAR: Vec = into(Vec::new()); assert_eq!(BAR, Vec::::new()); } + +#[test] +fn into_as_try_into() { + struct A; + struct B; + + impl Into for A { + fn into(self) -> B { + B + } + } + + // This wouldn't compile if the `TryInto`/`TryFrom` blanket impls used + // `U: From` instead of `T: Into` + let Ok(B) = A.try_into(); + let Ok(B) = B::try_from(A); +}