Skip to content

Commit

Permalink
Merge pull request #396 from dtolnay/deprecatedfrom
Browse files Browse the repository at this point in the history
Suppress deprecation warning on generated From impls
  • Loading branch information
dtolnay authored Dec 8, 2024
2 parents f1f159d + 6e8c724 commit e9a9085
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 2 additions & 4 deletions impl/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit e9a9085

Please sign in to comment.