Skip to content

Commit 507441d

Browse files
committed
Fix doc_markdown lints in bevy_ecs (#3473)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time. This PR fixes lints in the `bevy_ecs` crate.
1 parent 2d301ea commit 507441d

19 files changed

+129
-127
lines changed

crates/bevy_ecs/src/archetype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl Archetypes {
470470
/// `table_components` and `sparse_set_components` must be sorted
471471
///
472472
/// # Safety
473-
/// TableId must exist in tables
473+
/// [`TableId`] must exist in tables
474474
pub(crate) fn get_id_or_insert(
475475
&mut self,
476476
table_id: TableId,

crates/bevy_ecs/src/bundle.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Types for handling [`Bundle`]s.
22
//!
3-
//! This module contains the `Bundle` trait and some other helper types.
3+
//! This module contains the [`Bundle`] trait and some other helper types.
44
55
pub use bevy_ecs_macros::Bundle;
66

@@ -13,7 +13,7 @@ use crate::{
1313
use bevy_ecs_macros::all_tuples;
1414
use std::{any::TypeId, collections::HashMap};
1515

16-
/// An ordered collection of components.
16+
/// An ordered collection of [`Component`]s.
1717
///
1818
/// Commonly used for spawning entities and adding and removing components in bulk. This
1919
/// trait is automatically implemented for tuples of components: `(ComponentA, ComponentB)`
@@ -71,33 +71,32 @@ use std::{any::TypeId, collections::HashMap};
7171
///
7272
/// # Safety
7373
///
74-
/// - [Bundle::component_ids] must return the ComponentId for each component type in the bundle, in the
75-
/// _exact_ order that [Bundle::get_components] is called.
76-
/// - [Bundle::from_components] must call `func` exactly once for each [ComponentId] returned by
77-
/// [Bundle::component_ids].
74+
/// - [`Bundle::component_ids`] must return the [`ComponentId`] for each component type in the
75+
/// bundle, in the _exact_ order that [`Bundle::get_components`] is called.
76+
/// - [`Bundle::from_components`] must call `func` exactly once for each [`ComponentId`] returned by
77+
/// [`Bundle::component_ids`].
7878
pub unsafe trait Bundle: Send + Sync + 'static {
79-
/// Gets this [Bundle]'s component ids, in the order of this bundle's Components
79+
/// Gets this [`Bundle`]'s component ids, in the order of this bundle's [`Component`]s
8080
fn component_ids(components: &mut Components, storages: &mut Storages) -> Vec<ComponentId>;
8181

8282
/// Calls `func`, which should return data for each component in the bundle, in the order of
83-
/// this bundle's Components
83+
/// this bundle's [`Component`]s
8484
///
8585
/// # Safety
8686
/// Caller must return data for each component in the bundle, in the order of this bundle's
87-
/// Components
87+
/// [`Component`]s
8888
unsafe fn from_components(func: impl FnMut() -> *mut u8) -> Self
8989
where
9090
Self: Sized;
9191

92-
/// Calls `func` on each value, in the order of this bundle's Components. This will
93-
/// "mem::forget" the bundle fields, so callers are responsible for dropping the fields if
94-
/// that is desirable.
92+
/// Calls `func` on each value, in the order of this bundle's [`Component`]s. This will
93+
/// [`std::mem::forget`] the bundle fields, so callers are responsible for dropping the fields
94+
/// if that is desirable.
9595
fn get_components(self, func: impl FnMut(*mut u8));
9696
}
9797

9898
macro_rules! tuple_impl {
9999
($($name: ident),*) => {
100-
/// SAFE: Component is returned in tuple-order. [Bundle::from_components] and [Bundle::get_components] use tuple-order
101100
unsafe impl<$($name: Component),*> Bundle for ($($name,)*) {
102101
#[allow(unused_variables)]
103102
fn component_ids(components: &mut Components, storages: &mut Storages) -> Vec<ComponentId> {
@@ -258,7 +257,8 @@ impl BundleInfo {
258257
}
259258

260259
/// # Safety
261-
/// `table` must be the "new" table for `entity`. `table_row` must have space allocated for the `entity`, `bundle` must match this BundleInfo's type
260+
/// `table` must be the "new" table for `entity`. `table_row` must have space allocated for the
261+
/// `entity`, `bundle` must match this [`BundleInfo`]'s type
262262
#[inline]
263263
#[allow(clippy::too_many_arguments)]
264264
unsafe fn write_components<T: Bundle>(
@@ -301,9 +301,9 @@ impl BundleInfo {
301301
});
302302
}
303303

304-
/// Adds a bundle to the given archetype and returns the resulting archetype. This could be the same
305-
/// [ArchetypeId], in the event that adding the given bundle does not result in an Archetype change.
306-
/// Results are cached in the Archetype Graph to avoid redundant work.
304+
/// Adds a bundle to the given archetype and returns the resulting archetype. This could be the
305+
/// same [`ArchetypeId`], in the event that adding the given bundle does not result in an
306+
/// [`Archetype`] change. Results are cached in the [`Archetype`] graph to avoid redundant work.
307307
pub(crate) fn add_bundle_to_archetype(
308308
&self,
309309
archetypes: &mut Archetypes,
@@ -409,8 +409,8 @@ pub(crate) enum InsertBundleResult<'a> {
409409

410410
impl<'a, 'b> BundleInserter<'a, 'b> {
411411
/// # Safety
412-
/// `entity` must currently exist in the source archetype for this inserter. `archetype_index` must be `entity`'s location in the archetype.
413-
/// `T` must match this BundleInfo's type
412+
/// `entity` must currently exist in the source archetype for this inserter. `archetype_index`
413+
/// must be `entity`'s location in the archetype. `T` must match this [`BundleInfo`]'s type
414414
#[inline]
415415
pub unsafe fn insert<T: Bundle>(
416416
&mut self,
@@ -538,7 +538,7 @@ impl<'a, 'b> BundleSpawner<'a, 'b> {
538538
self.table.reserve(additional);
539539
}
540540
/// # Safety
541-
/// `entity` must be allocated (but non existent), `T` must match this BundleInfo's type
541+
/// `entity` must be allocated (but non-existent), `T` must match this [`BundleInfo`]'s type
542542
#[inline]
543543
pub unsafe fn spawn_non_existent<T: Bundle>(
544544
&mut self,
@@ -562,7 +562,7 @@ impl<'a, 'b> BundleSpawner<'a, 'b> {
562562
}
563563

564564
/// # Safety
565-
/// `T` must match this BundleInfo's type
565+
/// `T` must match this [`BundleInfo`]'s type
566566
#[inline]
567567
pub unsafe fn spawn<T: Bundle>(&mut self, bundle: T) -> Entity {
568568
let entity = self.entities.alloc();
@@ -612,7 +612,7 @@ impl Bundles {
612612

613613
/// # Safety
614614
///
615-
/// `component_id` must be valid [ComponentId]'s
615+
/// `component_id` must be valid [`ComponentId`]'s
616616
unsafe fn initialize_bundle(
617617
bundle_type_name: &'static str,
618618
component_ids: Vec<ComponentId>,

crates/bevy_ecs/src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl Components {
289289

290290
/// # Safety
291291
///
292-
/// `id` must be a valid [ComponentId]
292+
/// `id` must be a valid [`ComponentId`]
293293
#[inline]
294294
pub unsafe fn get_info_unchecked(&self, id: ComponentId) -> &ComponentInfo {
295295
debug_assert!(id.index() < self.components.len());

crates/bevy_ecs/src/entity/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,9 @@ impl Entities {
493493
/// `reserve_entities`, then initializes each one using the supplied function.
494494
///
495495
/// # Safety
496-
/// Flush _must_ set the entity location to the correct ArchetypeId for the given Entity
497-
/// each time init is called. This _can_ be ArchetypeId::INVALID, provided the Entity has
498-
/// not been assigned to an Archetype.
496+
/// Flush _must_ set the entity location to the correct [`ArchetypeId`] for the given [`Entity`]
497+
/// each time init is called. This _can_ be [`ArchetypeId::INVALID`], provided the [`Entity`]
498+
/// has not been assigned to an [`Archetype`][crate::archetype::Archetype].
499499
pub unsafe fn flush(&mut self, mut init: impl FnMut(Entity, &mut EntityLocation)) {
500500
let free_cursor = self.free_cursor.get_mut();
501501
let current_free_cursor = *free_cursor;

crates/bevy_ecs/src/event.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum State {
6767
/// [`Events::update`] exactly once per update/frame.
6868
///
6969
/// [`Events::update_system`] is a system that does this, typically intialized automatically using
70-
/// [`App::add_event`]. [EventReader]s are expected to read events from this collection at
70+
/// [`App::add_event`]. [`EventReader`]s are expected to read events from this collection at
7171
/// least once per loop/frame.
7272
/// Events will persist across a single frame boundary and so ordering of event producers and
7373
/// consumers is not critical (although poorly-planned ordering may cause accumulating lag).
@@ -103,16 +103,16 @@ enum State {
103103
///
104104
/// # Details
105105
///
106-
/// [Events] is implemented using a double buffer. Each call to [Events::update] swaps buffers and
107-
/// clears out the oldest buffer. [EventReader]s that read at least once per update will never drop
108-
/// events. [EventReader]s that read once within two updates might still receive some events.
109-
/// [EventReader]s that read after two updates are guaranteed to drop all events that occurred
106+
/// [`Events`] is implemented using a double buffer. Each call to [`Events::update`] swaps buffers
107+
/// and clears out the oldest buffer. [`EventReader`]s that read at least once per update will never
108+
/// drop events. [`EventReader`]s that read once within two updates might still receive some events.
109+
/// [`EventReader`]s that read after two updates are guaranteed to drop all events that occurred
110110
/// before those updates.
111111
///
112-
/// The buffers in [Events] will grow indefinitely if [Events::update] is never called.
112+
/// The buffers in [`Events`] will grow indefinitely if [`Events::update`] is never called.
113113
///
114-
/// An alternative call pattern would be to call [Events::update] manually across frames to control
115-
/// when events are cleared.
114+
/// An alternative call pattern would be to call [`Events::update`] manually across frames to
115+
/// control when events are cleared.
116116
/// This complicates consumption and risks ever-expanding memory usage if not cleaned up,
117117
/// but can be done by adding your event as a resource instead of using [`App::add_event`].
118118
///
@@ -254,9 +254,9 @@ fn internal_event_reader<'a, T>(
254254
}
255255

256256
impl<'w, 's, T: Resource> EventReader<'w, 's, T> {
257-
/// Iterates over the events this EventReader has not seen yet. This updates the EventReader's
258-
/// event counter, which means subsequent event reads will not include events that happened
259-
/// before now.
257+
/// Iterates over the events this [`EventReader`] has not seen yet. This updates the
258+
/// [`EventReader`]'s event counter, which means subsequent event reads will not include events
259+
/// that happened before now.
260260
pub fn iter(&mut self) -> impl DoubleEndedIterator<Item = &T> {
261261
self.iter_with_id().map(|(event, _id)| event)
262262
}
@@ -271,7 +271,7 @@ impl<'w, 's, T: Resource> EventReader<'w, 's, T> {
271271
}
272272

273273
impl<T: Resource> Events<T> {
274-
/// "Sends" an `event` by writing it to the current event buffer. [EventReader]s can then read
274+
/// "Sends" an `event` by writing it to the current event buffer. [`EventReader`]s can then read
275275
/// the event.
276276
pub fn send(&mut self, event: T) {
277277
let event_id = EventId {
@@ -290,16 +290,16 @@ impl<T: Resource> Events<T> {
290290
self.event_count += 1;
291291
}
292292

293-
/// Gets a new [ManualEventReader]. This will include all events already in the event buffers.
293+
/// Gets a new [`ManualEventReader`]. This will include all events already in the event buffers.
294294
pub fn get_reader(&self) -> ManualEventReader<T> {
295295
ManualEventReader {
296296
last_event_count: 0,
297297
_marker: PhantomData,
298298
}
299299
}
300300

301-
/// Gets a new [ManualEventReader]. This will ignore all events already in the event buffers. It
302-
/// will read all future events.
301+
/// Gets a new [`ManualEventReader`]. This will ignore all events already in the event buffers.
302+
/// It will read all future events.
303303
pub fn get_reader_current(&self) -> ManualEventReader<T> {
304304
ManualEventReader {
305305
last_event_count: self.event_count,
@@ -324,7 +324,7 @@ impl<T: Resource> Events<T> {
324324
}
325325
}
326326

327-
/// A system that calls [Events::update] once per frame.
327+
/// A system that calls [`Events::update`] once per frame.
328328
pub fn update_system(mut events: ResMut<Self>) {
329329
events.update();
330330
}

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ use std::{
2121
///
2222
/// See [`Query`](crate::system::Query) for a primer on queries.
2323
///
24-
/// # Basic WorldQueries
24+
/// # Basic [`WorldQuery`]'s
2525
///
2626
/// Here is a small list of the most important world queries to know about where `C` stands for a
2727
/// [`Component`] and `WQ` stands for a [`WorldQuery`]:
2828
/// - `&C`: Queries immutably for the component `C`
2929
/// - `&mut C`: Queries mutably for the component `C`
30-
/// - `Option<WQ>`: Queries the inner WorldQuery `WQ` but instead of discarding the entity if the world
30+
/// - `Option<WQ>`: Queries the inner [`WorldQuery`] `WQ` but instead of discarding the entity if the world
3131
/// query fails it returns [`None`]. See [`Query`](crate::system::Query).
3232
/// - `(WQ1, WQ2, ...)`: Queries all contained world queries allowing to query for more than one thing.
3333
/// This is the `And` operator for filters. See [`Or`].
@@ -57,8 +57,8 @@ pub trait Fetch<'world, 'state>: Sized {
5757
///
5858
/// # Safety
5959
///
60-
/// `state` must have been initialized (via [FetchState::init]) using the same `world` passed in
61-
/// to this function.
60+
/// `state` must have been initialized (via [`FetchState::init`]) using the same `world` passed
61+
/// in to this function.
6262
unsafe fn init(
6363
world: &World,
6464
state: &Self::State,
@@ -78,8 +78,8 @@ pub trait Fetch<'world, 'state>: Sized {
7878
///
7979
/// # Safety
8080
///
81-
/// `archetype` and `tables` must be from the [`World`] [`Fetch::init`] was called on. `state` must
82-
/// be the [Self::State] this was initialized with.
81+
/// `archetype` and `tables` must be from the [`World`] [`Fetch::init`] was called on. `state`
82+
/// must be the [`Self::State`] this was initialized with.
8383
unsafe fn set_archetype(&mut self, state: &Self::State, archetype: &Archetype, tables: &Tables);
8484

8585
/// Adjusts internal state to account for the next [`Table`]. This will always be called on tables
@@ -88,7 +88,7 @@ pub trait Fetch<'world, 'state>: Sized {
8888
/// # Safety
8989
///
9090
/// `table` must be from the [`World`] [`Fetch::init`] was called on. `state` must be the
91-
/// [Self::State] this was initialized with.
91+
/// [`Self::State`] this was initialized with.
9292
unsafe fn set_table(&mut self, state: &Self::State, table: &Table);
9393

9494
/// Fetch [`Self::Item`] for the given `archetype_index` in the current [`Archetype`]. This must
@@ -677,7 +677,7 @@ pub struct OptionFetch<T> {
677677
matches: bool,
678678
}
679679

680-
/// SAFETY: OptionFetch is read only because T is read only
680+
/// SAFETY: [`OptionFetch`] is read only because `T` is read only
681681
unsafe impl<T: ReadOnlyFetch> ReadOnlyFetch for OptionFetch<T> {}
682682

683683
/// The [`FetchState`] of `Option<T>`.

crates/bevy_ecs/src/query/iter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
3636
/// have unique access to the components they query.
3737
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a `world`
38-
/// with a mismatched WorldId is unsound.
38+
/// with a mismatched [`WorldId`] is unsound.
3939
pub(crate) unsafe fn new(
4040
world: &'w World,
4141
query_state: &'s QueryState<Q, F>,
@@ -174,8 +174,8 @@ where
174174
/// # Safety
175175
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
176176
/// have unique access to the components they query.
177-
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a `world`
178-
/// with a mismatched WorldId is unsound.
177+
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a
178+
/// `world` with a mismatched [`WorldId`] is unsound.
179179
pub(crate) unsafe fn new(
180180
world: &'w World,
181181
query_state: &'s QueryState<Q, F>,

crates/bevy_ecs/src/query/state.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ where
391391
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
392392
/// have unique access to the components they query.
393393
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
394-
/// with a mismatched WorldId is unsound.
394+
/// with a mismatched [`WorldId`] is unsound.
395395
#[inline]
396396
pub(crate) unsafe fn iter_unchecked_manual<'w, 's, QF: Fetch<'w, 's, State = Q::State>>(
397397
&'s self,
@@ -411,7 +411,7 @@ where
411411
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
412412
/// have unique access to the components they query.
413413
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
414-
/// with a mismatched WorldId is unsound.
414+
/// with a mismatched [`WorldId`] is unsound.
415415
#[inline]
416416
pub(crate) unsafe fn iter_combinations_unchecked_manual<
417417
'w,
@@ -450,7 +450,7 @@ where
450450
}
451451

452452
/// Runs `func` on each query result for the given [`World`]. This is faster than the equivalent
453-
/// iter_mut() method, but cannot be chained like a normal [`Iterator`].
453+
/// `iter_mut()` method, but cannot be chained like a normal [`Iterator`].
454454
#[inline]
455455
pub fn for_each_mut<'w, 's, FN: FnMut(<Q::Fetch as Fetch<'w, 's>>::Item)>(
456456
&'s mut self,
@@ -590,7 +590,7 @@ where
590590
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
591591
/// have unique access to the components they query.
592592
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
593-
/// with a mismatched WorldId is unsound.
593+
/// with a mismatched [`WorldId`] is unsound.
594594
pub(crate) unsafe fn for_each_unchecked_manual<
595595
'w,
596596
's,
@@ -650,7 +650,7 @@ where
650650
/// This does not check for mutable query correctness. To be safe, make sure mutable queries
651651
/// have unique access to the components they query.
652652
/// This does not validate that `world.id()` matches `self.world_id`. Calling this on a `world`
653-
/// with a mismatched WorldId is unsound.
653+
/// with a mismatched [`WorldId`] is unsound.
654654
pub(crate) unsafe fn par_for_each_unchecked_manual<
655655
'w,
656656
's,

crates/bevy_ecs/src/schedule/executor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl ParallelSystemExecutor for SingleThreadedExecutor {
4141
}
4242

4343
impl SingleThreadedExecutor {
44-
/// Calls system.new_archetype() for each archetype added since the last call to
45-
/// [update_archetypes] and updates cached archetype_component_access.
44+
/// Calls `system.new_archetype()` for each archetype added since the last call to
45+
/// `update_archetypes` and updates cached `archetype_component_access`.
4646
fn update_archetypes(&mut self, systems: &mut [ParallelSystemContainer], world: &World) {
4747
let archetypes = world.archetypes();
4848
let new_generation = archetypes.generation();

crates/bevy_ecs/src/schedule/executor_parallel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ impl ParallelSystemExecutor for ParallelExecutor {
154154
}
155155

156156
impl ParallelExecutor {
157-
/// Calls system.new_archetype() for each archetype added since the last call to
158-
/// [update_archetypes] and updates cached archetype_component_access.
157+
/// Calls `system.new_archetype()` for each archetype added since the last call to
158+
/// `update_archetypes` and updates cached `archetype_component_access`.
159159
fn update_archetypes(&mut self, systems: &mut [ParallelSystemContainer], world: &World) {
160160
#[cfg(feature = "trace")]
161161
let span = bevy_utils::tracing::info_span!("update_archetypes");

0 commit comments

Comments
 (0)