Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Assert compiler errors for compile_fail tests #3067

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
repository = "https://github.com/bevyengine/bevy"

[workspace]
exclude = ["benches"]
exclude = ["benches", "crates/bevy_ecs_ui_tests"]
members = ["crates/*", "examples/ios", "tools/ci", "errors"]

[features]
Expand Down Expand Up @@ -46,7 +46,7 @@ bevy_audio = ["bevy_internal/bevy_audio"]
bevy_dynamic_plugin = ["bevy_internal/bevy_dynamic_plugin"]
bevy_gilrs = ["bevy_internal/bevy_gilrs"]
bevy_gltf = ["bevy_internal/bevy_gltf"]
bevy_wgpu = ["bevy_internal/bevy_wgpu"]
bevy_wgpu = ["bevy_internal/bevy_wgpu"]
bevy_winit = ["bevy_internal/bevy_winit"]

trace_chrome = ["bevy_internal/trace_chrome"]
Expand Down
169 changes: 0 additions & 169 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 13 additions & 0 deletions crates/bevy_ecs_ui_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "bevy_ecs_ui_tests"
version = "0.5.0"
edition = "2021"
description = "UI 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 changes: 5 additions & 0 deletions crates/bevy_ecs_ui_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# UI 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. UI tests often fail for new Rust versions due to changed compiler output.

The `CI` workflow executes the UI tests on the stable rust toolchain (see [tools/ci](../../tools/ci/src/main.rs)).
1 change: 1 addition & 0 deletions crates/bevy_ecs_ui_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Nothing here, check out the integration tests
5 changes: 5 additions & 0 deletions crates/bevy_ecs_ui_tests/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[test]
fn test() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
}
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
Loading