Skip to content

Commit

Permalink
Interpolate WorldQuery path in docs of generated types (#14985)
Browse files Browse the repository at this point in the history
# Objective

Fixes #14972

## Solution

Uses the `concat!` macro to interpolate the `path` variable.

## Testing

* Run `cargo doc --workspace --open`
* Check functionality of `WorldQuery` links within `NodeQueryItem`,
`NodeQueryReadOnly`, `NodeQueryReadOnlyItem` docs
  • Loading branch information
no-materials authored Sep 1, 2024
1 parent 4147422 commit 3a8d559
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
20 changes: 14 additions & 6 deletions crates/bevy_ecs/macros/src/query_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,13 @@ pub fn derive_query_data_impl(input: TokenStream) -> TokenStream {
user_where_clauses_with_world,
);
let read_only_structs = quote! {
#[doc = "Automatically generated [`WorldQuery`] type for a read-only variant of [`"]
#[doc = stringify!(#struct_name)]
#[doc = "`]."]
#[doc = concat!(
"Automatically generated [`WorldQuery`](",
stringify!(#path),
"::query::WorldQuery) type for a read-only variant of [`",
stringify!(#struct_name),
"`]."
)]
#[automatically_derived]
#visibility struct #read_only_struct_name #user_impl_generics #user_where_clauses {
#(
Expand Down Expand Up @@ -331,9 +335,13 @@ pub fn derive_query_data_impl(input: TokenStream) -> TokenStream {

const _: () = {
#[doc(hidden)]
#[doc = "Automatically generated internal [`WorldQuery`] state type for [`"]
#[doc = stringify!(#struct_name)]
#[doc = "`], used for caching."]
#[doc = concat!(
"Automatically generated internal [`WorldQuery`](",
stringify!(#path),
"::query::WorldQuery) state type for [`",
stringify!(#struct_name),
"`], used for caching."
)]
#[automatically_derived]
#visibility struct #state_struct_name #user_impl_generics #user_where_clauses {
#(#named_field_idents: <#field_types as #path::query::WorldQuery>::State,)*
Expand Down
10 changes: 7 additions & 3 deletions crates/bevy_ecs/macros/src/query_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ pub fn derive_query_filter_impl(input: TokenStream) -> TokenStream {

const _: () = {
#[doc(hidden)]
#[doc = "Automatically generated internal [`WorldQuery`] state type for [`"]
#[doc = stringify!(#struct_name)]
#[doc = "`], used for caching."]
#[doc = concat!(
"Automatically generated internal [`WorldQuery`](",
stringify!(#path),
"::query::WorldQuery) state type for [`",
stringify!(#struct_name),
"`], used for caching."
)]
#[automatically_derived]
#visibility struct #state_struct_name #user_impl_generics #user_where_clauses {
#(#named_field_idents: <#field_types as #path::query::WorldQuery>::State,)*
Expand Down
26 changes: 17 additions & 9 deletions crates/bevy_ecs/macros/src/world_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ pub(crate) fn item_struct(
user_ty_generics_with_world: &TypeGenerics,
user_where_clauses_with_world: Option<&WhereClause>,
) -> proc_macro2::TokenStream {
let item_attrs = quote!(
#[doc = "Automatically generated [`WorldQuery`](#path::query::WorldQuery) item type for [`"]
#[doc = stringify!(#struct_name)]
#[doc = "`], returned when iterating over query results."]
#[automatically_derived]
);
let item_attrs = quote! {
#[doc = concat!(
"Automatically generated [`WorldQuery`](",
stringify!(#path),
"::query::WorldQuery) item type for [`",
stringify!(#struct_name),
"`], returned when iterating over query results."
)]
#[automatically_derived]
};

match fields {
Fields::Named(_) => quote! {
Expand Down Expand Up @@ -69,9 +73,13 @@ pub(crate) fn world_query_impl(
) -> proc_macro2::TokenStream {
quote! {
#[doc(hidden)]
#[doc = "Automatically generated internal [`WorldQuery`] fetch type for [`"]
#[doc = stringify!(#struct_name)]
#[doc = "`], used to define the world data accessed by this query."]
#[doc = concat!(
"Automatically generated internal [`WorldQuery`](",
stringify!(#path),
"::query::WorldQuery) fetch type for [`",
stringify!(#struct_name),
"`], used to define the world data accessed by this query."
)]
#[automatically_derived]
#visibility struct #fetch_struct_name #user_impl_generics_with_world #user_where_clauses_with_world {
#(#named_field_idents: <#field_types as #path::query::WorldQuery>::Fetch<'__w>,)*
Expand Down

0 comments on commit 3a8d559

Please sign in to comment.