Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More #[doc(fake_variadic)] goodness #16108

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2030,8 +2030,8 @@ macro_rules! impl_tuple_query_data {
}

macro_rules! impl_anytuple_fetch {
($(($name: ident, $state: ident)),*) => {

($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => {
$(#[$meta])*
#[allow(non_snake_case)]
#[allow(clippy::unused_unit)]
/// SAFETY:
Expand Down Expand Up @@ -2153,13 +2153,15 @@ macro_rules! impl_anytuple_fetch {
}
}

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

$(#[$meta])*
/// SAFETY: each item in the tuple is read only
unsafe impl<$($name: ReadOnlyQueryData),*> ReadOnlyQueryData for AnyOf<($($name,)*)> {}
};
Expand All @@ -2173,7 +2175,14 @@ all_tuples!(
F,
S
);
all_tuples!(impl_anytuple_fetch, 0, 15, F, S);
all_tuples!(
#[doc(fake_variadic)]
impl_anytuple_fetch,
0,
15,
F,
S
);

/// [`WorldQuery`] used to nullify queries by turning `Query<D>` into `Query<NopWorldQuery<D>>`
///
Expand Down
24 changes: 20 additions & 4 deletions crates/bevy_ecs/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ impl<T: WorldQuery> Clone for OrFetch<'_, T> {
}

macro_rules! impl_or_query_filter {
($(($filter: ident, $state: ident)),*) => {
($(#[$meta:meta])* $(($filter: ident, $state: ident)),*) => {
$(#[$meta])*
#[allow(unused_variables)]
#[allow(non_snake_case)]
#[allow(clippy::unused_unit)]
Expand Down Expand Up @@ -497,6 +498,7 @@ macro_rules! impl_or_query_filter {
}
}

$(#[$meta])*
// SAFETY: This only performs access that subqueries perform, and they impl `QueryFilter` and so perform no mutable access.
unsafe impl<$($filter: QueryFilter),*> QueryFilter for Or<($($filter,)*)> {
const IS_ARCHETYPAL: bool = true $(&& $filter::IS_ARCHETYPAL)*;
Expand Down Expand Up @@ -546,7 +548,14 @@ all_tuples!(
15,
F
);
all_tuples!(impl_or_query_filter, 0, 15, F, S);
all_tuples!(
#[doc(fake_variadic)]
impl_or_query_filter,
0,
15,
F,
S
);

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

macro_rules! impl_archetype_or_filter_tuple {
($($filter: ident),*) => {
($(#[$meta:meta])* $($filter: ident),*) => {
$(#[$meta])*
impl<$($filter: ArchetypeFilter),*> ArchetypeFilter for Or<($($filter,)*)> {}
};
}
Expand All @@ -1057,4 +1067,10 @@ all_tuples!(
F
);

all_tuples!(impl_archetype_or_filter_tuple, 0, 15, F);
all_tuples!(
#[doc(fake_variadic)]
impl_archetype_or_filter_tuple,
0,
15,
F
);
11 changes: 9 additions & 2 deletions crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ pub struct SystemState<Param: SystemParam + 'static> {
// So, generate a function for each arity with an explicit `FnMut` constraint to enable higher-order lifetimes,
// along with a regular `SystemParamFunction` constraint to allow the system to be built.
macro_rules! impl_build_system {
($($param: ident),*) => {
($(#[$meta:meta])* $($param: ident),*) => {
$(#[$meta])*
impl<$($param: SystemParam),*> SystemState<($($param,)*)> {
/// Create a [`FunctionSystem`] from a [`SystemState`].
/// This method signature allows type inference of closure parameters for a system with no input.
Expand Down Expand Up @@ -344,7 +345,13 @@ macro_rules! impl_build_system {
}
}

all_tuples!(impl_build_system, 0, 16, P);
all_tuples!(
#[doc(fake_variadic)]
impl_build_system,
0,
16,
P
);

impl<Param: SystemParam> SystemState<Param> {
/// Creates a new [`SystemState`] with default state.
Expand Down
12 changes: 10 additions & 2 deletions crates/bevy_render/src/render_graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ pub trait IntoRenderNodeArray<const N: usize> {
}

macro_rules! impl_render_label_tuples {
($N: expr, $(($T: ident, $I: ident)),*) => {
($N: expr, $(#[$meta:meta])* $(($T: ident, $I: ident)),*) => {
$(#[$meta])*
impl<$($T: RenderLabel),*> IntoRenderNodeArray<$N> for ($($T,)*) {
#[inline]
fn into_array(self) -> [InternedRenderLabel; $N] {
Expand All @@ -47,7 +48,14 @@ macro_rules! impl_render_label_tuples {
}
}

all_tuples_with_size!(impl_render_label_tuples, 1, 32, T, l);
all_tuples_with_size!(
#[doc(fake_variadic)]
impl_render_label_tuples,
1,
32,
T,
l
);

/// A render node that can be added to a [`RenderGraph`](super::RenderGraph).
///
Expand Down
12 changes: 10 additions & 2 deletions crates/bevy_render/src/render_resource/bind_group_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ pub trait IntoBindingArray<'b, const N: usize> {
}

macro_rules! impl_to_binding_slice {
($N: expr, $(($T: ident, $I: ident)),*) => {
($N: expr, $(#[$meta:meta])* $(($T: ident, $I: ident)),*) => {
$(#[$meta])*
impl<'b, $($T: IntoBinding<'b>),*> IntoBindingArray<'b, $N> for ($($T,)*) {
#[inline]
fn into_array(self) -> [BindingResource<'b>; $N] {
Expand All @@ -191,7 +192,14 @@ macro_rules! impl_to_binding_slice {
}
}

all_tuples_with_size!(impl_to_binding_slice, 1, 32, T, s);
all_tuples_with_size!(
#[doc(fake_variadic)]
impl_to_binding_slice,
1,
32,
T,
s
);

pub trait IntoIndexedBindingArray<'b, const N: usize> {
fn into_array(self) -> [(u32, BindingResource<'b>); N];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ pub trait IntoBindGroupLayoutEntryBuilderArray<const N: usize> {
fn into_array(self) -> [BindGroupLayoutEntryBuilder; N];
}
macro_rules! impl_to_binding_type_slice {
($N: expr, $(($T: ident, $I: ident)),*) => {
($N: expr, $(#[$meta:meta])* $(($T: ident, $I: ident)),*) => {
$(#[$meta])*
impl<$($T: IntoBindGroupLayoutEntryBuilder),*> IntoBindGroupLayoutEntryBuilderArray<$N> for ($($T,)*) {
#[inline]
fn into_array(self) -> [BindGroupLayoutEntryBuilder; $N] {
Expand All @@ -252,7 +253,14 @@ macro_rules! impl_to_binding_type_slice {
}
}
}
all_tuples_with_size!(impl_to_binding_type_slice, 1, 32, T, s);
all_tuples_with_size!(
#[doc(fake_variadic)]
impl_to_binding_type_slice,
1,
32,
T,
s
);

pub trait IntoIndexedBindGroupLayoutEntryBuilderArray<const N: usize> {
fn into_array(self) -> [(u32, BindGroupLayoutEntryBuilder); N];
Expand Down
9 changes: 7 additions & 2 deletions crates/bevy_utils/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,14 @@ pub fn all_tuples_with_size(input: TokenStream) -> TokenStream {
}
let macro_ident = &input.macro_ident;
let invocations = (input.start..=input.end).map(|i| {
let ident_tuples = &ident_tuples[..i];
let ident_tuples = choose_ident_tuples(&input, &ident_tuples, i);
let attrs = if input.fake_variadic {
fake_variadic_attrs(len, i)
} else {
TokenStream2::default()
};
quote! {
#macro_ident!(#i, #(#ident_tuples),*);
#macro_ident!(#i, #attrs #ident_tuples);
}
});
TokenStream::from(quote! {
Expand Down