Skip to content

Commit 100d916

Browse files
committed
Avoid associating #[from] with lint allow
1 parent 485c2b7 commit 100d916

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

impl/src/expand.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,18 @@ fn impl_struct(input: Struct) -> TokenStream {
169169
let from = unoptional_type(from_field.ty);
170170
let source_var = Ident::new("source", span);
171171
let body = from_initializer(from_field, backtrace_field, &source_var);
172-
quote_spanned! {span=>
173-
#[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)]
172+
let impl_impl = quote_spanned! {span=>
174173
#[automatically_derived]
175174
impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause {
176175
fn from(#source_var: #from) -> Self {
177176
#ty #body
178177
}
179178
}
180-
}
179+
};
180+
Some(quote! {
181+
#[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)]
182+
#impl_impl
183+
})
181184
});
182185

183186
if input.generics.type_params().next().is_some() {
@@ -433,14 +436,17 @@ fn impl_enum(input: Enum) -> TokenStream {
433436
let from = unoptional_type(from_field.ty);
434437
let source_var = Ident::new("source", span);
435438
let body = from_initializer(from_field, backtrace_field, &source_var);
436-
Some(quote_spanned! {span=>
437-
#[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)]
439+
let impl_impl = quote_spanned! {span=>
438440
#[automatically_derived]
439441
impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause {
440442
fn from(#source_var: #from) -> Self {
441443
#ty::#variant #body
442444
}
443445
}
446+
};
447+
Some(quote! {
448+
#[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)]
449+
#impl_impl
444450
})
445451
});
446452

tests/test_lints.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ use thiserror::Error;
44

55
pub use std::error::Error;
66

7+
#[test]
8+
fn test_allow_attributes() {
9+
#![deny(clippy::allow_attributes)]
10+
11+
#[derive(Error, Debug)]
12+
#[error("...")]
13+
pub struct MyError(#[from] anyhow::Error);
14+
15+
let _: MyError;
16+
}
17+
718
#[test]
819
fn test_unused_qualifications() {
920
#![deny(unused_qualifications)]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy