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

enforce cargo fmt --check #201

Merged
merged 3 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt

- name: Install alsa
run: sudo apt-get install libasound2-dev

- name: Build
run: cargo check

- name: Check the format
run: cargo +nightly fmt --all -- --check

- name: Run tests
run: cargo test --workspace

2 changes: 1 addition & 1 deletion crates/bevy_app/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn map_instance_event<T>(event_instance: &EventInstance<T>) -> &T {
&event_instance.event
}

/// Reads events of type `T` in order and tracks which events have already been read.
/// Reads events of type `T` in order and tracks which events have already been read.
pub struct EventReader<T> {
last_event_count: usize,
_marker: PhantomData<T>,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl HandleId {

/// A handle into a specific Asset of type `T`
///
/// Handles contain a unique id that corresponds to a specific asset in the [Assets](crate::Assets) collection.
/// Handles contain a unique id that corresponds to a specific asset in the [Assets](crate::Assets) collection.
#[derive(Properties)]
pub struct Handle<T>
where
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "filesystem_watcher")]
mod filesystem_watcher;
mod asset_server;
mod assets;
#[cfg(feature = "filesystem_watcher")]
mod filesystem_watcher;
mod handle;
mod load_request;
mod loader;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<T> AssetChannel<T> {
}
}

/// Reads [AssetResult]s from an [AssetChannel] and updates the [Assets] collection and [LoadState] accordingly
/// Reads [AssetResult]s from an [AssetChannel] and updates the [Assets] collection and [LoadState] accordingly
pub fn update_asset_storage_system<T: Resource>(
asset_channel: Res<AssetChannel<T>>,
asset_server: Res<AssetServer>,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core/src/float_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

/// A wrapper type that enables ordering floats. This is a work around for the famous "rust float ordering" problem.
/// By using it, you acknowledge that sorting NaN is undefined according to spec. This implementation treats NaN as the
/// "smallest" float.
/// "smallest" float.
#[derive(Debug, Copy, Clone, PartialOrd)]
pub struct FloatOrd(pub f32);

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT"
keywords = ["bevy"]

[features]
profiler = []
profiler = ["bevy_ecs/profiler"]

[dependencies]
# bevy
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Plugin for DiagnosticsPlugin {
#[cfg(feature = "profiler")]
{
use bevy_ecs::IntoQuerySystem;
app.add_resource::<Box<dyn bevy_ecs::profiler::Profiler>>(Box::new(
app.add_resource::<Box<dyn bevy_ecs::Profiler>>(Box::new(
system_profiler::SystemProfiler::default(),
))
.add_system_to_stage(
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/src/print_diagnostics_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_core::{Time, Timer};
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
use std::time::Duration;

/// An App Plugin that prints diagnostics to the console
/// An App Plugin that prints diagnostics to the console
pub struct PrintDiagnosticsPlugin {
pub debug: bool,
pub wait_duration: Duration,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_diagnostic/src/system_profiler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_ecs::{profiler::Profiler, Res, ResMut};
use bevy_ecs::{Profiler, Res, ResMut};
use std::{
borrow::Cow,
collections::HashMap,
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ bevy_hecs = { path = "hecs", features = ["macros", "serialize"], version = "0.1"
rand = "0.7.2"
rayon = "1.3"
crossbeam-channel = "0.4.2"
fixedbitset = "0.3.0"
fixedbitset = "0.3.0"
downcast-rs = "1.1.1"
4 changes: 3 additions & 1 deletion crates/bevy_ecs/hecs/examples/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
//! also be useful for serialization, or other row-oriented generic operations.

fn format_entity(entity: bevy_hecs::EntityRef<'_>) -> String {
fn fmt<T: bevy_hecs::Component + std::fmt::Display>(entity: bevy_hecs::EntityRef<'_>) -> Option<String> {
fn fmt<T: bevy_hecs::Component + std::fmt::Display>(
entity: bevy_hecs::EntityRef<'_>,
) -> Option<String> {
Some(entity.get::<T>()?.to_string())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/resource/resource_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::{
system::{SystemId, TypeAccess},
Resource, ResourceIndex,
};
use bevy_hecs::smaller_tuples_too;
use core::{
any::TypeId,
ops::{Deref, DerefMut},
ptr::NonNull,
};
use bevy_hecs::smaller_tuples_too;
use std::marker::PhantomData;

/// Shared borrow of a Resource
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/resource/resources.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{FetchResource, ResourceQuery};
use crate::system::SystemId;
use core::any::TypeId;
use bevy_hecs::{Archetype, Ref, RefMut, TypeInfo};
use core::any::TypeId;
use std::{collections::HashMap, ptr::NonNull};

/// A Resource type
Expand All @@ -19,7 +19,7 @@ pub enum ResourceIndex {
System(SystemId),
}

/// A collection of resource instances identified by their type.
/// A collection of resource instances identified by their type.
#[derive(Default)]
pub struct Resources {
pub(crate) resource_data: HashMap<TypeId, ResourceData>,
Expand Down
32 changes: 17 additions & 15 deletions crates/bevy_ecs/src/schedule/parallel_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::{
resource::Resources,
system::{ArchetypeAccess, System, ThreadLocalExecution, TypeAccess},
};
use bevy_hecs::{ArchetypesGeneration, World};
use crossbeam_channel::{Receiver, Sender};
use fixedbitset::FixedBitSet;
use bevy_hecs::{ArchetypesGeneration, World};
use rayon::ScopeFifo;
use std::{
ops::Range,
Expand Down Expand Up @@ -68,7 +68,6 @@ impl ParallelExecutor {
}
}


/// This can be added as an app resource to control the global `rayon::ThreadPool` used by ecs.
// Dev internal note: We cannot directly expose a ThreadPoolBuilder here as it does not implement Send and Sync.
#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -360,19 +359,22 @@ impl ExecutorStage {
self.running_systems.clear();

let mut run_ready_result = RunReadyResult::Ok;
let run_ready_system_index_range = if let Some(index) = self
.thread_local_system_indices
.get(0)
{
// if there is an upcoming thread local system, run up to (and including) it
0..(*index + 1)
} else {
// if there are no upcoming thread local systems, run everything right now
0..systems.len()
};
let run_ready_system_index_range =
if let Some(index) = self.thread_local_system_indices.get(0) {
// if there is an upcoming thread local system, run up to (and including) it
0..(*index + 1)
} else {
// if there are no upcoming thread local systems, run everything right now
0..systems.len()
};
rayon::scope_fifo(|scope| {
run_ready_result =
self.run_ready_systems(systems, RunReadyType::Range(run_ready_system_index_range), scope, world, resources);
run_ready_result = self.run_ready_systems(
systems,
RunReadyType::Range(run_ready_system_index_range),
scope,
world,
resources,
);
});
loop {
// if all systems in the stage are finished, break out of the loop
Expand Down Expand Up @@ -442,8 +444,8 @@ mod tests {
system::{IntoQuerySystem, IntoThreadLocalSystem, Query},
Commands,
};
use fixedbitset::FixedBitSet;
use bevy_hecs::{Entity, World};
use fixedbitset::FixedBitSet;
use std::sync::{Arc, Mutex};

#[derive(Default)]
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ impl Schedule {
for stage_name in self.stage_order.iter() {
if let Some(stage_systems) = self.stages.get_mut(stage_name) {
for system in stage_systems.iter_mut() {
#[cfg(feature = "profiler")]
crate::profiler::profiler_start(resources, system.name().clone());
let mut system = system.lock().unwrap();
#[cfg(feature = "profiler")]
crate::profiler_start(resources, system.name().clone());
system.update_archetype_access(world);
match system.thread_local_execution() {
ThreadLocalExecution::NextFlush => system.run(world, resources),
Expand All @@ -144,7 +144,7 @@ impl Schedule {
}
}
#[cfg(feature = "profiler")]
crate::profiler::profiler_stop(resources, system.name().clone());
crate::profiler_stop(resources, system.name().clone());
}

// "flush"
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ mod commands;
mod into_system;
#[cfg(feature = "profiler")]
mod profiler;
mod system;
mod query;
mod system;

pub use commands::*;
pub use into_system::*;
#[cfg(feature = "profiler")]
pub use profiler::*;
pub use system::*;
pub use query::*;
pub use system::*;
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/system/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ pub trait Profiler: Downcast + Send + Sync + 'static {
}

pub fn profiler_start(resources: &Resources, scope: Cow<'static, str>) {
if let Ok(profiler) = resources.get::<Box<dyn Profiler>>() {
if let Some(profiler) = resources.get::<Box<dyn Profiler>>() {
profiler.start(scope);
}
}

pub fn profiler_stop(resources: &Resources, scope: Cow<'static, str>) {
if let Ok(profiler) = resources.get::<Box<dyn Profiler>>() {
if let Some(profiler) = resources.get::<Box<dyn Profiler>>() {
profiler.stop(scope);
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/system/system.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::resource::Resources;
use fixedbitset::FixedBitSet;
use bevy_hecs::{Access, Query, World};
use fixedbitset::FixedBitSet;
use std::{any::TypeId, borrow::Cow, collections::HashSet};

/// Determines the strategy used to run the `run_thread_local` function in a [System]
Expand All @@ -19,7 +19,7 @@ impl SystemId {
}
}

/// An ECS system that can be added to a [Schedule](crate::Schedule)
/// An ECS system that can be added to a [Schedule](crate::Schedule)
pub trait System: Send + Sync {
fn name(&self) -> Cow<'static, str>;
fn id(&self) -> SystemId;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_input/src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Input;
use bevy_app::prelude::*;
use bevy_ecs::{Res, ResMut, Local};
use bevy_ecs::{Local, Res, ResMut};

/// A key input event from a keyboard device
#[derive(Debug, Clone)]
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_input/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ pub mod prelude {

use bevy_app::prelude::*;
use keyboard::{keyboard_input_system, KeyCode, KeyboardInput};
use mouse::{
mouse_button_input_system, MouseButton, MouseButtonInput, MouseMotion,
};
use mouse::{mouse_button_input_system, MouseButton, MouseButtonInput, MouseMotion};

use bevy_ecs::IntoQuerySystem;

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_input/src/mouse.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::keyboard::ElementState;
use crate::Input;
use bevy_app::prelude::{EventReader, Events};
use bevy_ecs::{Res, ResMut, Local};
use bevy_ecs::{Local, Res, ResMut};
use bevy_math::Vec2;

/// A mouse button input event
Expand Down
11 changes: 7 additions & 4 deletions crates/bevy_pbr/src/render_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod uniform {
pub const LIGHTS: &str = "Lights";
}

use crate::prelude::StandardMaterial;
use bevy_asset::Assets;
use bevy_ecs::Resources;
use bevy_render::{
Expand All @@ -24,7 +25,6 @@ use bevy_render::{
shader::Shader,
};
use bevy_transform::prelude::Transform;
use crate::prelude::StandardMaterial;

pub(crate) fn add_pbr_graph(graph: &mut RenderGraph, resources: &Resources) {
graph.add_system_node(node::TRANSFORM, RenderResourcesNode::<Transform>::new(true));
Expand All @@ -41,10 +41,13 @@ pub(crate) fn add_pbr_graph(graph: &mut RenderGraph, resources: &Resources) {
);

// TODO: replace these with "autowire" groups
graph.add_node_edge(node::STANDARD_MATERIAL, base::node::MAIN_PASS)
graph
.add_node_edge(node::STANDARD_MATERIAL, base::node::MAIN_PASS)
.unwrap();
graph.add_node_edge(node::TRANSFORM, base::node::MAIN_PASS)
graph
.add_node_edge(node::TRANSFORM, base::node::MAIN_PASS)
.unwrap();
graph.add_node_edge(node::LIGHTS, base::node::MAIN_PASS)
graph
.add_node_edge(node::LIGHTS, base::node::MAIN_PASS)
.unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
if let Some(properties) = value.as_properties() {
let len = properties.prop_len();
self.resize_with(len, || T::default());

if properties.property_type() != self.property_type() {
panic!(
"Properties type mismatch. This type is {:?} but the applied type is {:?}",
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/camera/projection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::DepthCalculation;
use bevy_math::Mat4;
use bevy_property::{Properties, Property};
use serde::{Deserialize, Serialize};
use super::DepthCalculation;

pub trait CameraProjection {
fn get_projection_matrix(&self) -> Mat4;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/camera/visible_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::{Camera, DepthCalculation};
use crate::Draw;
use bevy_core::FloatOrd;
use bevy_ecs::{Entity, Query};
use bevy_transform::prelude::Transform;
use bevy_property::Properties;
use bevy_transform::prelude::Transform;

#[derive(Debug)]
pub struct VisibleEntity {
Expand Down
6 changes: 2 additions & 4 deletions crates/bevy_render/src/mesh/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@ pub mod shape {

let points = raw_points
.iter()
.map(|&p| {
(p * sphere.radius).into()
})
.map(|&p| (p * sphere.radius).into())
.collect::<Vec<[f32; 3]>>();

let normals = raw_points
Expand All @@ -447,7 +445,7 @@ pub mod shape {
VertexAttribute::normal(normals),
VertexAttribute::uv(uvs),
],
indices: Some(indices)
indices: Some(indices),
}
}
}
Expand Down
Loading