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

Replace or document ignored doctests #11040

Merged
merged 9 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ impl App {

/// Registers the type `T` in the [`TypeRegistry`](bevy_reflect::TypeRegistry) resource,
/// adding reflect data as specified in the [`Reflect`](bevy_reflect::Reflect) derive:
/// ```rust,ignore
/// #[derive(Reflect)]
/// ```ignore (No serde "derive" feature)
/// #[derive(Component, Serialize, Deserialize, Reflect)]
/// #[reflect(Component, Serialize, Deserialize)] // will register ReflectComponent, ReflectSerialize, ReflectDeserialize
/// ```
///
Expand Down
11 changes: 10 additions & 1 deletion crates/bevy_ecs/src/reflect/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@
//! type, it tells the derive macro for `Reflect` to add the following single line to its
//! [`get_type_registration`] method (see the relevant code[^1]).
//!
//! ```ignore
//! ```
//! # use bevy_reflect::{FromType, Reflect};
//! # use bevy_ecs::prelude::{ReflectComponent, Component};
//! # #[derive(Default, Reflect, Component)]
//! # struct A;
//! # impl A {
//! # fn foo() {
//! # let mut registration = bevy_reflect::TypeRegistration::of::<A>();
//! registration.insert::<ReflectComponent>(FromType::<Self>::from_type());
//! # }
//! # }
//! ```
//!
//! This line adds a `ReflectComponent` to the registration data for the type in question.
Expand Down
17 changes: 10 additions & 7 deletions crates/bevy_macro_utils/src/fq_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,33 @@
//!
//! # Example
//! Instead of writing this:
//! ```ignore
//! ```
//! # use quote::quote;
//! quote!(
//! fn get_id() -> Option<i32> {
//! Some(0)
//! }
//! )
//! );
//! ```
//! Or this:
//! ```ignore
//! ```
//! # use quote::quote;
//! quote!(
//! fn get_id() -> ::core::option::Option<i32> {
//! ::core::option::Option::Some(0)
//! }
//! )
//! );
//! ```
//! We should write this:
//! ```ignore
//! use crate::fq_std::FQOption;
//! ```
//! use bevy_macro_utils::fq_std::FQOption;
//! # use quote::quote;
//!
//! quote!(
//! fn get_id() -> #FQOption<i32> {
//! #FQOption::Some(0)
//! }
//! )
//! );
//! ```

use proc_macro2::TokenStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ impl TypePathAttrs {
///
/// Registering the `Default` implementation:
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// // Import ReflectDefault so it's accessible by the derive macro
/// use bevy_reflect::prelude::ReflectDefault.
/// use bevy_reflect::prelude::ReflectDefault;
///
/// #[derive(Reflect, Default)]
/// #[reflect(Default)]
Expand All @@ -179,7 +179,7 @@ impl TypePathAttrs {
///
/// Registering the `Hash` implementation:
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// // `Hash` is a "special trait" and does not need (nor have) a ReflectHash struct
///
/// #[derive(Reflect, Hash)]
Expand All @@ -189,7 +189,7 @@ impl TypePathAttrs {
///
/// Registering the `Hash` implementation using a custom function:
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// // This function acts as our `Hash` implementation and
/// // corresponds to the `Reflect::reflect_hash` method.
/// fn get_hash(foo: &Foo) -> Option<u64> {
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_reflect/bevy_reflect_derive/src/derive_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) enum ReflectDerive<'a> {
///
/// # Example
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// #[derive(Reflect)]
/// // traits
/// // |----------------------------------------|
Expand All @@ -54,7 +54,7 @@ pub(crate) struct ReflectMeta<'a> {
///
/// # Example
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// #[derive(Reflect)]
/// #[reflect(PartialEq, Serialize, Deserialize, Default)]
/// struct ThingThatImReflecting<T1, T2, T3> {
Expand All @@ -73,7 +73,7 @@ pub(crate) struct ReflectStruct<'a> {
///
/// # Example
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// #[derive(Reflect)]
/// #[reflect(PartialEq, Serialize, Deserialize, Default)]
/// enum ThingThatImReflecting<T1, T2, T3> {
Expand Down Expand Up @@ -573,7 +573,7 @@ impl<'a> EnumVariant<'a> {
///
/// # Example
///
/// ```rust,ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// # use syn::parse_quote;
/// # use bevy_reflect_derive::ReflectTypePath;
/// let path: syn::Path = parse_quote!(::core::marker::PhantomData)?;
Expand Down
28 changes: 14 additions & 14 deletions crates/bevy_reflect/bevy_reflect_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub fn derive_type_uuid(input: TokenStream) -> TokenStream {
///
/// # Example
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// # use std::any::TypeId;
/// # use bevy_reflect_derive::{Reflect, reflect_trait};
/// #[reflect_trait] // Generates `ReflectMyTrait`
Expand Down Expand Up @@ -377,20 +377,20 @@ pub fn reflect_trait(args: TokenStream, input: TokenStream) -> TokenStream {
///
/// Types can be passed with or without registering type data:
///
/// ```ignore
/// impl_reflect_value!(::my_crate::Foo);
/// impl_reflect_value!(::my_crate::Bar(Debug, Default, Serialize, Deserialize));
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_reflect_value!(my_crate::Foo);
/// impl_reflect_value!(my_crate::Bar(Debug, Default, Serialize, Deserialize));
/// ```
///
/// Generic types can also specify their parameters and bounds:
///
/// ```ignore
/// impl_reflect_value!(::my_crate::Foo<T1, T2: Baz> where T1: Bar (Default, Serialize, Deserialize));
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_reflect_value!(my_crate::Foo<T1, T2: Baz> where T1: Bar (Default, Serialize, Deserialize));
/// ```
///
/// Custom type paths can be specified:
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_reflect_value!((in not_my_crate as NotFoo) Foo(Debug, Default));
/// ```
///
Expand Down Expand Up @@ -445,7 +445,7 @@ pub fn impl_reflect_value(input: TokenStream) -> TokenStream {
///
/// # Example
/// Implementing `Reflect` for `bevy::prelude::Vec3` as a struct type:
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// use bevy::prelude::Vec3;
///
/// impl_reflect_struct!(
Expand Down Expand Up @@ -520,7 +520,7 @@ pub fn impl_reflect_struct(input: TokenStream) -> TokenStream {
///
/// # Examples
///
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_from_reflect_value!(foo<T1, T2: Baz> where T1: Bar);
/// ```
///
Expand Down Expand Up @@ -565,27 +565,27 @@ pub fn impl_from_reflect_value(input: TokenStream) -> TokenStream {
/// # Examples
///
/// Implementing `TypePath` on a foreign type:
/// ```rust,ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_type_path!(::foreign_crate::foo::bar::Baz);
/// ```
///
/// On a generic type:
/// ```rust,ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_type_path!(::foreign_crate::Foo<T>);
/// ```
///
/// On a primitive (note this will not compile for a non-primitive type):
/// ```rust,ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_type_path!(bool);
/// ```
///
/// With a custom type path:
/// ```rust,ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_type_path!((in other_crate::foo::bar) Baz);
/// ```
///
/// With a custom type path and a custom type name:
/// ```rust,ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// impl_type_path!((in other_crate::foo as Baz) Bar);
/// ```
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use syn::{parenthesized, Attribute, Generics, Path};
///
/// This takes the form:
///
/// ```ignore
/// ```ignore (Method expecting TokenStream is better represented with raw tokens)
/// // Standard
/// ::my_crate::foo::Bar(TraitA, TraitB)
///
Expand Down
12 changes: 9 additions & 3 deletions crates/bevy_reflect/bevy_reflect_derive/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ pub(crate) fn get_bevy_reflect_path() -> Path {
///
/// # Example
///
/// ```ignore
/// ```
/// # use proc_macro2::Ident;
/// # // We can't import this method because of its visibility.
/// # fn get_reflect_ident(name: &str) -> Ident {
/// # let reflected = format!("Reflect{name}");
/// # Ident::new(&reflected, proc_macro2::Span::call_site())
/// # }
/// let reflected: Ident = get_reflect_ident("Hash");
/// assert_eq!("ReflectHash", reflected.to_string());
/// ```
Expand Down Expand Up @@ -195,7 +201,7 @@ impl WhereClauseOptions {
/// # Example
///
/// The struct:
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// #[derive(Reflect)]
/// struct Foo<T, U> {
/// a: T,
Expand All @@ -206,7 +212,7 @@ impl WhereClauseOptions {
/// will have active types: `[T]` and ignored types: `[U]`
///
/// The `extend_where_clause` function will yield the following `where` clause:
/// ```ignore
/// ```ignore (bevy_reflect is not accessible from this crate)
/// where
/// T: Reflect, // active_trait_bounds
/// U: Any + Send + Sync, // ignored_trait_bounds
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 @@ -1556,7 +1556,7 @@ mod tests {
///
/// # Example
///
/// ```ignore
/// ```ignore (This is only used for a unit test, no need to doc test)
/// let some_struct = SomeStruct;
/// ```
#[derive(Reflect)]
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_reflect/src/serde/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Container for TupleVariantInfo {
///
/// # Example
///
/// ```ignore
/// ```ignore (Can't import private struct from doctest)
/// let expected = vec!["foo", "bar", "baz"];
/// assert_eq!("`foo`, `bar`, `baz`", format!("{}", ExpectedValues(expected)));
/// ```
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_reflect/src/type_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ impl TypeRegistry {
}

/// Registers the type `T`, adding reflect data as specified in the [`Reflect`] derive:
/// ```rust,ignore
/// #[derive(Reflect)]
/// ```ignore (Neither bevy_ecs nor serde "derive" is availible.)
doonv marked this conversation as resolved.
Show resolved Hide resolved
/// #[derive(Component, serde::Serialize, serde::Deserialize, Reflect)]
/// #[reflect(Component, Serialize, Deserialize)] // will register ReflectComponent, ReflectSerialize, ReflectDeserialize
/// ```
pub fn register<T>(&mut self)
Expand Down
16 changes: 11 additions & 5 deletions crates/bevy_render/src/render_phase/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,21 @@ impl<P: PhaseItem> DrawFunctions<P> {
/// Multiple render commands can be combined together by wrapping them in a tuple.
///
/// # Example
/// The `DrawPbr` draw function is created from the following render command
///
/// The `DrawMaterial` draw function is created from the following render command
/// tuple. Const generics are used to set specific bind group locations:
///
/// ```ignore
/// pub type DrawPbr = (
/// ```
/// # use bevy_render::render_phase::SetItemPipeline;
/// # struct SetMeshViewBindGroup<const N: usize>;
/// # struct SetMeshBindGroup<const N: usize>;
/// # struct SetMaterialBindGroup<M, const N: usize>(core::marker::PhantomData<M>);
/// # struct DrawMesh;
/// pub type DrawMaterial<M> = (
/// SetItemPipeline,
/// SetMeshViewBindGroup<0>,
/// SetStandardMaterialBindGroup<1>,
/// SetTransformBindGroup<2>,
/// SetMeshBindGroup<1>,
/// SetMaterialBindGroup<M, 2>,
/// DrawMesh,
/// );
/// ```
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_render/src/render_resource/bind_group_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{Sampler, TextureView};
/// Helper for constructing bindgroups.
///
/// Allows constructing the descriptor's entries as:
/// ```ignore
/// ```ignore (render_device cannot be easily accessed)
/// render_device.create_bind_group(
/// "my_bind_group",
/// &my_layout,
Expand All @@ -19,7 +19,7 @@ use super::{Sampler, TextureView};
///
/// instead of
///
/// ```ignore
/// ```ignore (render_device cannot be easily accessed)
/// render_device.create_bind_group(
/// "my_bind_group",
/// &my_layout,
Expand All @@ -38,7 +38,7 @@ use super::{Sampler, TextureView};
///
/// or
///
/// ```ignore
/// ```ignore (render_device cannot be easily accessed)
/// render_device.create_bind_group(
/// "my_bind_group",
/// &my_layout,
Expand All @@ -51,7 +51,7 @@ use super::{Sampler, TextureView};
///
/// instead of
///
/// ```ignore
/// ```ignore (render_device cannot be easily accessed)
/// render_device.create_bind_group(
/// "my_bind_group",
/// &my_layout,
Expand All @@ -70,7 +70,7 @@ use super::{Sampler, TextureView};
///
/// or
///
/// ```ignore
/// ```ignore (render_device cannot be easily accessed)
/// render_device.create_bind_group(
/// "my_bind_group",
/// &my_layout,
Expand All @@ -80,7 +80,7 @@ use super::{Sampler, TextureView};
///
/// instead of
///
/// ```ignore
/// ```ignore (render_device cannot be easily accessed)
/// render_device.create_bind_group(
/// "my_bind_group",
/// &my_layout,
Expand Down
Loading