Remove redundant imports (#12817)

# Objective

- There are several redundant imports in the tests and examples that are
not caught by CI because additional flags need to be passed.

## Solution

- Run `cargo check --workspace --tests` and `cargo check --workspace
--examples`, then fix all warnings.
- Add `test-check` to CI, which will be run in the check-compiles job.
This should catch future warnings for tests. Examples are already
checked, but I'm not yet sure why they weren't caught.

## Discussion

- Should the `--tests` and `--examples` flags be added to CI, so this is
caught in the future?
- If so, #12818 will need to be merged first. It was also a warning
raised by checking the examples, but I chose to split off into a
separate PR.

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
This commit is contained in:
BD103 2024-04-01 15:59:08 -04:00 committed by GitHub
parent abd94480ab
commit 84363f2fab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 56 additions and 63 deletions

View file

@ -304,7 +304,6 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq, color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq,
Srgba,
}; };
#[test] #[test]

View file

@ -227,7 +227,6 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq, color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq,
Srgba,
}; };
#[test] #[test]

View file

@ -260,7 +260,6 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq, color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq,
Srgba,
}; };
#[test] #[test]

View file

@ -320,7 +320,6 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq, color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq,
Srgba,
}; };
#[test] #[test]

View file

@ -289,7 +289,6 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq, color_difference::EuclideanDistance, test_colors::TEST_COLORS, testing::assert_approx_eq,
Srgba,
}; };
#[test] #[test]

View file

@ -305,7 +305,7 @@ impl From<Oklaba> for Xyza {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{test_colors::TEST_COLORS, testing::assert_approx_eq, Srgba}; use crate::{test_colors::TEST_COLORS, testing::assert_approx_eq};
#[test] #[test]
fn test_to_from_srgba() { fn test_to_from_srgba() {

View file

@ -344,7 +344,7 @@ impl From<Oklcha> for Xyza {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{test_colors::TEST_COLORS, testing::assert_approx_eq, Srgba}; use crate::{test_colors::TEST_COLORS, testing::assert_approx_eq};
#[test] #[test]
fn test_to_from_srgba() { fn test_to_from_srgba() {

View file

@ -87,8 +87,6 @@ pub type EntityHashSet = hashbrown::HashSet<Entity, EntityHash>;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use static_assertions::assert_impl_all; use static_assertions::assert_impl_all;
// Check that the HashMaps are Clone if the key/values are Clone // Check that the HashMaps are Clone if the key/values are Clone

View file

@ -253,8 +253,6 @@ mod tests {
use crate::prelude::*; use crate::prelude::*;
use crate::world::FilteredEntityRef; use crate::world::FilteredEntityRef;
use super::QueryBuilder;
#[derive(Component, PartialEq, Debug)] #[derive(Component, PartialEq, Debug)]
struct A(usize); struct A(usize);

View file

@ -1032,7 +1032,7 @@ mod tests {
use crate as bevy_ecs; use crate as bevy_ecs;
use crate::component::Component; use crate::component::Component;
use crate::schedule::IntoSystemConfigs; use crate::schedule::IntoSystemConfigs;
use crate::schedule::{common_conditions::not, State, States}; use crate::schedule::{State, States};
use crate::system::Local; use crate::system::Local;
use crate::{change_detection::ResMut, schedule::Schedule, world::World}; use crate::{change_detection::ResMut, schedule::Schedule, world::World};
use bevy_ecs_macros::Event; use bevy_ecs_macros::Event;

View file

@ -26,7 +26,7 @@ mod tests {
use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::atomic::{AtomicU32, Ordering};
pub use crate as bevy_ecs; pub use crate as bevy_ecs;
pub use crate::schedule::{IntoSystemSetConfigs, Schedule, SystemSet}; pub use crate::schedule::{Schedule, SystemSet};
pub use crate::system::{Res, ResMut}; pub use crate::system::{Res, ResMut};
pub use crate::{prelude::World, system::Resource}; pub use crate::{prelude::World, system::Resource};
@ -724,7 +724,6 @@ mod tests {
use super::*; use super::*;
// Required to make the derive macro behave // Required to make the derive macro behave
use crate as bevy_ecs; use crate as bevy_ecs;
use crate::event::Events;
use crate::prelude::*; use crate::prelude::*;
#[derive(Resource)] #[derive(Resource)]

View file

@ -828,7 +828,7 @@ impl ScheduleState {
mod tests { mod tests {
use super::*; use super::*;
use crate::prelude::*; use crate::prelude::*;
use crate::{schedule::ScheduleLabel, world::World}; use crate::schedule::ScheduleLabel;
pub use crate as bevy_ecs; pub use crate as bevy_ecs;

View file

@ -1531,9 +1531,9 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
self as bevy_ecs, // Necessary for the `SystemParam` Derive when used inside `bevy_ecs`. self as bevy_ecs, // Necessary for the `SystemParam` Derive when used inside `bevy_ecs`.
system::{assert_is_system, Query}, system::assert_is_system,
}; };
use std::{cell::RefCell, marker::PhantomData}; use std::cell::RefCell;
// Compile test for https://github.com/bevyengine/bevy/pull/2838. // Compile test for https://github.com/bevyengine/bevy/pull/2838.
#[test] #[test]

View file

@ -564,7 +564,6 @@ impl approx::UlpsEq for Dir3A {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::InvalidDirectionError;
#[test] #[test]
fn dir2_creation() { fn dir2_creation() {

View file

@ -828,7 +828,6 @@ mod tests {
// Reference values were computed by hand and/or with external tools // Reference values were computed by hand and/or with external tools
use super::*; use super::*;
use crate::{InvalidDirectionError, Quat};
use approx::assert_relative_eq; use approx::assert_relative_eq;
#[test] #[test]

View file

@ -491,7 +491,6 @@ mod tests {
use super::*; use super::*;
use crate as bevy_reflect; use crate as bevy_reflect;
use crate::*; use crate::*;
use error::AccessErrorKind;
#[derive(Reflect)] #[derive(Reflect)]
struct A { struct A {

View file

@ -937,7 +937,6 @@ impl CompressedImageFormats {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::render_asset::RenderAssetUsages;
#[test] #[test]
fn image_size() { fn image_size() {

View file

@ -222,7 +222,6 @@ mod test {
use image::{GenericImage, Rgba}; use image::{GenericImage, Rgba};
use super::*; use super::*;
use crate::render_asset::RenderAssetUsages;
#[test] #[test]
fn two_way_conversion() { fn two_way_conversion() {

View file

@ -239,7 +239,6 @@ pub fn paused(time: Res<Time<Virtual>>) -> bool {
mod tests { mod tests {
use super::*; use super::*;
use bevy_ecs::schedule::{IntoSystemConfigs, Schedule}; use bevy_ecs::schedule::{IntoSystemConfigs, Schedule};
use std::time::Duration;
fn test_system() {} fn test_system() {}

View file

@ -188,10 +188,9 @@ mod test {
use bevy_math::{vec3, Vec3}; use bevy_math::{vec3, Vec3};
use bevy_tasks::{ComputeTaskPool, TaskPool}; use bevy_tasks::{ComputeTaskPool, TaskPool};
use crate::components::{GlobalTransform, Transform};
use crate::systems::*; use crate::systems::*;
use crate::TransformBundle; use crate::TransformBundle;
use bevy_hierarchy::{BuildChildren, BuildWorldChildren, Children, Parent}; use bevy_hierarchy::{BuildChildren, BuildWorldChildren};
#[test] #[test]
fn correct_parent_removed() { fn correct_parent_removed() {

View file

@ -1,6 +1,6 @@
//! This example demonstrates how to use the `Camera::viewport_to_world` method. //! This example demonstrates how to use the `Camera::viewport_to_world` method.
use bevy::{math::Dir3, prelude::*}; use bevy::prelude::*;
fn main() { fn main() {
App::new() App::new()

View file

@ -4,7 +4,7 @@ use std::f32::consts::PI;
use bevy::{ use bevy::{
color::palettes::basic::{BLUE, LIME, RED}, color::palettes::basic::{BLUE, LIME, RED},
pbr::{light_consts, CascadeShadowConfigBuilder, NotShadowCaster, NotShadowReceiver}, pbr::{CascadeShadowConfigBuilder, NotShadowCaster, NotShadowReceiver},
prelude::*, prelude::*,
}; };

View file

@ -2,7 +2,7 @@
use bevy::{ use bevy::{
color::palettes::css::{ORANGE, SILVER, WHITE}, color::palettes::css::{ORANGE, SILVER, WHITE},
math::{cubic_splines::CubicCurve, vec3}, math::vec3,
prelude::*, prelude::*,
}; };

View file

@ -4,7 +4,6 @@
use std::f32::consts::*; use std::f32::consts::*;
use bevy::{ use bevy::{
pbr::AmbientLight,
prelude::*, prelude::*,
render::{ render::{
mesh::{ mesh::{

View file

@ -3,7 +3,7 @@
use std::f32::consts::*; use std::f32::consts::*;
use bevy::{pbr::AmbientLight, prelude::*, render::mesh::skinning::SkinnedMesh}; use bevy::{prelude::*, render::mesh::skinning::SkinnedMesh};
fn main() { fn main() {
App::new() App::new()

View file

@ -5,7 +5,7 @@
//! - `App::run()` will never return on iOS and Web. //! - `App::run()` will never return on iOS and Web.
//! - It is not possible to recreate a window after the event loop has been terminated. //! - It is not possible to recreate a window after the event loop has been terminated.
use bevy::{prelude::*, window::WindowPlugin}; use bevy::prelude::*;
fn main() { fn main() {
println!("Running Bevy App"); println!("Running Bevy App");

View file

@ -1,7 +1,7 @@
//! Implements loader for a custom asset type. //! Implements loader for a custom asset type.
use bevy::{ use bevy::{
asset::{io::Reader, ron, AssetLoader, AsyncReadExt, LoadContext}, asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*, prelude::*,
reflect::TypePath, reflect::TypePath,
}; };

View file

@ -1,6 +1,6 @@
//! This example illustrates how to react to component change. //! This example illustrates how to react to component change.
use bevy::{ecs::world::Ref, prelude::*}; use bevy::prelude::*;
use rand::Rng; use rand::Rng;
fn main() { fn main() {

View file

@ -9,7 +9,7 @@ use bevy::prelude::*;
use bevy::{ use bevy::{
ecs::{ ecs::{
component::{ComponentDescriptor, ComponentId, ComponentInfo, StorageType}, component::{ComponentDescriptor, ComponentId, ComponentInfo, StorageType},
query::{QueryBuilder, QueryData}, query::QueryData,
world::FilteredEntityMut, world::FilteredEntityMut,
}, },
ptr::{Aligned, OwningPtr}, ptr::{Aligned, OwningPtr},

View file

@ -4,7 +4,6 @@ use std::f32::consts::{FRAC_PI_2, PI};
use bevy::{ use bevy::{
color::palettes::css::{DARK_CYAN, GOLD, GRAY, PURPLE}, color::palettes::css::{DARK_CYAN, GOLD, GRAY, PURPLE},
gizmos::light::{LightGizmoColor, LightGizmoConfigGroup},
prelude::*, prelude::*,
}; };

View file

@ -1,6 +1,6 @@
//! Prints out all chars as they are inputted. //! Prints out all chars as they are inputted.
use bevy::{prelude::*, window::ReceivedCharacter}; use bevy::prelude::*;
fn main() { fn main() {
App::new() App::new()

View file

@ -1,6 +1,6 @@
//! Shows handling of gamepad input, connections, and disconnections. //! Shows handling of gamepad input, connections, and disconnections.
use bevy::{input::gamepad::GamepadButton, prelude::*}; use bevy::prelude::*;
fn main() { fn main() {
App::new() App::new()

View file

@ -14,7 +14,6 @@ use bevy::{
renderer::{RenderContext, RenderDevice}, renderer::{RenderContext, RenderDevice},
Render, RenderApp, RenderSet, Render, RenderApp, RenderSet,
}, },
window::WindowPlugin,
}; };
use std::borrow::Cow; use std::borrow::Cow;

View file

@ -7,9 +7,7 @@ use std::time::Duration;
use bevy::{ use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
math::Quat,
prelude::*, prelude::*,
render::camera::Camera,
window::{PresentMode, WindowResolution}, window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings}, winit::{UpdateMode, WinitSettings},
}; };

View file

@ -5,7 +5,7 @@ use bevy::{
color::palettes::css::ORANGE_RED, color::palettes::css::ORANGE_RED,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*, prelude::*,
window::{PresentMode, WindowPlugin, WindowResolution}, window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings}, winit::{UpdateMode, WinitSettings},
}; };

View file

@ -10,7 +10,7 @@ use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*, prelude::*,
text::{BreakLineOn, Text2dBounds}, text::{BreakLineOn, Text2dBounds},
window::{PresentMode, WindowPlugin, WindowResolution}, window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings}, winit::{UpdateMode, WinitSettings},
}; };

View file

@ -10,7 +10,7 @@ use bevy::{
pbr::{ExtractedPointLight, GlobalLightMeta}, pbr::{ExtractedPointLight, GlobalLightMeta},
prelude::*, prelude::*,
render::{camera::ScalingMode, Render, RenderApp, RenderSet}, render::{camera::ScalingMode, Render, RenderApp, RenderSet},
window::{PresentMode, WindowPlugin, WindowResolution}, window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings}, winit::{UpdateMode, WinitSettings},
}; };
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};

View file

@ -11,7 +11,7 @@ use bevy::{
color::palettes::css::*, color::palettes::css::*,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*, prelude::*,
window::{PresentMode, WindowPlugin, WindowResolution}, window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings}, winit::{UpdateMode, WinitSettings},
}; };

View file

@ -7,7 +7,7 @@ use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*, prelude::*,
text::{BreakLineOn, Text2dBounds}, text::{BreakLineOn, Text2dBounds},
window::{PresentMode, WindowPlugin, WindowResolution}, window::{PresentMode, WindowResolution},
winit::{UpdateMode, WinitSettings}, winit::{UpdateMode, WinitSettings},
}; };

View file

@ -3,9 +3,7 @@
use std::f32::consts::PI; use std::f32::consts::PI;
use bevy::{ use bevy::{
input::gamepad::{ input::gamepad::{GamepadAxisChangedEvent, GamepadButtonChangedEvent, GamepadSettings},
GamepadAxisChangedEvent, GamepadButton, GamepadButtonChangedEvent, GamepadSettings,
},
prelude::*, prelude::*,
sprite::{Anchor, MaterialMesh2dBundle, Mesh2dHandle}, sprite::{Anchor, MaterialMesh2dBundle, Mesh2dHandle},
}; };

View file

@ -11,7 +11,6 @@ use bevy::{
math::Vec3A, math::Vec3A,
prelude::*, prelude::*,
render::primitives::{Aabb, Sphere}, render::primitives::{Aabb, Sphere},
window::WindowPlugin,
}; };
#[path = "../../helpers/camera_controller.rs"] #[path = "../../helpers/camera_controller.rs"]

View file

@ -1,10 +1,7 @@
//! This example shows how to align the orientations of objects in 3D space along two axes using the `Transform::align` API. //! This example shows how to align the orientations of objects in 3D space along two axes using the `Transform::align` API.
use bevy::color::{ use bevy::color::palettes::basic::{GRAY, RED, WHITE};
palettes::basic::{GRAY, RED, WHITE}, use bevy::input::mouse::{MouseButtonInput, MouseMotion};
Color,
};
use bevy::input::mouse::{MouseButton, MouseButtonInput, MouseMotion};
use bevy::prelude::*; use bevy::prelude::*;
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng; use rand_chacha::ChaCha8Rng;

View file

@ -1,10 +1,10 @@
//! Shows various text layout options. //! Shows various text layout options.
use bevy::{ use bevy::{
color::palettes::{basic::RED, css::*}, color::palettes::css::*,
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
prelude::*, prelude::*,
window::{PresentMode, WindowPlugin}, window::PresentMode,
}; };
fn main() { fn main() {

View file

@ -6,7 +6,7 @@
use bevy::{ use bevy::{
prelude::*, prelude::*,
utils::Duration, utils::Duration,
window::{PresentMode, RequestRedraw, WindowPlugin}, window::{PresentMode, RequestRedraw},
winit::WinitSettings, winit::WinitSettings,
}; };

View file

@ -4,12 +4,9 @@
//! [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.transparent) //! [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.transparent)
//! for more details. //! for more details.
use bevy::prelude::*;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use bevy::window::CompositeAlphaMode; use bevy::window::CompositeAlphaMode;
use bevy::{
prelude::*,
window::{Window, WindowPlugin},
};
fn main() { fn main() {
App::new() App::new()

View file

@ -1,4 +1,4 @@
use bevy::{ecs::event::Events, prelude::*}; use bevy::prelude::*;
#[derive(Component, Default)] #[derive(Component, Default)]
struct Enemy { struct Enemy {

View file

@ -18,6 +18,7 @@ bitflags! {
const EXAMPLE_CHECK = 0b10000000; const EXAMPLE_CHECK = 0b10000000;
const COMPILE_CHECK = 0b100000000; const COMPILE_CHECK = 0b100000000;
const CFG_CHECK = 0b1000000000; const CFG_CHECK = 0b1000000000;
const TEST_CHECK = 0b10000000000;
} }
} }
@ -56,13 +57,18 @@ fn main() {
("doc", Check::DOC_TEST | Check::DOC_CHECK), ("doc", Check::DOC_TEST | Check::DOC_CHECK),
( (
"compile", "compile",
Check::COMPILE_FAIL | Check::BENCH_CHECK | Check::EXAMPLE_CHECK | Check::COMPILE_CHECK, Check::COMPILE_FAIL
| Check::BENCH_CHECK
| Check::EXAMPLE_CHECK
| Check::COMPILE_CHECK
| Check::TEST_CHECK,
), ),
("format", Check::FORMAT), ("format", Check::FORMAT),
("clippy", Check::CLIPPY), ("clippy", Check::CLIPPY),
("compile-fail", Check::COMPILE_FAIL), ("compile-fail", Check::COMPILE_FAIL),
("bench-check", Check::BENCH_CHECK), ("bench-check", Check::BENCH_CHECK),
("example-check", Check::EXAMPLE_CHECK), ("example-check", Check::EXAMPLE_CHECK),
("test-check", Check::TEST_CHECK),
("cfg-check", Check::CFG_CHECK), ("cfg-check", Check::CFG_CHECK),
("doc-check", Check::DOC_CHECK), ("doc-check", Check::DOC_CHECK),
("doc-test", Check::DOC_TEST), ("doc-test", Check::DOC_TEST),
@ -314,6 +320,24 @@ fn main() {
); );
} }
if checks.contains(Check::TEST_CHECK) {
let mut args = vec!["--workspace", "--tests"];
if flags.contains(Flag::KEEP_GOING) {
args.push("--keep-going");
}
test_suite.insert(
Check::TEST_CHECK,
vec![CITest {
command: cmd!(sh, "cargo check {args...}"),
failure_message: "Please fix compiler examples for tests in output above.",
subdir: None,
env_vars: Vec::new(),
}],
);
}
// Actually run the tests: // Actually run the tests:
let mut failed_checks: Check = Check::empty(); let mut failed_checks: Check = Check::empty();