chore: satisfy clippy::manual_c_str_literals

This was previously an `allow`-by-default warning in Clippy's `pedantic`
group, but with Rust 1.83 it was promoted to a `warn`-by-default member
of its `complexity` group.

Co-Authored-By: Kevin Reid <kpreid@switchb.org>
This commit is contained in:
Erich Gubler 2024-11-24 15:05:22 -05:00
parent 18951ea3d2
commit 567fdbc2db
4 changed files with 10 additions and 17 deletions

View File

@ -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

View File

@ -440,14 +440,13 @@ impl crate::Instance for Instance {
unsafe fn init(desc: &crate::InstanceDescriptor) -> Result<Self, crate::InstanceError> {
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;

View File

@ -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.
///

View File

@ -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();