Skip to content

Commit

Permalink
Resolve lint warnings for deprecated_in_future, rust_2018_idioms
Browse files Browse the repository at this point in the history
…and `unused_qualifications`

These are 3 non-default lints that cause a lot of violations in this
project that are sensible to resolve, and reduce noise when
test-including a local `ash` checkout in other projects that have
stricter lint setups.
  • Loading branch information
MarijnS95 committed Oct 25, 2023
1 parent 8667154 commit 464aedc
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 65 deletions.
14 changes: 7 additions & 7 deletions ash/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::instance::Instance;
use crate::prelude::*;
use crate::vk;
use crate::RawPtr;
use std::error::Error;
use std::ffi::CStr;
#[cfg(feature = "loaded")]
use std::ffi::OsStr;
use std::fmt;
use std::mem;
use std::os::raw::c_char;
use std::os::raw::c_void;
Expand Down Expand Up @@ -156,7 +158,7 @@ impl Entry {
/// `static_fn` must contain valid function pointers that comply with the semantics specified
/// by Vulkan 1.0, which must remain valid for at least the lifetime of the returned [`Entry`].
pub unsafe fn from_static_fn(static_fn: vk::StaticFn) -> Self {
let load_fn = move |name: &std::ffi::CStr| {
let load_fn = move |name: &CStr| {
mem::transmute((static_fn.get_instance_proc_addr)(
vk::Instance::null(),
name.as_ptr(),
Expand Down Expand Up @@ -342,12 +344,12 @@ impl vk::StaticFn {

#[derive(Clone, Debug)]
pub struct MissingEntryPoint;
impl std::fmt::Display for MissingEntryPoint {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
impl fmt::Display for MissingEntryPoint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Cannot load `vkGetInstanceProcAddr` symbol from library")
}
}
impl std::error::Error for MissingEntryPoint {}
impl Error for MissingEntryPoint {}

#[cfg(feature = "linked")]
extern "system" {
Expand All @@ -357,8 +359,6 @@ extern "system" {

#[cfg(feature = "loaded")]
mod loaded {
use std::error::Error;
use std::fmt;

use super::*;

Expand All @@ -370,7 +370,7 @@ mod loaded {
}

impl fmt::Display for LoadingError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::LibraryLoadFailure(err) => fmt::Display::fmt(err, f),
Self::MissingEntryPoint(err) => fmt::Display::fmt(err, f),
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/tooling_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl ToolingInfo {
pub unsafe fn get_physical_device_tool_properties(
&self,
physical_device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::PhysicalDeviceToolPropertiesEXT>> {
) -> VkResult<Vec<vk::PhysicalDeviceToolPropertiesEXT<'_>>> {
read_into_defaulted_vector(|count, data| {
(self.fp.get_physical_device_tool_properties_ext)(physical_device, count, data)
})
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/cooperative_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl CooperativeMatrix {
pub unsafe fn get_physical_device_cooperative_matrix_properties(
&self,
physical_device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::CooperativeMatrixPropertiesKHR>> {
) -> VkResult<Vec<vk::CooperativeMatrixPropertiesKHR<'_>>> {
read_into_defaulted_vector(|count, data| {
(self
.fp
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Display {
pub unsafe fn get_physical_device_display_properties(
&self,
physical_device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::DisplayPropertiesKHR>> {
) -> VkResult<Vec<vk::DisplayPropertiesKHR<'_>>> {
read_into_uninitialized_vector(|count, data| {
(self.fp.get_physical_device_display_properties_khr)(physical_device, count, data)
})
Expand Down
6 changes: 3 additions & 3 deletions ash/src/extensions/khr/pipeline_executable_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl PipelineExecutableProperties {
pub unsafe fn get_pipeline_executable_internal_representations(
&self,
executable_info: &vk::PipelineExecutableInfoKHR<'_>,
) -> VkResult<Vec<vk::PipelineExecutableInternalRepresentationKHR>> {
) -> VkResult<Vec<vk::PipelineExecutableInternalRepresentationKHR<'_>>> {
read_into_defaulted_vector(|count, data| {
(self.fp.get_pipeline_executable_internal_representations_khr)(
self.handle,
Expand All @@ -40,7 +40,7 @@ impl PipelineExecutableProperties {
pub unsafe fn get_pipeline_executable_properties(
&self,
pipeline_info: &vk::PipelineInfoKHR<'_>,
) -> VkResult<Vec<vk::PipelineExecutablePropertiesKHR>> {
) -> VkResult<Vec<vk::PipelineExecutablePropertiesKHR<'_>>> {
read_into_defaulted_vector(|count, data| {
(self.fp.get_pipeline_executable_properties_khr)(
self.handle,
Expand All @@ -56,7 +56,7 @@ impl PipelineExecutableProperties {
pub unsafe fn get_pipeline_executable_statistics(
&self,
executable_info: &vk::PipelineExecutableInfoKHR<'_>,
) -> VkResult<Vec<vk::PipelineExecutableStatisticKHR>> {
) -> VkResult<Vec<vk::PipelineExecutableStatisticKHR<'_>>> {
read_into_defaulted_vector(|count, data| {
(self.fp.get_pipeline_executable_statistics_khr)(
self.handle,
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/nv/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl RayTracing {
pub unsafe fn get_acceleration_structure_memory_requirements(
&self,
info: &vk::AccelerationStructureMemoryRequirementsInfoNV<'_>,
) -> vk::MemoryRequirements2KHR {
) -> vk::MemoryRequirements2KHR<'_> {
let mut requirements = Default::default();
(self.fp.get_acceleration_structure_memory_requirements_nv)(
self.handle,
Expand Down
12 changes: 9 additions & 3 deletions ash/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#![deny(clippy::use_self)]
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(
clippy::use_self,
deprecated_in_future,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_qualifications
)]
#![allow(
clippy::too_many_arguments,
clippy::missing_safety_doc,
Expand Down Expand Up @@ -187,7 +193,7 @@ mod tests {
let mut device_create_info = vk::DeviceCreateInfo::default()
.push_next(&mut corner)
.push_next(&mut variable_pointers);
let chain2: Vec<*mut vk::BaseOutStructure> = unsafe {
let chain2: Vec<*mut vk::BaseOutStructure<'_>> = unsafe {
vk::ptr_chain_iter(&mut device_create_info)
.skip(1)
.collect()
Expand Down
2 changes: 1 addition & 1 deletion ash/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ where

#[cfg(feature = "debug")]
pub(crate) fn debug_flags<Value: Into<u64> + Copy>(
f: &mut fmt::Formatter,
f: &mut fmt::Formatter<'_>,
known: &[(Value, &'static str)],
value: Value,
) -> fmt::Result {
Expand Down
6 changes: 3 additions & 3 deletions ash/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Align<T> {
}

#[derive(Debug)]
pub struct AlignIter<'a, T: 'a> {
pub struct AlignIter<'a, T> {
align: &'a mut Align<T>,
current: vk::DeviceSize,
}
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<T> Align<T> {
}
}

pub fn iter_mut(&mut self) -> AlignIter<T> {
pub fn iter_mut(&mut self) -> AlignIter<'_, T> {
AlignIter {
current: 0,
align: self,
Expand Down Expand Up @@ -113,7 +113,7 @@ pub fn read_spv<R: io::Read + io::Seek>(x: &mut R) -> io::Result<Vec<u32>> {
"input length not divisible by 4",
));
}
if size > usize::max_value() as u64 {
if size > usize::MAX as u64 {
return Err(io::Error::new(io::ErrorKind::InvalidData, "input too long"));
}
let words = (size / 4) as usize;
Expand Down
6 changes: 4 additions & 2 deletions ash/src/vk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ mod platform_types;
pub use platform_types::*;
/// Iterates through the pointer chain. Includes the item that is passed into the function.
/// Stops at the last [`BaseOutStructure`] that has a null [`BaseOutStructure::p_next`] field.
pub(crate) unsafe fn ptr_chain_iter<T>(ptr: &mut T) -> impl Iterator<Item = *mut BaseOutStructure> {
let ptr = <*mut T>::cast::<BaseOutStructure>(ptr);
pub(crate) unsafe fn ptr_chain_iter<T>(
ptr: &mut T,
) -> impl Iterator<Item = *mut BaseOutStructure<'_>> {
let ptr = <*mut T>::cast::<BaseOutStructure<'_>>(ptr);
(0..).scan(ptr, |p_ptr, _| {
if p_ptr.is_null() {
return None;
Expand Down
2 changes: 2 additions & 0 deletions ash/src/vk/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_qualifications)] // Because we do not know in what file the PFNs are defined

use crate::vk::aliases::*;
use crate::vk::bitflags::*;
use crate::vk::definitions::*;
Expand Down
8 changes: 4 additions & 4 deletions ash/src/vk/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ macro_rules! handle_nondispatchable {
}
}
impl fmt::Pointer for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "0x{:x}", self.0)
}
}
impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "0x{:x}", self.0)
}
}
Expand Down Expand Up @@ -149,12 +149,12 @@ macro_rules! define_handle {
}
}
impl fmt::Pointer for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Pointer::fmt(&self.0, f)
}
}
impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}
Expand Down
18 changes: 12 additions & 6 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
extern crate ash;
extern crate winit;
#![warn(
clippy::use_self,
deprecated_in_future,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_qualifications
)]

use ash::extensions::{
ext::DebugUtils,
Expand Down Expand Up @@ -54,7 +60,7 @@ pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(
) {
unsafe {
device
.wait_for_fences(&[command_buffer_reuse_fence], true, std::u64::MAX)
.wait_for_fences(&[command_buffer_reuse_fence], true, u64::MAX)
.expect("Wait for fence failed.");

device
Expand Down Expand Up @@ -96,7 +102,7 @@ pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(
unsafe extern "system" fn vulkan_debug_callback(
message_severity: vk::DebugUtilsMessageSeverityFlagsEXT,
message_type: vk::DebugUtilsMessageTypeFlagsEXT,
p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT,
p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT<'_>,
_user_data: *mut std::os::raw::c_void,
) -> vk::Bool32 {
let callback_data = *p_callback_data;
Expand Down Expand Up @@ -355,7 +361,7 @@ impl ExampleBase {
desired_image_count = surface_capabilities.max_image_count;
}
let surface_resolution = match surface_capabilities.current_extent.width {
std::u32::MAX => vk::Extent2D {
u32::MAX => vk::Extent2D {
width: window_width,
height: window_height,
},
Expand Down Expand Up @@ -541,7 +547,7 @@ impl ExampleBase {
.create_semaphore(&semaphore_create_info, None)
.unwrap();

ExampleBase {
Self {
event_loop: RefCell::new(event_loop),
entry,
instance,
Expand Down
Loading

0 comments on commit 464aedc

Please sign in to comment.