Skip to content

Commit 5797593

Browse files
committed
rust-lang#66219 documented unsafe in core::{cell, hint, panic}
1 parent 267aebc commit 5797593

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/libcore/hint.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
//! Hints to compiler that affects how code should be emitted or optimized.
44
5-
// ignore-tidy-undocumented-unsafe
6-
75
use crate::intrinsics;
86

97
/// Informs the compiler that this point in the code is not reachable, enabling
@@ -71,10 +69,12 @@ pub fn spin_loop() {
7169
)
7270
)] {
7371
#[cfg(target_arch = "x86")] {
72+
// SAFETY: technically does nothing
7473
unsafe { crate::arch::x86::_mm_pause() };
7574
}
7675

7776
#[cfg(target_arch = "x86_64")] {
77+
// SAFETY: technically does nothing
7878
unsafe { crate::arch::x86_64::_mm_pause() };
7979
}
8080
}
@@ -86,9 +86,11 @@ pub fn spin_loop() {
8686
)
8787
)] {
8888
#[cfg(target_arch = "aarch64")] {
89+
// SAFETY: hardware hint
8990
unsafe { crate::arch::aarch64::__yield() };
9091
}
9192
#[cfg(target_arch = "arm")] {
93+
// SAFETY: hardware hint
9294
unsafe { crate::arch::arm::__yield() };
9395
}
9496
}
@@ -116,6 +118,7 @@ pub fn black_box<T>(dummy: T) -> T {
116118
// this. LLVM's intepretation of inline assembly is that it's, well, a black
117119
// box. This isn't the greatest implementation since it probably deoptimizes
118120
// more than we want, but it's so far good enough.
121+
// SAFETY: compiler hint
119122
unsafe {
120123
asm!("" : : "r"(&dummy));
121124
return dummy;

src/libcore/option.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@
133133
//! [`Box<T>`]: ../../std/boxed/struct.Box.html
134134
//! [`i32`]: ../../std/primitive.i32.html
135135
136-
// ignore-tidy-undocumented-unsafe
137-
138136
#![stable(feature = "rust1", since = "1.0.0")]
139137

140138
use crate::iter::{FromIterator, FusedIterator, TrustedLen};
@@ -298,6 +296,7 @@ impl<T> Option<T> {
298296
#[inline]
299297
#[stable(feature = "pin", since = "1.33.0")]
300298
pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
299+
// SAFETY: data already pinned
301300
unsafe {
302301
Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x))
303302
}
@@ -309,6 +308,7 @@ impl<T> Option<T> {
309308
#[inline]
310309
#[stable(feature = "pin", since = "1.33.0")]
311310
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
311+
// SAFETY: data already pinned
312312
unsafe {
313313
Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x))
314314
}
@@ -845,6 +845,7 @@ impl<T> Option<T> {
845845

846846
match *self {
847847
Some(ref mut v) => v,
848+
// SAFETY: *self is always Some(F)
848849
None => unsafe { hint::unreachable_unchecked() },
849850
}
850851
}

src/libcore/panicking.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
//! one function. Currently, the actual symbol is declared in the standard
2121
//! library, but the location of this may change over time.
2222
23-
// ignore-tidy-undocumented-unsafe
24-
2523
#![allow(dead_code, missing_docs)]
2624
#![unstable(feature = "core_panic",
2725
reason = "internal details of the implementation of the `panic!` \
@@ -39,6 +37,7 @@ use crate::panic::{Location, PanicInfo};
3937
#[lang = "panic"]
4038
pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
4139
if cfg!(feature = "panic_immediate_abort") {
40+
// SAFETY: ends the program
4241
unsafe { super::intrinsics::abort() }
4342
}
4443

@@ -60,6 +59,7 @@ pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
6059
#[lang = "panic"]
6160
pub fn panic(expr: &str, location: &Location<'_>) -> ! {
6261
if cfg!(feature = "panic_immediate_abort") {
62+
// SAFETY: ends the program
6363
unsafe { super::intrinsics::abort() }
6464
}
6565

@@ -79,6 +79,7 @@ pub fn panic(expr: &str, location: &Location<'_>) -> ! {
7979
fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
8080
index: usize, len: usize) -> ! {
8181
if cfg!(feature = "panic_immediate_abort") {
82+
// SAFETY: ends the program
8283
unsafe { super::intrinsics::abort() }
8384
}
8485

@@ -92,6 +93,7 @@ fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
9293
#[lang = "panic_bounds_check"]
9394
fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! {
9495
if cfg!(feature = "panic_immediate_abort") {
96+
// SAFETY: ends the program
9597
unsafe { super::intrinsics::abort() }
9698
}
9799

@@ -107,6 +109,7 @@ fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! {
107109
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
108110
pub fn panic_fmt(fmt: fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u32)) -> ! {
109111
if cfg!(feature = "panic_immediate_abort") {
112+
// SAFETY: ends the program
110113
unsafe { super::intrinsics::abort() }
111114
}
112115

@@ -119,6 +122,7 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u3
119122
let (file, line, col) = *file_line_col;
120123
let location = Location::internal_constructor(file, line, col);
121124
let pi = PanicInfo::internal_constructor(Some(&fmt), &location);
125+
// SAFETY: psuedo-FFI call to end the program
122126
unsafe { panic_impl(&pi) }
123127
}
124128

@@ -128,6 +132,7 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, file_line_col: &(&'static str, u32, u3
128132
#[cfg_attr( feature="panic_immediate_abort" ,inline)]
129133
pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
130134
if cfg!(feature = "panic_immediate_abort") {
135+
// SAFETY: ends the program
131136
unsafe { super::intrinsics::abort() }
132137
}
133138

@@ -138,5 +143,6 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
138143
}
139144

140145
let pi = PanicInfo::internal_constructor(Some(&fmt), location);
146+
// SAFETY: psuedo-FFI call to end the program
141147
unsafe { panic_impl(&pi) }
142148
}

0 commit comments

Comments
 (0)