Skip to content

Commit

Permalink
Avoid associating #[from] with lint allow
Browse files Browse the repository at this point in the history
  • Loading branch information
zertosh committed Dec 13, 2024
1 parent 485c2b7 commit 100d916
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 11 additions & 5 deletions impl/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,18 @@ fn impl_struct(input: Struct) -> TokenStream {
let from = unoptional_type(from_field.ty);
let source_var = Ident::new("source", span);
let body = from_initializer(from_field, backtrace_field, &source_var);
quote_spanned! {span=>
#[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)]
let impl_impl = quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause {
fn from(#source_var: #from) -> Self {
#ty #body
}
}
}
};
Some(quote! {
#[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)]
#impl_impl
})
});

if input.generics.type_params().next().is_some() {
Expand Down Expand Up @@ -433,14 +436,17 @@ fn impl_enum(input: Enum) -> TokenStream {
let from = unoptional_type(from_field.ty);
let source_var = Ident::new("source", span);
let body = from_initializer(from_field, backtrace_field, &source_var);
Some(quote_spanned! {span=>
#[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)]
let impl_impl = quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause {
fn from(#source_var: #from) -> Self {
#ty::#variant #body
}
}
};
Some(quote! {
#[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)]
#impl_impl
})
});

Expand Down
11 changes: 11 additions & 0 deletions tests/test_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ use thiserror::Error;

pub use std::error::Error;

#[test]
fn test_allow_attributes() {
#![deny(clippy::allow_attributes)]

#[derive(Error, Debug)]
#[error("...")]
pub struct MyError(#[from] anyhow::Error);

let _: MyError;
}

#[test]
fn test_unused_qualifications() {
#![deny(unused_qualifications)]
Expand Down

0 comments on commit 100d916

Please sign in to comment.