From caf585c978f43ef0348dcd669af301e7a7e8578b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 8 Dec 2024 10:34:17 -0800 Subject: [PATCH 1/2] Add test of deprecated type in From impl error: use of deprecated struct `test_deprecated::DeprecatedStruct` --> tests/test_lints.rs:73:13 | 73 | DeprecatedStruct, | ^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> tests/test_lints.rs:39:13 | 39 | #![deny(deprecated)] | ^^^^^^^^^^ --- tests/test_lints.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_lints.rs b/tests/test_lints.rs index b46a391..d272454 100644 --- a/tests/test_lints.rs +++ b/tests/test_lints.rs @@ -64,6 +64,16 @@ fn test_deprecated() { Variant, } + #[derive(Error, Debug)] + pub enum DeprecatedFrom { + #[error(transparent)] + Variant( + #[from] + #[allow(deprecated)] + DeprecatedStruct, + ), + } + #[allow(deprecated)] let _: DeprecatedStruct; #[allow(deprecated)] From 6e8c7244c9b396f0c194a660fcb4bcff75e50b08 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 8 Dec 2024 10:37:43 -0800 Subject: [PATCH 2/2] Suppress deprecation warning on generated From impls --- impl/src/expand.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/impl/src/expand.rs b/impl/src/expand.rs index d0b302b..20ba1d2 100644 --- a/impl/src/expand.rs +++ b/impl/src/expand.rs @@ -170,10 +170,9 @@ fn impl_struct(input: Struct) -> TokenStream { let source_var = Ident::new("source", span); let body = from_initializer(from_field, backtrace_field, &source_var); quote_spanned! {span=> - #[allow(unused_qualifications, clippy::needless_lifetimes)] + #[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)] #[automatically_derived] impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause { - #[allow(deprecated)] fn from(#source_var: #from) -> Self { #ty #body } @@ -435,10 +434,9 @@ fn impl_enum(input: Enum) -> TokenStream { let source_var = Ident::new("source", span); let body = from_initializer(from_field, backtrace_field, &source_var); Some(quote_spanned! {span=> - #[allow(unused_qualifications, clippy::needless_lifetimes)] + #[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)] #[automatically_derived] impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause { - #[allow(deprecated)] fn from(#source_var: #from) -> Self { #ty::#variant #body }