Skip to content

Commit 8ebc4e8

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 0d9ff25 commit 8ebc4e8

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
@@ -164,7 +164,10 @@ fn generate_unpin_impl(
164164
quote! {
165165
// This struct will be used for the unpin analysis. It is needed, because only structurally
166166
// pinned fields are relevant whether the struct should implement `Unpin`.
167-
#[allow(dead_code)] // The fields below are never used.
167+
#[allow(
168+
dead_code, // The fields below are never used.
169+
non_snake_case // The warning will be emitted on the struct definition.
170+
)]
168171
struct __Unpin #generics_with_pin_lt
169172
#where_token
170173
#predicates
@@ -300,7 +303,9 @@ fn generate_projections(
300303
let docs = format!(" Pin-projections of [`{ident}`]");
301304
quote! {
302305
#[doc = #docs]
303-
#[allow(dead_code)]
306+
// Allow `non_snake_case` since the same warning will be emitted on
307+
// the struct definition.
308+
#[allow(dead_code, non_snake_case)]
304309
#[doc(hidden)]
305310
#vis struct #projection #generics_with_pin_lt
306311
#whr
@@ -393,6 +398,9 @@ fn generate_the_pin_data(
393398
/// to deallocate.
394399
#pin_safety
395400
#(#attrs)*
401+
// Allow `non_snake_case` since the same warning will be emitted on
402+
// the struct definition.
403+
#[allow(non_snake_case)]
396404
#vis unsafe fn #ident<E>(
397405
self,
398406
slot: *mut #ty,

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
@@ -89,6 +89,7 @@ const _: () = {
8989
/// - `slot` is a valid pointer to uninitialized memory.
9090
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
9191
/// to deallocate.
92+
#[allow(non_snake_case)]
9293
unsafe fn array<E>(
9394
self,
9495
slot: *mut [u8; 1024 * 1024],
@@ -110,6 +111,7 @@ const _: () = {
110111
/// - `slot` is a valid pointer to uninitialized memory.
111112
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
112113
/// to deallocate.
114+
#[allow(non_snake_case)]
113115
unsafe fn r<E>(
114116
self,
115117
slot: *mut &'b mut [&'a mut T; SIZE],
@@ -132,6 +134,7 @@ const _: () = {
132134
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
133135
/// to deallocate.
134136
/// - `slot` will not move until it is dropped, i.e. it will be pinned.
137+
#[allow(non_snake_case)]
135138
unsafe fn _pin<E>(
136139
self,
137140
slot: *mut PhantomPinned,
@@ -176,7 +179,7 @@ const _: () = {
176179
{
177180
type Datee = Foo<'a, 'b, T, SIZE>;
178181
}
179-
#[allow(dead_code)]
182+
#[allow(dead_code, non_snake_case)]
180183
struct __Unpin<'__pin, 'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0>
181184
where
182185
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],
@@ -51,6 +51,7 @@ const _: () = {
5151
/// - `slot` is a valid pointer to uninitialized memory.
5252
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
5353
/// to deallocate.
54+
#[allow(non_snake_case)]
5455
unsafe fn array<E>(
5556
self,
5657
slot: *mut [u8; 1024 * 1024],
@@ -73,6 +74,7 @@ const _: () = {
7374
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
7475
/// to deallocate.
7576
/// - `slot` will not move until it is dropped, i.e. it will be pinned.
77+
#[allow(non_snake_case)]
7678
unsafe fn _pin<E>(
7779
self,
7880
slot: *mut PhantomPinned,
@@ -101,7 +103,7 @@ const _: () = {
101103
unsafe impl ::pin_init::__internal::PinData for __ThePinData {
102104
type Datee = Foo;
103105
}
104-
#[allow(dead_code)]
106+
#[allow(dead_code, non_snake_case)]
105107
struct __Unpin<'__pin> {
106108
__phantom_pin: ::core::marker::PhantomData<fn(&'__pin ()) -> &'__pin ()>,
107109
__phantom: ::core::marker::PhantomData<fn(Foo) -> 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],
@@ -51,6 +51,7 @@ const _: () = {
5151
/// - `slot` is a valid pointer to uninitialized memory.
5252
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
5353
/// to deallocate.
54+
#[allow(non_snake_case)]
5455
unsafe fn array<E>(
5556
self,
5657
slot: *mut [u8; 1024 * 1024],
@@ -73,6 +74,7 @@ const _: () = {
7374
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
7475
/// to deallocate.
7576
/// - `slot` will not move until it is dropped, i.e. it will be pinned.
77+
#[allow(non_snake_case)]
7678
unsafe fn _pin<E>(
7779
self,
7880
slot: *mut PhantomPinned,
@@ -101,7 +103,7 @@ const _: () = {
101103
unsafe impl ::pin_init::__internal::PinData for __ThePinData {
102104
type Datee = Foo;
103105
}
104-
#[allow(dead_code)]
106+
#[allow(dead_code, non_snake_case)]
105107
struct __Unpin<'__pin> {
106108
__phantom_pin: ::core::marker::PhantomData<fn(&'__pin ()) -> &'__pin ()>,
107109
__phantom: ::core::marker::PhantomData<fn(Foo) -> Foo>,

0 commit comments

Comments
 (0)