Skip to content

Commit

Permalink
Fix compile_fail tests (#2984)
Browse files Browse the repository at this point in the history
# Objective

- Bevy has several `compile_fail` test
- #2254 added `#[derive(Component)]`
- Those tests now fail for a different reason.
- This was not caught as these test still "successfully" failed to compile.

## Solution

- Add `#[derive(Component)]` to the doctest
- Also changed their cfg attribute from `doc` to `doctest`, so that these tests don't appear when running `cargo doc` with `--document-private-items`
  • Loading branch information
MinerSebas committed Oct 18, 2021
1 parent d65fbd7 commit 6a8a8c9
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,9 @@ mod tests {
}
}

/// ```compile_fail
/// ```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();
Expand All @@ -802,11 +803,12 @@ mod tests {
/// }
/// ```
#[allow(unused)]
#[cfg(doc)]
#[cfg(doctest)]
fn system_query_iter_lifetime_safety_test() {}

/// ```compile_fail
/// ```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();
Expand All @@ -816,11 +818,12 @@ fn system_query_iter_lifetime_safety_test() {}
/// }
/// ```
#[allow(unused)]
#[cfg(doc)]
#[cfg(doctest)]
fn system_query_get_lifetime_safety_test() {}

/// ```compile_fail
/// ```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();
Expand All @@ -836,11 +839,12 @@ fn system_query_get_lifetime_safety_test() {}
/// }
/// ```
#[allow(unused)]
#[cfg(doc)]
#[cfg(doctest)]
fn system_query_set_iter_lifetime_safety_test() {}

/// ```compile_fail
/// ```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();
Expand All @@ -856,11 +860,12 @@ fn system_query_set_iter_lifetime_safety_test() {}
/// }
/// ```
#[allow(unused)]
#[cfg(doc)]
#[cfg(doctest)]
fn system_query_set_iter_flip_lifetime_safety_test() {}

/// ```compile_fail
/// ```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();
Expand All @@ -874,11 +879,12 @@ fn system_query_set_iter_flip_lifetime_safety_test() {}
/// }
/// ```
#[allow(unused)]
#[cfg(doc)]
#[cfg(doctest)]
fn system_query_set_get_lifetime_safety_test() {}

/// ```compile_fail
/// ```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();
Expand All @@ -891,13 +897,15 @@ fn system_query_set_get_lifetime_safety_test() {}
/// }
/// ```
#[allow(unused)]
#[cfg(doc)]
#[cfg(doctest)]
fn system_query_set_get_flip_lifetime_safety_test() {}

/// ```compile_fail
/// ```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>>,
Expand All @@ -918,13 +926,15 @@ fn system_query_set_get_flip_lifetime_safety_test() {}
/// }
/// ```
#[allow(unused)]
#[cfg(doc)]
#[cfg(doctest)]
fn system_state_get_lifetime_safety_test() {}

/// ```compile_fail
/// ```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>>,
Expand All @@ -943,5 +953,5 @@ fn system_state_get_lifetime_safety_test() {}
/// }
/// ```
#[allow(unused)]
#[cfg(doc)]
#[cfg(doctest)]
fn system_state_iter_lifetime_safety_test() {}

0 comments on commit 6a8a8c9

Please sign in to comment.