mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Assert compiler errors for compile_fail tests (#3067)
# Objective bevy_ecs has several compile_fail tests that assert lifetime safety. In the past, these tests have been green for the wrong reasons (see e.g. #2984). This PR makes sure, that they will fail if the compiler error changes. ## Solution Use [trybuild](https://crates.io/crates/trybuild) to assert the compiler errors. The UI tests are in a separate crate that is not part of the Bevy workspace. This is to ensure that they do not break Bevy's crater builds. The tests get executed by the CI workflow on the stable toolchain.
This commit is contained in:
parent
94f5d194f4
commit
d0f423d653
19 changed files with 274 additions and 174 deletions
|
@ -12,7 +12,7 @@ readme = "README.md"
|
||||||
repository = "https://github.com/bevyengine/bevy"
|
repository = "https://github.com/bevyengine/bevy"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
exclude = ["benches"]
|
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests"]
|
||||||
members = ["crates/*", "examples/ios", "tools/ci", "errors"]
|
members = ["crates/*", "examples/ios", "tools/ci", "errors"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -47,7 +47,7 @@ bevy_audio = ["bevy_internal/bevy_audio"]
|
||||||
bevy_dynamic_plugin = ["bevy_internal/bevy_dynamic_plugin"]
|
bevy_dynamic_plugin = ["bevy_internal/bevy_dynamic_plugin"]
|
||||||
bevy_gilrs = ["bevy_internal/bevy_gilrs"]
|
bevy_gilrs = ["bevy_internal/bevy_gilrs"]
|
||||||
bevy_gltf = ["bevy_internal/bevy_gltf"]
|
bevy_gltf = ["bevy_internal/bevy_gltf"]
|
||||||
bevy_wgpu = ["bevy_internal/bevy_wgpu"]
|
bevy_wgpu = ["bevy_internal/bevy_wgpu"]
|
||||||
bevy_winit = ["bevy_internal/bevy_winit"]
|
bevy_winit = ["bevy_internal/bevy_winit"]
|
||||||
|
|
||||||
trace_chrome = ["bevy_internal/trace_chrome"]
|
trace_chrome = ["bevy_internal/trace_chrome"]
|
||||||
|
|
|
@ -786,172 +786,3 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ```compile_fail E0499
|
|
||||||
/// use bevy_ecs::prelude::*;
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct A(usize);
|
|
||||||
/// fn system(mut query: Query<&mut A>, e: Res<Entity>) {
|
|
||||||
/// let mut iter = query.iter_mut();
|
|
||||||
/// let a = &mut *iter.next().unwrap();
|
|
||||||
///
|
|
||||||
/// let mut iter2 = query.iter_mut();
|
|
||||||
/// let b = &mut *iter2.next().unwrap();
|
|
||||||
///
|
|
||||||
/// // this should fail to compile
|
|
||||||
/// println!("{}", a.0);
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[allow(unused)]
|
|
||||||
#[cfg(doctest)]
|
|
||||||
fn system_query_iter_lifetime_safety_test() {}
|
|
||||||
|
|
||||||
/// ```compile_fail E0499
|
|
||||||
/// use bevy_ecs::prelude::*;
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct A(usize);
|
|
||||||
/// fn system(mut query: Query<&mut A>, e: Res<Entity>) {
|
|
||||||
/// let mut a1 = query.get_mut(*e).unwrap();
|
|
||||||
/// let mut a2 = query.get_mut(*e).unwrap();
|
|
||||||
/// // this should fail to compile
|
|
||||||
/// println!("{} {}", a1.0, a2.0);
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[allow(unused)]
|
|
||||||
#[cfg(doctest)]
|
|
||||||
fn system_query_get_lifetime_safety_test() {}
|
|
||||||
|
|
||||||
/// ```compile_fail E0499
|
|
||||||
/// use bevy_ecs::prelude::*;
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct A(usize);
|
|
||||||
/// fn query_set(mut queries: QuerySet<(QueryState<&mut A>, QueryState<&A>)>, e: Res<Entity>) {
|
|
||||||
/// let mut q2 = queries.q0();
|
|
||||||
/// let mut iter2 = q2.iter_mut();
|
|
||||||
/// let mut b = iter2.next().unwrap();
|
|
||||||
///
|
|
||||||
/// let q1 = queries.q1();
|
|
||||||
/// let mut iter = q1.iter();
|
|
||||||
/// let a = &*iter.next().unwrap();
|
|
||||||
///
|
|
||||||
/// // this should fail to compile
|
|
||||||
/// b.0 = a.0
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[allow(unused)]
|
|
||||||
#[cfg(doctest)]
|
|
||||||
fn system_query_set_iter_lifetime_safety_test() {}
|
|
||||||
|
|
||||||
/// ```compile_fail E0499
|
|
||||||
/// use bevy_ecs::prelude::*;
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct A(usize);
|
|
||||||
/// fn query_set(mut queries: QuerySet<(QueryState<&mut A>, QueryState<&A>)>, e: Res<Entity>) {
|
|
||||||
/// let q1 = queries.q1();
|
|
||||||
/// let mut iter = q1.iter();
|
|
||||||
/// let a = &*iter.next().unwrap();
|
|
||||||
///
|
|
||||||
/// let mut q2 = queries.q0();
|
|
||||||
/// let mut iter2 = q2.iter_mut();
|
|
||||||
/// let mut b = iter2.next().unwrap();
|
|
||||||
///
|
|
||||||
/// // this should fail to compile
|
|
||||||
/// b.0 = a.0;
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[allow(unused)]
|
|
||||||
#[cfg(doctest)]
|
|
||||||
fn system_query_set_iter_flip_lifetime_safety_test() {}
|
|
||||||
|
|
||||||
/// ```compile_fail E0499
|
|
||||||
/// use bevy_ecs::prelude::*;
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct A(usize);
|
|
||||||
/// fn query_set(mut queries: QuerySet<(QueryState<&mut A>, QueryState<&A>)>, e: Res<Entity>) {
|
|
||||||
/// let mut q2 = queries.q0();
|
|
||||||
/// let mut b = q2.get_mut(*e).unwrap();
|
|
||||||
///
|
|
||||||
/// let q1 = queries.q1();
|
|
||||||
/// let a = q1.get(*e).unwrap();
|
|
||||||
///
|
|
||||||
/// // this should fail to compile
|
|
||||||
/// b.0 = a.0
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[allow(unused)]
|
|
||||||
#[cfg(doctest)]
|
|
||||||
fn system_query_set_get_lifetime_safety_test() {}
|
|
||||||
|
|
||||||
/// ```compile_fail E0499
|
|
||||||
/// use bevy_ecs::prelude::*;
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct A(usize);
|
|
||||||
/// fn query_set(mut queries: QuerySet<(QueryState<&mut A>, QueryState<&A>)>, e: Res<Entity>) {
|
|
||||||
/// let q1 = queries.q1();
|
|
||||||
/// let a = q1.get(*e).unwrap();
|
|
||||||
///
|
|
||||||
/// let mut q2 = queries.q0();
|
|
||||||
/// let mut b = q2.get_mut(*e).unwrap();
|
|
||||||
/// // this should fail to compile
|
|
||||||
/// b.0 = a.0
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[allow(unused)]
|
|
||||||
#[cfg(doctest)]
|
|
||||||
fn system_query_set_get_flip_lifetime_safety_test() {}
|
|
||||||
|
|
||||||
/// ```compile_fail E0502
|
|
||||||
/// use bevy_ecs::prelude::*;
|
|
||||||
/// use bevy_ecs::system::SystemState;
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct A(usize);
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct B(usize);
|
|
||||||
/// struct State {
|
|
||||||
/// state_r: SystemState<Query<'static, 'static, &'static A>>,
|
|
||||||
/// state_w: SystemState<Query<'static, 'static, &'static mut A>>,
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// impl State {
|
|
||||||
/// fn get_component<'w>(&mut self, world: &'w mut World, entity: Entity) {
|
|
||||||
/// let q1 = self.state_r.get(&world);
|
|
||||||
/// let a1 = q1.get(entity).unwrap();
|
|
||||||
///
|
|
||||||
/// let mut q2 = self.state_w.get_mut(world);
|
|
||||||
/// let a2 = q2.get_mut(entity).unwrap();
|
|
||||||
///
|
|
||||||
/// // this should fail to compile
|
|
||||||
/// println!("{}", a1.0);
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[allow(unused)]
|
|
||||||
#[cfg(doctest)]
|
|
||||||
fn system_state_get_lifetime_safety_test() {}
|
|
||||||
|
|
||||||
/// ```compile_fail E0502
|
|
||||||
/// use bevy_ecs::prelude::*;
|
|
||||||
/// use bevy_ecs::system::SystemState;
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct A(usize);
|
|
||||||
/// #[derive(Component)]
|
|
||||||
/// struct B(usize);
|
|
||||||
/// struct State {
|
|
||||||
/// state_r: SystemState<Query<'static, 'static, &'static A>>,
|
|
||||||
/// state_w: SystemState<Query<'static, 'static, &'static mut A>>,
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// impl State {
|
|
||||||
/// fn get_components<'w>(&mut self, world: &'w mut World) {
|
|
||||||
/// let q1 = self.state_r.get(&world);
|
|
||||||
/// let a1 = q1.iter().next().unwrap();
|
|
||||||
/// let mut q2 = self.state_w.get_mut(world);
|
|
||||||
/// let a2 = q2.iter_mut().next().unwrap();
|
|
||||||
/// // this should fail to compile
|
|
||||||
/// println!("{}", a1.0);
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[allow(unused)]
|
|
||||||
#[cfg(doctest)]
|
|
||||||
fn system_state_iter_lifetime_safety_test() {}
|
|
||||||
|
|
13
crates/bevy_ecs_compile_fail_tests/Cargo.toml
Normal file
13
crates/bevy_ecs_compile_fail_tests/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "bevy_ecs_compile_fail_tests"
|
||||||
|
version = "0.5.0"
|
||||||
|
edition = "2021"
|
||||||
|
description = "Compile fail tests for Bevy Engine's entity component system"
|
||||||
|
homepage = "https://bevyengine.org"
|
||||||
|
repository = "https://github.com/bevyengine/bevy"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" }
|
||||||
|
trybuild = "1.0"
|
5
crates/bevy_ecs_compile_fail_tests/README.md
Normal file
5
crates/bevy_ecs_compile_fail_tests/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Compile fail tests for bevy_ecs
|
||||||
|
|
||||||
|
This crate is separate from `bevy_ecs` and not part of the Bevy workspace in order to not fail `crater` tests for Bevy. The tests assert on the exact compiler errors and can easily fail for new Rust versions due to updated compiler errors (e.g. changes in spans).
|
||||||
|
|
||||||
|
The `CI` workflow executes these tests on the stable rust toolchain (see [tools/ci](../../tools/ci/src/main.rs)).
|
1
crates/bevy_ecs_compile_fail_tests/src/lib.rs
Normal file
1
crates/bevy_ecs_compile_fail_tests/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// Nothing here, check out the integration tests
|
5
crates/bevy_ecs_compile_fail_tests/tests/ui.rs
Normal file
5
crates/bevy_ecs_compile_fail_tests/tests/ui.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
|
let t = trybuild::TestCases::new();
|
||||||
|
t.compile_fail("tests/ui/*.rs");
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
use bevy_ecs::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct A(usize);
|
||||||
|
|
||||||
|
fn system(mut query: Query<&mut A>, e: Res<Entity>) {
|
||||||
|
let a1 = query.get_mut(*e).unwrap();
|
||||||
|
let a2 = query.get_mut(*e).unwrap();
|
||||||
|
// this should fail to compile
|
||||||
|
println!("{} {}", a1.0, a2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,10 @@
|
||||||
|
error[E0499]: cannot borrow `query` as mutable more than once at a time
|
||||||
|
--> tests/ui/system_query_get_lifetime_safety.rs:8:14
|
||||||
|
|
|
||||||
|
7 | let a1 = query.get_mut(*e).unwrap();
|
||||||
|
| ----- first mutable borrow occurs here
|
||||||
|
8 | let a2 = query.get_mut(*e).unwrap();
|
||||||
|
| ^^^^^ second mutable borrow occurs here
|
||||||
|
9 | // this should fail to compile
|
||||||
|
10 | println!("{} {}", a1.0, a2.0);
|
||||||
|
| -- first borrow later used here
|
|
@ -0,0 +1,17 @@
|
||||||
|
use bevy_ecs::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct A(usize);
|
||||||
|
|
||||||
|
fn system(mut query: Query<&mut A>) {
|
||||||
|
let mut iter = query.iter_mut();
|
||||||
|
let a = &mut *iter.next().unwrap();
|
||||||
|
|
||||||
|
let mut iter2 = query.iter_mut();
|
||||||
|
let _ = &mut *iter2.next().unwrap();
|
||||||
|
|
||||||
|
// this should fail to compile
|
||||||
|
println!("{}", a.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,11 @@
|
||||||
|
error[E0499]: cannot borrow `query` as mutable more than once at a time
|
||||||
|
--> tests/ui/system_query_iter_lifetime_safety.rs:10:21
|
||||||
|
|
|
||||||
|
7 | let mut iter = query.iter_mut();
|
||||||
|
| ----- first mutable borrow occurs here
|
||||||
|
...
|
||||||
|
10 | let mut iter2 = query.iter_mut();
|
||||||
|
| ^^^^^ second mutable borrow occurs here
|
||||||
|
...
|
||||||
|
14 | println!("{}", a.0);
|
||||||
|
| --- first borrow later used here
|
|
@ -0,0 +1,28 @@
|
||||||
|
use bevy_ecs::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct A(usize);
|
||||||
|
|
||||||
|
fn query_set(mut queries: QuerySet<(QueryState<&mut A>, QueryState<&A>)>, e: Res<Entity>) {
|
||||||
|
let mut q2 = queries.q0();
|
||||||
|
let mut b = q2.get_mut(*e).unwrap();
|
||||||
|
|
||||||
|
let q1 = queries.q1();
|
||||||
|
let a = q1.get(*e).unwrap();
|
||||||
|
|
||||||
|
// this should fail to compile
|
||||||
|
b.0 = a.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn query_set_flip(mut queries: QuerySet<(QueryState<&mut A>, QueryState<&A>)>, e: Res<Entity>) {
|
||||||
|
let q1 = queries.q1();
|
||||||
|
let a = q1.get(*e).unwrap();
|
||||||
|
|
||||||
|
let mut q2 = queries.q0();
|
||||||
|
let mut b = q2.get_mut(*e).unwrap();
|
||||||
|
|
||||||
|
// this should fail to compile
|
||||||
|
b.0 = a.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,23 @@
|
||||||
|
error[E0499]: cannot borrow `queries` as mutable more than once at a time
|
||||||
|
--> tests/ui/system_query_set_get_lifetime_safety.rs:10:14
|
||||||
|
|
|
||||||
|
7 | let mut q2 = queries.q0();
|
||||||
|
| ------- first mutable borrow occurs here
|
||||||
|
...
|
||||||
|
10 | let q1 = queries.q1();
|
||||||
|
| ^^^^^^^ second mutable borrow occurs here
|
||||||
|
...
|
||||||
|
14 | b.0 = a.0
|
||||||
|
| - first borrow later used here
|
||||||
|
|
||||||
|
error[E0499]: cannot borrow `queries` as mutable more than once at a time
|
||||||
|
--> tests/ui/system_query_set_get_lifetime_safety.rs:21:18
|
||||||
|
|
|
||||||
|
18 | let q1 = queries.q1();
|
||||||
|
| ------- first mutable borrow occurs here
|
||||||
|
...
|
||||||
|
21 | let mut q2 = queries.q0();
|
||||||
|
| ^^^^^^^ second mutable borrow occurs here
|
||||||
|
...
|
||||||
|
25 | b.0 = a.0
|
||||||
|
| --- first borrow later used here
|
|
@ -0,0 +1,32 @@
|
||||||
|
use bevy_ecs::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct A(usize);
|
||||||
|
|
||||||
|
fn query_set(mut queries: QuerySet<(QueryState<&mut A>, QueryState<&A>)>) {
|
||||||
|
let mut q2 = queries.q0();
|
||||||
|
let mut iter2 = q2.iter_mut();
|
||||||
|
let mut b = iter2.next().unwrap();
|
||||||
|
|
||||||
|
let q1 = queries.q1();
|
||||||
|
let mut iter = q1.iter();
|
||||||
|
let a = &*iter.next().unwrap();
|
||||||
|
|
||||||
|
// this should fail to compile
|
||||||
|
b.0 = a.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn query_set_flip(mut queries: QuerySet<(QueryState<&mut A>, QueryState<&A>)>) {
|
||||||
|
let q1 = queries.q1();
|
||||||
|
let mut iter = q1.iter();
|
||||||
|
let a = &*iter.next().unwrap();
|
||||||
|
|
||||||
|
let mut q2 = queries.q0();
|
||||||
|
let mut iter2 = q2.iter_mut();
|
||||||
|
let mut b = iter2.next().unwrap();
|
||||||
|
|
||||||
|
// this should fail to compile
|
||||||
|
b.0 = a.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,23 @@
|
||||||
|
error[E0499]: cannot borrow `queries` as mutable more than once at a time
|
||||||
|
--> tests/ui/system_query_set_iter_lifetime_safety.rs:11:14
|
||||||
|
|
|
||||||
|
7 | let mut q2 = queries.q0();
|
||||||
|
| ------- first mutable borrow occurs here
|
||||||
|
...
|
||||||
|
11 | let q1 = queries.q1();
|
||||||
|
| ^^^^^^^ second mutable borrow occurs here
|
||||||
|
...
|
||||||
|
16 | b.0 = a.0
|
||||||
|
| - first borrow later used here
|
||||||
|
|
||||||
|
error[E0499]: cannot borrow `queries` as mutable more than once at a time
|
||||||
|
--> tests/ui/system_query_set_iter_lifetime_safety.rs:24:18
|
||||||
|
|
|
||||||
|
20 | let q1 = queries.q1();
|
||||||
|
| ------- first mutable borrow occurs here
|
||||||
|
...
|
||||||
|
24 | let mut q2 = queries.q0();
|
||||||
|
| ^^^^^^^ second mutable borrow occurs here
|
||||||
|
...
|
||||||
|
29 | b.0 = a.0;
|
||||||
|
| --- first borrow later used here
|
|
@ -0,0 +1,28 @@
|
||||||
|
use bevy_ecs::prelude::*;
|
||||||
|
use bevy_ecs::system::SystemState;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct A(usize);
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct B(usize);
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
state_r: SystemState<Query<'static, 'static, &'static A>>,
|
||||||
|
state_w: SystemState<Query<'static, 'static, &'static mut A>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
fn get_component(&mut self, world: &mut World, entity: Entity) {
|
||||||
|
let q1 = self.state_r.get(&world);
|
||||||
|
let a1 = q1.get(entity).unwrap();
|
||||||
|
|
||||||
|
let mut q2 = self.state_w.get_mut(world);
|
||||||
|
let _ = q2.get_mut(entity).unwrap();
|
||||||
|
|
||||||
|
// this should fail to compile
|
||||||
|
println!("{}", a1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,11 @@
|
||||||
|
error[E0502]: cannot borrow `*world` as mutable because it is also borrowed as immutable
|
||||||
|
--> tests/ui/system_state_get_lifetime_safety.rs:20:22
|
||||||
|
|
|
||||||
|
17 | let q1 = self.state_r.get(&world);
|
||||||
|
| ------ immutable borrow occurs here
|
||||||
|
...
|
||||||
|
20 | let mut q2 = self.state_w.get_mut(world);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
|
||||||
|
...
|
||||||
|
24 | println!("{}", a1.0);
|
||||||
|
| ---- immutable borrow later used here
|
|
@ -0,0 +1,28 @@
|
||||||
|
use bevy_ecs::prelude::*;
|
||||||
|
use bevy_ecs::system::SystemState;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct A(usize);
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct B(usize);
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
state_r: SystemState<Query<'static, 'static, &'static A>>,
|
||||||
|
state_w: SystemState<Query<'static, 'static, &'static mut A>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
fn get_components(&mut self, world: &mut World) {
|
||||||
|
let q1 = self.state_r.get(&world);
|
||||||
|
let a1 = q1.iter().next().unwrap();
|
||||||
|
|
||||||
|
let mut q2 = self.state_w.get_mut(world);
|
||||||
|
let _ = q2.iter_mut().next().unwrap();
|
||||||
|
|
||||||
|
// this should fail to compile
|
||||||
|
println!("{}", a1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,11 @@
|
||||||
|
error[E0502]: cannot borrow `*world` as mutable because it is also borrowed as immutable
|
||||||
|
--> tests/ui/system_state_iter_lifetime_safety.rs:20:22
|
||||||
|
|
|
||||||
|
17 | let q1 = self.state_r.get(&world);
|
||||||
|
| ------ immutable borrow occurs here
|
||||||
|
...
|
||||||
|
20 | let mut q2 = self.state_w.get_mut(world);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
|
||||||
|
...
|
||||||
|
24 | println!("{}", a1.0);
|
||||||
|
| ---- immutable borrow later used here
|
|
@ -1,4 +1,4 @@
|
||||||
use xshell::cmd;
|
use xshell::{cmd, pushd};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// When run locally, results may differ from actual CI runs triggered by
|
// When run locally, results may differ from actual CI runs triggered by
|
||||||
|
@ -14,6 +14,16 @@ fn main() {
|
||||||
// See if clippy has any complaints.
|
// See if clippy has any complaints.
|
||||||
// - Type complexity must be ignored because we use huge templates for queries
|
// - Type complexity must be ignored because we use huge templates for queries
|
||||||
cmd!("cargo clippy --workspace --all-targets --all-features -- -D warnings -A clippy::type_complexity")
|
cmd!("cargo clippy --workspace --all-targets --all-features -- -D warnings -A clippy::type_complexity")
|
||||||
.run()
|
.run()
|
||||||
.expect("Please fix clippy errors in output above.");
|
.expect("Please fix clippy errors in output above.");
|
||||||
|
|
||||||
|
// Run UI tests (they do not get executed with the workspace tests)
|
||||||
|
// - See crates/bevy_ecs_compile_fail_tests/README.md
|
||||||
|
{
|
||||||
|
let _bevy_ecs_compile_fail_tests = pushd("crates/bevy_ecs_compile_fail_tests")
|
||||||
|
.expect("Failed to navigate to the 'bevy_ecs_compile_fail_tests' crate");
|
||||||
|
cmd!("cargo test")
|
||||||
|
.run()
|
||||||
|
.expect("Compiler errors of the ECS compile fail tests seem to be different than expected! Check locally and compare rust versions.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue