From f854b8533f7e94fa710d67279564ec70068fd7c0 Mon Sep 17 00:00:00 2001 From: Ellen Date: Fri, 2 Sep 2022 18:00:25 +0100 Subject: [PATCH] compile fail --- .../tests/ui/query_to_readonly.rs | 75 ------------------- .../tests/ui/query_to_readonly.stderr | 45 ----------- 2 files changed, 120 deletions(-) delete mode 100644 crates/bevy_ecs_compile_fail_tests/tests/ui/query_to_readonly.rs delete mode 100644 crates/bevy_ecs_compile_fail_tests/tests/ui/query_to_readonly.stderr diff --git a/crates/bevy_ecs_compile_fail_tests/tests/ui/query_to_readonly.rs b/crates/bevy_ecs_compile_fail_tests/tests/ui/query_to_readonly.rs deleted file mode 100644 index 060793023339b..0000000000000 --- a/crates/bevy_ecs_compile_fail_tests/tests/ui/query_to_readonly.rs +++ /dev/null @@ -1,75 +0,0 @@ -use bevy_ecs::prelude::*; - -#[derive(Component, Debug)] -struct Foo; - -fn for_loops(mut query: Query<&mut Foo>) { - // this should fail to compile - for _ in query.iter_mut() { - for _ in query.to_readonly().iter() {} - } - - // this should fail to compile - for _ in query.to_readonly().iter() { - for _ in query.iter_mut() {} - } - - // this should *not* fail to compile - for _ in query.to_readonly().iter() { - for _ in query.to_readonly().iter() {} - } - - // this should *not* fail to compile - for _ in query.to_readonly().iter() { - for _ in query.iter() {} - } - - // this should *not* fail to compile - for _ in query.iter() { - for _ in query.to_readonly().iter() {} - } -} - -fn single_mut_query(mut query: Query<&mut Foo>) { - // this should fail to compile - { - let mut mut_foo = query.single_mut(); - - // This solves "temporary value dropped while borrowed" - let readonly_query = query.to_readonly(); - - let ref_foo = readonly_query.single(); - - *mut_foo = Foo; - - println!("{ref_foo:?}"); - } - - // this should fail to compile - { - // This solves "temporary value dropped while borrowed" - let readonly_query = query.to_readonly(); - - let ref_foo = readonly_query.single(); - - let mut mut_foo = query.single_mut(); - - println!("{ref_foo:?}"); - - *mut_foo = Foo; - } - - // this should *not* fail to compile - { - // This solves "temporary value dropped while borrowed" - let readonly_query = query.to_readonly(); - - let readonly_foo = readonly_query.single(); - - let query_foo = query.single(); - - println!("{readonly_foo:?}, {query_foo:?}"); - } -} - -fn main() {} \ No newline at end of file diff --git a/crates/bevy_ecs_compile_fail_tests/tests/ui/query_to_readonly.stderr b/crates/bevy_ecs_compile_fail_tests/tests/ui/query_to_readonly.stderr deleted file mode 100644 index b57108182203f..0000000000000 --- a/crates/bevy_ecs_compile_fail_tests/tests/ui/query_to_readonly.stderr +++ /dev/null @@ -1,45 +0,0 @@ -error[E0502]: cannot borrow `query` as immutable because it is also borrowed as mutable - --> tests/ui/query_to_readonly.rs:9:18 - | -8 | for _ in query.iter_mut() { - | ---------------- - | | - | mutable borrow occurs here - | mutable borrow later used here -9 | for _ in query.to_readonly().iter() {} - | ^^^^^^^^^^^^^^^^^^^ immutable borrow occurs here - -error[E0502]: cannot borrow `query` as mutable because it is also borrowed as immutable - --> tests/ui/query_to_readonly.rs:14:18 - | -13 | for _ in query.to_readonly().iter() { - | -------------------------- - | | - | immutable borrow occurs here - | immutable borrow later used here -14 | for _ in query.iter_mut() {} - | ^^^^^^^^^^^^^^^^ mutable borrow occurs here - -error[E0502]: cannot borrow `query` as immutable because it is also borrowed as mutable - --> tests/ui/query_to_readonly.rs:39:30 - | -36 | let mut mut_foo = query.single_mut(); - | ------------------ mutable borrow occurs here -... -39 | let readonly_query = query.to_readonly(); - | ^^^^^^^^^^^^^^^^^^^ immutable borrow occurs here -... -43 | *mut_foo = Foo; - | ------- mutable borrow later used here - -error[E0502]: cannot borrow `query` as mutable because it is also borrowed as immutable - --> tests/ui/query_to_readonly.rs:55:27 - | -51 | let readonly_query = query.to_readonly(); - | ------------------- immutable borrow occurs here -... -55 | let mut mut_foo = query.single_mut(); - | ^^^^^^^^^^^^^^^^^^ mutable borrow occurs here -56 | -57 | println!("{ref_foo:?}"); - | ------- immutable borrow later used here