Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 57 additions & 46 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion library/core/src/net/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ enum AddrKind {
/// use std::net::SocketAddr;
///
/// // No problem, the `panic!` message has disappeared.
/// let _foo: SocketAddr = "127.0.0.1:8080".parse().expect("unreachable panic");
/// let _foo: SocketAddr = "127.0.0.1:8080".parse().expect("`parse` should succeed");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
32 changes: 16 additions & 16 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ impl<T: PointeeSized> *const T {
/// ```
#[stable(feature = "ptr_offset_from", since = "1.47.0")]
#[rustc_const_stable(feature = "const_ptr_offset_from", since = "1.65.0")]
#[inline]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn offset_from(self, origin: *const T) -> isize
where
Expand Down Expand Up @@ -1142,7 +1142,7 @@ impl<T: PointeeSized> *const T {
/// [`ptr::read`]: crate::ptr::read()
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")]
#[inline]
#[inline(always)]
#[track_caller]
pub const unsafe fn read(self) -> T
where
Expand All @@ -1164,7 +1164,7 @@ impl<T: PointeeSized> *const T {
/// [`ptr::read_volatile`]: crate::ptr::read_volatile()
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_volatile", issue = "159094")]
#[inline]
#[inline(always)]
#[track_caller]
pub const unsafe fn read_volatile(self) -> T
where
Expand All @@ -1184,7 +1184,7 @@ impl<T: PointeeSized> *const T {
/// [`ptr::read_unaligned`]: crate::ptr::read_unaligned()
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")]
#[inline]
#[inline(always)]
#[track_caller]
pub const unsafe fn read_unaligned(self) -> T
where
Expand All @@ -1204,7 +1204,7 @@ impl<T: PointeeSized> *const T {
/// [`ptr::copy`]: crate::ptr::copy()
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[inline]
#[inline(always)]
#[track_caller]
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
where
Expand All @@ -1224,7 +1224,7 @@ impl<T: PointeeSized> *const T {
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[inline]
#[inline(always)]
#[track_caller]
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
where
Expand Down Expand Up @@ -1435,7 +1435,7 @@ impl<T> *const [T] {
/// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
/// assert_eq!(slice.len(), 3);
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "slice_ptr_len", since = "1.79.0")]
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "1.79.0")]
pub const fn len(self) -> usize {
Expand Down Expand Up @@ -1472,7 +1472,7 @@ impl<T> *const [T] {
/// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
/// assert_eq!(slice.as_ptr(), ptr::null());
/// ```
#[inline]
#[inline(always)]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_ptr(self) -> *const T {
self as *const T
Expand Down Expand Up @@ -1516,7 +1516,7 @@ impl<T> *const [T] {
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
#[inline]
#[inline(always)]
pub const unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output
where
I: [const] SliceIndex<[T]>,
Expand Down Expand Up @@ -1561,7 +1561,7 @@ impl<T, const N: usize> *const [T; N] {
/// let arr: *const [i8; 3] = ptr::null();
/// assert_eq!(arr.as_ptr(), ptr::null());
/// ```
#[inline]
#[inline(always)]
#[unstable(feature = "array_ptr_get", issue = "119834")]
pub const fn as_ptr(self) -> *const T {
self as *const T
Expand Down Expand Up @@ -1592,7 +1592,7 @@ impl<T, const N: usize> *const [T; N] {
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
)]
impl<T: PointeeSized> PartialEq for *const T {
#[inline]
#[inline(always)]
#[allow(ambiguous_wide_pointer_comparisons)]
fn eq(&self, other: &*const T) -> bool {
*self == *other
Expand Down Expand Up @@ -1634,31 +1634,31 @@ impl<T: PointeeSized> Ord for *const T {
note = "see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information"
)]
impl<T: PointeeSized> PartialOrd for *const T {
#[inline]
#[inline(always)]
#[allow(ambiguous_wide_pointer_comparisons)]
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
Some(self.cmp(other))
}

#[inline]
#[inline(always)]
#[allow(ambiguous_wide_pointer_comparisons)]
fn lt(&self, other: &*const T) -> bool {
*self < *other
}

#[inline]
#[inline(always)]
#[allow(ambiguous_wide_pointer_comparisons)]
fn le(&self, other: &*const T) -> bool {
*self <= *other
}

#[inline]
#[inline(always)]
#[allow(ambiguous_wide_pointer_comparisons)]
fn gt(&self, other: &*const T) -> bool {
*self > *other
}

#[inline]
#[inline(always)]
#[allow(ambiguous_wide_pointer_comparisons)]
fn ge(&self, other: &*const T) -> bool {
*self >= *other
Expand Down
16 changes: 8 additions & 8 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
/// assert_eq!([1, 0, 1, 2], array);
/// }
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_swap", since = "1.85.0")]
#[rustc_diagnostic_item = "ptr_swap"]
Expand Down Expand Up @@ -1573,7 +1573,7 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, bytes: NonZero<usize
/// assert_eq!(b, 'b');
/// assert_eq!(rust, &['r', 'u', 's', 't']);
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_replace", since = "1.83.0")]
#[rustc_diagnostic_item = "ptr_replace"]
Expand Down Expand Up @@ -1708,7 +1708,7 @@ pub const unsafe fn replace<T>(dst: *mut T, src: T) -> T {
/// ```
///
/// [valid]: self#safety
#[inline]
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")]
#[track_caller]
Expand Down Expand Up @@ -1826,7 +1826,7 @@ pub const unsafe fn read<T>(src: *const T) -> T {
/// unsafe { ptr.read_unaligned() }
/// }
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
#[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")]
#[track_caller]
Expand Down Expand Up @@ -1932,7 +1932,7 @@ pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
/// assert_eq!(foo, "bar");
/// assert_eq!(bar, "foo");
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_ptr_write", since = "1.83.0")]
#[rustc_diagnostic_item = "ptr_write"]
Expand Down Expand Up @@ -2036,7 +2036,7 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
/// unsafe { ptr.write_unaligned(val) }
/// }
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
#[rustc_const_stable(feature = "const_ptr_write", since = "1.83.0")]
#[rustc_diagnostic_item = "ptr_write_unaligned"]
Expand Down Expand Up @@ -2141,7 +2141,7 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
/// assert_eq!(std::ptr::read_volatile(y), 12);
/// }
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "volatile", since = "1.9.0")]
#[rustc_const_unstable(feature = "const_volatile", issue = "159094")]
#[track_caller]
Expand Down Expand Up @@ -2247,7 +2247,7 @@ pub const unsafe fn read_volatile<T>(src: *const T) -> T {
/// assert_eq!(std::ptr::read_volatile(y), 12);
/// }
/// ```
#[inline]
#[inline(always)]
#[stable(feature = "volatile", since = "1.9.0")]
#[rustc_const_unstable(feature = "const_volatile", issue = "159094")]
#[rustc_diagnostic_item = "ptr_write_volatile"]
Expand Down
150 changes: 150 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,63 @@ impl Dir {
.map(|inner| Self { inner })
}

/// Attempts to open a directory at `path` according to `opts`.
///
/// This function opens a directory. To open a file instead, see [`File::open`].
///
/// # Errors
///
/// This function will return an error if `path` does not point to an existing directory.
/// Other errors may also be returned according to [`OpenOptions::open`].
///
/// # Examples
///
/// ```no_run
/// #![feature(dirfd)]
/// use std::{fs::{Dir, OpenOptions}, io};
///
/// fn main() -> std::io::Result<()> {
/// let dir = Dir::open_with("foo", &OpenOptions::new().read(true))?;
/// let mut f = dir.open_file("bar.txt")?;
/// let contents = io::read_to_string(f)?;
/// assert_eq!(contents, "Hello, world!");
/// Ok(())
/// }
/// ```
#[unstable(feature = "dirfd", issue = "120426")]
pub fn open_with<P: AsRef<Path>>(path: P, opts: &OpenOptions) -> io::Result<Self> {
fs_imp::Dir::open(path.as_ref(), &opts.0).map(|inner| Self { inner })
}

/// Attempts to open a directory at `path` with the minimum permissions for traversal.
///
/// The permissions requested by this function are guaranteed to be sufficient to open a child
/// file or folder, but not necessarily to list all children.
///
/// # Errors
///
/// This function may return an error according to [`OpenOptions::open`].
///
/// # Examples
///
/// ```no_run
/// #![feature(dirfd)]
/// use std::{fs::Dir, io};
///
/// fn main() -> std::io::Result<()> {
/// let foo = Dir::open_for_traversal("foo")?;
/// let foobar = foo.open_dir("bar")?;
/// let mut foobarbaz = foobar.open_file("baz")?;
/// let contents = io::read_to_string(foobarbaz)?;
/// assert_eq!(contents, "Hello, world!");
/// Ok(())
/// }
/// ```
#[unstable(feature = "dirfd", issue = "120426")]
pub fn open_for_traversal<P: AsRef<Path>>(path: P) -> io::Result<Self> {
fs_imp::Dir::open_for_traversal(path.as_ref()).map(|inner| Self { inner })
}

/// Queries metadata about the underlying directory.
///
/// # Examples
Expand Down Expand Up @@ -1712,6 +1769,99 @@ impl Dir {
) -> io::Result<()> {
self.inner.rename(from.as_ref(), &to_dir.inner, to.as_ref())
}

/// Attempts to create a directory relative to this directory.
///
/// This function interprets `path` relative to the directory provided by `self`. To create a directory
/// relative to the current working directory, or at an absolute path, see
/// [`fs::create_dir`][crate::fs::create_dir].
#[unstable(feature = "dirfd", issue = "120426")]
pub fn create_dir<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
self.inner.create_dir(path.as_ref())
}

/// Attempts to open a directory in read-only mode relative to this directory.
///
/// This function interprets `path` relative to the directory provided by `self`. To open a directory
/// relative to the current working directory, or at an absolute path, see [`Dir::open`].
///
/// # Errors
///
/// This function will return an error if `path` does not point to an existing directory.
/// Other errors may also be returned according to [`OpenOptions::open`].
///
/// # Examples
///
/// ```no_run
/// #![feature(dirfd)]
/// use std::{fs::Dir};
///
/// fn main() -> std::io::Result<()> {
/// let dir = Dir::open("foo")?;
/// let foobar = dir.open_dir("bar")?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "dirfd", issue = "120426")]
pub fn open_dir<P: AsRef<Path>>(&self, path: P) -> io::Result<Self> {
self.inner
.open_dir(path.as_ref(), &OpenOptions::new().read(true).0)
.map(|inner| Self { inner })
}

/// Attempts to open a directory relative to this directory according to `opts`.
///
/// This function interprets `path` relative to the directory provided by `self`. To open a directory
/// relative to the current working directory, or at an absolute path, see [`Dir::open`].
///
/// # Errors
///
/// This function will return errors according to [`OpenOptions::open`].
///
/// # Examples
///
/// ```no_run
/// #![feature(dirfd)]
/// use std::fs::{Dir, OpenOptions};
///
/// fn main() -> std::io::Result<()> {
/// let dir = Dir::open("foo")?;
/// let foobar_w = dir.open_dir_with("bar", &OpenOptions::new().write(true))?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "dirfd", issue = "120426")]
pub fn open_dir_with<P: AsRef<Path>>(&self, path: P, opts: &OpenOptions) -> io::Result<Self> {
self.inner.open_dir(path.as_ref(), &opts.0).map(|inner| Self { inner })
}

/// Attempts to remove a directory relative to this directory.
///
/// This function interprets `path` relative to the directory provided by `self`. To remove a directory
/// relative to the current working directory, or at an absolute path, see
/// [`fs::remove_dir`][crate::fs::remove_dir].
///
/// # Errors
///
/// This function will return an error if `path` does not point to an existing directory.
/// Other errors may also be returned according to [`OpenOptions::open`].
///
/// # Examples
///
/// ```no_run
/// #![feature(dirfd)]
/// use std::{fs::Dir};
///
/// fn main() -> std::io::Result<()> {
/// let dir = Dir::open("foo")?;
/// dir.remove_dir("bar")?;
/// Ok(())
/// }
/// ```
#[unstable(feature = "dirfd", issue = "120426")]
pub fn remove_dir<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
self.inner.remove_dir(path.as_ref())
}
}

impl AsInner<fs_imp::Dir> for Dir {
Expand Down
Loading
Loading