Skip to content

Commit 2fb3d56

Browse files
committed
Suppress various lints in generated code
1 parent 3fa6e92 commit 2fb3d56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1538
-1121
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
1212

1313
## [Unreleased]
1414

15+
- Suppress `unnameable_types`, `clippy::absolute_paths`, `clippy::min_ident_chars`, `clippy::pub_with_shorthand`, `clippy::single_call_fn`, `clippy::single_char_lifetime_names` lints in generated code.
16+
1517
## [1.1.7] - 2024-10-24
1618

1719
- Work around an issue on negative_impls that allows unsound overlapping `Unpin` implementations. ([#357](https://github.com/taiki-e/pin-project/pull/357))

pin-project-internal/src/pin_project/derive.rs

+47-38
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ impl GenerateTokens {
8686
// - https://github.com/rust-lang/rust/issues/63281
8787
// - https://github.com/taiki-e/pin-project/pull/53#issuecomment-525906867
8888
// - https://github.com/taiki-e/pin-project/pull/70
89-
#allowed_lints
90-
#[allow(unused_qualifications)]
91-
#[allow(clippy::needless_lifetimes)]
92-
#[allow(clippy::semicolon_if_nothing_returned)]
93-
#[allow(clippy::use_self)]
94-
#[allow(clippy::used_underscore_binding)]
89+
#[allow(
90+
unused_qualifications,
91+
#allowed_lints
92+
clippy::needless_lifetimes,
93+
clippy::semicolon_if_nothing_returned,
94+
clippy::use_self,
95+
clippy::used_underscore_binding
96+
)]
9597
const _: () = {
9698
#[allow(unused_extern_crates)]
9799
extern crate pin_project as _pin_project;
@@ -107,52 +109,59 @@ impl GenerateTokens {
107109
/// Returns attributes that should be applied to all generated code.
108110
fn global_allowed_lints() -> TokenStream {
109111
quote! {
110-
#[allow(deprecated)]
111-
#[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993
112-
#[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058
113-
#[allow(unreachable_pub)] // This lint warns `pub` field in private struct.
114-
#[allow(unused_tuple_struct_fields)]
112+
deprecated,
113+
explicit_outlives_requirements, // https://github.com/rust-lang/rust/issues/60993
114+
single_use_lifetimes, // https://github.com/rust-lang/rust/issues/55058
115+
unreachable_pub, // This lint warns `pub` field in private struct.
116+
unused_tuple_struct_fields,
115117
// This lint warns of `clippy::*` generated by external macros.
116118
// We allow this lint for compatibility with older compilers.
117-
#[allow(clippy::unknown_clippy_lints)]
118-
#[allow(clippy::pattern_type_mismatch)]
119-
#[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct.
120-
#[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326
119+
clippy::unknown_clippy_lints,
120+
clippy::absolute_paths,
121+
clippy::min_ident_chars,
122+
clippy::pattern_type_mismatch,
123+
clippy::pub_with_shorthand,
124+
clippy::redundant_pub_crate, // This lint warns `pub(crate)` field in private struct.
125+
clippy::single_char_lifetime_names,
126+
clippy::type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/4326
121127
}
122128
}
123129

124130
/// Returns attributes used on projected types.
125131
fn proj_allowed_lints(cx: &Context<'_>) -> (TokenStream, TokenStream, TokenStream) {
126-
let large_enum_variant = if cx.kind == Enum {
127-
Some(quote! {
128-
#[allow(variant_size_differences)]
129-
#[allow(clippy::large_enum_variant)]
130-
})
131-
} else {
132-
None
133-
};
134132
let global_allowed_lints = global_allowed_lints();
135133
let proj_mut_allowed_lints = if cx.project { Some(&global_allowed_lints) } else { None };
136134
let proj_mut = quote! {
137-
#proj_mut_allowed_lints
138-
#[allow(dead_code)] // This lint warns unused fields/variants.
139-
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
140-
#[allow(clippy::missing_docs_in_private_items)]
135+
#[allow(
136+
dead_code, // This lint warns unused fields/variants.
137+
#proj_mut_allowed_lints
138+
clippy::missing_docs_in_private_items,
139+
clippy::mut_mut // This lint warns `&mut &mut <ty>`.
140+
)]
141141
};
142142
let proj_ref_allowed_lints = if cx.project_ref { Some(&global_allowed_lints) } else { None };
143143
let proj_ref = quote! {
144-
#proj_ref_allowed_lints
145-
#[allow(dead_code)] // This lint warns unused fields/variants.
146-
#[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`.
147-
#[allow(clippy::missing_docs_in_private_items)]
144+
#[allow(
145+
dead_code, // This lint warns unused fields/variants.
146+
#proj_ref_allowed_lints
147+
clippy::missing_docs_in_private_items,
148+
clippy::ref_option_ref // This lint warns `&Option<&<ty>>`.
149+
)]
148150
};
149151
let proj_own_allowed_lints =
150152
if cx.project_replace.ident().is_some() { Some(&global_allowed_lints) } else { None };
153+
let variant_size_differences = if cx.kind == Enum {
154+
Some(quote! { variant_size_differences, clippy::large_enum_variant, })
155+
} else {
156+
None
157+
};
151158
let proj_own = quote! {
152-
#proj_own_allowed_lints
153-
#[allow(dead_code)] // This lint warns unused fields/variants.
154-
#[allow(clippy::missing_docs_in_private_items)]
155-
#large_enum_variant
159+
#[allow(
160+
dead_code, // This lint warns unused fields/variants.
161+
#proj_own_allowed_lints
162+
#variant_size_differences
163+
clippy::missing_docs_in_private_items
164+
)]
156165
};
157166
(proj_mut, proj_ref, proj_own)
158167
}
@@ -808,7 +817,7 @@ fn make_unpin_impl(cx: &Context<'_>) -> TokenStream {
808817
// `__UnpinStruct` type must also be public.
809818
// However, we ensure that the user can never actually reference
810819
// this 'public' type by creating this type in the inside of `const`.
811-
#[allow(missing_debug_implementations)]
820+
#[allow(missing_debug_implementations, unnameable_types)]
812821
#vis struct #struct_ident #proj_generics #ty_where_clause {
813822
__pin_project_use_generics: _pin_project::__private::AlwaysUnpin<
814823
#lifetime, (#(_pin_project::__private::PhantomData<#type_params>),*)
@@ -975,14 +984,14 @@ fn make_proj_impl(
975984
let mut project_replace = cx.project_replace.span().map(|span| {
976985
// It is enough to only set the span of the signature.
977986
let sig = quote_spanned! { span =>
978-
#allow_dead_code
979-
#[inline]
980987
#vis fn project_replace(
981988
self: _pin_project::__private::Pin<&mut Self>,
982989
__replacement: Self,
983990
) -> #proj_own_ident #orig_ty_generics
984991
};
985992
quote! {
993+
#allow_dead_code
994+
#[inline]
986995
#sig {
987996
unsafe {
988997
let __self_ptr: *mut Self = self.get_unchecked_mut();

pin-project-internal/src/pinned_drop.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ pub(crate) fn attribute(args: &TokenStream, mut input: ItemImpl) -> TokenStream
4747
}
4848
tokens
4949
} else {
50-
input.attrs.push(parse_quote!(#[allow(unused_qualifications)])); // https://github.com/rust-lang/rust/issues/122519
50+
input.attrs.push(parse_quote!(#[allow(
51+
unused_qualifications, // https://github.com/rust-lang/rust/issues/122519
52+
// This lint warns of `clippy::*` generated by external macros.
53+
// We allow this lint for compatibility with older compilers.
54+
clippy::unknown_clippy_lints,
55+
clippy::absolute_paths
56+
)]));
5157
input.into_token_stream()
5258
}
5359
}
@@ -198,6 +204,7 @@ fn expand_impl(item: &mut ItemImpl) {
198204
let ident = format_ident!("__drop_inner");
199205
// Add a dummy `__drop_inner` function to prevent users call outer `__drop_inner`.
200206
drop_inner.block.stmts.insert(0, parse_quote!(fn #ident() {}));
207+
drop_inner.attrs.push(parse_quote!(#[allow(clippy::single_call_fn)]));
201208
drop_inner.sig.ident = ident;
202209
drop_inner.sig.generics = item.generics.clone();
203210
let receiver = drop_inner.sig.receiver().expect("drop() should have a receiver").clone();

tests/expand/default/enum.expanded.rs

+57-39
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ enum Enum<T, U> {
55
Tuple(#[pin] T, U),
66
Unit,
77
}
8-
#[allow(deprecated)]
9-
#[allow(explicit_outlives_requirements)]
10-
#[allow(single_use_lifetimes)]
11-
#[allow(unreachable_pub)]
12-
#[allow(unused_tuple_struct_fields)]
13-
#[allow(clippy::unknown_clippy_lints)]
14-
#[allow(clippy::pattern_type_mismatch)]
15-
#[allow(clippy::redundant_pub_crate)]
16-
#[allow(clippy::type_repetition_in_bounds)]
17-
#[allow(dead_code)]
18-
#[allow(clippy::mut_mut)]
19-
#[allow(clippy::missing_docs_in_private_items)]
8+
#[allow(
9+
dead_code,
10+
deprecated,
11+
explicit_outlives_requirements,
12+
single_use_lifetimes,
13+
unreachable_pub,
14+
unused_tuple_struct_fields,
15+
clippy::unknown_clippy_lints,
16+
clippy::absolute_paths,
17+
clippy::min_ident_chars,
18+
clippy::pattern_type_mismatch,
19+
clippy::pub_with_shorthand,
20+
clippy::redundant_pub_crate,
21+
clippy::single_char_lifetime_names,
22+
clippy::type_repetition_in_bounds,
23+
clippy::missing_docs_in_private_items,
24+
clippy::mut_mut
25+
)]
2026
enum EnumProj<'pin, T, U>
2127
where
2228
Enum<T, U>: 'pin,
@@ -28,18 +34,24 @@ where
2834
Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)),
2935
Unit,
3036
}
31-
#[allow(deprecated)]
32-
#[allow(explicit_outlives_requirements)]
33-
#[allow(single_use_lifetimes)]
34-
#[allow(unreachable_pub)]
35-
#[allow(unused_tuple_struct_fields)]
36-
#[allow(clippy::unknown_clippy_lints)]
37-
#[allow(clippy::pattern_type_mismatch)]
38-
#[allow(clippy::redundant_pub_crate)]
39-
#[allow(clippy::type_repetition_in_bounds)]
40-
#[allow(dead_code)]
41-
#[allow(clippy::ref_option_ref)]
42-
#[allow(clippy::missing_docs_in_private_items)]
37+
#[allow(
38+
dead_code,
39+
deprecated,
40+
explicit_outlives_requirements,
41+
single_use_lifetimes,
42+
unreachable_pub,
43+
unused_tuple_struct_fields,
44+
clippy::unknown_clippy_lints,
45+
clippy::absolute_paths,
46+
clippy::min_ident_chars,
47+
clippy::pattern_type_mismatch,
48+
clippy::pub_with_shorthand,
49+
clippy::redundant_pub_crate,
50+
clippy::single_char_lifetime_names,
51+
clippy::type_repetition_in_bounds,
52+
clippy::missing_docs_in_private_items,
53+
clippy::ref_option_ref
54+
)]
4355
enum EnumProjRef<'pin, T, U>
4456
where
4557
Enum<T, U>: 'pin,
@@ -48,20 +60,26 @@ where
4860
Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)),
4961
Unit,
5062
}
51-
#[allow(deprecated)]
52-
#[allow(explicit_outlives_requirements)]
53-
#[allow(single_use_lifetimes)]
54-
#[allow(unreachable_pub)]
55-
#[allow(unused_tuple_struct_fields)]
56-
#[allow(clippy::unknown_clippy_lints)]
57-
#[allow(clippy::pattern_type_mismatch)]
58-
#[allow(clippy::redundant_pub_crate)]
59-
#[allow(clippy::type_repetition_in_bounds)]
60-
#[allow(unused_qualifications)]
61-
#[allow(clippy::needless_lifetimes)]
62-
#[allow(clippy::semicolon_if_nothing_returned)]
63-
#[allow(clippy::use_self)]
64-
#[allow(clippy::used_underscore_binding)]
63+
#[allow(
64+
unused_qualifications,
65+
deprecated,
66+
explicit_outlives_requirements,
67+
single_use_lifetimes,
68+
unreachable_pub,
69+
unused_tuple_struct_fields,
70+
clippy::unknown_clippy_lints,
71+
clippy::absolute_paths,
72+
clippy::min_ident_chars,
73+
clippy::pattern_type_mismatch,
74+
clippy::pub_with_shorthand,
75+
clippy::redundant_pub_crate,
76+
clippy::single_char_lifetime_names,
77+
clippy::type_repetition_in_bounds,
78+
clippy::needless_lifetimes,
79+
clippy::semicolon_if_nothing_returned,
80+
clippy::use_self,
81+
clippy::used_underscore_binding
82+
)]
6583
const _: () = {
6684
#[allow(unused_extern_crates)]
6785
extern crate pin_project as _pin_project;
@@ -114,7 +132,7 @@ const _: () = {
114132
}
115133
}
116134
}
117-
#[allow(missing_debug_implementations)]
135+
#[allow(missing_debug_implementations, unnameable_types)]
118136
struct __Enum<'pin, T, U> {
119137
__pin_project_use_generics: _pin_project::__private::AlwaysUnpin<
120138
'pin,

tests/expand/default/struct.expanded.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,38 @@ struct Struct<T, U> {
55
pinned: T,
66
unpinned: U,
77
}
8-
#[allow(deprecated)]
9-
#[allow(explicit_outlives_requirements)]
10-
#[allow(single_use_lifetimes)]
11-
#[allow(unreachable_pub)]
12-
#[allow(unused_tuple_struct_fields)]
13-
#[allow(clippy::unknown_clippy_lints)]
14-
#[allow(clippy::pattern_type_mismatch)]
15-
#[allow(clippy::redundant_pub_crate)]
16-
#[allow(clippy::type_repetition_in_bounds)]
17-
#[allow(unused_qualifications)]
18-
#[allow(clippy::needless_lifetimes)]
19-
#[allow(clippy::semicolon_if_nothing_returned)]
20-
#[allow(clippy::use_self)]
21-
#[allow(clippy::used_underscore_binding)]
8+
#[allow(
9+
unused_qualifications,
10+
deprecated,
11+
explicit_outlives_requirements,
12+
single_use_lifetimes,
13+
unreachable_pub,
14+
unused_tuple_struct_fields,
15+
clippy::unknown_clippy_lints,
16+
clippy::absolute_paths,
17+
clippy::min_ident_chars,
18+
clippy::pattern_type_mismatch,
19+
clippy::pub_with_shorthand,
20+
clippy::redundant_pub_crate,
21+
clippy::single_char_lifetime_names,
22+
clippy::type_repetition_in_bounds,
23+
clippy::needless_lifetimes,
24+
clippy::semicolon_if_nothing_returned,
25+
clippy::use_self,
26+
clippy::used_underscore_binding
27+
)]
2228
const _: () = {
2329
#[allow(unused_extern_crates)]
2430
extern crate pin_project as _pin_project;
25-
#[allow(dead_code)]
26-
#[allow(clippy::mut_mut)]
27-
#[allow(clippy::missing_docs_in_private_items)]
31+
#[allow(dead_code, clippy::missing_docs_in_private_items, clippy::mut_mut)]
2832
struct __StructProjection<'pin, T, U>
2933
where
3034
Struct<T, U>: 'pin,
3135
{
3236
pinned: ::pin_project::__private::Pin<&'pin mut (T)>,
3337
unpinned: &'pin mut (U),
3438
}
35-
#[allow(dead_code)]
36-
#[allow(clippy::ref_option_ref)]
37-
#[allow(clippy::missing_docs_in_private_items)]
39+
#[allow(dead_code, clippy::missing_docs_in_private_items, clippy::ref_option_ref)]
3840
struct __StructProjectionRef<'pin, T, U>
3941
where
4042
Struct<T, U>: 'pin,
@@ -76,7 +78,7 @@ const _: () = {
7678
let _ = &this.pinned;
7779
let _ = &this.unpinned;
7880
}
79-
#[allow(missing_debug_implementations)]
81+
#[allow(missing_debug_implementations, unnameable_types)]
8082
struct __Struct<'pin, T, U> {
8183
__pin_project_use_generics: _pin_project::__private::AlwaysUnpin<
8284
'pin,

0 commit comments

Comments
 (0)