Skip to content

Commit

Permalink
enforce cargo fmt --check
Browse files Browse the repository at this point in the history
  • Loading branch information
multun committed Aug 16, 2020
1 parent ece54e9 commit d138647
Show file tree
Hide file tree
Showing 42 changed files with 114 additions and 81 deletions.
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/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
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
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/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
4 changes: 2 additions & 2 deletions crates/bevy_render/src/pipeline/pipeline_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::{
shader::{Shader, ShaderSource},
};
use bevy_asset::{Assets, Handle};
use bevy_property::{Properties, Property};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use bevy_property::{Properties, Property};
use serde::{Serialize, Deserialize};
#[derive(Clone, Eq, PartialEq, Debug, Properties)]
pub struct PipelineSpecialization {
pub shader_specialization: ShaderSpecialization,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/pipeline/state_descriptors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::texture::TextureFormat;
use serde::{Serialize, Deserialize};
use bevy_property::Property;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug)]
pub struct DepthStencilStateDescriptor {
Expand Down
11 changes: 6 additions & 5 deletions crates/bevy_render/src/render_graph/nodes/pass_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use crate::{
draw::{Draw, RenderCommand},
pass::{ClearColor, LoadOp, PassDescriptor, TextureAttachment},
pipeline::{
BindGroupDescriptor, BindType, BindingDescriptor, PipelineDescriptor, UniformProperty,
BindingShaderStage,
BindGroupDescriptor, BindType, BindingDescriptor, BindingShaderStage, PipelineDescriptor,
UniformProperty,
},
render_graph::{Node, ResourceSlotInfo, ResourceSlots},
renderer::{
BindGroup, BindGroupId, BufferId, RenderContext, RenderResourceBindings, RenderResourceType,
},
};
use bevy_asset::{Assets, Handle};
use bevy_ecs::{Resources, World, HecsQuery};
use bevy_ecs::{HecsQuery, Resources, World};
use std::marker::PhantomData;

struct CameraInfo {
Expand Down Expand Up @@ -136,8 +136,9 @@ impl<Q: HecsQuery + Send + Sync + 'static> Node for PassNode<Q> {
TextureAttachment::Id(input.get(input_index).unwrap().get_texture().unwrap());
}
if let Some(input_index) = self.color_resolve_target_indices[i] {
color_attachment.resolve_target =
Some(TextureAttachment::Id(input.get(input_index).unwrap().get_texture().unwrap()));
color_attachment.resolve_target = Some(TextureAttachment::Id(
input.get(input_index).unwrap().get_texture().unwrap(),
));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ fn asset_render_resources_node_system<T: RenderResources>(

for (asset_handle, draw, mut render_pipelines) in &mut query.iter() {
if !draw.is_visible {
continue
continue;
}
if let Some(asset_bindings) = asset_render_resource_bindings.get(*asset_handle) {
render_pipelines.bindings.extend(asset_bindings);
Expand Down
Loading

0 comments on commit d138647

Please sign in to comment.