Skip to content

Commit 33db507

Browse files
Thanks clippy
1 parent cceedb7 commit 33db507

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

crates/bevy_ecs/src/schedule/ambiguity_detection.rs

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::component::ComponentId;
22
use crate::schedule::{AmbiguityDetection, SystemContainer, SystemStage};
33
use crate::world::World;
44

5-
use bevy_utils::HashSet;
65
use fixedbitset::FixedBitSet;
6+
use std::hash::Hash;
77

88
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
99
/// Systems that access the same Component or Resource within the same stage
@@ -58,10 +58,10 @@ pub enum ExecutionOrderAmbiguities {
5858
///
5959
/// Created by applying [`find_ambiguities`] to a [`SystemContainer`].
6060
/// These can be reported by configuring the [`ReportExecutionOrderAmbiguities`] resource.
61-
#[derive(Debug, Clone, Eq, Hash)]
61+
#[derive(Debug, Clone, Eq)]
6262
pub struct SystemOrderAmbiguity {
6363
// The names of the conflicting systems
64-
pub system_names: (String, String),
64+
pub system_names: [String; 2],
6565
/// The components (and resources) that these systems have incompatible access to
6666
pub conflicts: Vec<String>,
6767
/// The segment of the [`SystemStage`] that the conflicting systems were stored in
@@ -70,20 +70,37 @@ pub struct SystemOrderAmbiguity {
7070

7171
impl PartialEq for SystemOrderAmbiguity {
7272
fn eq(&self, other: &Self) -> bool {
73-
// The order of the systems doesn't matter
74-
let names_aligned = (self.system_names.0 == other.system_names.0)
75-
& (self.system_names.1 == other.system_names.1);
76-
let names_inverted = (self.system_names.0 == other.system_names.1)
77-
& (self.system_names.0 == other.system_names.1);
78-
let names_match = names_aligned | names_inverted;
73+
let mut self_names = self.system_names.clone();
74+
self_names.sort();
7975

80-
// The order of the reported conflicts doesn't matter
81-
let conflicts_match =
82-
HashSet::from_iter(self.conflicts.iter()) == HashSet::from_iter(other.conflicts.iter());
76+
let mut other_names = self.system_names.clone();
77+
other_names.sort();
78+
79+
let mut self_conflicts = self.conflicts.clone();
80+
self_conflicts.sort();
81+
82+
let mut other_conflicts = self.conflicts.clone();
83+
other_conflicts.sort();
8384

84-
let segments_match = self.segment == other.segment;
85+
(self_names == other_names)
86+
&& (self_conflicts == other_conflicts)
87+
&& (self.segment == other.segment)
88+
}
89+
}
8590

86-
names_match & conflicts_match & segments_match
91+
// This impl is needed to allow us to test whether a returned set of ambiguities
92+
// matches the expected value
93+
impl Hash for SystemOrderAmbiguity {
94+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
95+
// The order of the systems doesn't matter
96+
let mut system_names = self.system_names.clone();
97+
system_names.sort();
98+
system_names.hash(state);
99+
// The order of the reported conflicts doesn't matter
100+
let mut conflicts = self.conflicts.clone();
101+
conflicts.sort();
102+
conflicts.hash(state);
103+
self.segment.hash(state);
87104
}
88105
}
89106

@@ -150,7 +167,7 @@ impl SystemOrderAmbiguity {
150167

151168
Self {
152169
// Don't bother with Cows here
153-
system_names: (system_a_name.into(), system_b_name.into()),
170+
system_names: [system_a_name.into(), system_b_name.into()],
154171
conflicts,
155172
segment,
156173
}
@@ -318,8 +335,8 @@ impl SystemStage {
318335
*system_b_index,
319336
component_ids.to_vec(),
320337
SystemStageSegment::Parallel,
321-
&self,
322-
&world,
338+
self,
339+
world,
323340
)
324341
})
325342
.collect();
@@ -333,8 +350,8 @@ impl SystemStage {
333350
*system_b_index,
334351
component_ids.to_vec(),
335352
SystemStageSegment::ExclusiveAtStart,
336-
&self,
337-
&world,
353+
self,
354+
world,
338355
)
339356
})
340357
.collect();
@@ -351,8 +368,8 @@ impl SystemStage {
351368
*system_b_index,
352369
component_ids.to_vec(),
353370
SystemStageSegment::ExclusiveBeforeCommands,
354-
&self,
355-
&world,
371+
self,
372+
world,
356373
)
357374
})
358375
.collect();
@@ -366,8 +383,8 @@ impl SystemStage {
366383
*system_b_index,
367384
component_ids.to_vec(),
368385
SystemStageSegment::ExclusiveAtEnd,
369-
&self,
370-
&world,
386+
self,
387+
world,
371388
)
372389
})
373390
.collect();
@@ -415,8 +432,8 @@ impl SystemStage {
415432
for (i, ambiguity) in ambiguities.iter().enumerate() {
416433
let ambiguity_number = i + 1;
417434
// The path name is often just noise, and this gets us consistency with `conflicts`'s formatting
418-
let system_a_name = format_type_name(ambiguity.system_names.0.as_str());
419-
let system_b_name = format_type_name(ambiguity.system_names.1.as_str());
435+
let system_a_name = format_type_name(ambiguity.system_names[0].as_str());
436+
let system_b_name = format_type_name(ambiguity.system_names[1].as_str());
420437
let mut conflicts: Vec<String> = ambiguity
421438
.conflicts
422439
.iter()
@@ -431,13 +448,13 @@ impl SystemStage {
431448
println!("{ambiguity_number:?}. `{system_a_name}` conflicts with `{system_b_name}` on {conflicts:?}");
432449
}
433450
// Print an empty line to space out multiple stages nicely
434-
println!("");
451+
println!();
435452
}
436453

437454
if report_level == ExecutionOrderAmbiguities::Deny
438455
|| report_level == ExecutionOrderAmbiguities::Forbid
439456
{
440-
panic!("The ReportExecutionOrderAmbiguities resource is set to a level that forbids the app from running with unresolved system execution order ambiguities.")
457+
panic!("The `ReportExecutionOrderAmbiguities` resource is set to a level that forbids the app from running with unresolved system execution order ambiguities.")
441458
}
442459
}
443460
}
@@ -875,18 +892,18 @@ mod tests {
875892
HashSet::from_iter(ambiguities),
876893
HashSet::from_iter(vec![
877894
SystemOrderAmbiguity {
878-
system_names: (
895+
system_names: [
879896
"bevy_ecs::schedule::ambiguity_detection::tests::system_a".to_string(),
880897
"bevy_ecs::schedule::ambiguity_detection::tests::system_b".to_string()
881-
),
898+
],
882899
conflicts: vec!["bevy_ecs::schedule::ambiguity_detection::tests::R".to_string()],
883900
segment: bevy_ecs::schedule::SystemStageSegment::Parallel,
884901
},
885902
SystemOrderAmbiguity {
886-
system_names: (
903+
system_names: [
887904
"bevy_ecs::schedule::ambiguity_detection::tests::system_a".to_string(),
888905
"bevy_ecs::schedule::ambiguity_detection::tests::system_d".to_string()
889-
),
906+
],
890907
conflicts: vec!["bevy_ecs::schedule::ambiguity_detection::tests::R".to_string()],
891908
segment: bevy_ecs::schedule::SystemStageSegment::Parallel,
892909
},

crates/bevy_ecs/src/schedule/stage.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ impl SystemStage {
111111
self.executor.rebuild_cached_data(&self.parallel);
112112
self.executor_modified = false;
113113
// This cannot panic, so we insert the default value if it was not present
114-
let report_level = world
115-
.get_resource_or_insert_with(ExecutionOrderAmbiguities::default)
116-
.clone();
114+
let report_level =
115+
*world.get_resource_or_insert_with(ExecutionOrderAmbiguities::default);
117116
self.report_ambiguities(world, report_level);
118117
} else if self.executor_modified {
119118
self.executor.rebuild_cached_data(&self.parallel);

0 commit comments

Comments
 (0)