Skip to content

Commit 900e66f

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 9b26bae + 78f5f68 commit 900e66f

File tree

27 files changed

+207
-148
lines changed

27 files changed

+207
-148
lines changed

alloc/src/boxed.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,6 @@ impl<T: ?Sized> Box<T> {
10531053
/// ```
10541054
///
10551055
/// [memory layout]: self#memory-layout
1056-
/// [`Layout`]: crate::Layout
10571056
#[stable(feature = "box_raw", since = "1.4.0")]
10581057
#[inline]
10591058
#[must_use = "call `drop(Box::from_raw(ptr))` if you intend to drop the `Box`"]
@@ -1108,7 +1107,6 @@ impl<T: ?Sized> Box<T> {
11081107
/// ```
11091108
///
11101109
/// [memory layout]: self#memory-layout
1111-
/// [`Layout`]: crate::Layout
11121110
#[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
11131111
#[inline]
11141112
#[must_use = "call `drop(Box::from_non_null(ptr))` if you intend to drop the `Box`"]
@@ -1165,7 +1163,6 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11651163
/// ```
11661164
///
11671165
/// [memory layout]: self#memory-layout
1168-
/// [`Layout`]: crate::Layout
11691166
#[unstable(feature = "allocator_api", issue = "32838")]
11701167
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
11711168
#[inline]
@@ -1219,7 +1216,6 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12191216
/// ```
12201217
///
12211218
/// [memory layout]: self#memory-layout
1222-
/// [`Layout`]: crate::Layout
12231219
#[unstable(feature = "allocator_api", issue = "32838")]
12241220
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
12251221
#[rustc_const_unstable(feature = "const_box", issue = "92521")]

core/src/alloc/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use crate::{cmp, ptr};
7070
/// {
7171
/// return null_mut();
7272
/// };
73-
/// self.arena.get().cast::<u8>().add(allocated)
73+
/// unsafe { self.arena.get().cast::<u8>().add(allocated) }
7474
/// }
7575
/// unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
7676
/// }

core/src/error.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ use crate::fmt::{self, Debug, Display, Formatter};
2222
/// accessing that error via [`Error::source()`]. This makes it possible for the
2323
/// high-level module to provide its own errors while also revealing some of the
2424
/// implementation for debugging.
25+
///
26+
/// # Example
27+
///
28+
/// Implementing the `Error` trait only requires that `Debug` and `Display` are implemented too.
29+
///
30+
/// ```
31+
/// use std::error::Error;
32+
/// use std::fmt;
33+
/// use std::path::PathBuf;
34+
///
35+
/// #[derive(Debug)]
36+
/// struct ReadConfigError {
37+
/// path: PathBuf
38+
/// }
39+
///
40+
/// impl fmt::Display for ReadConfigError {
41+
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42+
/// let path = self.path.display();
43+
/// write!(f, "unable to read configuration at {path}")
44+
/// }
45+
/// }
46+
///
47+
/// impl Error for ReadConfigError {}
48+
/// ```
2549
#[stable(feature = "rust1", since = "1.0.0")]
2650
#[cfg_attr(not(test), rustc_diagnostic_item = "Error")]
2751
#[rustc_has_incoherent_inherent_impls]

core/src/hint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::{intrinsics, ub_checks};
5252
/// // Safety: `divisor` can't be zero because of `prepare_inputs`,
5353
/// // but the compiler does not know about this. We *promise*
5454
/// // that we always call `prepare_inputs`.
55-
/// std::hint::unreachable_unchecked()
55+
/// unsafe { std::hint::unreachable_unchecked() }
5656
/// }
5757
/// // The compiler would normally introduce a check here that prevents
5858
/// // a division by zero. However, if `divisor` was zero, the branch

core/src/intrinsics/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,12 +1703,12 @@ pub const fn forget<T: ?Sized>(_: T) {
17031703
/// ```
17041704
/// struct R<'a>(&'a i32);
17051705
/// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1706-
/// std::mem::transmute::<R<'b>, R<'static>>(r)
1706+
/// unsafe { std::mem::transmute::<R<'b>, R<'static>>(r) }
17071707
/// }
17081708
///
17091709
/// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
17101710
/// -> &'b mut R<'c> {
1711-
/// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1711+
/// unsafe { std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r) }
17121712
/// }
17131713
/// ```
17141714
///
@@ -4498,11 +4498,11 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
44984498
///
44994499
/// // SAFETY: Our precondition ensures the source is aligned and valid,
45004500
/// // and `Vec::with_capacity` ensures that we have usable space to write them.
4501-
/// ptr::copy(ptr, dst.as_mut_ptr(), elts);
4501+
/// unsafe { ptr::copy(ptr, dst.as_mut_ptr(), elts); }
45024502
///
45034503
/// // SAFETY: We created it with this much capacity earlier,
45044504
/// // and the previous `copy` has initialized these elements.
4505-
/// dst.set_len(elts);
4505+
/// unsafe { dst.set_len(elts); }
45064506
/// dst
45074507
/// }
45084508
/// ```

core/src/mem/maybe_uninit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ use crate::{fmt, intrinsics, ptr, slice};
9898
///
9999
/// unsafe fn make_vec(out: *mut Vec<i32>) {
100100
/// // `write` does not drop the old contents, which is important.
101-
/// out.write(vec![1, 2, 3]);
101+
/// unsafe { out.write(vec![1, 2, 3]); }
102102
/// }
103103
///
104104
/// let mut v = MaybeUninit::uninit();
@@ -844,7 +844,7 @@ impl<T> MaybeUninit<T> {
844844
/// # #![allow(unexpected_cfgs)]
845845
/// use std::mem::MaybeUninit;
846846
///
847-
/// # unsafe extern "C" fn initialize_buffer(buf: *mut [u8; 1024]) { *buf = [0; 1024] }
847+
/// # unsafe extern "C" fn initialize_buffer(buf: *mut [u8; 1024]) { unsafe { *buf = [0; 1024] } }
848848
/// # #[cfg(FALSE)]
849849
/// extern "C" {
850850
/// /// Initializes *all* the bytes of the input buffer.

core/src/mem/transmutability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
3232
/// src: ManuallyDrop::new(src),
3333
/// };
3434
///
35-
/// let dst = transmute.dst;
35+
/// let dst = unsafe { transmute.dst };
3636
///
3737
/// ManuallyDrop::into_inner(dst)
3838
/// }

core/src/ptr/const_ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,13 @@ impl<T: ?Sized> *const T {
724724
/// that their safety preconditions are met:
725725
/// ```rust
726726
/// # #![feature(ptr_sub_ptr)]
727-
/// # unsafe fn blah(ptr: *const i32, origin: *const i32, count: usize) -> bool {
727+
/// # unsafe fn blah(ptr: *const i32, origin: *const i32, count: usize) -> bool { unsafe {
728728
/// ptr.sub_ptr(origin) == count
729729
/// # &&
730730
/// origin.add(count) == ptr
731731
/// # &&
732732
/// ptr.sub(count) == origin
733-
/// # }
733+
/// # } }
734734
/// ```
735735
///
736736
/// # Safety

core/src/ptr/mut_ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,13 +896,13 @@ impl<T: ?Sized> *mut T {
896896
/// that their safety preconditions are met:
897897
/// ```rust
898898
/// # #![feature(ptr_sub_ptr)]
899-
/// # unsafe fn blah(ptr: *mut i32, origin: *mut i32, count: usize) -> bool {
899+
/// # unsafe fn blah(ptr: *mut i32, origin: *mut i32, count: usize) -> bool { unsafe {
900900
/// ptr.sub_ptr(origin) == count
901901
/// # &&
902902
/// origin.add(count) == ptr
903903
/// # &&
904904
/// ptr.sub(count) == origin
905-
/// # }
905+
/// # } }
906906
/// ```
907907
///
908908
/// # Safety

core/src/ptr/non_null.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,13 @@ impl<T: ?Sized> NonNull<T> {
857857
/// that their safety preconditions are met:
858858
/// ```rust
859859
/// # #![feature(ptr_sub_ptr)]
860-
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool {
860+
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool { unsafe {
861861
/// ptr.sub_ptr(origin) == count
862862
/// # &&
863863
/// origin.add(count) == ptr
864864
/// # &&
865865
/// ptr.sub(count) == origin
866-
/// # }
866+
/// # } }
867867
/// ```
868868
///
869869
/// # Safety

core/src/task/wake.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,14 @@ impl RawWaker {
4040
/// of the `vtable` as the first parameter.
4141
///
4242
/// It is important to consider that the `data` pointer must point to a
43-
/// thread safe type such as an `[Arc]<T: Send + Sync>`
43+
/// thread safe type such as an `Arc<T: Send + Sync>`
4444
/// when used to construct a [`Waker`]. This restriction is lifted when
4545
/// constructing a [`LocalWaker`], which allows using types that do not implement
46-
/// <code>[Send] + [Sync]</code> like `[Rc]<T>`.
46+
/// <code>[Send] + [Sync]</code> like `Rc<T>`.
4747
///
4848
/// The `vtable` customizes the behavior of a `Waker` which gets created
4949
/// from a `RawWaker`. For each operation on the `Waker`, the associated
5050
/// function in the `vtable` of the underlying `RawWaker` will be called.
51-
///
52-
/// [`Arc`]: std::sync::Arc
53-
/// [`Rc`]: std::rc::Rc
5451
#[inline]
5552
#[rustc_promotable]
5653
#[stable(feature = "futures_api", since = "1.36.0")]

panic_abort/src/android.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ type SetAbortMessageType = unsafe extern "C" fn(*const libc::c_char) -> ();
1616
// Weakly resolve the symbol for android_set_abort_message. This function is only available
1717
// for API >= 21.
1818
pub(crate) unsafe fn android_set_abort_message(payload: &mut dyn PanicPayload) {
19-
let func_addr =
19+
let func_addr = unsafe {
2020
libc::dlsym(libc::RTLD_DEFAULT, ANDROID_SET_ABORT_MESSAGE.as_ptr() as *const libc::c_char)
21-
as usize;
21+
as usize
22+
};
2223
if func_addr == 0 {
2324
return;
2425
}
@@ -37,13 +38,14 @@ pub(crate) unsafe fn android_set_abort_message(payload: &mut dyn PanicPayload) {
3738

3839
// Allocate a new buffer to append the null byte.
3940
let size = msg.len() + 1usize;
40-
let buf = libc::malloc(size) as *mut libc::c_char;
41+
let buf = unsafe { libc::malloc(size) as *mut libc::c_char };
4142
if buf.is_null() {
4243
return; // allocation failure
4344
}
44-
copy_nonoverlapping(msg.as_ptr(), buf as *mut u8, msg.len());
45-
buf.add(msg.len()).write(0);
46-
47-
let func = transmute::<usize, SetAbortMessageType>(func_addr);
48-
func(buf);
45+
unsafe {
46+
copy_nonoverlapping(msg.as_ptr(), buf as *mut u8, msg.len());
47+
buf.add(msg.len()).write(0);
48+
let func = transmute::<usize, SetAbortMessageType>(func_addr);
49+
func(buf);
50+
}
4951
}

panic_abort/src/lib.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(staged_api)]
1616
#![feature(rustc_attrs)]
1717
#![allow(internal_features)]
18+
#![deny(unsafe_op_in_unsafe_fn)]
1819

1920
#[cfg(target_os = "android")]
2021
mod android;
@@ -36,16 +37,22 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen
3637
pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
3738
// Android has the ability to attach a message as part of the abort.
3839
#[cfg(target_os = "android")]
39-
android::android_set_abort_message(_payload);
40+
unsafe {
41+
android::android_set_abort_message(_payload);
42+
}
4043
#[cfg(target_os = "zkvm")]
41-
zkvm::zkvm_set_abort_message(_payload);
44+
unsafe {
45+
zkvm::zkvm_set_abort_message(_payload);
46+
}
4247

43-
abort();
48+
unsafe {
49+
abort();
50+
}
4451

4552
cfg_if::cfg_if! {
4653
if #[cfg(any(unix, target_os = "solid_asp3"))] {
4754
unsafe fn abort() -> ! {
48-
libc::abort();
55+
unsafe { libc::abort(); }
4956
}
5057
} else if #[cfg(any(target_os = "hermit",
5158
all(target_vendor = "fortanix", target_env = "sgx"),
@@ -57,7 +64,7 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
5764
unsafe extern "C" {
5865
pub fn __rust_abort() -> !;
5966
}
60-
__rust_abort();
67+
unsafe { __rust_abort(); }
6168
}
6269
} else if #[cfg(all(windows, not(miri)))] {
6370
// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
@@ -75,11 +82,17 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
7582
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
7683
cfg_if::cfg_if! {
7784
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
78-
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
85+
unsafe {
86+
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
87+
}
7988
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
80-
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
89+
unsafe {
90+
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
91+
}
8192
} else if #[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] {
82-
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
93+
unsafe {
94+
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
95+
}
8396
} else {
8497
core::intrinsics::abort();
8598
}
@@ -93,7 +106,7 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
93106
}
94107

95108
unsafe fn abort() -> ! {
96-
teeos::TEE_Panic(1);
109+
unsafe { teeos::TEE_Panic(1); }
97110
}
98111
} else {
99112
unsafe fn abort() -> ! {

panic_abort/src/zkvm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ pub(crate) unsafe fn zkvm_set_abort_message(payload: &mut dyn PanicPayload) {
2020
fn sys_panic(msg_ptr: *const u8, len: usize) -> !;
2121
}
2222

23-
sys_panic(msg.as_ptr(), msg.len());
23+
unsafe {
24+
sys_panic(msg.as_ptr(), msg.len());
25+
}
2426
}

panic_unwind/src/emcc.rs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,46 @@ pub(crate) unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
7171
ptr: *mut u8,
7272
is_rust_panic: bool,
7373
}
74-
let catch_data = &*(ptr as *mut CatchData);
74+
unsafe {
75+
let catch_data = &*(ptr as *mut CatchData);
7576

76-
let adjusted_ptr = __cxa_begin_catch(catch_data.ptr as *mut libc::c_void) as *mut Exception;
77-
if !catch_data.is_rust_panic {
78-
super::__rust_foreign_exception();
79-
}
77+
let adjusted_ptr = __cxa_begin_catch(catch_data.ptr as *mut libc::c_void) as *mut Exception;
78+
if !catch_data.is_rust_panic {
79+
super::__rust_foreign_exception();
80+
}
8081

81-
let canary = (&raw const (*adjusted_ptr).canary).read();
82-
if !ptr::eq(canary, &EXCEPTION_TYPE_INFO) {
83-
super::__rust_foreign_exception();
84-
}
82+
let canary = (&raw const (*adjusted_ptr).canary).read();
83+
if !ptr::eq(canary, &EXCEPTION_TYPE_INFO) {
84+
super::__rust_foreign_exception();
85+
}
8586

86-
let was_caught = (*adjusted_ptr).caught.swap(true, Ordering::Relaxed);
87-
if was_caught {
88-
// Since cleanup() isn't allowed to panic, we just abort instead.
89-
intrinsics::abort();
87+
let was_caught = (*adjusted_ptr).caught.swap(true, Ordering::Relaxed);
88+
if was_caught {
89+
// Since cleanup() isn't allowed to panic, we just abort instead.
90+
intrinsics::abort();
91+
}
92+
let out = (*adjusted_ptr).data.take().unwrap();
93+
__cxa_end_catch();
94+
out
9095
}
91-
let out = (*adjusted_ptr).data.take().unwrap();
92-
__cxa_end_catch();
93-
out
9496
}
9597

9698
pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
97-
let exception = __cxa_allocate_exception(mem::size_of::<Exception>()) as *mut Exception;
98-
if exception.is_null() {
99-
return uw::_URC_FATAL_PHASE1_ERROR as u32;
99+
unsafe {
100+
let exception = __cxa_allocate_exception(mem::size_of::<Exception>()) as *mut Exception;
101+
if exception.is_null() {
102+
return uw::_URC_FATAL_PHASE1_ERROR as u32;
103+
}
104+
ptr::write(
105+
exception,
106+
Exception {
107+
canary: &EXCEPTION_TYPE_INFO,
108+
caught: AtomicBool::new(false),
109+
data: Some(data),
110+
},
111+
);
112+
__cxa_throw(exception as *mut _, &EXCEPTION_TYPE_INFO, exception_cleanup);
100113
}
101-
ptr::write(
102-
exception,
103-
Exception {
104-
canary: &EXCEPTION_TYPE_INFO,
105-
caught: AtomicBool::new(false),
106-
data: Some(data),
107-
},
108-
);
109-
__cxa_throw(exception as *mut _, &EXCEPTION_TYPE_INFO, exception_cleanup);
110114
}
111115

112116
extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> *mut libc::c_void {

0 commit comments

Comments
 (0)