Skip to content

Commit e71c4d2

Browse files
fix nightly clippy warnings (#6395)
# Objective - fix new clippy lints before they get stable and break CI ## Solution - run `clippy --fix` to auto-fix machine-applicable lints - silence `clippy::should_implement_trait` for `fn HandleId::default<T: Asset>` ## Changes - always prefer `format!("{inline}")` over `format!("{}", not_inline)` - prefer `Box::default` (or `Box::<T>::default` if necessary) over `Box::new(T::default())`
1 parent c27186c commit e71c4d2

File tree

61 files changed

+153
-157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+153
-157
lines changed

crates/bevy_asset/src/asset_server.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ impl AssetServer {
147147
.server
148148
.asset_lifecycles
149149
.write()
150-
.insert(
151-
T::TYPE_UUID,
152-
Box::new(AssetLifecycleChannel::<T>::default()),
153-
)
150+
.insert(T::TYPE_UUID, Box::<AssetLifecycleChannel<T>>::default())
154151
.is_some()
155152
{
156153
panic!("Error while registering new asset type: {:?} with UUID: {:?}. Another type with the same UUID is already registered. Can not register new asset type with the same UUID",

crates/bevy_asset/src/handle.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl HandleId {
6262

6363
/// Creates the default id for an asset of type `T`.
6464
#[inline]
65+
#[allow(clippy::should_implement_trait)] // `Default` is not implemented for `HandleId`, the default value depends on the asset type
6566
pub fn default<T: Asset>() -> Self {
6667
HandleId::Id(T::TYPE_UUID, 0)
6768
}
@@ -294,7 +295,7 @@ impl<T: Asset> Default for Handle<T> {
294295
impl<T: Asset> Debug for Handle<T> {
295296
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
296297
let name = std::any::type_name::<T>().split("::").last().unwrap();
297-
write!(f, "{:?}Handle<{}>({:?})", self.handle_type, name, self.id)
298+
write!(f, "{:?}Handle<{name}>({:?})", self.handle_type, self.id)
298299
}
299300
}
300301

crates/bevy_ecs/examples/change_detection.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636

3737
// Simulate 10 frames in our world
3838
for iteration in 1..=10 {
39-
println!("Simulating frame {}/10", iteration);
39+
println!("Simulating frame {iteration}/10");
4040
schedule.run(&mut world);
4141
}
4242
}
@@ -66,7 +66,7 @@ enum SimulationSystem {
6666
fn spawn_entities(mut commands: Commands, mut entity_counter: ResMut<EntityCounter>) {
6767
if rand::thread_rng().gen_bool(0.6) {
6868
let entity_id = commands.spawn(Age::default()).id();
69-
println!(" spawning {:?}", entity_id);
69+
println!(" spawning {entity_id:?}");
7070
entity_counter.value += 1;
7171
}
7272
}
@@ -82,10 +82,10 @@ fn print_changed_entities(
8282
entity_with_mutated_component: Query<(Entity, &Age), Changed<Age>>,
8383
) {
8484
for entity in &entity_with_added_component {
85-
println!(" {:?} has it's first birthday!", entity);
85+
println!(" {entity:?} has it's first birthday!");
8686
}
8787
for (entity, value) in &entity_with_mutated_component {
88-
println!(" {:?} is now {:?} frames old", entity, value);
88+
println!(" {entity:?} is now {value:?} frames old");
8989
}
9090
}
9191

@@ -100,7 +100,7 @@ fn age_all_entities(mut entities: Query<&mut Age>) {
100100
fn remove_old_entities(mut commands: Commands, entities: Query<(Entity, &Age)>) {
101101
for (entity, age) in &entities {
102102
if age.frames > 2 {
103-
println!(" despawning {:?} due to age > 2", entity);
103+
println!(" despawning {entity:?} due to age > 2");
104104
commands.entity(entity).despawn();
105105
}
106106
}

crates/bevy_ecs/examples/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn main() {
3535

3636
// Simulate 10 frames of our world
3737
for iteration in 1..=10 {
38-
println!("Simulating frame {}/10", iteration);
38+
println!("Simulating frame {iteration}/10");
3939
schedule.run(&mut world);
4040
}
4141
}

crates/bevy_ecs/examples/resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
schedule.add_stage(Update, update);
2828

2929
for iteration in 1..=10 {
30-
println!("Simulating frame {}/10", iteration);
30+
println!("Simulating frame {iteration}/10");
3131
schedule.run(&mut world);
3232
}
3333
}

crates/bevy_ecs/macros/src/fetch.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
7676
}
7777
Ok(())
7878
})
79-
.unwrap_or_else(|_| panic!("Invalid `{}` attribute format", WORLD_QUERY_ATTRIBUTE_NAME));
79+
.unwrap_or_else(|_| panic!("Invalid `{WORLD_QUERY_ATTRIBUTE_NAME}` attribute format"));
8080
}
8181

8282
let path = bevy_ecs_path();
@@ -93,26 +93,26 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
9393

9494
let struct_name = ast.ident.clone();
9595
let read_only_struct_name = if fetch_struct_attributes.is_mutable {
96-
Ident::new(&format!("{}ReadOnly", struct_name), Span::call_site())
96+
Ident::new(&format!("{struct_name}ReadOnly"), Span::call_site())
9797
} else {
9898
struct_name.clone()
9999
};
100100

101-
let item_struct_name = Ident::new(&format!("{}Item", struct_name), Span::call_site());
101+
let item_struct_name = Ident::new(&format!("{struct_name}Item"), Span::call_site());
102102
let read_only_item_struct_name = if fetch_struct_attributes.is_mutable {
103-
Ident::new(&format!("{}ReadOnlyItem", struct_name), Span::call_site())
103+
Ident::new(&format!("{struct_name}ReadOnlyItem"), Span::call_site())
104104
} else {
105105
item_struct_name.clone()
106106
};
107107

108-
let fetch_struct_name = Ident::new(&format!("{}Fetch", struct_name), Span::call_site());
108+
let fetch_struct_name = Ident::new(&format!("{struct_name}Fetch"), Span::call_site());
109109
let read_only_fetch_struct_name = if fetch_struct_attributes.is_mutable {
110-
Ident::new(&format!("{}ReadOnlyFetch", struct_name), Span::call_site())
110+
Ident::new(&format!("{struct_name}ReadOnlyFetch"), Span::call_site())
111111
} else {
112112
fetch_struct_name.clone()
113113
};
114114

115-
let state_struct_name = Ident::new(&format!("{}State", struct_name), Span::call_site());
115+
let state_struct_name = Ident::new(&format!("{struct_name}State"), Span::call_site());
116116

117117
let fields = match &ast.data {
118118
Data::Struct(DataStruct {
@@ -438,9 +438,7 @@ fn read_world_query_field_info(field: &Field) -> WorldQueryFieldInfo {
438438
}
439439
Ok(())
440440
})
441-
.unwrap_or_else(|_| {
442-
panic!("Invalid `{}` attribute format", WORLD_QUERY_ATTRIBUTE_NAME)
443-
});
441+
.unwrap_or_else(|_| panic!("Invalid `{WORLD_QUERY_ATTRIBUTE_NAME}` attribute format"));
444442

445443
is_ignored
446444
});

crates/bevy_ecs/macros/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ fn get_idents(fmt_string: fn(usize) -> String, count: usize) -> Vec<Ident> {
208208
pub fn impl_param_set(_input: TokenStream) -> TokenStream {
209209
let mut tokens = TokenStream::new();
210210
let max_params = 8;
211-
let params = get_idents(|i| format!("P{}", i), max_params);
212-
let params_fetch = get_idents(|i| format!("PF{}", i), max_params);
213-
let metas = get_idents(|i| format!("m{}", i), max_params);
211+
let params = get_idents(|i| format!("P{i}"), max_params);
212+
let params_fetch = get_idents(|i| format!("PF{i}"), max_params);
213+
let metas = get_idents(|i| format!("m{i}"), max_params);
214214
let mut param_fn_muts = Vec::new();
215215
for (i, param) in params.iter().enumerate() {
216-
let fn_name = Ident::new(&format!("p{}", i), Span::call_site());
216+
let fn_name = Ident::new(&format!("p{i}"), Span::call_site());
217217
let index = Index::from(i);
218218
param_fn_muts.push(quote! {
219219
pub fn #fn_name<'a>(&'a mut self) -> <#param::Fetch as SystemParamFetch<'a, 'a>>::Item {

crates/bevy_ecs/src/query/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,9 @@ impl std::error::Error for QuerySingleError {}
14001400
impl std::fmt::Display for QuerySingleError {
14011401
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14021402
match self {
1403-
QuerySingleError::NoEntities(query) => write!(f, "No entities fit the query {}", query),
1403+
QuerySingleError::NoEntities(query) => write!(f, "No entities fit the query {query}"),
14041404
QuerySingleError::MultipleEntities(query) => {
1405-
write!(f, "Multiple entities fit the query {}!", query)
1405+
write!(f, "Multiple entities fit the query {query}!")
14061406
}
14071407
}
14081408
}

crates/bevy_ecs/src/schedule/ambiguity_detection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl SystemStage {
101101
last_segment_kind = Some(segment);
102102
}
103103

104-
writeln!(string, " -- {:?} and {:?}", system_a, system_b).unwrap();
104+
writeln!(string, " -- {system_a:?} and {system_b:?}").unwrap();
105105

106106
if !conflicts.is_empty() {
107107
writeln!(string, " conflicts: {conflicts:?}").unwrap();

crates/bevy_ecs/src/schedule/executor_parallel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ mod tests {
558558
StartedSystems(1),
559559
]
560560
);
561-
stage.set_executor(Box::new(SingleThreadedExecutor::default()));
561+
stage.set_executor(Box::<SingleThreadedExecutor>::default());
562562
stage.run(&mut world);
563563
}
564564
}

0 commit comments

Comments
 (0)