Skip to content

Commit

Permalink
Documentation for variadics (#15387)
Browse files Browse the repository at this point in the history
# Objective

Relevant: #15208

## Solution

I went ahead and added the variadics documentation in all applicable
locations.

## Testing

- I built the documentation and inspected it to see whether the feature
is there.
  • Loading branch information
BenjaminBrienen authored Oct 2, 2024
1 parent 461305b commit c841dd9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
4 changes: 3 additions & 1 deletion crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
// `rustdoc_internals` is needed for `#[doc(fake_variadics)]`
#![allow(internal_features)]
#![cfg_attr(any(docsrs, docsrs_dep), feature(doc_auto_cfg, rustdoc_internals))]
#![forbid(unsafe_code)]
#![doc(
html_logo_url = "https://bevyengine.org/assets/icon.png",
Expand Down
12 changes: 10 additions & 2 deletions crates/bevy_app/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ mod sealed {
}

macro_rules! impl_plugins_tuples {
($(($param: ident, $plugins: ident)),*) => {
($(#[$meta:meta])* $(($param: ident, $plugins: ident)),*) => {
$(#[$meta])*
impl<$($param, $plugins),*> Plugins<(PluginsTupleMarker, $($param,)*)> for ($($plugins,)*)
where
$($plugins: Plugins<$param>),*
Expand All @@ -179,5 +180,12 @@ mod sealed {
}
}

all_tuples!(impl_plugins_tuples, 0, 15, P, S);
all_tuples!(
#[doc(fake_variadic)]
impl_plugins_tuples,
0,
15,
P,
S
);
}
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ macro_rules! tuple_impl {
}
}

$(#[$meta])*
impl<$($name: Bundle),*> DynamicBundle for ($($name,)*) {
#[allow(unused_variables, unused_mut)]
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,6 @@ pub struct AnyOf<T>(PhantomData<T>);

macro_rules! impl_tuple_query_data {
($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => {

#[allow(non_snake_case)]
#[allow(clippy::unused_unit)]
$(#[$meta])*
Expand All @@ -2023,6 +2022,7 @@ macro_rules! impl_tuple_query_data {
type ReadOnly = ($($name::ReadOnly,)*);
}

$(#[$meta])*
/// SAFETY: each item in the tuple is read only
unsafe impl<$($name: ReadOnlyQueryData),*> ReadOnlyQueryData for ($($name,)*) {}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@
//! [the language feature for dyn upcasting coercion]: https://github.com/rust-lang/rust/issues/65991
//! [derive macro]: derive@crate::Reflect
//! [`'static` lifetime]: https://doc.rust-lang.org/rust-by-example/scope/lifetime/static_lifetime.html#trait-bound
//! [`Function`]: func::Function
//! [`Function`]: crate::func::Function
//! [derive macro documentation]: derive@crate::Reflect
//! [deriving `Reflect`]: derive@crate::Reflect
//! [type data]: TypeData
Expand Down
34 changes: 28 additions & 6 deletions crates/bevy_reflect/src/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J,

macro_rules! impl_type_path_tuple {
($(#[$meta:meta])*) => {
$(#[$meta])*
impl TypePath for () {
fn type_path() -> &'static str {
"()"
Expand Down Expand Up @@ -737,29 +738,50 @@ all_tuples!(
#[cfg(feature = "functions")]
const _: () = {
macro_rules! impl_get_ownership_tuple {
($($name: ident),*) => {
($(#[$meta:meta])* $($name: ident),*) => {
$(#[$meta])*
$crate::func::args::impl_get_ownership!(($($name,)*); <$($name),*>);
};
}

all_tuples!(impl_get_ownership_tuple, 0, 12, P);
all_tuples!(
#[doc(fake_variadic)]
impl_get_ownership_tuple,
0,
12,
P
);

macro_rules! impl_from_arg_tuple {
($($name: ident),*) => {
($(#[$meta:meta])* $($name: ident),*) => {
$(#[$meta])*
$crate::func::args::impl_from_arg!(($($name,)*); <$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*>);
};
}

all_tuples!(impl_from_arg_tuple, 0, 12, P);
all_tuples!(
#[doc(fake_variadic)]
impl_from_arg_tuple,
0,
12,
P
);

macro_rules! impl_into_return_tuple {
($($name: ident),+) => {
($(#[$meta:meta])* $($name: ident),+) => {
$(#[$meta])*
$crate::func::impl_into_return!(($($name,)*); <$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*>);
};
}

// The unit type (i.e. `()`) is special-cased, so we skip implementing it here.
all_tuples!(impl_into_return_tuple, 1, 12, P);
all_tuples!(
#[doc(fake_variadic)]
impl_into_return_tuple,
1,
12,
P
);
};

#[cfg(test)]
Expand Down

0 comments on commit c841dd9

Please sign in to comment.