Skip to content

Deny Rust 2018 idioms #15916

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

Closed
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docsrs_dep)'] }
unsafe_code = "deny"
unsafe_op_in_unsafe_fn = "warn"
unused_qualifications = "warn"
rust_2018_idioms = "deny"

# Unfortunately, cargo does not currently support overriding workspace lints
# inside a particular crate. See https://github.com/rust-lang/cargo/issues/13157
Expand Down
4 changes: 2 additions & 2 deletions benches/benches/bevy_ecs/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn few_changed_detection_generic<T: Component + Default + BenchModify>(
let mut world = setup::<T>(entity_count);
world.clear_trackers();
let mut query = world.query::<&mut T>();
let mut to_modify: Vec<bevy_ecs::prelude::Mut<T>> =
let mut to_modify: Vec<bevy_ecs::prelude::Mut<'_, T>> =
query.iter_mut(&mut world).collect();
to_modify.shuffle(&mut deterministic_rand());
for component in to_modify[0..amount_to_modify].iter_mut() {
Expand Down Expand Up @@ -265,7 +265,7 @@ fn none_changed_detection(criterion: &mut Criterion) {
);
}
}
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut<'_>, i: u16) {
if i & 1 << B != 0 {
entity.insert(Data::<B>(1.0));
}
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/components/archetype_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn setup(system_count: usize) -> (World, Schedule) {
(world, schedule)
}

fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut<'_>, i: u16) {
if i & 1 << B != 0 {
entity.insert(A::<B>(1.0));
}
Expand Down
8 changes: 4 additions & 4 deletions benches/benches/bevy_ecs/empty_archetypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ criterion_main!(benches);
struct A<const N: u16>(f32);

fn iter(
query: Query<(
query: Query<'_, '_, (
&A<0>,
&A<1>,
&A<2>,
Expand All @@ -31,7 +31,7 @@ fn iter(
}

fn for_each(
query: Query<(
query: Query<'_, '_, (
&A<0>,
&A<1>,
&A<2>,
Expand All @@ -53,8 +53,8 @@ fn for_each(
}

fn par_for_each(
task_pool: Res<ComputeTaskPool>,
query: Query<(
task_pool: Res<'_, ComputeTaskPool>,
query: Query<'_, '_, (
&A<0>,
&A<1>,
&A<2>,
Expand Down
8 changes: 4 additions & 4 deletions benches/benches/bevy_ecs/fragmentation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fn iter_frag_empty(c: &mut Criterion) {
group.bench_function("foreach_table", |b| {
let mut world = World::new();
spawn_empty_frag_archetype::<Table>(&mut world);
let mut q: SystemState<Query<(Entity, &Table)>> =
SystemState::<Query<(Entity, &Table<0>)>>::new(&mut world);
let mut q: SystemState<Query<'_, '_, (Entity, &Table)>> =
SystemState::<Query<'_, '_, (Entity, &Table<0>)>>::new(&mut world);
let query = q.get(&world);
b.iter(move || {
let mut res = 0;
Expand All @@ -37,8 +37,8 @@ fn iter_frag_empty(c: &mut Criterion) {
group.bench_function("foreach_sparse", |b| {
let mut world = World::new();
spawn_empty_frag_archetype::<Sparse>(&mut world);
let mut q: SystemState<Query<(Entity, &Sparse)>> =
SystemState::<Query<(Entity, &Sparse<0>)>>::new(&mut world);
let mut q: SystemState<Query<'_, '_, (Entity, &Sparse)>> =
SystemState::<Query<'_, '_, (Entity, &Sparse<0>)>>::new(&mut world);
let query = q.get(&world);
b.iter(move || {
let mut res = 0;
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/iteration/heavy_compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn heavy_compute(c: &mut Criterion) {
)
}));

fn sys(mut query: Query<(&mut Position, &mut Transform)>) {
fn sys(mut query: Query<'_, '_, (&mut Position, &mut Transform)>) {
query.par_iter_mut().for_each(|(mut pos, mut mat)| {
for _ in 0..100 {
mat.0 = mat.0.inverse();
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/iteration/iter_simple_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Benchmark {
.take(10_000),
);

fn query_system(mut query: Query<(&Velocity, &mut Position)>) {
fn query_system(mut query: Query<'_, '_, (&Velocity, &mut Position)>) {
for (velocity, mut position) in &mut query {
position.0 += velocity.0;
}
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/iteration/par_iter_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Velocity(Vec3);
struct Data<const X: u16>(f32);
pub struct Benchmark<'w>(World, QueryState<(&'w Velocity, &'w mut Position)>);

fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut<'_>, i: u16) {
if i & 1 << B != 0 {
entity.insert(Data::<B>(1.0));
}
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/observers/propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ fn add_listeners_to_hierarchy<const DENSITY: usize, const N: usize>(
}
}

fn empty_listener<const N: usize>(trigger: Trigger<TestEvent<N>>) {
fn empty_listener<const N: usize>(trigger: Trigger<'_, TestEvent<N>>) {
black_box(trigger);
}
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/observers/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn observe_simple(criterion: &mut Criterion) {
group.finish();
}

fn empty_listener_base(trigger: Trigger<EventBase>) {
fn empty_listener_base(trigger: Trigger<'_, EventBase>) {
black_box(trigger);
}

Expand Down
4 changes: 2 additions & 2 deletions benches/benches/bevy_ecs/scheduling/run_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn run_condition_yes_with_query(criterion: &mut Criterion) {
group.warm_up_time(core::time::Duration::from_millis(500));
group.measurement_time(core::time::Duration::from_secs(3));
fn empty() {}
fn yes_with_query(query: Single<&TestBool>) -> bool {
fn yes_with_query(query: Single<'_, &TestBool>) -> bool {
query.0
}
for amount in 0..21 {
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn run_condition_yes_with_resource(criterion: &mut Criterion) {
group.warm_up_time(core::time::Duration::from_millis(500));
group.measurement_time(core::time::Duration::from_secs(3));
fn empty() {}
fn yes_with_resource(res: Res<TestBool>) -> bool {
fn yes_with_resource(res: Res<'_, TestBool>) -> bool {
res.0
}
for amount in 0..21 {
Expand Down
12 changes: 6 additions & 6 deletions benches/benches/bevy_ecs/scheduling/running_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ pub fn empty_systems(criterion: &mut Criterion) {
}

pub fn busy_systems(criterion: &mut Criterion) {
fn ab(mut q: Query<(&mut A, &mut B)>) {
fn ab(mut q: Query<'_, '_, (&mut A, &mut B)>) {
q.iter_mut().for_each(|(mut a, mut b)| {
core::mem::swap(&mut a.0, &mut b.0);
});
}
fn cd(mut q: Query<(&mut C, &mut D)>) {
fn cd(mut q: Query<'_, '_, (&mut C, &mut D)>) {
q.iter_mut().for_each(|(mut c, mut d)| {
core::mem::swap(&mut c.0, &mut d.0);
});
}
fn ce(mut q: Query<(&mut C, &mut E)>) {
fn ce(mut q: Query<'_, '_, (&mut C, &mut E)>) {
q.iter_mut().for_each(|(mut c, mut e)| {
core::mem::swap(&mut c.0, &mut e.0);
});
Expand Down Expand Up @@ -97,20 +97,20 @@ pub fn busy_systems(criterion: &mut Criterion) {
}

pub fn contrived(criterion: &mut Criterion) {
fn s_0(mut q_0: Query<(&mut A, &mut B)>) {
fn s_0(mut q_0: Query<'_, '_, (&mut A, &mut B)>) {
q_0.iter_mut().for_each(|(mut c_0, mut c_1)| {
core::mem::swap(&mut c_0.0, &mut c_1.0);
});
}
fn s_1(mut q_0: Query<(&mut A, &mut C)>, mut q_1: Query<(&mut B, &mut D)>) {
fn s_1(mut q_0: Query<'_, '_, (&mut A, &mut C)>, mut q_1: Query<'_, '_, (&mut B, &mut D)>) {
q_0.iter_mut().for_each(|(mut c_0, mut c_1)| {
core::mem::swap(&mut c_0.0, &mut c_1.0);
});
q_1.iter_mut().for_each(|(mut c_0, mut c_1)| {
core::mem::swap(&mut c_0.0, &mut c_1.0);
});
}
fn s_2(mut q_0: Query<(&mut C, &mut D)>) {
fn s_2(mut q_0: Query<'_, '_, (&mut C, &mut D)>) {
q_0.iter_mut().for_each(|(mut c_0, mut c_1)| {
core::mem::swap(&mut c_0.0, &mut c_1.0);
});
Expand Down
6 changes: 3 additions & 3 deletions benches/benches/bevy_ecs/scheduling/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ pub fn schedule(c: &mut Criterion) {
#[derive(Component)]
struct E(f32);

fn ab(mut query: Query<(&mut A, &mut B)>) {
fn ab(mut query: Query<'_, '_, (&mut A, &mut B)>) {
query.iter_mut().for_each(|(mut a, mut b)| {
core::mem::swap(&mut a.0, &mut b.0);
});
}

fn cd(mut query: Query<(&mut C, &mut D)>) {
fn cd(mut query: Query<'_, '_, (&mut C, &mut D)>) {
query.iter_mut().for_each(|(mut c, mut d)| {
core::mem::swap(&mut c.0, &mut d.0);
});
}

fn ce(mut query: Query<(&mut C, &mut E)>) {
fn ce(mut query: Query<'_, '_, (&mut C, &mut E)>) {
query.iter_mut().for_each(|(mut c, mut e)| {
core::mem::swap(&mut c.0, &mut e.0);
});
Expand Down
8 changes: 4 additions & 4 deletions benches/benches/bevy_ecs/world/world_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub fn query_get(criterion: &mut Criterion) {
.spawn_batch((0..entity_count).map(|_| Table::default()))
.collect();
entities.shuffle(&mut deterministic_rand());
let mut query = SystemState::<Query<&Table>>::new(&mut world);
let mut query = SystemState::<Query<'_, '_, &Table>>::new(&mut world);
let query = query.get(&world);

bencher.iter(|| {
Expand All @@ -287,7 +287,7 @@ pub fn query_get(criterion: &mut Criterion) {
.spawn_batch((0..entity_count).map(|_| Sparse::default()))
.collect();
entities.shuffle(&mut deterministic_rand());
let mut query = SystemState::<Query<&Sparse>>::new(&mut world);
let mut query = SystemState::<Query<'_, '_, &Sparse>>::new(&mut world);
let query = query.get(&world);

bencher.iter(|| {
Expand Down Expand Up @@ -318,7 +318,7 @@ pub fn query_get_many<const N: usize>(criterion: &mut Criterion) {
.collect();
entity_groups.shuffle(&mut deterministic_rand());

let mut query = SystemState::<Query<&Table>>::new(&mut world);
let mut query = SystemState::<Query<'_, '_, &Table>>::new(&mut world);
let query = query.get(&world);

bencher.iter(|| {
Expand All @@ -341,7 +341,7 @@ pub fn query_get_many<const N: usize>(criterion: &mut Criterion) {
.collect();
entity_groups.shuffle(&mut deterministic_rand());

let mut query = SystemState::<Query<&Sparse>>::new(&mut world);
let mut query = SystemState::<Query<'_, '_, &Sparse>>::new(&mut world);
let query = query.get(&world);

bencher.iter(|| {
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_animation/derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Derive macros for `bevy_animation`.

extern crate proc_macro;

use bevy_macro_utils::BevyManifest;
use proc_macro::TokenStream;
use quote::quote;
Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_animation/src/animation_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ pub(crate) fn trigger_animation_event(
/// #[derive(Event, AnimationEvent, Reflect, Clone)]
/// struct Say(String);
///
/// fn on_say(trigger: Trigger<Say>) {
/// fn on_say(trigger: Trigger<'_, Say>) {
/// println!("{}", trigger.event().0);
/// }
///
/// fn setup_animation(
/// mut commands: Commands,
/// mut animations: ResMut<Assets<AnimationClip>>,
/// mut graphs: ResMut<Assets<AnimationGraph>>,
/// mut commands: Commands<'_, '_>,
/// mut animations: ResMut<'_, Assets<AnimationClip>>,
/// mut graphs: ResMut<'_, Assets<AnimationGraph>>,
/// ) {
/// // Create a new animation and add an event at 1.0s.
/// let mut animation = AnimationClip::default();
/// animation.add_event(1.0, Say("Hello".into()));
///
///
/// // Create an animation graph.
/// let (graph, animation_index) = AnimationGraph::from_clip(animations.add(animation));
///
/// // Start playing the animation.
/// let mut player = AnimationPlayer::default();
/// player.play(animation_index).repeat();
///
///
/// commands.spawn((AnimationGraphHandle(graphs.add(graph)), player));
/// }
/// #
Expand Down Expand Up @@ -153,7 +153,7 @@ impl TupleStruct for AnimationEventData {
1
}

fn iter_fields(&self) -> TupleStructFieldIter {
fn iter_fields(&self) -> TupleStructFieldIter<'_> {
TupleStructFieldIter::new(self)
}

Expand Down Expand Up @@ -215,11 +215,11 @@ impl PartialReflect for AnimationEventData {
Ok(())
}

fn reflect_ref(&self) -> ReflectRef {
fn reflect_ref(&self) -> ReflectRef<'_> {
ReflectRef::TupleStruct(self)
}

fn reflect_mut(&mut self) -> ReflectMut {
fn reflect_mut(&mut self) -> ReflectMut<'_> {
ReflectMut::TupleStruct(self)
}

Expand Down
30 changes: 15 additions & 15 deletions crates/bevy_animation/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ use crate::{AnimationClip, AnimationTargetId};
/// For example, consider the following graph:
///
/// ```text
/// ┌────────────┐
/// │ │
/// │ Idle ├─────────────────────┐
/// │ │ │
/// └────────────┘ │
/// │
/// ┌────────────┐
/// │ │
/// │ Idle ├─────────────────────┐
/// │ │ │
/// └────────────┘ │
/// │
/// ┌────────────┐ │ ┌────────────┐
/// │ │ │ │ │
/// │ Run ├──┐ ├──┤ Root │
/// │ │ │ ┌────────────┐ │ │ │
/// └────────────┘ │ │ Blend │ │ └────────────┘
/// ├──┤ ├──┘
/// ┌────────────┐ │ │ 0.5 │
/// │ │ │ └────────────┘
/// │ Walk ├──┘
/// │ │
/// └────────────┘
/// ├──┤ ├──┘
/// ┌────────────┐ │ │ 0.5 │
/// │ │ │ └────────────┘
/// │ Walk ├──┘
/// │ │
/// └────────────┘
/// ```
///
/// In this case, assuming that Idle, Run, and Walk are all playing with weight
Expand Down Expand Up @@ -821,9 +821,9 @@ impl From<AnimationGraph> for SerializedAnimationGraph {
/// The [`ThreadedAnimationGraph`] contains acceleration structures that allow
/// for quick evaluation of that graph's animations.
pub(crate) fn thread_animation_graphs(
mut threaded_animation_graphs: ResMut<ThreadedAnimationGraphs>,
animation_graphs: Res<Assets<AnimationGraph>>,
mut animation_graph_asset_events: EventReader<AssetEvent<AnimationGraph>>,
mut threaded_animation_graphs: ResMut<'_, ThreadedAnimationGraphs>,
animation_graphs: Res<'_, Assets<AnimationGraph>>,
mut animation_graph_asset_events: EventReader<'_, '_, AssetEvent<AnimationGraph>>,
) {
for animation_graph_asset_event in animation_graph_asset_events.read() {
match *animation_graph_asset_event {
Expand Down
Loading