Skip to content

Commit db14558

Browse files
authored
Set and test MSRV at 1.82 (#350)
This also makes use of `size_of(_val)()` being imporced via the prelude, `&raw` pointers being available to - for example - save on casts from borrows to raw pointers, and C-string literals automatically appending NUL terminators to strings.
1 parent 802799a commit db14558

File tree

15 files changed

+37
-54
lines changed

15 files changed

+37
-54
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
channel: [stable, nightly]
16+
channel: [1.82, stable, nightly]
1717

1818
steps:
1919
- uses: actions/checkout@v4
2020

2121
- name: Setup rust toolchain
22-
uses: dtolnay/rust-toolchain@stable
22+
uses: dtolnay/rust-toolchain@master
2323
with:
2424
toolchain: ${{ matrix.channel }}
2525

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ exclude = [
1717
"Cargo.lock",
1818
"target/**/*",
1919
]
20+
rust-version = "1.82"
2021

2122
[package.metadata.docs.rs]
2223
targets = [

examples/circle/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn main() {
5252
device.sample_timestamps(&mut cpu_start, &mut gpu_start);
5353
let counter_sample_buffer = create_counter_sample_buffer(&device);
5454
let destination_buffer = device.new_buffer(
55-
(std::mem::size_of::<u64>() * 4 as usize) as u64,
55+
(size_of::<u64>() * 4 as usize) as u64,
5656
MTLResourceOptions::StorageModeShared,
5757
);
5858
let counter_sampling_point = MTLCounterSamplingPoint::AtStageBoundary;
@@ -116,7 +116,7 @@ fn main() {
116116

117117
device.new_buffer_with_data(
118118
vertex_data.as_ptr() as *const _,
119-
(vertex_data.len() * mem::size_of::<AAPLVertex>()) as u64,
119+
(vertex_data.len() * size_of::<AAPLVertex>()) as u64,
120120
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
121121
)
122122
};

examples/compute/compute-argument-buffer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ fn main() {
2323

2424
let buffer = device.new_buffer_with_data(
2525
unsafe { mem::transmute(data.as_ptr()) },
26-
(data.len() * mem::size_of::<u32>()) as u64,
26+
(data.len() * size_of::<u32>()) as u64,
2727
MTLResourceOptions::CPUCacheModeDefaultCache,
2828
);
2929

3030
let sum = {
3131
let data = [0u32];
3232
device.new_buffer_with_data(
3333
unsafe { mem::transmute(data.as_ptr()) },
34-
(data.len() * mem::size_of::<u32>()) as u64,
34+
(data.len() * size_of::<u32>()) as u64,
3535
MTLResourceOptions::CPUCacheModeDefaultCache,
3636
)
3737
};

examples/compute/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818

1919
let counter_sample_buffer = create_counter_sample_buffer(&device);
2020
let destination_buffer = device.new_buffer(
21-
(std::mem::size_of::<u64>() * NUM_SAMPLES as usize) as u64,
21+
(size_of::<u64>() * NUM_SAMPLES as usize) as u64,
2222
MTLResourceOptions::StorageModeShared,
2323
);
2424

@@ -171,15 +171,15 @@ fn create_input_and_output_buffers(
171171

172172
let buffer = device.new_buffer_with_data(
173173
unsafe { std::mem::transmute(data.as_ptr()) },
174-
(data.len() * std::mem::size_of::<u32>()) as u64,
174+
(data.len() * size_of::<u32>()) as u64,
175175
MTLResourceOptions::CPUCacheModeDefaultCache,
176176
);
177177

178178
let sum = {
179179
let data = [0u32];
180180
device.new_buffer_with_data(
181181
unsafe { std::mem::transmute(data.as_ptr()) },
182-
(data.len() * std::mem::size_of::<u32>()) as u64,
182+
(data.len() * size_of::<u32>()) as u64,
183183
MTLResourceOptions::CPUCacheModeDefaultCache,
184184
)
185185
};

examples/headless-render/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::mem;
21
use std::path::PathBuf;
32

43
use std::fs::File;
@@ -144,7 +143,7 @@ fn prepare_pipeline_state(device: &DeviceRef, library: &LibraryRef) -> RenderPip
144143
fn create_vertex_buffer(device: &DeviceRef) -> Buffer {
145144
device.new_buffer_with_data(
146145
VERTEX_ATTRIBS.as_ptr() as *const _,
147-
(VERTEX_ATTRIBS.len() * mem::size_of::<f32>()) as u64,
146+
(VERTEX_ATTRIBS.len() * size_of::<f32>()) as u64,
148147
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
149148
)
150149
}

examples/mps/main.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use metal::*;
22
use std::ffi::c_void;
3-
use std::mem;
43

54
#[repr(C)]
65
struct Vertex {
@@ -39,7 +38,7 @@ fn main() {
3938
},
4039
];
4140

42-
let vertex_stride = mem::size_of::<Vertex>();
41+
let vertex_stride = size_of::<Vertex>();
4342

4443
let indices: [u32; 3] = [0, 1, 2];
4544

@@ -56,7 +55,7 @@ fn main() {
5655

5756
let index_buffer = device.new_buffer_with_data(
5857
indices.as_ptr() as *const c_void,
59-
(mem::size_of::<u32>() * indices.len()) as u64,
58+
(size_of::<u32>() * indices.len()) as u64,
6059
buffer_opts,
6160
);
6261

@@ -75,22 +74,22 @@ fn main() {
7574
let ray_intersector =
7675
mps::RayIntersector::from_device(&device).expect("Failed to create ray intersector");
7776

78-
ray_intersector.set_ray_stride(mem::size_of::<Ray>() as u64);
77+
ray_intersector.set_ray_stride(size_of::<Ray>() as u64);
7978
ray_intersector.set_ray_data_type(mps::MPSRayDataType::OriginMinDistanceDirectionMaxDistance);
80-
ray_intersector.set_intersection_stride(mem::size_of::<Intersection>() as u64);
79+
ray_intersector.set_intersection_stride(size_of::<Intersection>() as u64);
8180
ray_intersector.set_intersection_data_type(
8281
mps::MPSIntersectionDataType::DistancePrimitiveIndexCoordinates,
8382
);
8483

8584
// Create a buffer to hold generated rays and intersection results
8685
let ray_count = 1024;
8786
let ray_buffer = device.new_buffer(
88-
(mem::size_of::<Ray>() * ray_count) as u64,
87+
(size_of::<Ray>() * ray_count) as u64,
8988
MTLResourceOptions::StorageModePrivate,
9089
);
9190

9291
let intersection_buffer = device.new_buffer(
93-
(mem::size_of::<Intersection>() * ray_count) as u64,
92+
(size_of::<Intersection>() * ray_count) as u64,
9493
MTLResourceOptions::StorageModePrivate,
9594
);
9695

examples/raytracing/geometry.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::{
2-
mem::{size_of, transmute},
3-
sync::Arc,
4-
};
1+
use std::{mem::transmute, sync::Arc};
52

63
use glam::{
74
f32::{Mat4, Vec3, Vec4},

examples/raytracing/renderer.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core_graphics_types::{base::CGFloat, geometry::CGSize};
22
use std::{
33
collections::BTreeMap,
44
ffi::c_void,
5-
mem::{size_of, transmute},
5+
mem::transmute,
66
ops::Index,
77
sync::{Arc, Condvar, Mutex},
88
};
@@ -475,21 +475,13 @@ impl Renderer {
475475
let constants = FunctionConstantValues::new();
476476
let resources_stride = resources_stride * size_of::<u64>() as u32;
477477
constants.set_constant_value_at_index(
478-
&resources_stride as *const u32 as *const c_void,
478+
&raw const resources_stride as *const c_void,
479479
MTLDataType::UInt,
480480
0,
481481
);
482482
let v = true;
483-
constants.set_constant_value_at_index(
484-
&v as *const bool as *const c_void,
485-
MTLDataType::Bool,
486-
1,
487-
);
488-
constants.set_constant_value_at_index(
489-
&v as *const bool as *const c_void,
490-
MTLDataType::Bool,
491-
2,
492-
);
483+
constants.set_constant_value_at_index(&raw const v as *const c_void, MTLDataType::Bool, 1);
484+
constants.set_constant_value_at_index(&raw const v as *const c_void, MTLDataType::Bool, 2);
493485
library.get_function(name, Some(constants)).unwrap()
494486
}
495487

examples/raytracing/scene.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{ffi::c_void, mem::size_of, sync::Arc};
1+
use std::{ffi::c_void, sync::Arc};
22

33
use glam::{Mat4, Vec3, Vec4};
44
use rand::{thread_rng, Rng};

examples/texture/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() {
4141
let vertex_data = vertices();
4242
let vertex_buffer = device.new_buffer_with_data(
4343
vertex_data.as_ptr() as *const _,
44-
(vertex_data.len() * std::mem::size_of::<TexturedVertex>()) as u64,
44+
(vertex_data.len() * size_of::<TexturedVertex>()) as u64,
4545
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
4646
);
4747

@@ -225,7 +225,7 @@ fn prepare_pipeline_state(device: &Device, library: &Library) -> RenderPipelineS
225225
fn update_viewport_size_buffer(viewport_size_buffer: &Buffer, size: (u32, u32)) {
226226
let contents = viewport_size_buffer.contents();
227227
let viewport_size: [u32; 2] = [size.0, size.1];
228-
let byte_count = (viewport_size.len() * std::mem::size_of::<u32>()) as usize;
228+
let byte_count = (viewport_size.len() * size_of::<u32>()) as usize;
229229

230230
unsafe {
231231
std::ptr::copy(viewport_size.as_ptr(), contents as *mut u32, byte_count);

examples/window/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn main() {
135135

136136
device.new_buffer_with_data(
137137
vertex_data.as_ptr() as *const _,
138-
(vertex_data.len() * mem::size_of::<f32>()) as u64,
138+
(vertex_data.len() * size_of::<f32>()) as u64,
139139
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
140140
)
141141
};
@@ -159,7 +159,7 @@ fn main() {
159159

160160
let clear_rect_buffer = device.new_buffer_with_data(
161161
clear_rect.as_ptr() as *const _,
162-
mem::size_of::<ClearRect>() as u64,
162+
size_of::<ClearRect>() as u64,
163163
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
164164
);
165165

@@ -202,13 +202,13 @@ fn main() {
202202
std::ptr::copy(
203203
vertex_data.as_ptr(),
204204
p as *mut f32,
205-
(vertex_data.len() * mem::size_of::<f32>()) as usize,
205+
(vertex_data.len() * size_of::<f32>()) as usize,
206206
);
207207
}
208208

209209
vbuf.did_modify_range(crate::NSRange::new(
210210
0 as u64,
211-
(vertex_data.len() * mem::size_of::<f32>()) as u64,
211+
(vertex_data.len() * size_of::<f32>()) as u64,
212212
));
213213

214214
let drawable = match layer.next_drawable() {

src/counters.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{MTLStorageMode, NSUInteger};
2-
use std::mem;
32

43
/// See <https://developer.apple.com/documentation/metal/mtlcountersamplebufferdescriptor>
54
pub enum MTLCounterSampleBufferDescriptor {}
@@ -71,7 +70,7 @@ impl CounterSampleBufferRef {
7170

7271
pub fn resolve_counter_range(&self, range: crate::NSRange) -> Vec<NSUInteger> {
7372
let mut data = vec![0 as NSUInteger; range.length as usize];
74-
let total_bytes = range.length * mem::size_of::<NSUInteger>() as u64;
73+
let total_bytes = range.length * size_of::<NSUInteger>() as u64;
7574
unsafe {
7675
let ns_data: *mut crate::Object = msg_send![self, resolveCounterRange: range];
7776
let () = msg_send![ns_data, getBytes: data.as_mut_ptr() length: total_bytes];

src/device.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ use block::Block;
1111
use log::warn;
1212
use objc::runtime::{NO, YES};
1313

14-
use std::{
15-
ffi::CStr,
16-
os::raw::c_char,
17-
path::Path,
18-
ptr::{self, addr_of_mut},
19-
};
14+
use std::{ffi::CStr, os::raw::c_char, path::Path, ptr};
2015

2116
/// Available on macOS 10.11+, iOS 8.0+, tvOS 9.0+
2217
///
@@ -1730,7 +1725,7 @@ impl DeviceRef {
17301725
let data = dispatch_data_create(
17311726
library_data.as_ptr() as *const std::ffi::c_void,
17321727
library_data.len() as crate::c_size_t,
1733-
addr_of_mut!(_dispatch_main_q),
1728+
&raw mut _dispatch_main_q,
17341729
DISPATCH_DATA_DESTRUCTOR_DEFAULT,
17351730
);
17361731

src/sync.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8+
use std::ffi::CStr;
9+
810
use super::*;
911
use block::{Block, RcBlock};
10-
use std::ptr;
1112

1213
#[cfg(feature = "dispatch")]
1314
use dispatch;
@@ -63,14 +64,14 @@ impl SharedEventRef {
6364
*mut BlockBase<(&SharedEventRef, u64), ()>,
6465
>(block);
6566
(*block).flags |= BLOCK_HAS_SIGNATURE | BLOCK_HAS_COPY_DISPOSE;
66-
(*block).extra = ptr::addr_of!(BLOCK_EXTRA);
67+
(*block).extra = &raw const BLOCK_EXTRA;
6768
let () = msg_send![self, notifyListener:listener atValue:value block:block];
6869
}
6970

7071
extern "C" fn dtor(_: *mut BlockBase<(&SharedEventRef, u64), ()>) {}
7172

72-
const SIGNATURE: &[u8] = b"v16@?0Q8\0";
73-
const SIGNATURE_PTR: *const i8 = &SIGNATURE[0] as *const u8 as *const i8;
73+
const SIGNATURE: &CStr = c"v16@?0Q8";
74+
const SIGNATURE_PTR: *const i8 = SIGNATURE.as_ptr().cast();
7475
static mut BLOCK_EXTRA: BlockExtra<(&SharedEventRef, u64), ()> = BlockExtra {
7576
unknown0: 0 as *mut i32,
7677
unknown1: 0 as *mut i32,

0 commit comments

Comments
 (0)