Skip to content

Commit 2168ce3

Browse files
committed
Auto merge of rust-lang#129398 - matthiaskrgr:rollup-50l01ry, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#128432 (WASI: forbid `unsafe_op_in_unsafe_fn` for `std::{os, sys}`) - rust-lang#129373 (Add missing module flags for CFI and KCFI sanitizers) - rust-lang#129374 (Use `assert_unsafe_precondition!` in `AsciiChar::digit_unchecked`) - rust-lang#129376 (Change `assert_unsafe_precondition` docs to refer to `check_language_ub`) - rust-lang#129382 (Add `const_cell_into_inner` to `OnceCell`) - rust-lang#129387 (Advise against removing the remaining Python scripts from `tests/run-make`) - rust-lang#129388 (Do not rely on names to find lifetimes.) - rust-lang#129395 (Pretty-print own args of existential projections (dyn-Trait w/ GAT constraints)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f671c11 + 6f534f9 commit 2168ce3

File tree

17 files changed

+34
-23
lines changed

17 files changed

+34
-23
lines changed

Diff for: core/src/ascii/ascii_char.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//! suggestions from rustc if you get anything slightly wrong in here, and overall
44
//! helps with clarity as we're also referring to `char` intentionally in here.
55
6-
use crate::fmt;
76
use crate::mem::transmute;
7+
use crate::{assert_unsafe_precondition, fmt};
88

99
/// One of the 128 Unicode characters from U+0000 through U+007F,
1010
/// often known as the [ASCII] subset.
@@ -497,14 +497,18 @@ impl AsciiChar {
497497
/// Notably, it should not be expected to return hex digits, or any other
498498
/// reasonable extension of the decimal digits.
499499
///
500-
/// (This lose safety condition is intended to simplify soundness proofs
500+
/// (This loose safety condition is intended to simplify soundness proofs
501501
/// when writing code using this method, since the implementation doesn't
502502
/// need something really specific, not to make those other arguments do
503503
/// something useful. It might be tightened before stabilization.)
504504
#[unstable(feature = "ascii_char", issue = "110998")]
505505
#[inline]
506506
pub const unsafe fn digit_unchecked(d: u8) -> Self {
507-
debug_assert!(d < 10);
507+
assert_unsafe_precondition!(
508+
check_language_ub,
509+
"`AsciiChar::digit_unchecked` input cannot exceed 9.",
510+
(d: u8 = d) => d < 10
511+
);
508512

509513
// SAFETY: `'0'` through `'9'` are U+00030 through U+0039,
510514
// so because `d` must be 64 or less the addition can return at most

Diff for: core/src/cell/once.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ impl<T> OnceCell<T> {
309309
/// ```
310310
#[inline]
311311
#[stable(feature = "once_cell", since = "1.70.0")]
312-
pub fn into_inner(self) -> Option<T> {
312+
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
313+
pub const fn into_inner(self) -> Option<T> {
313314
// Because `into_inner` takes `self` by value, the compiler statically verifies
314315
// that it is not currently borrowed. So it is safe to move out `Option<T>`.
315316
self.inner.into_inner()

Diff for: core/src/ub_checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::intrinsics::{self, const_eval_select};
1010
/// macro for language UB are always ignored.
1111
///
1212
/// This macro should be called as
13-
/// `assert_unsafe_precondition!(check_{library,lang}_ub, "message", (ident: type = expr, ident: type = expr) => check_expr)`
13+
/// `assert_unsafe_precondition!(check_{library,language}_ub, "message", (ident: type = expr, ident: type = expr) => check_expr)`
1414
/// where each `expr` will be evaluated and passed in as function argument `ident: type`. Then all
1515
/// those arguments are passed to a function with the body `check_expr`.
1616
/// Pick `check_language_ub` when this is guarding a violation of language UB, i.e., immediate UB

Diff for: std/src/os/wasi/fs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! [`std::fs`]: crate::fs
44
5-
#![deny(unsafe_op_in_unsafe_fn)]
65
#![unstable(feature = "wasi_ext", issue = "71213")]
76

87
// Used for `File::read` on intra-doc links

Diff for: std/src/os/wasi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
#![cfg_attr(not(target_env = "p2"), stable(feature = "rust1", since = "1.0.0"))]
3232
#![cfg_attr(target_env = "p2", unstable(feature = "wasip2", issue = "none"))]
33-
#![deny(unsafe_op_in_unsafe_fn)]
33+
#![forbid(unsafe_op_in_unsafe_fn)]
3434
#![doc(cfg(target_os = "wasi"))]
3535

3636
pub mod ffi;

Diff for: std/src/os/wasip2/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
//!
33
//! This module is currently empty, but will be filled over time as wasi-libc support for WASI Preview 2 is stabilized.
44
5+
#![forbid(unsafe_op_in_unsafe_fn)]
56
#![stable(feature = "raw_ext", since = "1.1.0")]

Diff for: std/src/sys/pal/wasi/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use crate::ffi::{CStr, OsStr, OsString};
44
use crate::os::wasi::ffi::OsStrExt;

Diff for: std/src/sys/pal/wasi/env.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![forbid(unsafe_op_in_unsafe_fn)]
2+
13
pub mod os {
24
pub const FAMILY: &str = "";
35
pub const OS: &str = "";

Diff for: std/src/sys/pal/wasi/fd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22
#![allow(dead_code)]
33

44
use super::err2io;

Diff for: std/src/sys/pal/wasi/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use super::fd::WasiFd;
44
use crate::ffi::{CStr, OsStr, OsString};

Diff for: std/src/sys/pal/wasi/helpers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![forbid(unsafe_op_in_unsafe_fn)]
2+
13
use crate::{io as std_io, mem};
24

35
#[inline]

Diff for: std/src/sys/pal/wasi/io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use crate::marker::PhantomData;
44
use crate::os::fd::{AsFd, AsRawFd};

Diff for: std/src/sys/pal/wasi/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use super::err2io;
44
use super::fd::WasiFd;

Diff for: std/src/sys/pal/wasi/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use core::slice::memchr;
44

Diff for: std/src/sys/pal/wasi/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use super::fd::WasiFd;
44
use crate::io::{self, IoSlice, IoSliceMut};

Diff for: std/src/sys/pal/wasi/thread.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![forbid(unsafe_op_in_unsafe_fn)]
2+
13
use crate::ffi::CStr;
24
use crate::num::NonZero;
35
use crate::sys::unsupported;
@@ -73,13 +75,13 @@ impl Thread {
7375
if #[cfg(target_feature = "atomics")] {
7476
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
7577
let p = Box::into_raw(Box::new(p));
76-
let mut native: libc::pthread_t = mem::zeroed();
77-
let mut attr: libc::pthread_attr_t = mem::zeroed();
78-
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
78+
let mut native: libc::pthread_t = unsafe { mem::zeroed() };
79+
let mut attr: libc::pthread_attr_t = unsafe { mem::zeroed() };
80+
assert_eq!(unsafe { libc::pthread_attr_init(&mut attr) }, 0);
7981

8082
let stack_size = cmp::max(stack, DEFAULT_MIN_STACK_SIZE);
8183

82-
match libc::pthread_attr_setstacksize(&mut attr, stack_size) {
84+
match unsafe { libc::pthread_attr_setstacksize(&mut attr, stack_size) } {
8385
0 => {}
8486
n => {
8587
assert_eq!(n, libc::EINVAL);
@@ -90,20 +92,20 @@ impl Thread {
9092
let page_size = os::page_size();
9193
let stack_size =
9294
(stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1);
93-
assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size), 0);
95+
assert_eq!(unsafe { libc::pthread_attr_setstacksize(&mut attr, stack_size) }, 0);
9496
}
9597
};
9698

97-
let ret = libc::pthread_create(&mut native, &attr, thread_start, p as *mut _);
99+
let ret = unsafe { libc::pthread_create(&mut native, &attr, thread_start, p as *mut _) };
98100
// Note: if the thread creation fails and this assert fails, then p will
99101
// be leaked. However, an alternative design could cause double-free
100102
// which is clearly worse.
101-
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
103+
assert_eq!(unsafe {libc::pthread_attr_destroy(&mut attr) }, 0);
102104

103105
return if ret != 0 {
104106
// The thread failed to start and as a result p was not consumed. Therefore, it is
105107
// safe to reconstruct the box so that it gets deallocated.
106-
drop(Box::from_raw(p));
108+
unsafe { drop(Box::from_raw(p)); }
107109
Err(io::Error::from_raw_os_error(ret))
108110
} else {
109111
Ok(Thread { id: native })

Diff for: std/src/sys/pal/wasi/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
1+
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
use crate::time::Duration;
44

0 commit comments

Comments
 (0)