diff --git a/Cargo.toml b/Cargo.toml index f085766ea..760b9c85b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,6 @@ default-members = [ ] [workspace.lints.clippy] -manual_c_str_literals = "allow" ref_as_ptr = "warn" # NOTE: disallowed-types is configured in other file: clippy.toml diff --git a/wgpu-hal/src/gles/wgl.rs b/wgpu-hal/src/gles/wgl.rs index 0e7acc188..71dedf194 100644 --- a/wgpu-hal/src/gles/wgl.rs +++ b/wgpu-hal/src/gles/wgl.rs @@ -440,14 +440,13 @@ impl crate::Instance for Instance { unsafe fn init(desc: &crate::InstanceDescriptor) -> Result { profiling::scope!("Init OpenGL (WGL) Backend"); let opengl_module = - unsafe { LibraryLoader::LoadLibraryA(PCSTR("opengl32.dll\0".as_ptr())) }.map_err( - |e| { + unsafe { LibraryLoader::LoadLibraryA(PCSTR(c"opengl32.dll".as_ptr().cast())) } + .map_err(|e| { crate::InstanceError::with_source( String::from("unable to load the OpenGL library"), e, ) - }, - )?; + })?; let device = create_instance_device()?; let dc = device.dc; diff --git a/wgpu-hal/src/metal/layer_observer.rs b/wgpu-hal/src/metal/layer_observer.rs index 6f1fade72..8acd83b53 100644 --- a/wgpu-hal/src/metal/layer_observer.rs +++ b/wgpu-hal/src/metal/layer_observer.rs @@ -23,8 +23,8 @@ const NSKeyValueObservingOptionNew: usize = 0x01; #[allow(non_upper_case_globals)] const NSKeyValueObservingOptionInitial: usize = 0x04; -const CONTENTS_SCALE: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"contentsScale\0") }; -const BOUNDS: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"bounds\0") }; +const CONTENTS_SCALE: &CStr = c"contentsScale"; +const BOUNDS: &CStr = c"bounds"; /// Create a new custom layer that tracks parameters from the given super layer. /// diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index a67781dba..cf216e62f 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -34,10 +34,8 @@ unsafe extern "system" fn debug_utils_messenger_callback( // https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5671 // Versions 1.3.240 through 1.3.250 return a spurious error here if // the debug range start and end appear in different command buffers. - const KHRONOS_VALIDATION_LAYER: &CStr = - unsafe { CStr::from_bytes_with_nul_unchecked(b"Khronos Validation Layer\0") }; if let Some(layer_properties) = user_data.validation_layer_properties.as_ref() { - if layer_properties.layer_description.as_ref() == KHRONOS_VALIDATION_LAYER + if layer_properties.layer_description.as_ref() == c"Khronos Validation Layer" && layer_properties.layer_spec_version >= vk::make_api_version(0, 1, 3, 240) && layer_properties.layer_spec_version <= vk::make_api_version(0, 1, 3, 250) { @@ -611,7 +609,7 @@ impl crate::Instance for super::Instance { let app_info = vk::ApplicationInfo::default() .application_name(app_name.as_c_str()) .application_version(1) - .engine_name(CStr::from_bytes_with_nul(b"wgpu-hal\0").unwrap()) + .engine_name(c"wgpu-hal") .engine_version(2) .api_version( // Vulkan 1.0 doesn't like anything but 1.0 passed in here... @@ -653,8 +651,7 @@ impl crate::Instance for super::Instance { .find(|inst_layer| inst_layer.layer_name_as_c_str() == Ok(name)) } - let validation_layer_name = - CStr::from_bytes_with_nul(b"VK_LAYER_KHRONOS_validation\0").unwrap(); + let validation_layer_name = c"VK_LAYER_KHRONOS_validation"; let validation_layer_properties = find_layer(&instance_layers, validation_layer_name); // Determine if VK_EXT_validation_features is available, so we can enable @@ -678,11 +675,9 @@ impl crate::Instance for super::Instance { .intersects(wgt::InstanceFlags::GPU_BASED_VALIDATION) && validation_features_are_enabled; - let nv_optimus_layer = CStr::from_bytes_with_nul(b"VK_LAYER_NV_optimus\0").unwrap(); - let has_nv_optimus = find_layer(&instance_layers, nv_optimus_layer).is_some(); + let has_nv_optimus = find_layer(&instance_layers, c"VK_LAYER_NV_optimus").is_some(); - let obs_layer = CStr::from_bytes_with_nul(b"VK_LAYER_OBS_HOOK\0").unwrap(); - let has_obs_layer = find_layer(&instance_layers, obs_layer).is_some(); + let has_obs_layer = find_layer(&instance_layers, c"VK_LAYER_OBS_HOOK").is_some(); let mut layers: Vec<&'static CStr> = Vec::new();