Skip to content

Commit 6699b73

Browse files
committed
pin_init: allow nonstandard_style for generated identifiers
Allows `nonstandard_style` lint on locally generated identifiers in `pin_init!`. Since the same warning will be reported by the compiler on the struct definition, having the extra warning emitted at the macro call site is unnecessary and confusing. Suggested-by: Gary Guo <gary@garyguo.net> Link: #125 Signed-off-by: Mirko Adzic <adzicmirko97@gmail.com>
1 parent d4e1179 commit 6699b73

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

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+
nonstandard_style // The warning will be emitted on the struct definition.
170+
)]
168171
struct __Unpin #generics_with_pin_lt
169172
#where_token
170173
#predicates
@@ -302,7 +305,9 @@ fn generate_projections(
302305
let docs = format!(" Pin-projections of [`{ident}`]");
303306
quote! {
304307
#[doc = #docs]
305-
#[allow(dead_code)]
308+
// Allow `nonstandard_style` since the same warning will be emitted on
309+
// the struct definition.
310+
#[allow(dead_code, nonstandard_style)]
306311
#[doc(hidden)]
307312
#vis struct #projection #generics_with_pin_lt {
308313
#(#fields_decl)*
@@ -395,6 +400,9 @@ fn generate_the_pin_data(
395400
/// to deallocate.
396401
#pin_safety
397402
#(#attrs)*
403+
// Allow `nonstandard_style` since the same warning will be emitted on
404+
// the struct definition.
405+
#[allow(nonstandard_style)]
398406
#vis unsafe fn #ident<E>(
399407
self,
400408
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, nonstandard_style)]
1717
#[doc(hidden)]
1818
struct FooProjection<
1919
'__pin,
@@ -92,6 +92,7 @@ const _: () = {
9292
/// - `slot` is a valid pointer to uninitialized memory.
9393
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
9494
/// to deallocate.
95+
#[allow(nonstandard_style)]
9596
unsafe fn array<E>(
9697
self,
9798
slot: *mut [u8; 1024 * 1024],
@@ -113,6 +114,7 @@ const _: () = {
113114
/// - `slot` is a valid pointer to uninitialized memory.
114115
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
115116
/// to deallocate.
117+
#[allow(nonstandard_style)]
116118
unsafe fn r<E>(
117119
self,
118120
slot: *mut &'b mut [&'a mut T; SIZE],
@@ -135,6 +137,7 @@ const _: () = {
135137
/// - the caller does not touch `slot` when `Err` is returned, they are only permitted
136138
/// to deallocate.
137139
/// - `slot` will not move until it is dropped, i.e. it will be pinned.
140+
#[allow(nonstandard_style)]
138141
unsafe fn _pin<E>(
139142
self,
140143
slot: *mut PhantomPinned,
@@ -179,7 +182,7 @@ const _: () = {
179182
{
180183
type Datee = Foo<'a, 'b, T, SIZE>;
181184
}
182-
#[allow(dead_code)]
185+
#[allow(dead_code, nonstandard_style)]
183186
struct __Unpin<'__pin, 'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0>
184187
where
185188
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, nonstandard_style)]
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(nonstandard_style)]
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(nonstandard_style)]
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, nonstandard_style)]
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, nonstandard_style)]
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(nonstandard_style)]
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(nonstandard_style)]
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, nonstandard_style)]
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)