fix clippy::uninlined_format_args (#705)

* ash/util: fix `clippy::seek_to_start_instead_of_rewind`

* examples: fix `clippy::uninlined_format_args`

* ash: fix `clippy::uninlined_format_args`

* generator: fix `clippy::uninlined_format_args`

* rust: upgrade to edition 2021
This commit is contained in:
Philippe Renon 2023-02-17 18:11:44 +01:00 committed by GitHub
parent 86dccdfcd8
commit 9cd6c07744
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 46 deletions

View file

@ -2,7 +2,6 @@
name = "ash-window" name = "ash-window"
version = "0.11.0" version = "0.11.0"
authors = ["msiglreith <m.siglreith@gmail.com>"] authors = ["msiglreith <m.siglreith@gmail.com>"]
edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "Interop library between ash and raw-window-handle" description = "Interop library between ash and raw-window-handle"
documentation = "https://docs.rs/ash-window" documentation = "https://docs.rs/ash-window"
@ -12,6 +11,7 @@ keywords = ["window", "ash", "graphics"]
categories = ["game-engines", "graphics"] categories = ["game-engines", "graphics"]
exclude = [".github/*"] exclude = [".github/*"]
workspace = ".." workspace = ".."
edition = "2021"
rust-version = "1.59.0" rust-version = "1.59.0"
[dependencies] [dependencies]

View file

@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn Error>> {
None, None,
)?; )?;
let surface_fn = ash::extensions::khr::Surface::new(&entry, &instance); let surface_fn = ash::extensions::khr::Surface::new(&entry, &instance);
println!("surface: {:?}", surface); println!("surface: {surface:?}");
event_loop.run(move |event, _, control_flow| match event { event_loop.run(move |event, _, control_flow| match event {
winit::event::Event::WindowEvent { winit::event::Event::WindowEvent {

View file

@ -12,7 +12,7 @@ repository = "https://github.com/MaikKlein/ash"
readme = "../README.md" readme = "../README.md"
keywords = ["vulkan", "graphic"] keywords = ["vulkan", "graphic"]
documentation = "https://docs.rs/ash" documentation = "https://docs.rs/ash"
edition = "2018" edition = "2021"
rust-version = "1.59.0" rust-version = "1.59.0"
[dependencies] [dependencies]

View file

@ -13,12 +13,12 @@ fn main() {
("windows", "64") => "Lib", ("windows", "64") => "Lib",
_ => "lib", _ => "lib",
}; };
println!("cargo:rustc-link-search={}/{}", var, suffix); println!("cargo:rustc-link-search={var}/{suffix}");
} }
let lib = match &*target_family { let lib = match &*target_family {
"windows" => "vulkan-1", "windows" => "vulkan-1",
_ => "vulkan", _ => "vulkan",
}; };
println!("cargo:rustc-link-lib={}", lib); println!("cargo:rustc-link-lib={lib}");
} }
} }

View file

@ -116,7 +116,7 @@ pub(crate) fn debug_flags<Value: Into<u64> + Copy>(
if !first { if !first {
f.write_str(" | ")?; f.write_str(" | ")?;
} }
write!(f, "{:b}", accum)?; write!(f, "{accum:b}")?;
} }
Ok(()) Ok(())
} }

View file

@ -104,7 +104,9 @@ impl<'a, T: Copy + 'a> Iterator for AlignIter<'a, T> {
/// let words = ash::util::read_spv(&mut std::io::Cursor::new(&SPIRV[..])).unwrap(); /// let words = ash::util::read_spv(&mut std::io::Cursor::new(&SPIRV[..])).unwrap();
/// ``` /// ```
pub fn read_spv<R: io::Read + io::Seek>(x: &mut R) -> io::Result<Vec<u32>> { pub fn read_spv<R: io::Read + io::Seek>(x: &mut R) -> io::Result<Vec<u32>> {
// TODO use stream_len() once it is stabilized and remove the subsequent rewind() call
let size = x.seek(io::SeekFrom::End(0))?; let size = x.seek(io::SeekFrom::End(0))?;
x.rewind()?;
if size % 4 != 0 { if size % 4 != 0 {
return Err(io::Error::new( return Err(io::Error::new(
io::ErrorKind::InvalidData, io::ErrorKind::InvalidData,
@ -119,7 +121,6 @@ pub fn read_spv<R: io::Read + io::Seek>(x: &mut R) -> io::Result<Vec<u32>> {
// Zero-initialize the result to prevent read_exact from possibly // Zero-initialize the result to prevent read_exact from possibly
// reading uninitialized memory. // reading uninitialized memory.
let mut result = vec![0u32; words]; let mut result = vec![0u32; words];
x.seek(io::SeekFrom::Start(0))?;
x.read_exact(unsafe { x.read_exact(unsafe {
slice::from_raw_parts_mut(result.as_mut_ptr().cast::<u8>(), words * 4) slice::from_raw_parts_mut(result.as_mut_ptr().cast::<u8>(), words * 4)
})?; })?;

View file

@ -2,7 +2,7 @@
name = "examples" name = "examples"
version = "0.1.0" version = "0.1.0"
authors = ["maik klein <maikklein@googlemail.com>"] authors = ["maik klein <maikklein@googlemail.com>"]
edition = "2018" edition = "2021"
[dependencies] [dependencies]
image = "0.24" image = "0.24"

View file

@ -115,8 +115,7 @@ unsafe extern "system" fn vulkan_debug_callback(
}; };
println!( println!(
"{:?}:\n{:?} [{} ({})] : {}\n", "{message_severity:?}:\n{message_type:?} [{message_id_name} ({message_id_number})] : {message}\n",
message_severity, message_type, message_id_name, message_id_number, message,
); );
vk::FALSE vk::FALSE

View file

@ -2,7 +2,7 @@
name = "generator" name = "generator"
version = "0.1.0" version = "0.1.0"
authors = ["Maik Klein <maikklein@googlemail.com>"] authors = ["Maik Klein <maikklein@googlemail.com>"]
edition = "2018" edition = "2021"
[dependencies] [dependencies]
bindgen = "0.61" bindgen = "0.61"

View file

@ -80,7 +80,7 @@ fn parse_ctype<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, CType
fn parse_cexpr<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (CType, String), E> { fn parse_cexpr<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (CType, String), E> {
(alt(( (alt((
map(parse_cfloat, |f| (CType::Float, format!("{:.2}", f))), map(parse_cfloat, |f| (CType::Float, format!("{f:.2}"))),
parse_inverse_number, parse_inverse_number,
parse_decimal_number, parse_decimal_number,
parse_hexadecimal_number, parse_hexadecimal_number,
@ -105,9 +105,9 @@ fn parse_inverse_number<'a, E: ParseError<&'a str>>(
), ),
|((ctyp, num), minus_num)| { |((ctyp, num), minus_num)| {
let expr = if let Some(minus) = minus_num { let expr = if let Some(minus) = minus_num {
format!("!{}-{}", num, minus) format!("!{num}-{minus}")
} else { } else {
format!("!{}", num) format!("!{num}")
}; };
(ctyp, expr) (ctyp, expr)
}, },
@ -158,8 +158,7 @@ fn parse_hexadecimal_number<'a, E: ParseError<&'a str>>(
fn khronos_link<S: Display + ?Sized>(name: &S) -> Literal { fn khronos_link<S: Display + ?Sized>(name: &S) -> Literal {
Literal::string(&format!( Literal::string(&format!(
"<https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/{name}.html>", "<https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/{name}.html>"
name = name
)) ))
} }
@ -283,7 +282,7 @@ impl quote::ToTokens for Constant {
} }
Constant::Hex(ref s) => { Constant::Hex(ref s) => {
let number = interleave_number('_', 4, s); let number = interleave_number('_', 4, s);
syn::LitInt::new(&format!("0x{}", number), Span::call_site()).to_tokens(tokens); syn::LitInt::new(&format!("0x{number}"), Span::call_site()).to_tokens(tokens);
} }
Constant::Text(ref text) => text.to_tokens(tokens), Constant::Text(ref text) => text.to_tokens(tokens),
Constant::CExpr(ref expr) => { Constant::CExpr(ref expr) => {
@ -293,9 +292,9 @@ impl quote::ToTokens for Constant {
} }
Constant::BitPos(pos) => { Constant::BitPos(pos) => {
let value = 1u64 << pos; let value = 1u64 << pos;
let bit_string = format!("{:b}", value); let bit_string = format!("{value:b}");
let bit_string = interleave_number('_', 4, &bit_string); let bit_string = interleave_number('_', 4, &bit_string);
syn::LitInt::new(&format!("0b{}", bit_string), Span::call_site()).to_tokens(tokens); syn::LitInt::new(&format!("0b{bit_string}"), Span::call_site()).to_tokens(tokens);
} }
Constant::Alias(ref value) => tokens.extend(quote!(Self::#value)), Constant::Alias(ref value) => tokens.extend(quote!(Self::#value)),
} }
@ -432,7 +431,7 @@ impl FeatureExt for vkxml::Feature {
fn version_string(&self) -> String { fn version_string(&self) -> String {
let mut version = format!("{}", self.version); let mut version = format!("{}", self.version);
if version.len() == 1 { if version.len() == 1 {
version = format!("{}_0", version) version = format!("{version}_0")
} }
version.replace('.', "_") version.replace('.', "_")
@ -588,7 +587,7 @@ fn convert_c_literal(lit: Literal) -> Literal {
// If expression rewriting succeeds this should parse into a single literal // If expression rewriting succeeds this should parse into a single literal
match (stream.next(), stream.next()) { match (stream.next(), stream.next()) {
(Some(TokenTree::Literal(l)), None) => l, (Some(TokenTree::Literal(l)), None) => l,
x => panic!("Stream must contain a single literal, not {:?}", x), x => panic!("Stream must contain a single literal, not {x:?}"),
} }
} else { } else {
lit lit
@ -628,7 +627,7 @@ fn convert_c_expression(c_expr: &str, identifier_renames: &BTreeMap<String, Iden
} }
let c_expr = c_expr let c_expr = c_expr
.parse() .parse()
.unwrap_or_else(|_| panic!("Failed to parse `{}` as Rust", c_expr)); .unwrap_or_else(|_| panic!("Failed to parse `{c_expr}` as Rust"));
rewrite_token_stream(c_expr, identifier_renames) rewrite_token_stream(c_expr, identifier_renames)
} }
@ -986,7 +985,7 @@ pub fn generate_extension_constants<'a>(
let enum_tokens = extended_enums.iter().map(|(extends, constants)| { let enum_tokens = extended_enums.iter().map(|(extends, constants)| {
let ident = name_to_tokens(extends); let ident = name_to_tokens(extends);
let doc_string = format!("Generated from '{}'", extension_name); let doc_string = format!("Generated from '{extension_name}'");
let impl_block = bitflags_impl_block(ident, extends, &constants.iter().collect_vec()); let impl_block = bitflags_impl_block(ident, extends, &constants.iter().collect_vec());
quote! { quote! {
#[doc = #doc_string] #[doc = #doc_string]
@ -1045,7 +1044,7 @@ pub fn generate_extension_commands<'a>(
} }
}); });
let byte_name_ident = Literal::byte_string(format!("{}\0", extension_name).as_bytes()); let byte_name_ident = Literal::byte_string(format!("{extension_name}\0").as_bytes());
let extension_cstr = quote! { let extension_cstr = quote! {
impl #ident { impl #ident {
#[inline] #[inline]
@ -1261,10 +1260,7 @@ pub fn variant_ident(enum_name: &str, variant_name: &str) -> Ident {
if enum_name == "VkResult" { if enum_name == "VkResult" {
variant_name.strip_prefix("VK").unwrap() variant_name.strip_prefix("VK").unwrap()
} else { } else {
panic!( panic!("Failed to strip {struct_name} prefix from enum variant {variant_name}")
"Failed to strip {} prefix from enum variant {}",
struct_name, variant_name
)
} }
}); });
@ -1772,7 +1768,7 @@ pub fn derive_setters(
#[inline] #[inline]
pub fn #param_ident_short(mut self, #param_ident_short: &'a #mutable #slice_param_ty_tokens) -> Self { pub fn #param_ident_short(mut self, #param_ident_short: &'a #mutable #slice_param_ty_tokens) -> Self {
#set_size_stmt #set_size_stmt
self.#param_ident = #param_ident_short#ptr; self.#param_ident = #param_ident_short #ptr;
self self
} }
}); });
@ -2389,8 +2385,7 @@ pub fn extract_native_types(registry: &vk_parse::Registry) -> (Vec<(String, Stri
header_includes header_includes
.iter() .iter()
.all(|(other_name, _)| other_name != &name), .all(|(other_name, _)| other_name != &name),
"Header `{}` being redefined", "Header `{name}` being redefined",
name
); );
let (rem, path) = parse_c_include::<VerboseError<&str>>(&code.code) let (rem, path) = parse_c_include::<VerboseError<&str>>(&code.code)
@ -2708,23 +2703,18 @@ pub fn write_source_code<P: AsRef<Path>>(vk_headers_dir: &Path, src_dir: P) {
#(#aliases)* #(#aliases)*
}; };
write!(&mut vk_features_file, "{}", feature_code).expect("Unable to write vk/features.rs"); write!(&mut vk_features_file, "{feature_code}").expect("Unable to write vk/features.rs");
write!(&mut vk_definitions_file, "{}", definition_code) write!(&mut vk_definitions_file, "{definition_code}")
.expect("Unable to write vk/definitions.rs"); .expect("Unable to write vk/definitions.rs");
write!(&mut vk_enums_file, "{}", enum_code).expect("Unable to write vk/enums.rs"); write!(&mut vk_enums_file, "{enum_code}").expect("Unable to write vk/enums.rs");
write!(&mut vk_bitflags_file, "{}", bitflags_code).expect("Unable to write vk/bitflags.rs"); write!(&mut vk_bitflags_file, "{bitflags_code}").expect("Unable to write vk/bitflags.rs");
write!(&mut vk_constants_file, "{}", constants_code).expect("Unable to write vk/constants.rs"); write!(&mut vk_constants_file, "{constants_code}").expect("Unable to write vk/constants.rs");
write!(&mut vk_extensions_file, "{}", extension_code) write!(&mut vk_extensions_file, "{extension_code}").expect("Unable to write vk/extensions.rs");
.expect("Unable to write vk/extensions.rs"); write!(&mut vk_feature_extensions_file, "{feature_extensions_code}")
write!( .expect("Unable to write vk/feature_extensions.rs");
&mut vk_feature_extensions_file, write!(&mut vk_const_debugs_file, "{const_debugs}")
"{}",
feature_extensions_code
)
.expect("Unable to write vk/feature_extensions.rs");
write!(&mut vk_const_debugs_file, "{}", const_debugs)
.expect("Unable to write vk/const_debugs.rs"); .expect("Unable to write vk/const_debugs.rs");
write!(&mut vk_aliases_file, "{}", aliases).expect("Unable to write vk/aliases.rs"); write!(&mut vk_aliases_file, "{aliases}").expect("Unable to write vk/aliases.rs");
let vk_include = vk_headers_dir.join("include"); let vk_include = vk_headers_dir.join("include");