Skip to content

Commit 1390386

Browse files
authored
Increase MSRV to 1.38 and use ptr.cast::<T>() whenever practical to clarify casts. (#425)
Avoid anonymous type casts of the form `as *{const,mut} _`. Make it clearer that we're never casting away constness by avoiding `as *mut T` whenever practical.
1 parent bcbadc1 commit 1390386

19 files changed

+39
-27
lines changed

.clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.36"
1+
msrv = "1.38"

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
strategy:
4545
matrix:
4646
os: [ubuntu-22.04, windows-2022]
47-
toolchain: [nightly, beta, stable, 1.36]
47+
toolchain: [nightly, beta, stable, 1.38]
4848
# Only Test macOS on stable to reduce macOS CI jobs
4949
include:
5050
# x86_64-apple-darwin.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
### Breaking Changes
10+
- Update MSRV to 1.38 [#425]
11+
12+
[#425]: https://github.com/rust-random/getrandom/pull/425
13+
714
## [0.2.15] - 2024-05-06
815
### Added
916
- Apple visionOS support [#410]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ crate features, WASM support and Custom RNGs see the
5252

5353
## Minimum Supported Rust Version
5454

55-
This crate requires Rust 1.36.0 or later.
55+
This crate requires Rust 1.38.0 or later.
5656

5757
## Platform Support
5858

src/apple-other.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern "C" {
1414
}
1515

1616
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
17-
let ret = unsafe { CCRandomGenerateBytes(dest.as_mut_ptr() as *mut c_void, dest.len()) };
17+
let ret = unsafe { CCRandomGenerateBytes(dest.as_mut_ptr().cast::<c_void>(), dest.len()) };
1818
// kCCSuccess (from CommonCryptoError.h) is always zero.
1919
if ret != 0 {
2020
Err(Error::IOS_SEC_RANDOM)

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Error {
9999
cfg_if! {
100100
if #[cfg(unix)] {
101101
fn os_err(errno: i32, buf: &mut [u8]) -> Option<&str> {
102-
let buf_ptr = buf.as_mut_ptr() as *mut libc::c_char;
102+
let buf_ptr = buf.as_mut_ptr().cast::<libc::c_char>();
103103
if unsafe { libc::strerror_r(errno, buf_ptr, buf.len()) } != 0 {
104104
return None;
105105
}

src/fuchsia.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ extern "C" {
88
}
99

1010
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
11-
unsafe { zx_cprng_draw(dest.as_mut_ptr() as *mut u8, dest.len()) }
11+
unsafe { zx_cprng_draw(dest.as_mut_ptr().cast::<u8>(), dest.len()) }
1212
Ok(())
1313
}

src/getentropy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
//!
99
//! For these targets, we use getentropy(2) because getrandom(2) doesn't exist.
1010
use crate::{util_libc::last_os_error, Error};
11-
use core::mem::MaybeUninit;
11+
use core::{ffi::c_void, mem::MaybeUninit};
1212

1313
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1414
for chunk in dest.chunks_mut(256) {
15-
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) };
15+
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr().cast::<c_void>(), chunk.len()) };
1616
if ret != 0 {
1717
return Err(last_os_error());
1818
}

src/getrandom.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
//! nothing. On illumos, the default pool is used to implement getentropy(2),
1717
//! so we assume it is acceptable here.
1818
use crate::{util_libc::sys_fill_exact, Error};
19-
use core::mem::MaybeUninit;
19+
use core::{ffi::c_void, mem::MaybeUninit};
2020

2121
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
2222
sys_fill_exact(dest, |buf| unsafe {
23-
libc::getrandom(buf.as_mut_ptr() as *mut libc::c_void, buf.len(), 0)
23+
libc::getrandom(buf.as_mut_ptr().cast::<c_void>(), buf.len(), 0)
2424
})
2525
}

src/hermit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313

1414
pub fn getrandom_inner(mut dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1515
while !dest.is_empty() {
16-
let res = unsafe { sys_read_entropy(dest.as_mut_ptr() as *mut u8, dest.len(), 0) };
16+
let res = unsafe { sys_read_entropy(dest.as_mut_ptr().cast::<u8>(), dest.len(), 0) };
1717
// Positive `isize`s can be safely casted to `usize`
1818
if res > 0 && (res as usize) <= dest.len() {
1919
dest = &mut dest[res as usize..];

0 commit comments

Comments
 (0)