Address all the clippy lints (#233)

* Fix literals in vk.rs

* Address all the other clippy lints in ash

* Module level clippy lint

* More lints

* Make hashmaps generic for clippy

* Remove unused macro import
This commit is contained in:
Maik Klein 2019-10-20 17:18:40 +02:00 committed by GitHub
parent f935337aa8
commit 855068323d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 785 additions and 733 deletions

View file

@ -1,4 +1,4 @@
#![allow(dead_code)]
#![allow(clippy::trivially_copy_pass_by_ref)]
use crate::prelude::*;
use crate::vk;
use crate::RawPtr;

View file

@ -13,19 +13,19 @@ use std::ptr;
use std::sync::Arc;
#[cfg(windows)]
const LIB_PATH: &'static str = "vulkan-1.dll";
const LIB_PATH: &str = "vulkan-1.dll";
#[cfg(all(
unix,
not(any(target_os = "macos", target_os = "ios", target_os = "android"))
))]
const LIB_PATH: &'static str = "libvulkan.so.1";
const LIB_PATH: &str = "libvulkan.so.1";
#[cfg(target_os = "android")]
const LIB_PATH: &'static str = "libvulkan.so";
const LIB_PATH: &str = "libvulkan.so";
#[cfg(any(target_os = "macos", target_os = "ios"))]
const LIB_PATH: &'static str = "libvulkan.dylib";
const LIB_PATH: &str = "libvulkan.dylib";
/// Function loader
pub type Entry = EntryCustom<Arc<DynamicLibrary>>;
@ -126,12 +126,12 @@ pub trait EntryV1_0 {
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkGetInstanceProcAddr.html>"]
fn get_instance_proc_addr(
unsafe fn get_instance_proc_addr(
&self,
instance: vk::Instance,
p_name: *const c_char,
) -> vk::PFN_vkVoidFunction {
unsafe { self.static_fn().get_instance_proc_addr(instance, p_name) }
self.static_fn().get_instance_proc_addr(instance, p_name)
}
}
@ -200,7 +200,7 @@ impl EntryCustom<Arc<DynamicLibrary>> {
|| {
DynamicLibrary::open(Some(&Path::new(LIB_PATH)))
.map_err(|err| LoadingError::LibraryLoadError(err.clone()))
.map(|dl| Arc::new(dl))
.map(Arc::new)
},
|vk_lib, name| unsafe {
vk_lib

View file

@ -1,3 +1,5 @@
#![allow(clippy::unreadable_literal)]
/*
***********************************************************************************************************************
*

View file

@ -15,9 +15,7 @@ impl DebugMarker {
let debug_marker_fn = vk::ExtDebugMarkerFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});
DebugMarker {
debug_marker_fn: debug_marker_fn,
}
DebugMarker { debug_marker_fn }
}
pub fn name() -> &'static CStr {

View file

@ -19,7 +19,7 @@ impl DisplaySwapchain {
});
DisplaySwapchain {
handle: device.handle(),
swapchain_fn: swapchain_fn,
swapchain_fn,
}
}

View file

@ -20,7 +20,7 @@ impl Surface {
});
Surface {
handle: instance.handle(),
surface_fn: surface_fn,
surface_fn,
}
}

View file

@ -20,7 +20,7 @@ impl Swapchain {
});
Swapchain {
handle: device.handle(),
swapchain_fn: swapchain_fn,
swapchain_fn,
}
}

View file

@ -1,3 +1,4 @@
#![allow(clippy::too_many_arguments)]
//! # Vulkan API
//!
//! <https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/index.html>
@ -43,8 +44,8 @@ pub trait RawPtr<T> {
impl<'r, T> RawPtr<T> for Option<&'r T> {
fn as_raw_ptr(&self) -> *const T {
match self {
&Some(inner) => inner as *const T,
match *self {
Some(inner) => inner as *const T,
_ => ::std::ptr::null(),
}

View file

@ -122,13 +122,13 @@ pub fn read_spv<R: io::Read + io::Seek>(x: &mut R) -> io::Result<Vec<u32>> {
))?;
result.set_len(words);
}
const MAGIC_NUMBER: u32 = 0x07230203;
if result.len() > 0 && result[0] == MAGIC_NUMBER.swap_bytes() {
const MAGIC_NUMBER: u32 = 0x0723_0203;
if !result.is_empty() && result[0] == MAGIC_NUMBER.swap_bytes() {
for word in &mut result {
*word = word.swap_bytes();
}
}
if result.len() == 0 || result[0] != MAGIC_NUMBER {
if result.is_empty() || result[0] != MAGIC_NUMBER {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"input missing SPIR-V magic number",

File diff suppressed because it is too large Load diff

View file

@ -522,7 +522,7 @@ fn main() {
let tex_descriptor = vk::DescriptorImageInfo {
image_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
image_view: tex_image_view,
sampler: sampler,
sampler,
};
let write_desc_sets = [
@ -624,7 +624,7 @@ fn main() {
max_depth: 1.0,
}];
let scissors = [vk::Rect2D {
extent: base.surface_resolution.clone(),
extent: base.surface_resolution,
..Default::default()
}];
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
@ -652,8 +652,8 @@ fn main() {
depth_test_enable: 1,
depth_write_enable: 1,
depth_compare_op: vk::CompareOp::LESS_OR_EQUAL,
front: noop_stencil_state.clone(),
back: noop_stencil_state.clone(),
front: noop_stencil_state,
back: noop_stencil_state,
max_depth_bounds: 1.0,
..Default::default()
};
@ -729,7 +729,7 @@ fn main() {
.framebuffer(framebuffers[present_index as usize])
.render_area(vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: base.surface_resolution.clone(),
extent: base.surface_resolution,
})
.clear_values(&clear_values);

View file

@ -284,7 +284,7 @@ fn main() {
}];
let scissors = [vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: base.surface_resolution.clone(),
extent: base.surface_resolution,
}];
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
.scissors(&scissors)
@ -311,8 +311,8 @@ fn main() {
depth_test_enable: 1,
depth_write_enable: 1,
depth_compare_op: vk::CompareOp::LESS_OR_EQUAL,
front: noop_stencil_state.clone(),
back: noop_stencil_state.clone(),
front: noop_stencil_state,
back: noop_stencil_state,
max_depth_bounds: 1.0,
..Default::default()
};
@ -387,7 +387,7 @@ fn main() {
.framebuffer(framebuffers[present_index as usize])
.render_area(vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: base.surface_resolution.clone(),
extent: base.surface_resolution,
})
.clear_values(&clear_values);

View file

@ -1,4 +1,3 @@
#[macro_use]
extern crate ash;
#[cfg(target_os = "windows")]
extern crate winapi;
@ -170,7 +169,7 @@ unsafe fn create_surface<E: EntryV1_0, I: InstanceV1_0>(
s_type: vk::StructureType::WIN32_SURFACE_CREATE_INFO_KHR,
p_next: ptr::null(),
flags: Default::default(),
hinstance: hinstance,
hinstance,
hwnd: hwnd as *const c_void,
};
let win32_surface_loader = Win32Surface::new(entry, instance);
@ -245,12 +244,10 @@ pub fn find_memorytype_index_f<F: Fn(vk::MemoryPropertyFlags, vk::MemoryProperty
) -> Option<u32> {
let mut memory_type_bits = memory_req.memory_type_bits;
for (index, ref memory_type) in memory_prop.memory_types.iter().enumerate() {
if memory_type_bits & 1 == 1 {
if f(memory_type.property_flags, flags) {
return Some(index as u32);
}
if memory_type_bits & 1 == 1 && f(memory_type.property_flags, flags) {
return Some(index as u32);
}
memory_type_bits = memory_type_bits >> 1;
memory_type_bits >>= 1;
}
None
}
@ -319,8 +316,8 @@ impl ExampleBase {
let window = winit::WindowBuilder::new()
.with_title("Ash - Example")
.with_dimensions(winit::dpi::LogicalSize::new(
window_width as f64,
window_height as f64,
f64::from(window_width),
f64::from(window_height),
))
.build(&events_loop)
.unwrap();
@ -385,9 +382,10 @@ impl ExampleBase {
surface,
)
.unwrap();
match supports_graphic_and_surface {
true => Some((*pdevice, index)),
_ => None,
if supports_graphic_and_surface {
Some((*pdevice, index))
} else {
None
}
})
.nth(0)
@ -429,7 +427,7 @@ impl ExampleBase {
format: vk::Format::B8G8R8_UNORM,
color_space: sfmt.color_space,
},
_ => sfmt.clone(),
_ => *sfmt,
})
.nth(0)
.expect("Unable to find suitable surface format.");
@ -472,7 +470,7 @@ impl ExampleBase {
.min_image_count(desired_image_count)
.image_color_space(surface_format.color_space)
.image_format(surface_format.format)
.image_extent(surface_resolution.clone())
.image_extent(surface_resolution)
.image_usage(vk::ImageUsageFlags::COLOR_ATTACHMENT)
.image_sharing_mode(vk::SharingMode::EXCLUSIVE)
.pre_transform(pre_transform)
@ -625,32 +623,32 @@ impl ExampleBase {
.unwrap();
ExampleBase {
events_loop: RefCell::new(events_loop),
entry: entry,
instance: instance,
device: device,
queue_family_index: queue_family_index,
pdevice: pdevice,
device_memory_properties: device_memory_properties,
window: window,
surface_loader: surface_loader,
surface_format: surface_format,
present_queue: present_queue,
surface_resolution: surface_resolution,
swapchain_loader: swapchain_loader,
swapchain: swapchain,
present_images: present_images,
present_image_views: present_image_views,
pool: pool,
draw_command_buffer: draw_command_buffer,
setup_command_buffer: setup_command_buffer,
depth_image: depth_image,
depth_image_view: depth_image_view,
present_complete_semaphore: present_complete_semaphore,
rendering_complete_semaphore: rendering_complete_semaphore,
surface: surface,
debug_call_back: debug_call_back,
debug_report_loader: debug_report_loader,
depth_image_memory: depth_image_memory,
entry,
instance,
device,
queue_family_index,
pdevice,
device_memory_properties,
window,
surface_loader,
surface_format,
present_queue,
surface_resolution,
swapchain_loader,
swapchain,
present_images,
present_image_views,
pool,
draw_command_buffer,
setup_command_buffer,
depth_image,
depth_image_view,
present_complete_semaphore,
rendering_complete_semaphore,
surface,
debug_call_back,
debug_report_loader,
depth_image_memory,
}
}
}

View file

@ -15,6 +15,7 @@ use proc_macro2::{Literal, Term};
use quote::Tokens;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::Display;
use std::hash::BuildHasher;
use std::path::Path;
use syn::Ident;
@ -83,7 +84,7 @@ named!(inverse_number<&str, (CType, String)>,
);
named!(cfloat<&str, f32>,
terminated!(nom::float_s, char!('f'))
terminated!(nom::float, char!('f'))
);
fn khronos_link<S: Display>(name: &S) -> Literal {
@ -429,6 +430,22 @@ impl quote::ToTokens for ConstVal {
}
}
}
// Interleaves a number, for example 100000 => 100_000. Mostly used to make clippy happy
fn interleave_number(symbol: char, count: usize, n: &str) -> String {
let number: String = n
.chars()
.rev()
.enumerate()
.fold(String::new(), |mut acc, (idx, next)| {
if idx != 0 && idx % count == 0 {
acc.push(symbol);
}
acc.push(next);
acc
});
number.chars().rev().collect()
}
impl Constant {
pub fn value(&self) -> Option<ConstVal> {
match *self {
@ -453,11 +470,13 @@ impl Constant {
pub fn to_tokens(&self) -> Tokens {
match *self {
Constant::Number(n) => {
let term = Term::intern(&n.to_string());
let number = interleave_number('_', 3, &n.to_string());
let term = Term::intern(&number);
quote! {#term}
}
Constant::Hex(ref s) => {
let term = Term::intern(&format!("0x{}", s));
let number = interleave_number('_', 4, s);
let term = Term::intern(&format!("0x{}", number));
quote! {#term}
}
Constant::Text(ref text) => {
@ -470,7 +489,9 @@ impl Constant {
}
Constant::BitPos(pos) => {
let value = 1 << pos;
let term = Term::intern(&format!("0b{:b}", value));
let bit_string = format!("{:b}", value);
let bit_string = interleave_number('_', 4, &bit_string);
let term = Term::intern(&format!("0b{}", bit_string));
quote! {#term}
}
}
@ -501,8 +522,14 @@ impl Constant {
pub trait FeatureExt {
fn version_string(&self) -> String;
fn is_version(&self, major: u32, minor: u32) -> bool;
}
impl FeatureExt for vkxml::Feature {
fn is_version(&self, major: u32, minor: u32) -> bool {
let self_major = self.version as u32;
let self_minor = (self.version * 10.0) as u32 - self_major;
major == self_major && self_minor == minor
}
fn version_string(&self) -> String {
let mut version = format!("{}", self.version);
if version.len() == 1 {
@ -689,7 +716,7 @@ pub type CommandMap<'a> = HashMap<vkxml::Identifier, &'a vkxml::Command>;
fn generate_function_pointers<'a>(
ident: Ident,
commands: &[&'a vkxml::Command],
fn_cache: &mut HashSet<&'a str>,
fn_cache: &mut HashSet<&'a str, impl BuildHasher>,
) -> quote::Tokens {
let names: Vec<_> = commands.iter().map(|cmd| cmd.command_ident()).collect();
let names_ref = &names;
@ -711,9 +738,9 @@ fn generate_function_pointers<'a>(
let ident = cmd.name.as_str();
if !fn_cache.contains(ident) {
fn_cache.insert(ident);
return true;
true
} else {
return false;
false
}
})
.collect();
@ -879,7 +906,7 @@ pub fn generate_extension_constants<'a>(
extension_name: &str,
extension_number: i64,
extension_items: &'a [vk_parse::ExtensionChild],
const_cache: &mut HashSet<&'a str>,
const_cache: &mut HashSet<&'a str, impl BuildHasher>,
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
) -> quote::Tokens {
use vk_parse::EnumSpec;
@ -944,16 +971,14 @@ pub fn generate_extension_commands<'a>(
extension_name: &str,
items: &[vk_parse::ExtensionChild],
cmd_map: &CommandMap<'a>,
fn_cache: &mut HashSet<&'a str>,
fn_cache: &mut HashSet<&'a str, impl BuildHasher>,
) -> Tokens {
let commands = items
.iter()
.filter_map(|ext_item| match ext_item {
vk_parse::ExtensionChild::Require { items, .. } => {
Some(items.iter().filter_map(|item| match item {
vk_parse::InterfaceItem::Command { ref name, .. } => {
cmd_map.get(name).map(|c| *c)
}
vk_parse::InterfaceItem::Command { ref name, .. } => cmd_map.get(name).copied(),
_ => None,
}))
}
@ -983,9 +1008,9 @@ pub fn generate_extension_commands<'a>(
pub fn generate_extension<'a>(
extension: &'a vk_parse::Extension,
cmd_map: &CommandMap<'a>,
const_cache: &mut HashSet<&'a str>,
const_cache: &mut HashSet<&'a str, impl BuildHasher>,
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
fn_cache: &mut HashSet<&'a str>,
fn_cache: &mut HashSet<&'a str, impl BuildHasher>,
) -> Option<quote::Tokens> {
// Okay this is a little bit odd. We need to generate all extensions, even disabled ones,
// because otherwise some StructureTypes won't get generated. But we don't generate extensions
@ -1018,7 +1043,7 @@ pub fn generate_typedef(typedef: &vkxml::Typedef) -> Tokens {
}
pub fn generate_bitmask(
bitmask: &vkxml::Bitmask,
bitflags_cache: &mut HashSet<Ident>,
bitflags_cache: &mut HashSet<Ident, impl BuildHasher>,
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
) -> Option<Tokens> {
// Workaround for empty bitmask
@ -1035,8 +1060,8 @@ pub fn generate_bitmask(
if bitflags_cache.contains(&ident) {
return None;
};
bitflags_cache.insert(ident.clone());
const_values.insert(ident.clone(), Vec::new());
bitflags_cache.insert(ident);
const_values.insert(ident, Vec::new());
let khronos_link = khronos_link(&bitmask.name);
Some(quote! {
#[repr(transparent)]
@ -1060,7 +1085,7 @@ pub fn variant_ident(enum_name: &str, variant_name: &str) -> Ident {
let vendors = ["_NVX", "_KHR", "_EXT", "_NV", "_AMD", "_ANDROID", "_GOOGLE"];
let mut struct_name = _name.to_shouty_snake_case();
let vendor = vendors
.into_iter()
.iter()
.find(|&vendor| struct_name.contains(vendor))
.cloned()
.unwrap_or("");
@ -1124,9 +1149,9 @@ pub fn bitflags_impl_block(
pub fn generate_enum<'a>(
_enum: &'a vkxml::Enumeration,
const_cache: &mut HashSet<&'a str>,
const_cache: &mut HashSet<&'a str, impl BuildHasher>,
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
bitflags_cache: &mut HashSet<Ident>,
bitflags_cache: &mut HashSet<Ident, impl BuildHasher>,
) -> EnumType {
let name = &_enum.name[2..];
let _name = name.replace("FlagBits", "Flags");
@ -1144,7 +1169,7 @@ pub fn generate_enum<'a>(
const_cache.insert(constant.name.as_str());
values.push(constant.variant_ident(&_enum.name));
}
const_values.insert(ident.clone(), values);
const_values.insert(ident, values);
let khronos_link = khronos_link(&_enum.name);
@ -1154,13 +1179,15 @@ pub fn generate_enum<'a>(
.iter()
.filter_map(|constant| Constant::from_constant(constant).value())
.fold(0, |acc, next| acc | next.bits());
let all_bits_term = Term::intern(&format!("0b{:b}", all_bits));
let bit_string = format!("{:b}", all_bits);
let bit_string = interleave_number('_', 4, &bit_string);
let all_bits_term = Term::intern(&format!("0b{}", bit_string));
let impl_bitflags = bitflags_impl_block(ident, &_enum.name, &constants);
if bitflags_cache.contains(&ident) {
EnumType::Bitflags(quote! {})
} else {
bitflags_cache.insert(ident.clone());
bitflags_cache.insert(ident);
let q = quote! {
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -1344,7 +1371,10 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<Tokens> {
};
Some(q)
}
pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Option<Tokens> {
pub fn derive_debug(
_struct: &vkxml::Struct,
union_types: &HashSet<&str, impl BuildHasher>,
) -> Option<Tokens> {
let name = name_to_tokens(&_struct.name);
let members = _struct.elements.iter().filter_map(|elem| match *elem {
vkxml::StructElement::Member(ref field) => Some(field),
@ -1405,7 +1435,7 @@ pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Opt
pub fn derive_setters(
_struct: &vkxml::Struct,
root_struct_names: &HashSet<String>,
root_struct_names: &HashSet<String, impl BuildHasher>,
) -> Option<Tokens> {
if &_struct.name == "VkBaseInStructure" || &_struct.name == "VkBaseOutStructure" {
return None;
@ -1421,7 +1451,7 @@ pub fn derive_setters(
let (has_next, _is_next_const) = match members
.clone()
.find(|field| field.param_ident().to_string() == "p_next")
.find(|field| field.param_ident().as_ref() == "p_next")
{
Some(p_next) => {
if p_next.type_tokens(false).to_string().starts_with("*const") {
@ -1449,7 +1479,7 @@ pub fn derive_setters(
if !array_size.starts_with("latexmath")
&& !nofilter_count_members
.iter()
.any(|n| *n == &(_struct.name.clone() + "." + field_name))
.any(|&n| n == (_struct.name.clone() + "." + field_name))
{
return Some((*array_size).clone());
}
@ -1561,8 +1591,7 @@ pub fn derive_setters(
let slice_param_ty_tokens = Term::intern(&slice_param_ty_tokens);
let ptr = Term::intern(ptr);
match array_type {
vkxml::ArrayType::Dynamic => {
if let vkxml::ArrayType::Dynamic = array_type {
return Some(quote!{
pub fn #param_ident_short(mut self, #param_ident_short: #slice_param_ty_tokens) -> #name_builder<'a> {
self.inner.#array_size_ident = #param_ident_short.len() as _;
@ -1570,8 +1599,6 @@ pub fn derive_setters(
self
}
});
}
_ => {}
}
}
}
@ -1618,7 +1645,7 @@ pub fn derive_setters(
.map(|extends| name_to_tokens(&format!("Extends{}", name_to_tokens(&extends))))
.collect()
})
.unwrap_or(vec![]);
.unwrap_or_else(|| vec![]);
// We only implement a next methods for root structs with a `pnext` field.
let next_function = if has_next && root_structs.is_empty() {
@ -1735,8 +1762,8 @@ pub fn manual_derives(_struct: &vkxml::Struct) -> Tokens {
}
pub fn generate_struct(
_struct: &vkxml::Struct,
root_struct_names: &HashSet<String>,
union_types: &HashSet<&str>,
root_struct_names: &HashSet<String, impl BuildHasher>,
union_types: &HashSet<&str, impl BuildHasher>,
) -> Tokens {
let name = name_to_tokens(&_struct.name);
let members = _struct.elements.iter().filter_map(|elem| match *elem {
@ -1863,9 +1890,9 @@ pub fn root_struct_names(definitions: &[&vkxml::DefinitionsElement]) -> HashSet<
}
pub fn generate_definition(
definition: &vkxml::DefinitionsElement,
union_types: &HashSet<&str>,
root_structs: &HashSet<String>,
bitflags_cache: &mut HashSet<Ident>,
union_types: &HashSet<&str, impl BuildHasher>,
root_structs: &HashSet<String, impl BuildHasher>,
bitflags_cache: &mut HashSet<Ident, impl BuildHasher>,
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
) -> Option<Tokens> {
match *definition {
@ -1885,7 +1912,7 @@ pub fn generate_definition(
pub fn generate_feature<'a>(
feature: &vkxml::Feature,
commands: &CommandMap<'a>,
fn_cache: &mut HashSet<&'a str>,
fn_cache: &mut HashSet<&'a str, impl BuildHasher>,
) -> quote::Tokens {
let (static_commands, entry_commands, device_commands, instance_commands) = feature
.elements
@ -1929,7 +1956,7 @@ pub fn generate_feature<'a>(
},
);
let version = feature.version_string();
let static_fn = if feature.version == 1.0 {
let static_fn = if feature.is_version(1, 0) {
generate_function_pointers(Ident::from("StaticFn"), &static_commands, fn_cache)
} else {
quote! {}
@ -1962,7 +1989,7 @@ pub fn constant_name(name: &str) -> String {
pub fn generate_constant<'a>(
constant: &'a vkxml::Constant,
cache: &mut HashSet<&'a str>,
cache: &mut HashSet<&'a str, impl BuildHasher>,
) -> Tokens {
cache.insert(constant.name.as_str());
let c = Constant::from_constant(constant);
@ -1982,7 +2009,7 @@ pub fn generate_constant<'a>(
pub fn generate_feature_extension<'a>(
registry: &'a vk_parse::Registry,
const_cache: &mut HashSet<&'a str>,
const_cache: &mut HashSet<&'a str, impl BuildHasher>,
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
) -> Tokens {
let constants = registry.0.iter().filter_map(|item| match item {
@ -2000,7 +2027,7 @@ pub fn generate_feature_extension<'a>(
}
}
pub fn generate_const_debugs<'a>(const_values: &BTreeMap<Ident, Vec<Ident>>) -> Tokens {
pub fn generate_const_debugs(const_values: &BTreeMap<Ident, Vec<Ident>>) -> Tokens {
let impls = const_values.iter().map(|(ty, values)| {
if ty.to_string().contains("Flags") {
let cases = values.iter().map(|value| {
@ -2061,7 +2088,7 @@ pub fn generate_const_debugs<'a>(const_values: &BTreeMap<Ident, Vec<Ident>>) ->
}
pub fn generate_aliases_of_types<'a>(
types: &'a vk_parse::Types,
ty_cache: &mut HashSet<Ident>,
ty_cache: &mut HashSet<Ident, impl BuildHasher>,
) -> Tokens {
let aliases = types
.children
@ -2075,7 +2102,7 @@ pub fn generate_aliases_of_types<'a>(
if ty_cache.contains(&name_ident) {
return None;
};
ty_cache.insert(name_ident.clone());
ty_cache.insert(name_ident);
let alias_ident = name_to_tokens(alias);
let tokens = quote! {
pub type #name_ident = #alias_ident;
@ -2239,6 +2266,7 @@ pub fn write_source_code(path: &Path) {
let version_macros = vk_version_macros();
let platform_specific_types = platform_specific_types();
let source_code = quote! {
#![allow(clippy::too_many_arguments, clippy::cognitive_complexity)]
use std::fmt;
use std::os::raw::*;
/// Iterates through the pointer chain. Includes the item that is passed into the function.
@ -2246,10 +2274,9 @@ pub fn write_source_code(path: &Path) {
pub(crate) unsafe fn ptr_chain_iter<T>(
ptr: &mut T,
) -> impl Iterator<Item = *mut BaseOutStructure> {
use std::ptr::null_mut;
let ptr: *mut BaseOutStructure = ptr as *mut T as _;
(0..).scan(ptr, |p_ptr, _| {
if *p_ptr == null_mut() {
if p_ptr.is_null() {
return None;
}
let n_ptr = (**p_ptr).p_next as *mut BaseOutStructure;