Skip to content

Commit 28b9300

Browse files
committed
Rename private type os_str::Slice to OsSlice
1 parent 3d5e0a7 commit 28b9300

File tree

5 files changed

+76
-76
lines changed

5 files changed

+76
-76
lines changed

library/std/src/ffi/os_str.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::ops::{self, Range};
1212
use crate::rc::Rc;
1313
use crate::str::FromStr;
1414
use crate::sync::Arc;
15-
use crate::sys::os_str::{Buf, Slice};
15+
use crate::sys::os_str::{Buf, OsSlice};
1616
use crate::sys_common::{AsInner, FromInner, IntoInner};
1717
use crate::{cmp, fmt, slice};
1818

@@ -113,11 +113,11 @@ impl crate::sealed::Sealed for OsString {}
113113
#[cfg_attr(not(test), rustc_diagnostic_item = "OsStr")]
114114
#[stable(feature = "rust1", since = "1.0.0")]
115115
// `OsStr::from_inner` and `impl CloneToUninit for OsStr` current implementation relies
116-
// on `OsStr` being layout-compatible with `Slice`.
116+
// on `OsStr` being layout-compatible with `OsSlice`.
117117
// However, `OsStr` layout is considered an implementation detail and must not be relied upon.
118118
#[repr(transparent)]
119119
pub struct OsStr {
120-
inner: Slice,
120+
inner: OsSlice,
121121
}
122122

123123
/// Allows extension traits within `std`.
@@ -871,23 +871,23 @@ impl OsStr {
871871
#[inline]
872872
#[stable(feature = "os_str_bytes", since = "1.74.0")]
873873
pub unsafe fn from_encoded_bytes_unchecked(bytes: &[u8]) -> &Self {
874-
Self::from_inner(unsafe { Slice::from_encoded_bytes_unchecked(bytes) })
874+
Self::from_inner(unsafe { OsSlice::from_encoded_bytes_unchecked(bytes) })
875875
}
876876

877877
#[inline]
878-
fn from_inner(inner: &Slice) -> &OsStr {
879-
// SAFETY: OsStr is just a wrapper of Slice,
880-
// therefore converting &Slice to &OsStr is safe.
881-
unsafe { &*(inner as *const Slice as *const OsStr) }
878+
fn from_inner(inner: &OsSlice) -> &OsStr {
879+
// SAFETY: OsStr is just a wrapper of OsSlice,
880+
// therefore converting &OsSlice to &OsStr is safe.
881+
unsafe { &*(inner as *const OsSlice as *const OsStr) }
882882
}
883883

884884
#[inline]
885-
fn from_inner_mut(inner: &mut Slice) -> &mut OsStr {
886-
// SAFETY: OsStr is just a wrapper of Slice,
887-
// therefore converting &mut Slice to &mut OsStr is safe.
885+
fn from_inner_mut(inner: &mut OsSlice) -> &mut OsStr {
886+
// SAFETY: OsStr is just a wrapper of OsSlice,
887+
// therefore converting &mut OsSlice to &mut OsStr is safe.
888888
// Any method that mutates OsStr must be careful not to
889889
// break platform-specific encoding, in particular Wtf8 on Windows.
890-
unsafe { &mut *(inner as *mut Slice as *mut OsStr) }
890+
unsafe { &mut *(inner as *mut OsSlice as *mut OsStr) }
891891
}
892892

893893
/// Yields a <code>&[str]</code> slice if the `OsStr` is valid Unicode.
@@ -1041,7 +1041,7 @@ impl OsStr {
10411041
#[stable(feature = "into_boxed_os_str", since = "1.20.0")]
10421042
#[must_use = "`self` will be dropped if the result is not used"]
10431043
pub fn into_os_string(self: Box<OsStr>) -> OsString {
1044-
let boxed = unsafe { Box::from_raw(Box::into_raw(self) as *mut Slice) };
1044+
let boxed = unsafe { Box::from_raw(Box::into_raw(self) as *mut OsSlice) };
10451045
OsString { inner: Buf::from_box(boxed) }
10461046
}
10471047

@@ -1338,7 +1338,7 @@ unsafe impl CloneToUninit for OsStr {
13381338
#[inline]
13391339
#[cfg_attr(debug_assertions, track_caller)]
13401340
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
1341-
// SAFETY: we're just a transparent wrapper around a platform-specific Slice
1341+
// SAFETY: we're just a transparent wrapper around a platform-specific OsSlice
13421342
unsafe { self.inner.clone_to_uninit(dst) }
13431343
}
13441344
}
@@ -1462,7 +1462,7 @@ impl<'a> TryFrom<&'a OsStr> for &'a str {
14621462
impl Default for Box<OsStr> {
14631463
#[inline]
14641464
fn default() -> Box<OsStr> {
1465-
let rw = Box::into_raw(Slice::empty_box()) as *mut OsStr;
1465+
let rw = Box::into_raw(OsSlice::empty_box()) as *mut OsStr;
14661466
unsafe { Box::from_raw(rw) }
14671467
}
14681468
}
@@ -1699,7 +1699,7 @@ impl AsRef<OsStr> for OsString {
16991699
impl AsRef<OsStr> for str {
17001700
#[inline]
17011701
fn as_ref(&self) -> &OsStr {
1702-
OsStr::from_inner(Slice::from_str(self))
1702+
OsStr::from_inner(OsSlice::from_str(self))
17031703
}
17041704
}
17051705

@@ -1725,9 +1725,9 @@ impl IntoInner<Buf> for OsString {
17251725
}
17261726
}
17271727

1728-
impl AsInner<Slice> for OsStr {
1728+
impl AsInner<OsSlice> for OsStr {
17291729
#[inline]
1730-
fn as_inner(&self) -> &Slice {
1730+
fn as_inner(&self) -> &OsSlice {
17311731
&self.inner
17321732
}
17331733
}

library/std/src/sys/os_str/bytes.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Buf {
2121
}
2222

2323
#[repr(transparent)]
24-
pub struct Slice {
24+
pub struct OsSlice {
2525
pub inner: [u8],
2626
}
2727

@@ -56,13 +56,13 @@ impl fmt::Display for Buf {
5656
}
5757
}
5858

59-
impl fmt::Debug for Slice {
59+
impl fmt::Debug for OsSlice {
6060
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6161
fmt::Debug::fmt(&self.inner.utf8_chunks().debug(), f)
6262
}
6363
}
6464

65-
impl fmt::Display for Slice {
65+
impl fmt::Display for OsSlice {
6666
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6767
// If we're the empty string then our iterator won't actually yield
6868
// anything, so perform the formatting manually
@@ -135,7 +135,7 @@ impl Buf {
135135
}
136136

137137
#[inline]
138-
pub fn push_slice(&mut self, s: &Slice) {
138+
pub fn push_slice(&mut self, s: &OsSlice) {
139139
self.inner.extend_from_slice(&s.inner)
140140
}
141141

@@ -175,44 +175,44 @@ impl Buf {
175175
}
176176

177177
#[inline]
178-
pub fn as_slice(&self) -> &Slice {
179-
// SAFETY: Slice just wraps [u8],
178+
pub fn as_slice(&self) -> &OsSlice {
179+
// SAFETY: OsSlice just wraps [u8],
180180
// and &*self.inner is &[u8], therefore
181-
// transmuting &[u8] to &Slice is safe.
181+
// transmuting &[u8] to &OsSlice is safe.
182182
unsafe { mem::transmute(self.inner.as_slice()) }
183183
}
184184

185185
#[inline]
186-
pub fn as_mut_slice(&mut self) -> &mut Slice {
187-
// SAFETY: Slice just wraps [u8],
186+
pub fn as_mut_slice(&mut self) -> &mut OsSlice {
187+
// SAFETY: OsSlice just wraps [u8],
188188
// and &mut *self.inner is &mut [u8], therefore
189-
// transmuting &mut [u8] to &mut Slice is safe.
189+
// transmuting &mut [u8] to &mut OsSlice is safe.
190190
unsafe { mem::transmute(self.inner.as_mut_slice()) }
191191
}
192192

193193
#[inline]
194-
pub fn leak<'a>(self) -> &'a mut Slice {
194+
pub fn leak<'a>(self) -> &'a mut OsSlice {
195195
unsafe { mem::transmute(self.inner.leak()) }
196196
}
197197

198198
#[inline]
199-
pub fn into_box(self) -> Box<Slice> {
199+
pub fn into_box(self) -> Box<OsSlice> {
200200
unsafe { mem::transmute(self.inner.into_boxed_slice()) }
201201
}
202202

203203
#[inline]
204-
pub fn from_box(boxed: Box<Slice>) -> Buf {
204+
pub fn from_box(boxed: Box<OsSlice>) -> Buf {
205205
let inner: Box<[u8]> = unsafe { mem::transmute(boxed) };
206206
Buf { inner: inner.into_vec() }
207207
}
208208

209209
#[inline]
210-
pub fn into_arc(&self) -> Arc<Slice> {
210+
pub fn into_arc(&self) -> Arc<OsSlice> {
211211
self.as_slice().into_arc()
212212
}
213213

214214
#[inline]
215-
pub fn into_rc(&self) -> Rc<Slice> {
215+
pub fn into_rc(&self) -> Rc<OsSlice> {
216216
self.as_slice().into_rc()
217217
}
218218

@@ -222,7 +222,7 @@ impl Buf {
222222
/// # Safety
223223
///
224224
/// The length must be at an `OsStr` boundary, according to
225-
/// `Slice::check_public_boundary`.
225+
/// `OsSlice::check_public_boundary`.
226226
#[inline]
227227
pub unsafe fn truncate_unchecked(&mut self, len: usize) {
228228
self.inner.truncate(len);
@@ -240,14 +240,14 @@ impl Buf {
240240
}
241241
}
242242

243-
impl Slice {
243+
impl OsSlice {
244244
#[inline]
245245
pub fn as_encoded_bytes(&self) -> &[u8] {
246246
&self.inner
247247
}
248248

249249
#[inline]
250-
pub unsafe fn from_encoded_bytes_unchecked(s: &[u8]) -> &Slice {
250+
pub unsafe fn from_encoded_bytes_unchecked(s: &[u8]) -> &OsSlice {
251251
unsafe { mem::transmute(s) }
252252
}
253253

@@ -295,8 +295,8 @@ impl Slice {
295295
}
296296

297297
#[inline]
298-
pub fn from_str(s: &str) -> &Slice {
299-
unsafe { Slice::from_encoded_bytes_unchecked(s.as_bytes()) }
298+
pub fn from_str(s: &str) -> &OsSlice {
299+
unsafe { OsSlice::from_encoded_bytes_unchecked(s.as_bytes()) }
300300
}
301301

302302
#[inline]
@@ -320,27 +320,27 @@ impl Slice {
320320
}
321321

322322
#[inline]
323-
pub fn into_box(&self) -> Box<Slice> {
323+
pub fn into_box(&self) -> Box<OsSlice> {
324324
let boxed: Box<[u8]> = self.inner.into();
325325
unsafe { mem::transmute(boxed) }
326326
}
327327

328328
#[inline]
329-
pub fn empty_box() -> Box<Slice> {
329+
pub fn empty_box() -> Box<OsSlice> {
330330
let boxed: Box<[u8]> = Default::default();
331331
unsafe { mem::transmute(boxed) }
332332
}
333333

334334
#[inline]
335-
pub fn into_arc(&self) -> Arc<Slice> {
335+
pub fn into_arc(&self) -> Arc<OsSlice> {
336336
let arc: Arc<[u8]> = Arc::from(&self.inner);
337-
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const Slice) }
337+
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const OsSlice) }
338338
}
339339

340340
#[inline]
341-
pub fn into_rc(&self) -> Rc<Slice> {
341+
pub fn into_rc(&self) -> Rc<OsSlice> {
342342
let rc: Rc<[u8]> = Rc::from(&self.inner);
343-
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const Slice) }
343+
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const OsSlice) }
344344
}
345345

346346
#[inline]
@@ -375,7 +375,7 @@ impl Slice {
375375
}
376376

377377
#[unstable(feature = "clone_to_uninit", issue = "126799")]
378-
unsafe impl CloneToUninit for Slice {
378+
unsafe impl CloneToUninit for OsSlice {
379379
#[inline]
380380
#[cfg_attr(debug_assertions, track_caller)]
381381
unsafe fn clone_to_uninit(&self, dst: *mut u8) {

library/std/src/sys/os_str/bytes/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::*;
22

33
#[test]
44
fn slice_debug_output() {
5-
let input = unsafe { Slice::from_encoded_bytes_unchecked(b"\xF0hello,\tworld") };
5+
let input = unsafe { OsSlice::from_encoded_bytes_unchecked(b"\xF0hello,\tworld") };
66
let expected = r#""\xF0hello,\tworld""#;
77
let output = format!("{input:?}");
88

@@ -12,6 +12,6 @@ fn slice_debug_output() {
1212
#[test]
1313
fn display() {
1414
assert_eq!("Hello\u{FFFD}\u{FFFD} There\u{FFFD} Goodbye", unsafe {
15-
Slice::from_encoded_bytes_unchecked(b"Hello\xC0\x80 There\xE6\x83 Goodbye").to_string()
15+
OsSlice::from_encoded_bytes_unchecked(b"Hello\xC0\x80 There\xE6\x83 Goodbye").to_string()
1616
},);
1717
}

library/std/src/sys/os_str/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ cfg_if::cfg_if! {
66
target_os = "uefi",
77
))] {
88
mod wtf8;
9-
pub use wtf8::{Buf, Slice};
9+
pub use wtf8::{Buf, OsSlice};
1010
} else {
1111
mod bytes;
12-
pub use bytes::{Buf, Slice};
12+
pub use bytes::{Buf, OsSlice};
1313
}
1414
}

0 commit comments

Comments
 (0)