Skip to content

Commit 7c66b8a

Browse files
Mirko-Anbdd0121
authored andcommitted
internal: suppress non_snake_case lint in #[pin_data]
Allows `non_snake_case` lint on struct fields generated by `#[pin_data]`. Since the same warning will be reported by the compiler on the struct definition, having extra warnings for the generated code is unnecessary and confusing. Reported-by: Gary Guo <gary@garyguo.net> Link: #125 Closes: https://lore.kernel.org/rust-for-linux/DGTBJBIVFZ2K.2F1ZEFGY0G7NK@garyguo.net/ Fixes: db96c51 ("add references to previously initialized fields") Signed-off-by: Mirko Adzic <adzicmirko97@gmail.com>
1 parent d5ac5a8 commit 7c66b8a

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939

4040
- Corrected `T: Sized` bounds to `T: ?Sized` in the generated `PinnedDrop`
4141
check by `#[pin_data]`.
42+
- `#[pin_data]` no longer produces additional `non_snake_case` warnings if field names
43+
are not of snake case. Standard field definition warnings are unaffected.
4244

4345
## [0.0.10] - 2025-08-19
4446

internal/src/pin_data.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ fn generate_unpin_impl(
175175
quote! {
176176
// This struct will be used for the unpin analysis. It is needed, because only structurally
177177
// pinned fields are relevant whether the struct should implement `Unpin`.
178-
#[allow(dead_code)] // The fields below are never used.
178+
#[allow(
179+
dead_code, // The fields below are never used.
180+
non_snake_case // The warning will be emitted on the struct definition.
181+
)]
179182
struct __Unpin #generics_with_pin_lt
180183
#where_token
181184
#predicates
@@ -309,7 +312,9 @@ fn generate_projections(
309312
let docs = format!(" Pin-projections of [`{ident}`]");
310313
quote! {
311314
#[doc = #docs]
312-
#[allow(dead_code)]
315+
// Allow `non_snake_case` since the same warning will be emitted on
316+
// the struct definition.
317+
#[allow(dead_code, non_snake_case)]
313318
#[doc(hidden)]
314319
#vis struct #projection #generics_with_pin_lt
315320
#whr
@@ -382,6 +387,9 @@ fn generate_the_pin_data(
382387
/// - `(*slot).#field_name` points to uninitialized and exclusively accessed
383388
/// memory.
384389
#(#attrs)*
390+
// Allow `non_snake_case` since the same warning will be emitted on
391+
// the struct definition.
392+
#[allow(non_snake_case)]
385393
#[inline(always)]
386394
#vis unsafe fn #field_name(
387395
self,

tests/ui/expand/many_generics.expanded.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ where
1313
_pin: PhantomPinned,
1414
}
1515
/// Pin-projections of [`Foo`]
16-
#[allow(dead_code)]
16+
#[allow(dead_code, non_snake_case)]
1717
#[doc(hidden)]
1818
struct FooProjection<'__pin, 'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0>
1919
where
@@ -98,6 +98,7 @@ const _: () = {
9898
/// - `(*slot).#field_name` is properly aligned.
9999
/// - `(*slot).#field_name` points to uninitialized and exclusively accessed
100100
/// memory.
101+
#[allow(non_snake_case)]
101102
#[inline(always)]
102103
unsafe fn array(
103104
self,
@@ -114,6 +115,7 @@ const _: () = {
114115
/// - `(*slot).#field_name` is properly aligned.
115116
/// - `(*slot).#field_name` points to uninitialized and exclusively accessed
116117
/// memory.
118+
#[allow(non_snake_case)]
117119
#[inline(always)]
118120
unsafe fn r(
119121
self,
@@ -130,6 +132,7 @@ const _: () = {
130132
/// - `(*slot).#field_name` is properly aligned.
131133
/// - `(*slot).#field_name` points to uninitialized and exclusively accessed
132134
/// memory.
135+
#[allow(non_snake_case)]
133136
#[inline(always)]
134137
unsafe fn _pin(
135138
self,
@@ -157,7 +160,7 @@ const _: () = {
157160
}
158161
}
159162
}
160-
#[allow(dead_code)]
163+
#[allow(dead_code, non_snake_case)]
161164
struct __Unpin<'__pin, 'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0>
162165
where
163166
T: Bar<'a, 1>,

tests/ui/expand/pin-data.expanded.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct Foo {
55
_pin: PhantomPinned,
66
}
77
/// Pin-projections of [`Foo`]
8-
#[allow(dead_code)]
8+
#[allow(dead_code, non_snake_case)]
99
#[doc(hidden)]
1010
struct FooProjection<'__pin> {
1111
array: &'__pin mut [u8; 1024 * 1024],
@@ -62,6 +62,7 @@ const _: () = {
6262
/// - `(*slot).#field_name` is properly aligned.
6363
/// - `(*slot).#field_name` points to uninitialized and exclusively accessed
6464
/// memory.
65+
#[allow(non_snake_case)]
6566
#[inline(always)]
6667
unsafe fn array(
6768
self,
@@ -78,6 +79,7 @@ const _: () = {
7879
/// - `(*slot).#field_name` is properly aligned.
7980
/// - `(*slot).#field_name` points to uninitialized and exclusively accessed
8081
/// memory.
82+
#[allow(non_snake_case)]
8183
#[inline(always)]
8284
unsafe fn _pin(
8385
self,
@@ -97,7 +99,7 @@ const _: () = {
9799
}
98100
}
99101
}
100-
#[allow(dead_code)]
102+
#[allow(dead_code, non_snake_case)]
101103
struct __Unpin<'__pin> {
102104
__phantom_pin: ::pin_init::__internal::PhantomInvariantLifetime<'__pin>,
103105
__phantom: ::pin_init::__internal::PhantomInvariant<Foo>,

tests/ui/expand/pinned_drop.expanded.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct Foo {
55
_pin: PhantomPinned,
66
}
77
/// Pin-projections of [`Foo`]
8-
#[allow(dead_code)]
8+
#[allow(dead_code, non_snake_case)]
99
#[doc(hidden)]
1010
struct FooProjection<'__pin> {
1111
array: &'__pin mut [u8; 1024 * 1024],
@@ -62,6 +62,7 @@ const _: () = {
6262
/// - `(*slot).#field_name` is properly aligned.
6363
/// - `(*slot).#field_name` points to uninitialized and exclusively accessed
6464
/// memory.
65+
#[allow(non_snake_case)]
6566
#[inline(always)]
6667
unsafe fn array(
6768
self,
@@ -78,6 +79,7 @@ const _: () = {
7879
/// - `(*slot).#field_name` is properly aligned.
7980
/// - `(*slot).#field_name` points to uninitialized and exclusively accessed
8081
/// memory.
82+
#[allow(non_snake_case)]
8183
#[inline(always)]
8284
unsafe fn _pin(
8385
self,
@@ -97,7 +99,7 @@ const _: () = {
9799
}
98100
}
99101
}
100-
#[allow(dead_code)]
102+
#[allow(dead_code, non_snake_case)]
101103
struct __Unpin<'__pin> {
102104
__phantom_pin: ::pin_init::__internal::PhantomInvariantLifetime<'__pin>,
103105
__phantom: ::pin_init::__internal::PhantomInvariant<Foo>,

0 commit comments

Comments
 (0)