From 0380181094b52becb06fe066bcf969f2b66a4650 Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Thu, 20 Apr 2023 09:40:41 -0400 Subject: [PATCH] subject_name: deprecate From for DnsName. As mentioned in the comment we can't outright `#[deprecate]` this one because it's a trait impl. Instead, promote the deprecation note to the rustdoc comment, add a TODO to remove it outright, and switch our own tests to call `to_owned()` directly in preparation of an eventual removal. --- src/subject_name/dns_name.rs | 5 ++++- tests/name_tests.rs | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/subject_name/dns_name.rs b/src/subject_name/dns_name.rs index 54e3c979..13bb462e 100644 --- a/src/subject_name/dns_name.rs +++ b/src/subject_name/dns_name.rs @@ -55,9 +55,12 @@ impl AsRef for DnsName { } /// Requires the `alloc` feature. -// Deprecated +/// Deprecated. #[cfg(feature = "alloc")] impl From> for DnsName { + // TODO(XXX): Remove this trait impl in the next release. We can't mark it as + // hard deprecated as this isn't supported and produces a + // 'useless_deprecated' warning. fn from(dns_name: DnsNameRef) -> Self { dns_name.to_owned() } diff --git a/tests/name_tests.rs b/tests/name_tests.rs index cde88acf..62e9a092 100644 --- a/tests/name_tests.rs +++ b/tests/name_tests.rs @@ -41,6 +41,7 @@ fn test_dns_name_traits() { let a_ref = DnsNameRef::try_from_ascii(b"example.com").unwrap(); // `From` + // TODO(XXX): Remove when deprecated From for DnsName trait is removed. let a: DnsName = DnsName::from(a_ref); // `Clone`, `Debug`, `PartialEq`. @@ -52,16 +53,22 @@ fn test_dns_name_traits() { // PartialEq is case-insensitive assert_eq!( a, - DnsName::from(DnsNameRef::try_from_ascii(b"Example.Com").unwrap()) + DnsNameRef::try_from_ascii(b"Example.Com") + .unwrap() + .to_owned() ); // PartialEq isn't completely wrong. assert_ne!( a, - DnsName::from(DnsNameRef::try_from_ascii(b"fxample.com").unwrap()) + DnsNameRef::try_from_ascii(b"fxample.com") + .unwrap() + .to_owned() ); assert_ne!( a, - DnsName::from(DnsNameRef::try_from_ascii(b"example.co").unwrap()) + DnsNameRef::try_from_ascii(b"example.co") + .unwrap() + .to_owned() ); }