Commit 582543d
authored
# Objective
calling `register_info` and `register_contributed_bundle_info` with
incorrect arguments results in panics in 100% safe code
part of breaking up #20739
## Solution
Mark `register_info` and `register_contributed_bundle_info` as unsafe.
## Testing
cargo test in crates/bevy_ecs
---
It's pretty obvious why this is unsafe, but the function doesn't
explicitly forbid it:
```rust
fn safe_bundle_register_world_unsafety() {
#![forbid(unsafe_code)]
let mut world = World::new();
let mut antiworld = World::new();
#[derive(crate::prelude::Component, Debug, PartialEq, Eq)]
struct A(u32);
let mut world_components = world.components_registrator();
let _ = antiworld
.bundles
.register_info::<(A,)>(&mut world_components, &mut antiworld.storages);
// unsound beyond this point
let e = antiworld.spawn((A(3),));
let a = e.get::<A>().unwrap();
assert_eq!(a, &A(3));
}
```
1 parent 914bcff commit 582543d
File tree
6 files changed
+72
-26
lines changed- crates/bevy_ecs/src
- bundle
- world
6 files changed
+72
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
422 | 429 | | |
423 | 430 | | |
424 | 431 | | |
| |||
442 | 449 | | |
443 | 450 | | |
444 | 451 | | |
445 | | - | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
446 | 460 | | |
447 | 461 | | |
448 | 462 | | |
449 | 463 | | |
450 | 464 | | |
451 | 465 | | |
452 | 466 | | |
453 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
454 | 471 | | |
455 | 472 | | |
456 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2304 | 2304 | | |
2305 | 2305 | | |
2306 | 2306 | | |
2307 | | - | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
2308 | 2311 | | |
2309 | 2312 | | |
2310 | 2313 | | |
| |||
2351 | 2354 | | |
2352 | 2355 | | |
2353 | 2356 | | |
2354 | | - | |
2355 | | - | |
2356 | | - | |
2357 | | - | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
2358 | 2364 | | |
2359 | 2365 | | |
2360 | 2366 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2305 | 2305 | | |
2306 | 2306 | | |
2307 | 2307 | | |
2308 | | - | |
2309 | | - | |
2310 | | - | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
2311 | 2314 | | |
2312 | 2315 | | |
2313 | 2316 | | |
| |||
2450 | 2453 | | |
2451 | 2454 | | |
2452 | 2455 | | |
2453 | | - | |
2454 | | - | |
2455 | | - | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
2456 | 2462 | | |
2457 | 2463 | | |
2458 | 2464 | | |
| |||
3072 | 3078 | | |
3073 | 3079 | | |
3074 | 3080 | | |
3075 | | - | |
3076 | | - | |
3077 | | - | |
| 3081 | + | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
3078 | 3088 | | |
3079 | 3089 | | |
3080 | 3090 | | |
| |||
0 commit comments