Fix beta clippy lints (#7154)

# Objective

- When I run `cargo run -p ci` for my pr locally using latest beta toolchain, the ci failed due to [uninlined_format_args](https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args) and [needless_lifetimes](https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes) lints

## Solution

- Fix lints according to clippy suggestions.
This commit is contained in:
张林伟 2023-01-11 09:51:22 +00:00
parent bb79903938
commit 0d2cdb450d
22 changed files with 66 additions and 140 deletions

View File

@ -872,8 +872,7 @@ impl App {
match self.add_boxed_plugin(Box::new(plugin)) {
Ok(app) => app,
Err(AppError::DuplicatePlugin { plugin_name }) => panic!(
"Error adding plugin {}: : plugin was already added in application",
plugin_name
"Error adding plugin {plugin_name}: : plugin was already added in application"
),
}
}

View File

@ -94,13 +94,13 @@ impl ReflectAsset {
}
/// Equivalent of [`Assets::add`]
pub fn add<'w>(&self, world: &'w mut World, value: &dyn Reflect) -> HandleUntyped {
pub fn add(&self, world: &mut World, value: &dyn Reflect) -> HandleUntyped {
(self.add)(world, value)
}
/// Equivalent of [`Assets::set`]
pub fn set<'w>(
pub fn set(
&self,
world: &'w mut World,
world: &mut World,
handle: HandleUntyped,
value: &dyn Reflect,
) -> HandleUntyped {

View File

@ -86,8 +86,7 @@ fn parse_component_attr(ast: &DeriveInput) -> Result<Attrs> {
return Err(Error::new_spanned(
m.lit,
format!(
"Invalid storage type `{}`, expected '{}' or '{}'.",
s, TABLE, SPARSE_SET
"Invalid storage type `{s}`, expected '{TABLE}' or '{SPARSE_SET}'.",
),
))
}

View File

@ -52,8 +52,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
fetch_struct_attributes.is_mutable = true;
} else {
panic!(
"The `{}` attribute is expected to have no value or arguments",
MUTABLE_ATTRIBUTE_NAME
"The `{MUTABLE_ATTRIBUTE_NAME}` attribute is expected to have no value or arguments",
);
}
} else if ident == DERIVE_ATTRIBUTE_NAME {
@ -63,8 +62,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
.extend(meta_list.nested.iter().cloned());
} else {
panic!(
"Expected a structured list within the `{}` attribute",
DERIVE_ATTRIBUTE_NAME
"Expected a structured list within the `{DERIVE_ATTRIBUTE_NAME}` attribute",
);
}
} else {

View File

@ -731,8 +731,7 @@ unsafe fn initialize_bundle(
deduped.dedup();
assert!(
deduped.len() == component_ids.len(),
"Bundle {} has duplicate components",
bundle_type_name
"Bundle {bundle_type_name} has duplicate components",
);
BundleInfo { id, component_ids }

View File

@ -224,10 +224,7 @@ impl Schedule {
// of the game. Closures inherit generic parameters from their enclosing function.
#[cold]
fn stage_not_found(stage_label: &dyn Debug) -> ! {
panic!(
"Stage '{:?}' does not exist or is not a SystemStage",
stage_label
)
panic!("Stage '{stage_label:?}' does not exist or is not a SystemStage",)
}
let label = stage_label.as_label();

View File

@ -287,10 +287,9 @@ impl SystemStage {
.then(|| descriptor.system.name())
{
panic!(
"The system {} has a run criteria, but its `SystemSet` also has a run \
"The system {name} has a run criteria, but its `SystemSet` also has a run \
criteria. This is not supported. Consider moving the system into a \
different `SystemSet` or calling `add_system()` instead.",
name
different `SystemSet` or calling `add_system()` instead."
)
}
}
@ -459,8 +458,7 @@ impl SystemStage {
writeln!(message, " - {}", nodes[*index].name()).unwrap();
writeln!(
message,
" wants to be after (because of labels: {:?})",
labels,
" wants to be after (because of labels: {labels:?})",
)
.unwrap();
}
@ -565,10 +563,7 @@ impl SystemStage {
if let RunCriteriaInner::Piped { input: parent, .. } = &mut criteria.inner {
let label = &criteria.after[0];
*parent = *labels.get(label).unwrap_or_else(|| {
panic!(
"Couldn't find run criteria labelled {:?} to pipe from.",
label
)
panic!("Couldn't find run criteria labelled {label:?} to pipe from.",)
});
}
}

View File

@ -282,8 +282,7 @@ impl<'w, 's> Commands<'w, 's> {
pub fn entity<'a>(&'a mut self, entity: Entity) -> EntityCommands<'w, 's, 'a> {
self.get_entity(entity).unwrap_or_else(|| {
panic!(
"Attempting to create an EntityCommands for entity {:?}, which doesn't exist.",
entity
"Attempting to create an EntityCommands for entity {entity:?}, which doesn't exist.",
)
})
}

View File

@ -250,8 +250,7 @@ fn assert_component_access_compatibility(
.map(|component_id| world.components.get_info(component_id).unwrap().name())
.collect::<Vec<&str>>();
let accesses = conflicting_components.join(", ");
panic!("error[B0001]: Query<{}, {}> in system {} accesses component(s) {} in a way that conflicts with a previous system parameter. Consider using `Without<T>` to create disjoint Queries or merging conflicting Queries into a `ParamSet`.",
query_type, filter_type, system_name, accesses);
panic!("error[B0001]: Query<{query_type}, {filter_type}> in system {system_name} accesses component(s) {accesses} in a way that conflicts with a previous system parameter. Consider using `Without<T>` to create disjoint Queries or merging conflicting Queries into a `ParamSet`.");
}
/// A collection of potentially conflicting [`SystemParam`]s allowed by disjoint access.

View File

@ -1256,8 +1256,7 @@ mod tests {
let actual = settings.filter(new_value, old_value);
assert_eq!(
expected, actual,
"Testing filtering for {:?} with new_value = {:?}, old_value = {:?}",
settings, new_value, old_value
"Testing filtering for {settings:?} with new_value = {new_value:?}, old_value = {old_value:?}",
);
}
@ -1312,8 +1311,7 @@ mod tests {
let actual = settings.filter(new_value, old_value);
assert_eq!(
expected, actual,
"Testing filtering for {:?} with new_value = {:?}, old_value = {:?}",
settings, new_value, old_value
"Testing filtering for {settings:?} with new_value = {new_value:?}, old_value = {old_value:?}",
);
}
@ -1398,8 +1396,7 @@ mod tests {
assert_eq!(
expected, actual,
"testing ButtonSettings::is_pressed() for value: {}",
value
"testing ButtonSettings::is_pressed() for value: {value}",
);
}
}
@ -1424,8 +1421,7 @@ mod tests {
assert_eq!(
expected, actual,
"testing ButtonSettings::is_released() for value: {}",
value
"testing ButtonSettings::is_released() for value: {value}",
);
}
}
@ -1450,8 +1446,7 @@ mod tests {
}
Err(_) => {
panic!(
"ButtonSettings::new({}, {}) should be valid ",
press_threshold, release_threshold
"ButtonSettings::new({press_threshold}, {release_threshold}) should be valid"
);
}
}
@ -1476,8 +1471,7 @@ mod tests {
match bs {
Ok(_) => {
panic!(
"ButtonSettings::new({}, {}) should be invalid",
press_threshold, release_threshold
"ButtonSettings::new({press_threshold}, {release_threshold}) should be invalid"
);
}
Err(err_code) => match err_code {

View File

@ -24,10 +24,7 @@ pub fn get_lit_str(attr_name: Symbol, lit: &syn::Lit) -> syn::Result<&syn::LitSt
} else {
Err(syn::Error::new_spanned(
lit,
format!(
"expected {} attribute to be a string: `{} = \"...\"`",
attr_name, attr_name
),
format!("expected {attr_name} attribute to be a string: `{attr_name} = \"...\"`"),
))
}
}
@ -38,10 +35,7 @@ pub fn get_lit_bool(attr_name: Symbol, lit: &syn::Lit) -> syn::Result<bool> {
} else {
Err(syn::Error::new_spanned(
lit,
format!(
"expected {} attribute to be a bool value, `true` or `false`: `{} = ...`",
attr_name, attr_name
),
format!("expected {attr_name} attribute to be a bool value, `true` or `false`: `{attr_name} = ...`"),
))
}
}

View File

@ -1190,7 +1190,7 @@ pub fn prepare_lights(
.spawn((
ShadowView {
depth_texture_view,
pass_name: format!("shadow pass directional light {}", light_index),
pass_name: format!("shadow pass directional light {light_index}"),
},
ExtractedView {
viewport: UVec4::new(

View File

@ -35,21 +35,16 @@ pub(crate) fn reflect_trait(_args: &TokenStream, input: TokenStream) -> TokenStr
let bevy_reflect_path = BevyManifest::default().get_path("bevy_reflect");
let struct_doc = format!(
" A type generated by the #[reflect_trait] macro for the `{}` trait.\n\n This allows casting from `dyn Reflect` to `dyn {}`.",
trait_ident,
trait_ident
" A type generated by the #[reflect_trait] macro for the `{trait_ident}` trait.\n\n This allows casting from `dyn Reflect` to `dyn {trait_ident}`.",
);
let get_doc = format!(
" Downcast a `&dyn Reflect` type to `&dyn {}`.\n\n If the type cannot be downcast, `None` is returned.",
trait_ident,
" Downcast a `&dyn Reflect` type to `&dyn {trait_ident}`.\n\n If the type cannot be downcast, `None` is returned.",
);
let get_mut_doc = format!(
" Downcast a `&mut dyn Reflect` type to `&mut dyn {}`.\n\n If the type cannot be downcast, `None` is returned.",
trait_ident,
" Downcast a `&mut dyn Reflect` type to `&mut dyn {trait_ident}`.\n\n If the type cannot be downcast, `None` is returned.",
);
let get_box_doc = format!(
" Downcast a `Box<dyn Reflect>` type to `Box<dyn {}>`.\n\n If the type cannot be downcast, this will return `Err(Box<dyn Reflect>)`.",
trait_ident,
" Downcast a `Box<dyn Reflect>` type to `Box<dyn {trait_ident}>`.\n\n If the type cannot be downcast, this will return `Err(Box<dyn Reflect>)`.",
);
TokenStream::from(quote! {

View File

@ -467,16 +467,14 @@ impl<'a, 'de> DeserializeSeed<'de> for TypedReflectDeserializer<'a> {
TypeInfo::Value(_) => {
// This case should already be handled
Err(de::Error::custom(format_args!(
"the TypeRegistration for {} doesn't have ReflectDeserialize",
type_name
"the TypeRegistration for {type_name} doesn't have ReflectDeserialize",
)))
}
TypeInfo::Dynamic(_) => {
// We could potentially allow this but we'd have no idea what the actual types of the
// fields are and would rely on the deserializer to determine them (e.g. `i32` vs `i64`)
Err(de::Error::custom(format_args!(
"cannot deserialize arbitrary dynamic type {}",
type_name
"cannot deserialize arbitrary dynamic type {type_name}",
)))
}
}
@ -1080,10 +1078,7 @@ fn get_registration<'a, E: Error>(
registry: &'a TypeRegistry,
) -> Result<&'a TypeRegistration, E> {
let registration = registry.get(type_id).ok_or_else(|| {
Error::custom(format_args!(
"no registration found for type `{}`",
type_name
))
Error::custom(format_args!("no registration found for type `{type_name}`",))
})?;
Ok(registration)
}

View File

@ -56,8 +56,7 @@ fn get_type_info<E: Error>(
TypeInfo::Dynamic(..) => match registry.get_with_name(type_name) {
Some(registration) => Ok(registration.type_info()),
None => Err(Error::custom(format_args!(
"no registration found for dynamic type with name {}",
type_name
"no registration found for dynamic type with name {type_name}",
))),
},
info => Ok(info),
@ -197,8 +196,7 @@ impl<'a> Serialize for StructSerializer<'a> {
TypeInfo::Struct(struct_info) => struct_info,
info => {
return Err(Error::custom(format_args!(
"expected struct type but received {:?}",
info
"expected struct type but received {info:?}"
)));
}
};
@ -247,8 +245,7 @@ impl<'a> Serialize for TupleStructSerializer<'a> {
TypeInfo::TupleStruct(tuple_struct_info) => tuple_struct_info,
info => {
return Err(Error::custom(format_args!(
"expected tuple struct type but received {:?}",
info
"expected tuple struct type but received {info:?}"
)));
}
};
@ -296,8 +293,7 @@ impl<'a> Serialize for EnumSerializer<'a> {
TypeInfo::Enum(enum_info) => enum_info,
info => {
return Err(Error::custom(format_args!(
"expected enum type but received {:?}",
info
"expected enum type but received {info:?}"
)));
}
};
@ -308,8 +304,7 @@ impl<'a> Serialize for EnumSerializer<'a> {
.variant_at(variant_index as usize)
.ok_or_else(|| {
Error::custom(format_args!(
"variant at index `{}` does not exist",
variant_index
"variant at index `{variant_index}` does not exist",
))
})?;
let variant_name = variant_info.name();
@ -333,8 +328,7 @@ impl<'a> Serialize for EnumSerializer<'a> {
VariantInfo::Struct(struct_info) => struct_info,
info => {
return Err(Error::custom(format_args!(
"expected struct variant type but received {:?}",
info
"expected struct variant type but received {info:?}",
)));
}
};

View File

@ -33,14 +33,12 @@ pub fn basis_buffer_to_image(
let basis_texture_format = transcoder.basis_texture_format(buffer);
if !basis_texture_format.can_transcode_to_format(transcode_format) {
return Err(TextureError::UnsupportedTextureFormat(format!(
"{:?} cannot be transcoded to {:?}",
basis_texture_format, transcode_format
"{basis_texture_format:?} cannot be transcoded to {transcode_format:?}",
)));
}
transcoder.prepare_transcoding(buffer).map_err(|_| {
TextureError::TranscodeError(format!(
"Failed to prepare for transcoding from {:?}",
basis_texture_format
"Failed to prepare for transcoding from {basis_texture_format:?}",
))
})?;
let mut transcoded = Vec::new();
@ -49,8 +47,7 @@ pub fn basis_buffer_to_image(
let texture_type = transcoder.basis_texture_type(buffer);
if texture_type == BasisTextureType::TextureTypeCubemapArray && image_count % 6 != 0 {
return Err(TextureError::InvalidData(format!(
"Basis file with cube map array texture with non-modulo 6 number of images: {}",
image_count,
"Basis file with cube map array texture with non-modulo 6 number of images: {image_count}",
)));
}
@ -74,10 +71,7 @@ pub fn basis_buffer_to_image(
let mip_level_count = transcoder.image_level_count(buffer, image_index);
if mip_level_count != image0_mip_level_count {
return Err(TextureError::InvalidData(format!(
"Array or volume texture has inconsistent number of mip levels. Image {} has {} but image 0 has {}",
image_index,
mip_level_count,
image0_mip_level_count,
"Array or volume texture has inconsistent number of mip levels. Image {image_index} has {mip_level_count} but image 0 has {image0_mip_level_count}",
)));
}
for level_index in 0..mip_level_count {
@ -94,8 +88,7 @@ pub fn basis_buffer_to_image(
)
.map_err(|error| {
TextureError::TranscodeError(format!(
"Failed to transcode mip level {} from {:?} to {:?}: {:?}",
level_index, basis_texture_format, transcode_format, error
"Failed to transcode mip level {level_index} from {basis_texture_format:?} to {transcode_format:?}: {error:?}",
))
})?;
transcoded.append(&mut data);
@ -118,8 +111,7 @@ pub fn basis_buffer_to_image(
BasisTextureType::TextureTypeVolume => TextureDimension::D3,
basis_texture_type => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"{:?}",
basis_texture_type
"{basis_texture_type:?}",
)))
}
};

View File

@ -14,8 +14,7 @@ pub fn dds_buffer_to_image(
let texture_format = dds_format_to_texture_format(&dds, is_srgb)?;
if !supported_compressed_formats.supports(texture_format) {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Format not supported by this GPU: {:?}",
texture_format
"Format not supported by this GPU: {texture_format:?}",
)));
}
let mut image = Image::default();
@ -116,8 +115,7 @@ pub fn dds_format_to_texture_format(
| D3DFormat::YUY2
| D3DFormat::CXV8U8 => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"{:?}",
d3d_format
"{d3d_format:?}",
)))
}
}
@ -227,8 +225,7 @@ pub fn dds_format_to_texture_format(
}
_ => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"{:?}",
dxgi_format
"{dxgi_format:?}",
)))
}
}

View File

@ -51,8 +51,7 @@ pub fn ktx2_buffer_to_image(
let mut decompressed = Vec::new();
decoder.read_to_end(&mut decompressed).map_err(|err| {
TextureError::SuperDecompressionError(format!(
"Failed to decompress {:?} for mip {}: {:?}",
supercompression_scheme, _level, err
"Failed to decompress {supercompression_scheme:?} for mip {_level}: {err:?}",
))
})?;
levels.push(decompressed);
@ -65,16 +64,14 @@ pub fn ktx2_buffer_to_image(
let mut decompressed = Vec::new();
decoder.read_to_end(&mut decompressed).map_err(|err| {
TextureError::SuperDecompressionError(format!(
"Failed to decompress {:?} for mip {}: {:?}",
supercompression_scheme, _level, err
"Failed to decompress {supercompression_scheme:?} for mip {_level}: {err:?}",
))
})?;
levels.push(decompressed);
}
_ => {
return Err(TextureError::SuperDecompressionError(format!(
"Unsupported supercompression scheme: {:?}",
supercompression_scheme
"Unsupported supercompression scheme: {supercompression_scheme:?}",
)));
}
}
@ -159,8 +156,7 @@ pub fn ktx2_buffer_to_image(
.map(|mut transcoded_level| transcoded[level].append(&mut transcoded_level))
.map_err(|error| {
TextureError::SuperDecompressionError(format!(
"Failed to transcode mip level {} from UASTC to {:?}: {:?}",
level, transcode_block_format, error
"Failed to transcode mip level {level} from UASTC to {transcode_block_format:?}: {error:?}",
))
})?;
offset += level_bytes;
@ -193,8 +189,7 @@ pub fn ktx2_buffer_to_image(
})?;
if !supported_compressed_formats.supports(texture_format) {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Format not supported by this GPU: {:?}",
texture_format
"Format not supported by this GPU: {texture_format:?}",
)));
}
@ -510,8 +505,7 @@ pub fn ktx2_dfd_to_texture_format(
},
v => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Unsupported sample bit length for RGBSDA 1-channel format: {}",
v
"Unsupported sample bit length for RGBSDA 1-channel format: {v}",
)));
}
}
@ -593,8 +587,7 @@ pub fn ktx2_dfd_to_texture_format(
},
v => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Unsupported sample bit length for RGBSDA 2-channel format: {}",
v
"Unsupported sample bit length for RGBSDA 2-channel format: {v}",
)));
}
}
@ -829,16 +822,14 @@ pub fn ktx2_dfd_to_texture_format(
},
v => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Unsupported sample bit length for RGBSDA 4-channel format: {}",
v
"Unsupported sample bit length for RGBSDA 4-channel format: {v}",
)));
}
}
}
v => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Unsupported channel count for RGBSDA format: {}",
v
"Unsupported channel count for RGBSDA format: {v}",
)));
}
}
@ -954,16 +945,14 @@ pub fn ktx2_dfd_to_texture_format(
},
v => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Unsupported sample bit length for XYZW 4-channel format: {}",
v
"Unsupported sample bit length for XYZW 4-channel format: {v}",
)));
}
}
}
v => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Unsupported channel count for XYZW format: {}",
v
"Unsupported channel count for XYZW format: {v}",
)));
}
}
@ -1088,8 +1077,7 @@ pub fn ktx2_dfd_to_texture_format(
}
v => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Unsupported channel count for ETC2 format: {}",
v
"Unsupported channel count for ETC2 format: {v}",
)));
}
},
@ -1148,8 +1136,7 @@ pub fn ktx2_dfd_to_texture_format(
6 => DataFormat::Rg,
channel_type => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Invalid KTX2 UASTC channel type: {}",
channel_type
"Invalid KTX2 UASTC channel type: {channel_type}",
)))
}
}),
@ -1177,8 +1164,7 @@ pub fn ktx2_format_to_texture_format(
ktx2::Format::R8_UNORM | ktx2::Format::R8_SRGB => {
if is_srgb {
return Err(TextureError::UnsupportedTextureFormat(format!(
"{:?}",
ktx2_format
"{ktx2_format:?}"
)));
}
TextureFormat::R8Unorm
@ -1189,8 +1175,7 @@ pub fn ktx2_format_to_texture_format(
ktx2::Format::R8G8_UNORM | ktx2::Format::R8G8_SRGB => {
if is_srgb {
return Err(TextureError::UnsupportedTextureFormat(format!(
"{:?}",
ktx2_format
"{ktx2_format:?}"
)));
}
TextureFormat::Rg8Unorm
@ -1456,8 +1441,7 @@ pub fn ktx2_format_to_texture_format(
}
_ => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"{:?}",
ktx2_format
"{ktx2_format:?}"
)))
}
})

View File

@ -192,8 +192,7 @@ pub fn prepare_windows(
.get(0)
.unwrap_or_else(|| {
panic!(
"No supported formats found for surface {:?} on adapter {:?}",
surface, render_adapter
"No supported formats found for surface {surface:?} on adapter {render_adapter:?}"
)
});
SurfaceData { surface, format }

View File

@ -688,9 +688,7 @@ mod tests {
expected
.reflect_partial_eq(received.as_ref())
.unwrap_or_default(),
"components did not match: (expected: `{:?}`, received: `{:?}`)",
expected,
received
"components did not match: (expected: `{expected:?}`, received: `{received:?}`)",
);
}
}

View File

@ -92,7 +92,7 @@ unsafe fn propagate_recursive(
mut changed: bool,
) {
let Ok(actual_parent) = parent_query.get(entity) else {
panic!("Propagated child for {:?} has no Parent component!", entity);
panic!("Propagated child for {entity:?} has no Parent component!");
};
assert_eq!(
actual_parent.get(), expected_parent,

View File

@ -173,8 +173,7 @@ fn change_text_system(
}
text.sections[0].value = format!(
"This text changes in the bottom right - {:.1} fps, {:.3} ms/frame",
fps, frame_time,
"This text changes in the bottom right - {fps:.1} fps, {frame_time:.3} ms/frame",
);
text.sections[2].value = format!("{fps:.1}");