Skip to content

Commit 1aac231

Browse files
bashmockersf
authored andcommitted
More #[doc(fake_variadic)] goodness (#16108)
This PR adds `#[doc(fake_variadic)]` to that were previously not supported by rustdoc. Thanks to an [upstream contribution](rust-lang/rust#132115) by yours truly, `#[doc(fake_variadic)]` is now supported on impls such as `impl QueryData for AnyOf<(T, ...)>` 🎉 Requires the latest nightly compiler (2024-10-25) which is already available on [docs.rs](https://docs.rs/about/builds). ![image](https://github.com/user-attachments/assets/68589c7e-f68f-44fb-9a7b-09d24ccf19c9) ![image](https://github.com/user-attachments/assets/f09d20d6-d89b-471b-9a81-4a72c8968178) This means that the impl sections for `QueryData` and `QueryFilter` are now nice and tidy ✨ --- I also added `fake_variadic` to some impls that use `all_tuples_with_size`, however I'm not entirely happy because the docs are slightly misleading now: ![image](https://github.com/user-attachments/assets/fac93d08-dc02-430f-9f34-c97456256c56) Note that the docs say `IntoBindGroupLayoutEntryBuilderArray<1>` instead of `IntoBindGroupLayoutEntryBuilderArray<N>`.
1 parent 3c0aca0 commit 1aac231

File tree

7 files changed

+78
-17
lines changed

7 files changed

+78
-17
lines changed

crates/bevy_ecs/src/query/fetch.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -2030,8 +2030,8 @@ macro_rules! impl_tuple_query_data {
20302030
}
20312031

20322032
macro_rules! impl_anytuple_fetch {
2033-
($(($name: ident, $state: ident)),*) => {
2034-
2033+
($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => {
2034+
$(#[$meta])*
20352035
#[allow(non_snake_case)]
20362036
#[allow(clippy::unused_unit)]
20372037
/// SAFETY:
@@ -2153,13 +2153,15 @@ macro_rules! impl_anytuple_fetch {
21532153
}
21542154
}
21552155

2156+
$(#[$meta])*
21562157
#[allow(non_snake_case)]
21572158
#[allow(clippy::unused_unit)]
21582159
// SAFETY: defers to soundness of `$name: WorldQuery` impl
21592160
unsafe impl<$($name: QueryData),*> QueryData for AnyOf<($($name,)*)> {
21602161
type ReadOnly = AnyOf<($($name::ReadOnly,)*)>;
21612162
}
21622163

2164+
$(#[$meta])*
21632165
/// SAFETY: each item in the tuple is read only
21642166
unsafe impl<$($name: ReadOnlyQueryData),*> ReadOnlyQueryData for AnyOf<($($name,)*)> {}
21652167
};
@@ -2173,7 +2175,14 @@ all_tuples!(
21732175
F,
21742176
S
21752177
);
2176-
all_tuples!(impl_anytuple_fetch, 0, 15, F, S);
2178+
all_tuples!(
2179+
#[doc(fake_variadic)]
2180+
impl_anytuple_fetch,
2181+
0,
2182+
15,
2183+
F,
2184+
S
2185+
);
21772186

21782187
/// [`WorldQuery`] used to nullify queries by turning `Query<D>` into `Query<NopWorldQuery<D>>`
21792188
///

crates/bevy_ecs/src/query/filter.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ impl<T: WorldQuery> Clone for OrFetch<'_, T> {
379379
}
380380

381381
macro_rules! impl_or_query_filter {
382-
($(($filter: ident, $state: ident)),*) => {
382+
($(#[$meta:meta])* $(($filter: ident, $state: ident)),*) => {
383+
$(#[$meta])*
383384
#[allow(unused_variables)]
384385
#[allow(non_snake_case)]
385386
#[allow(clippy::unused_unit)]
@@ -497,6 +498,7 @@ macro_rules! impl_or_query_filter {
497498
}
498499
}
499500

501+
$(#[$meta])*
500502
// SAFETY: This only performs access that subqueries perform, and they impl `QueryFilter` and so perform no mutable access.
501503
unsafe impl<$($filter: QueryFilter),*> QueryFilter for Or<($($filter,)*)> {
502504
const IS_ARCHETYPAL: bool = true $(&& $filter::IS_ARCHETYPAL)*;
@@ -546,7 +548,14 @@ all_tuples!(
546548
15,
547549
F
548550
);
549-
all_tuples!(impl_or_query_filter, 0, 15, F, S);
551+
all_tuples!(
552+
#[doc(fake_variadic)]
553+
impl_or_query_filter,
554+
0,
555+
15,
556+
F,
557+
S
558+
);
550559

551560
/// A filter on a component that only retains results the first time after they have been added.
552561
///
@@ -1044,7 +1053,8 @@ macro_rules! impl_archetype_filter_tuple {
10441053
}
10451054

10461055
macro_rules! impl_archetype_or_filter_tuple {
1047-
($($filter: ident),*) => {
1056+
($(#[$meta:meta])* $($filter: ident),*) => {
1057+
$(#[$meta])*
10481058
impl<$($filter: ArchetypeFilter),*> ArchetypeFilter for Or<($($filter,)*)> {}
10491059
};
10501060
}
@@ -1057,4 +1067,10 @@ all_tuples!(
10571067
F
10581068
);
10591069

1060-
all_tuples!(impl_archetype_or_filter_tuple, 0, 15, F);
1070+
all_tuples!(
1071+
#[doc(fake_variadic)]
1072+
impl_archetype_or_filter_tuple,
1073+
0,
1074+
15,
1075+
F
1076+
);

crates/bevy_ecs/src/system/function_system.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ pub struct SystemState<Param: SystemParam + 'static> {
306306
// So, generate a function for each arity with an explicit `FnMut` constraint to enable higher-order lifetimes,
307307
// along with a regular `SystemParamFunction` constraint to allow the system to be built.
308308
macro_rules! impl_build_system {
309-
($($param: ident),*) => {
309+
($(#[$meta:meta])* $($param: ident),*) => {
310+
$(#[$meta])*
310311
impl<$($param: SystemParam),*> SystemState<($($param,)*)> {
311312
/// Create a [`FunctionSystem`] from a [`SystemState`].
312313
/// This method signature allows type inference of closure parameters for a system with no input.
@@ -344,7 +345,13 @@ macro_rules! impl_build_system {
344345
}
345346
}
346347

347-
all_tuples!(impl_build_system, 0, 16, P);
348+
all_tuples!(
349+
#[doc(fake_variadic)]
350+
impl_build_system,
351+
0,
352+
16,
353+
P
354+
);
348355

349356
impl<Param: SystemParam> SystemState<Param> {
350357
/// Creates a new [`SystemState`] with default state.

crates/bevy_render/src/render_graph/node.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pub trait IntoRenderNodeArray<const N: usize> {
3636
}
3737

3838
macro_rules! impl_render_label_tuples {
39-
($N: expr, $(($T: ident, $I: ident)),*) => {
39+
($N: expr, $(#[$meta:meta])* $(($T: ident, $I: ident)),*) => {
40+
$(#[$meta])*
4041
impl<$($T: RenderLabel),*> IntoRenderNodeArray<$N> for ($($T,)*) {
4142
#[inline]
4243
fn into_array(self) -> [InternedRenderLabel; $N] {
@@ -47,7 +48,14 @@ macro_rules! impl_render_label_tuples {
4748
}
4849
}
4950

50-
all_tuples_with_size!(impl_render_label_tuples, 1, 32, T, l);
51+
all_tuples_with_size!(
52+
#[doc(fake_variadic)]
53+
impl_render_label_tuples,
54+
1,
55+
32,
56+
T,
57+
l
58+
);
5159

5260
/// A render node that can be added to a [`RenderGraph`](super::RenderGraph).
5361
///

crates/bevy_render/src/render_resource/bind_group_entries.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ pub trait IntoBindingArray<'b, const N: usize> {
180180
}
181181

182182
macro_rules! impl_to_binding_slice {
183-
($N: expr, $(($T: ident, $I: ident)),*) => {
183+
($N: expr, $(#[$meta:meta])* $(($T: ident, $I: ident)),*) => {
184+
$(#[$meta])*
184185
impl<'b, $($T: IntoBinding<'b>),*> IntoBindingArray<'b, $N> for ($($T,)*) {
185186
#[inline]
186187
fn into_array(self) -> [BindingResource<'b>; $N] {
@@ -191,7 +192,14 @@ macro_rules! impl_to_binding_slice {
191192
}
192193
}
193194

194-
all_tuples_with_size!(impl_to_binding_slice, 1, 32, T, s);
195+
all_tuples_with_size!(
196+
#[doc(fake_variadic)]
197+
impl_to_binding_slice,
198+
1,
199+
32,
200+
T,
201+
s
202+
);
195203

196204
pub trait IntoIndexedBindingArray<'b, const N: usize> {
197205
fn into_array(self) -> [(u32, BindingResource<'b>); N];

crates/bevy_render/src/render_resource/bind_group_layout_entries.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ pub trait IntoBindGroupLayoutEntryBuilderArray<const N: usize> {
242242
fn into_array(self) -> [BindGroupLayoutEntryBuilder; N];
243243
}
244244
macro_rules! impl_to_binding_type_slice {
245-
($N: expr, $(($T: ident, $I: ident)),*) => {
245+
($N: expr, $(#[$meta:meta])* $(($T: ident, $I: ident)),*) => {
246+
$(#[$meta])*
246247
impl<$($T: IntoBindGroupLayoutEntryBuilder),*> IntoBindGroupLayoutEntryBuilderArray<$N> for ($($T,)*) {
247248
#[inline]
248249
fn into_array(self) -> [BindGroupLayoutEntryBuilder; $N] {
@@ -252,7 +253,14 @@ macro_rules! impl_to_binding_type_slice {
252253
}
253254
}
254255
}
255-
all_tuples_with_size!(impl_to_binding_type_slice, 1, 32, T, s);
256+
all_tuples_with_size!(
257+
#[doc(fake_variadic)]
258+
impl_to_binding_type_slice,
259+
1,
260+
32,
261+
T,
262+
s
263+
);
256264

257265
pub trait IntoIndexedBindGroupLayoutEntryBuilderArray<const N: usize> {
258266
fn into_array(self) -> [(u32, BindGroupLayoutEntryBuilder); N];

crates/bevy_utils/macros/src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,14 @@ pub fn all_tuples_with_size(input: TokenStream) -> TokenStream {
315315
}
316316
let macro_ident = &input.macro_ident;
317317
let invocations = (input.start..=input.end).map(|i| {
318-
let ident_tuples = &ident_tuples[..i];
318+
let ident_tuples = choose_ident_tuples(&input, &ident_tuples, i);
319+
let attrs = if input.fake_variadic {
320+
fake_variadic_attrs(len, i)
321+
} else {
322+
TokenStream2::default()
323+
};
319324
quote! {
320-
#macro_ident!(#i, #(#ident_tuples),*);
325+
#macro_ident!(#i, #attrs #ident_tuples);
321326
}
322327
});
323328
TokenStream::from(quote! {

0 commit comments

Comments
 (0)