Merge pull request 397 from zertosh/from_allow_expect

This commit is contained in:
David Tolnay 2024-12-13 14:40:11 -08:00
commit 2deec96fc0
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 22 additions and 5 deletions

View file

@ -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 from_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)]
#from_impl
})
});
if input.generics.type_params().next().is_some() {
@ -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 from_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)]
#from_impl
})
});

View file

@ -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)]