Skip to content

Commit ca91108

Browse files
committed
Factor out construction of lint suppress attribute
1 parent 987f01c commit ca91108

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/expand.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use quote::{format_ident, quote, quote_spanned, ToTokens};
66
use syn::punctuated::Punctuated;
77
use syn::visit_mut::VisitMut;
88
use syn::{
9-
parse_quote, Block, FnArg, GenericParam, Generics, Ident, ImplItem, Lifetime, Pat, PatIdent,
10-
Receiver, ReturnType, Signature, Stmt, Token, TraitItem, Type, TypeParamBound, WhereClause,
9+
parse_quote, Attribute, Block, FnArg, GenericParam, Generics, Ident, ImplItem, Lifetime, Pat,
10+
PatIdent, Receiver, ReturnType, Signature, Stmt, Token, TraitItem, Type, TypeParamBound,
11+
WhereClause,
1112
};
1213

1314
macro_rules! parse_quote_spanned {
@@ -71,13 +72,9 @@ pub fn expand(input: &mut Item, is_local: bool) {
7172
if let Some(block) = block {
7273
has_self |= has_self_in_block(block);
7374
transform_block(sig, block);
74-
method
75-
.attrs
76-
.push(parse_quote!(#[allow(clippy::type_repetition_in_bounds, clippy::used_underscore_binding)]));
75+
method.attrs.push(lint_suppress_with_body());
7776
} else {
78-
method
79-
.attrs
80-
.push(parse_quote!(#[allow(clippy::type_repetition_in_bounds)]));
77+
method.attrs.push(lint_suppress_without_body());
8178
}
8279
let has_default = method.default.is_some();
8380
transform_sig(context, sig, has_self, has_default, is_local);
@@ -104,16 +101,29 @@ pub fn expand(input: &mut Item, is_local: bool) {
104101
let has_self = has_self_in_sig(sig) || has_self_in_block(block);
105102
transform_block(sig, block);
106103
transform_sig(context, sig, has_self, false, is_local);
107-
method
108-
.attrs
109-
.push(parse_quote!(#[allow(clippy::type_repetition_in_bounds, clippy::used_underscore_binding)]));
104+
method.attrs.push(lint_suppress_with_body());
110105
}
111106
}
112107
}
113108
}
114109
}
115110
}
116111

112+
fn lint_suppress_with_body() -> Attribute {
113+
parse_quote! {
114+
#[allow(
115+
clippy::type_repetition_in_bounds,
116+
clippy::used_underscore_binding
117+
)]
118+
}
119+
}
120+
121+
fn lint_suppress_without_body() -> Attribute {
122+
parse_quote! {
123+
#[allow(clippy::type_repetition_in_bounds)]
124+
}
125+
}
126+
117127
// Input:
118128
// async fn f<T>(&self, x: &T) -> Ret;
119129
//

0 commit comments

Comments
 (0)