Soundness issue with random access API within a system
- Lingua principale
- Rust
- Stelle
- 1.7k
- Fork
- 140
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
The following snippet demonstrates the issue (only occurs when building with `--release`):
```rust
use legion::prelude::*;
fn main() {
let mut world = World::new();
world.insert((), Some((14u32,)));
let query = >::query();
let system = SystemBuilder::new("soundness issue")
.write_component::()
.with_query(query)
.build(|_, world, _, query| {
for (entity, mut number) in query.iter_entities(world) {
dbg!(&number); // prints 14
*number += 1;
dbg!(&number); // prints 15
let mut number2 = world.get_component_mut::(entity).unwrap();
dbg!(&number); // prints 15
dbg!(&number2); // prints 15
*number2 += 1;
dbg!(&number); // prints 16
dbg!(&number2); // prints 16
}
});
system.run(&world);
}
```
As far as I can tell this is due to some lifetime issue in `Query::iter_entities` or the fact that runtime borrow checking is disabled in release builds. While I am not against such an optimization, this clearly violates Rust's soundness and aliasing guarantees.
For users who still need/want such an optimization, would it be possible to make this an opt-in feature instead? This has the benefit of making potential issues more visible to the developer.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.