@@ -149,7 +149,7 @@ impl RequiredComponents {
149
149
///
150
150
/// # Safety
151
151
///
152
- /// - all other components in this [`RequiredComponents`] instance must have been registrated in `components`.
152
+ /// - all other components in this [`RequiredComponents`] instance must have been registered in `components`.
153
153
pub unsafe fn register < C : Component > (
154
154
& mut self ,
155
155
components : & mut ComponentsRegistrator < ' _ > ,
@@ -171,7 +171,7 @@ impl RequiredComponents {
171
171
/// # Safety
172
172
///
173
173
/// - `component_id` must be a valid component in `components` for the type `C`;
174
- /// - all other components in this [`RequiredComponents`] instance must have been registrated in `components`.
174
+ /// - all other components in this [`RequiredComponents`] instance must have been registered in `components`.
175
175
pub unsafe fn register_by_id < C : Component > (
176
176
& mut self ,
177
177
component_id : ComponentId ,
@@ -198,7 +198,7 @@ impl RequiredComponents {
198
198
/// # Safety
199
199
///
200
200
/// - `component_id` must be a valid component in `components`;
201
- /// - all other components in this [`RequiredComponents`] instance must have been registrated in `components`;
201
+ /// - all other components in `self` must have been registered in `components`;
202
202
/// - `constructor` must return a [`RequiredComponentConstructor`] that constructs a valid instance for the
203
203
/// component with ID `component_id`.
204
204
pub unsafe fn register_dynamic_with (
@@ -219,14 +219,17 @@ impl RequiredComponents {
219
219
entry. insert ( required_component. clone ( ) ) ;
220
220
221
221
// Register inherited required components.
222
+ // SAFETY:
223
+ // - the caller guarantees all components that were in `self` have been registered in `components`;
224
+ // - `component_id` has just been added, but is also guaranteed by the called to be valid in `components`.
222
225
unsafe {
223
226
Self :: register_inherited_required_components_unchecked (
224
227
& mut self . all ,
225
228
component_id,
226
229
required_component,
227
230
components,
228
- )
229
- } ;
231
+ ) ;
232
+ }
230
233
231
234
true
232
235
}
@@ -235,7 +238,7 @@ impl RequiredComponents {
235
238
///
236
239
/// # Safety
237
240
///
238
- /// - all components in this [`RequiredComponents`] instance must have been registrated in `components`.
241
+ /// - all components in `self` must have been registered in `components`.
239
242
unsafe fn rebuild_inherited_required_components ( & mut self , components : & Components ) {
240
243
// Clear `all`, we are re-initializing it.
241
244
self . all . clear ( ) ;
@@ -252,7 +255,7 @@ impl RequiredComponents {
252
255
required_id,
253
256
required_component. clone ( ) ,
254
257
components,
255
- )
258
+ ) ;
256
259
}
257
260
}
258
261
}
@@ -281,7 +284,7 @@ impl RequiredComponents {
281
284
for ( & inherited_id, inherited_required) in & info. required_components ( ) . all {
282
285
// This is an inherited required component: insert it only if not already present.
283
286
// By the invariants of `RequiredComponents`, `info.required_components().all` holds the required
284
- // components in a depth-first order, and this makes us store teh components in `self.all` also
287
+ // components in a depth-first order, and this makes us store the components in `self.all` also
285
288
// in depth-first order, as long as we don't overwrite existing ones.
286
289
//
287
290
// SAFETY:
@@ -426,7 +429,7 @@ impl Components {
426
429
for & indirect_requiree in & new_requiree_components {
427
430
// Extract the required components to avoid conflicting borrows. Remember to put this back before continuing!
428
431
// SAFETY: `indirect_requiree` comes from `self`, so it must be valid.
429
- let mut required_components = std :: mem:: take ( unsafe {
432
+ let mut required_components = core :: mem:: take ( unsafe {
430
433
self . get_required_components_mut ( indirect_requiree)
431
434
. debug_checked_unwrap ( )
432
435
} ) ;
@@ -474,7 +477,7 @@ impl Components {
474
477
) {
475
478
// Extract the required components to avoid conflicting borrows. Remember to put this back before returning!
476
479
// SAFETY: The caller ensures that the `requiree` is valid.
477
- let mut required_components = std :: mem:: take ( unsafe {
480
+ let mut required_components = core :: mem:: take ( unsafe {
478
481
self . get_required_components_mut ( requiree)
479
482
. debug_checked_unwrap ( )
480
483
} ) ;
@@ -537,7 +540,7 @@ pub(super) fn enforce_no_required_components_recursion(
537
540
538
541
#[ cfg( test) ]
539
542
mod tests {
540
- use std :: string:: { String , ToString } ;
543
+ use alloc :: string:: { String , ToString } ;
541
544
542
545
use crate :: {
543
546
bundle:: Bundle ,
@@ -1251,14 +1254,14 @@ mod tests {
1251
1254
#[ test]
1252
1255
fn regression_19333 ( ) {
1253
1256
#[ derive( Component ) ]
1254
- struct X ( bool ) ;
1257
+ struct X ( usize ) ;
1255
1258
1256
1259
#[ derive( Default , Component ) ]
1257
- #[ require( X ( false ) ) ]
1260
+ #[ require( X ( 0 ) ) ]
1258
1261
struct Base ;
1259
1262
1260
1263
#[ derive( Default , Component ) ]
1261
- #[ require( X ( true ) , Base ) ]
1264
+ #[ require( X ( 1 ) , Base ) ]
1262
1265
struct A ;
1263
1266
1264
1267
#[ derive( Default , Component ) ]
@@ -1271,7 +1274,7 @@ mod tests {
1271
1274
1272
1275
let mut w = World :: new ( ) ;
1273
1276
1274
- assert_eq ! ( w. spawn( B ) . get:: <X >( ) . unwrap( ) . 0 , true ) ;
1275
- assert_eq ! ( w. spawn( C ) . get:: <X >( ) . unwrap( ) . 0 , true ) ;
1277
+ assert_eq ! ( w. spawn( B ) . get:: <X >( ) . unwrap( ) . 0 , 1 ) ;
1278
+ assert_eq ! ( w. spawn( C ) . get:: <X >( ) . unwrap( ) . 0 , 1 ) ;
1276
1279
}
1277
1280
}
0 commit comments