Skip to content

Commit 6c00987

Browse files
authored
Capitalize SAFETY in safety comments. (#559)
Follow the convention [here] and in the majority of safety comments in std and use '// SAFETY:' instead of '// Safety:'. [here]: https://std-dev-guide.rust-lang.org/documentation/safety-comments.html#inside-safe-elements
1 parent 9d2db17 commit 6c00987

File tree

24 files changed

+75
-75
lines changed

24 files changed

+75
-75
lines changed

src/backend/libc/fs/inotify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bitflags! {
7777
/// descriptor from being implicitly passed across `exec` boundaries.
7878
#[doc(alias = "inotify_init1")]
7979
pub fn inotify_init(flags: CreateFlags) -> io::Result<OwnedFd> {
80-
// Safety: `inotify_init1` has no safety preconditions.
80+
// SAFETY: `inotify_init1` has no safety preconditions.
8181
unsafe { ret_owned_fd(c::inotify_init1(flags.bits())) }
8282
}
8383

@@ -96,7 +96,7 @@ pub fn inotify_add_watch<P: crate::path::Arg>(
9696
flags: WatchFlags,
9797
) -> io::Result<i32> {
9898
let path = path.as_cow_c_str().unwrap();
99-
// Safety: The fd and path we are passing is guranteed valid by the type
99+
// SAFETY: The fd and path we are passing is guranteed valid by the type
100100
// system.
101101
unsafe {
102102
ret_c_int(c::inotify_add_watch(
@@ -116,6 +116,6 @@ pub fn inotify_remove_watch(inot: BorrowedFd<'_>, wd: i32) -> io::Result<()> {
116116
// Android's `inotify_rm_watch` takes u32 despite `inotify_add_watch` is i32.
117117
#[cfg(target_os = "android")]
118118
let wd = wd as u32;
119-
// Safety: The fd is valid and closing an arbitrary wd is valid.
119+
// SAFETY: The fd is valid and closing an arbitrary wd is valid.
120120
unsafe { ret(c::inotify_rm_watch(borrowed_fd(inot), wd)) }
121121
}

src/backend/libc/io/epoll.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bitflags! {
126126
#[inline]
127127
#[doc(alias = "epoll_create1")]
128128
pub fn epoll_create(flags: CreateFlags) -> io::Result<OwnedFd> {
129-
// Safety: We're calling `epoll_create1` via FFI and we know how it
129+
// SAFETY: We're calling `epoll_create1` via FFI and we know how it
130130
// behaves.
131131
unsafe { ret_owned_fd(c::epoll_create1(flags.bits())) }
132132
}
@@ -147,7 +147,7 @@ pub fn epoll_add(
147147
data: u64,
148148
event_flags: EventFlags,
149149
) -> io::Result<()> {
150-
// Safety: We're calling `epoll_ctl` via FFI and we know how it
150+
// SAFETY: We're calling `epoll_ctl` via FFI and we know how it
151151
// behaves.
152152
unsafe {
153153
let raw_fd = source.as_fd().as_raw_fd();
@@ -176,7 +176,7 @@ pub fn epoll_mod(
176176
) -> io::Result<()> {
177177
let raw_fd = source.as_fd().as_raw_fd();
178178

179-
// Safety: We're calling `epoll_ctl` via FFI and we know how it
179+
// SAFETY: We're calling `epoll_ctl` via FFI and we know how it
180180
// behaves.
181181
unsafe {
182182
ret(c::epoll_ctl(
@@ -195,7 +195,7 @@ pub fn epoll_mod(
195195
/// this `Epoll`.
196196
#[doc(alias = "epoll_ctl")]
197197
pub fn epoll_del(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
198-
// Safety: We're calling `epoll_ctl` via FFI and we know how it
198+
// SAFETY: We're calling `epoll_ctl` via FFI and we know how it
199199
// behaves.
200200
unsafe {
201201
let raw_fd = source.as_fd().as_raw_fd();
@@ -218,7 +218,7 @@ pub fn epoll_wait(
218218
event_list: &mut EventVec,
219219
timeout: c::c_int,
220220
) -> io::Result<()> {
221-
// Safety: We're calling `epoll_wait` via FFI and we know how it
221+
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
222222
// behaves.
223223
unsafe {
224224
event_list.events.set_len(0);
@@ -243,7 +243,7 @@ impl<'a> Iterator for Iter<'a> {
243243
type Item = (EventFlags, u64);
244244

245245
fn next(&mut self) -> Option<Self::Item> {
246-
// Safety: `self.context` is guaranteed to be valid because we hold
246+
// SAFETY: `self.context` is guaranteed to be valid because we hold
247247
// `'context` for it. And we know this event is associated with this
248248
// context because `wait` sets both.
249249
self.iter

src/backend/libc/io/poll_fd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'fd> PollFd<'fd> {
119119
impl<'fd> AsFd for PollFd<'fd> {
120120
#[inline]
121121
fn as_fd(&self) -> BorrowedFd<'_> {
122-
// Safety: Our constructors and `set_fd` require `pollfd.fd` to be
122+
// SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be
123123
// valid for the `fd lifetime.
124124
unsafe { BorrowedFd::borrow_raw(self.pollfd.fd) }
125125
}
@@ -129,7 +129,7 @@ impl<'fd> AsFd for PollFd<'fd> {
129129
impl<'fd> io_lifetimes::AsSocket for PollFd<'fd> {
130130
#[inline]
131131
fn as_socket(&self) -> BorrowedFd<'_> {
132-
// Safety: Our constructors and `set_fd` require `pollfd.fd` to be
132+
// SAFETY: Our constructors and `set_fd` require `pollfd.fd` to be
133133
// valid for the `fd lifetime.
134134
unsafe { BorrowedFd::borrow_raw(self.pollfd.fd as RawFd) }
135135
}

src/backend/libc/net/addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl SocketAddrUnix {
9797
if len != 0 && self.unix.sun_path[0] != b'\0' as c::c_char {
9898
let end = len as usize - offsetof_sun_path();
9999
let bytes = &self.unix.sun_path[..end];
100-
// Safety: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`. And
100+
// SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`. And
101101
// `from_bytes_with_nul_unchecked` since the string is NUL-terminated.
102102
unsafe {
103103
Some(CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(
@@ -118,7 +118,7 @@ impl SocketAddrUnix {
118118
if len != 0 && self.unix.sun_path[0] == b'\0' as c::c_char {
119119
let end = len as usize - offsetof_sun_path();
120120
let bytes = &self.unix.sun_path[1..end];
121-
// Safety: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
121+
// SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
122122
unsafe { Some(slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len())) }
123123
} else {
124124
None

src/backend/linux_raw/conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'a, Num: ArgNumber> From<Option<&'a CStr>> for ArgReg<'a, Num> {
143143
impl<'a, Num: ArgNumber> From<BorrowedFd<'a>> for ArgReg<'a, Num> {
144144
#[inline]
145145
fn from(fd: BorrowedFd<'a>) -> Self {
146-
// Safety: `BorrowedFd` ensures that the file descriptor is valid, and the
146+
// SAFETY: `BorrowedFd` ensures that the file descriptor is valid, and the
147147
// lifetime parameter on the resulting `ArgReg` ensures that the result is
148148
// bounded by the `BorrowedFd`'s lifetime.
149149
unsafe { raw_fd(fd.as_raw_fd()) }

src/backend/linux_raw/io/epoll.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn epoll_add(
147147
data: u64,
148148
event_flags: EventFlags,
149149
) -> io::Result<()> {
150-
// Safety: We're calling `epoll_ctl` via FFI and we know how it
150+
// SAFETY: We're calling `epoll_ctl` via FFI and we know how it
151151
// behaves.
152152
unsafe {
153153
syscalls::epoll_add(
@@ -172,7 +172,7 @@ pub fn epoll_mod(
172172
data: u64,
173173
event_flags: EventFlags,
174174
) -> io::Result<()> {
175-
// Safety: We're calling `epoll_ctl` via FFI and we know how it
175+
// SAFETY: We're calling `epoll_ctl` via FFI and we know how it
176176
// behaves.
177177
unsafe {
178178
let raw_fd = source.as_fd().as_raw_fd();
@@ -193,7 +193,7 @@ pub fn epoll_mod(
193193
/// This also returns the owning `Data`.
194194
#[doc(alias = "epoll_ctl")]
195195
pub fn epoll_del(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
196-
// Safety: We're calling `epoll_ctl` via FFI and we know how it
196+
// SAFETY: We're calling `epoll_ctl` via FFI and we know how it
197197
// behaves.
198198
unsafe {
199199
let raw_fd = source.as_fd().as_raw_fd();
@@ -211,7 +211,7 @@ pub fn epoll_wait(
211211
event_list: &mut EventVec,
212212
timeout: c::c_int,
213213
) -> io::Result<()> {
214-
// Safety: We're calling `epoll_wait` via FFI and we know how it
214+
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
215215
// behaves.
216216
unsafe {
217217
event_list.events.set_len(0);

src/backend/linux_raw/io/errno.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Errno {
6969
// TODO: Use Range::contains, once that's `const`.
7070
const_assert!(encoded >= 0xf001);
7171

72-
// Safety: Linux syscalls return negated error values in the range
72+
// SAFETY: Linux syscalls return negated error values in the range
7373
// `-4095..0`, which we just asserted.
7474
unsafe { Self(encoded) }
7575
}
@@ -82,7 +82,7 @@ pub(in crate::backend) fn try_decode_c_int<Num: RetNumber>(
8282
raw: RetReg<Num>,
8383
) -> io::Result<c::c_int> {
8484
if raw.is_in_range(-4095..0) {
85-
// Safety: `raw` must be in `-4095..0`, and we just checked that raw is
85+
// SAFETY: `raw` must be in `-4095..0`, and we just checked that raw is
8686
// in that range.
8787
return Err(unsafe { Errno(raw.decode_error_code()) });
8888
}
@@ -97,7 +97,7 @@ pub(in crate::backend) fn try_decode_c_uint<Num: RetNumber>(
9797
raw: RetReg<Num>,
9898
) -> io::Result<c::c_uint> {
9999
if raw.is_in_range(-4095..0) {
100-
// Safety: `raw` must be in `-4095..0`, and we just checked that raw is
100+
// SAFETY: `raw` must be in `-4095..0`, and we just checked that raw is
101101
// in that range.
102102
return Err(unsafe { Errno(raw.decode_error_code()) });
103103
}
@@ -110,7 +110,7 @@ pub(in crate::backend) fn try_decode_c_uint<Num: RetNumber>(
110110
#[inline]
111111
pub(in crate::backend) fn try_decode_usize<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<usize> {
112112
if raw.is_in_range(-4095..0) {
113-
// Safety: `raw` must be in `-4095..0`, and we just checked that raw is
113+
// SAFETY: `raw` must be in `-4095..0`, and we just checked that raw is
114114
// in that range.
115115
return Err(unsafe { Errno(raw.decode_error_code()) });
116116
}
@@ -125,7 +125,7 @@ pub(in crate::backend) fn try_decode_void_star<Num: RetNumber>(
125125
raw: RetReg<Num>,
126126
) -> io::Result<*mut c::c_void> {
127127
if raw.is_in_range(-4095..0) {
128-
// Safety: `raw` must be in `-4095..0`, and we just checked that raw is
128+
// SAFETY: `raw` must be in `-4095..0`, and we just checked that raw is
129129
// in that range.
130130
return Err(unsafe { Errno(raw.decode_error_code()) });
131131
}
@@ -139,7 +139,7 @@ pub(in crate::backend) fn try_decode_void_star<Num: RetNumber>(
139139
#[inline]
140140
pub(in crate::backend) fn try_decode_u64<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<u64> {
141141
if raw.is_in_range(-4095..0) {
142-
// Safety: `raw` must be in `-4095..0`, and we just checked that raw is
142+
// SAFETY: `raw` must be in `-4095..0`, and we just checked that raw is
143143
// in that range.
144144
return Err(unsafe { Errno(raw.decode_error_code()) });
145145
}

src/backend/linux_raw/net/addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl SocketAddrUnix {
7171
if len != 0 && self.unix.sun_path[0] != b'\0' as c::c_char {
7272
let end = len as usize - offsetof_sun_path();
7373
let bytes = &self.unix.sun_path[..end];
74-
// Safety: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`. And
74+
// SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`. And
7575
// `from_bytes_with_nul_unchecked` since the string is NUL-terminated.
7676
unsafe {
7777
Some(CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(
@@ -91,7 +91,7 @@ impl SocketAddrUnix {
9191
if len != 0 && self.unix.sun_path[0] == b'\0' as c::c_char {
9292
let end = len as usize - offsetof_sun_path();
9393
let bytes = &self.unix.sun_path[1..end];
94-
// Safety: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
94+
// SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
9595
unsafe { Some(slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len())) }
9696
} else {
9797
None

src/backend/linux_raw/param/auxv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub(crate) fn linux_execfn() -> &'static CStr {
7777
execfn = EXECFN.load(Relaxed);
7878
}
7979

80-
// Safety: We assume the `AT_EXECFN` value provided by the kernel is a
80+
// SAFETY: We assume the `AT_EXECFN` value provided by the kernel is a
8181
// valid pointer to a valid NUL-terminated array of bytes.
8282
unsafe { CStr::from_ptr(execfn.cast()) }
8383
}
@@ -102,7 +102,7 @@ pub(crate) fn exe_phdrs() -> (*const c::c_void, usize) {
102102
pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] {
103103
let (phdr, phnum) = exe_phdrs();
104104

105-
// Safety: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the
105+
// SAFETY: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the
106106
// kernel form a valid slice.
107107
unsafe { slice::from_raw_parts(phdr.cast(), phnum) }
108108
}
@@ -177,7 +177,7 @@ fn init_from_auxv_file(auxv: OwnedFd) -> Option<()> {
177177
buffer.resize(cur + n, 0_u8);
178178
}
179179

180-
// Safety: We loaded from an auxv file into the buffer.
180+
// SAFETY: We loaded from an auxv file into the buffer.
181181
unsafe { init_from_auxp(buffer.as_ptr().cast()) }
182182
}
183183

src/backend/linux_raw/param/libc_auxv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(crate) fn exe_phdrs() -> (*const libc::c_void, usize) {
6666
pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] {
6767
let (phdr, phnum) = exe_phdrs();
6868

69-
// Safety: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the
69+
// SAFETY: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the
7070
// kernel form a valid slice.
7171
unsafe { slice::from_raw_parts(phdr.cast(), phnum) }
7272
}

0 commit comments

Comments
 (0)