From f56c02311ee87b34bd3c06468886c1d5d0f4a22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Tue, 11 Jun 2024 18:33:40 +0200 Subject: [PATCH 1/3] Rename `std::fs::try_exists` to `std::fs::exists` and stabilize fs_try_exists --- std/src/fs.rs | 13 +++++-------- std/src/path.rs | 4 +++- std/src/sys/pal/hermit/fs.rs | 2 +- std/src/sys/pal/solid/fs.rs | 2 +- std/src/sys/pal/unix/fs.rs | 2 +- std/src/sys/pal/unix/thread.rs | 6 +++--- std/src/sys/pal/unsupported/fs.rs | 2 +- std/src/sys/pal/wasi/fs.rs | 2 +- std/src/sys/pal/windows/fs.rs | 2 +- std/src/sys_common/fs.rs | 2 +- 10 files changed, 18 insertions(+), 19 deletions(-) diff --git a/std/src/fs.rs b/std/src/fs.rs index 0dcf554770c5c..008e6b6e97389 100644 --- a/std/src/fs.rs +++ b/std/src/fs.rs @@ -2739,18 +2739,15 @@ impl AsInnerMut for DirBuilder { /// # Examples /// /// ```no_run -/// #![feature(fs_try_exists)] /// use std::fs; /// -/// assert!(!fs::try_exists("does_not_exist.txt").expect("Can't check existence of file does_not_exist.txt")); -/// assert!(fs::try_exists("/root/secret_file.txt").is_err()); +/// assert!(!fs::exists("does_not_exist.txt").expect("Can't check existence of file does_not_exist.txt")); +/// assert!(fs::exists("/root/secret_file.txt").is_err()); /// ``` /// /// [`Path::exists`]: crate::path::Path::exists -// FIXME: stabilization should modify documentation of `exists()` to recommend this method -// instead. -#[unstable(feature = "fs_try_exists", issue = "83186")] +#[stable(feature = "fs_try_exists", since = "CURRENT_RUSTC_VERSION")] #[inline] -pub fn try_exists>(path: P) -> io::Result { - fs_imp::try_exists(path.as_ref()) +pub fn exists>(path: P) -> io::Result { + fs_imp::exists(path.as_ref()) } diff --git a/std/src/path.rs b/std/src/path.rs index f4e1e2a38c106..753f1563249a2 100644 --- a/std/src/path.rs +++ b/std/src/path.rs @@ -2888,6 +2888,8 @@ impl Path { /// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios /// where those bugs are not an issue. /// + /// This is an alias for [`std::fs::exists`](crate::fs::exists). + /// /// # Examples /// /// ```no_run @@ -2900,7 +2902,7 @@ impl Path { #[stable(feature = "path_try_exists", since = "1.63.0")] #[inline] pub fn try_exists(&self) -> io::Result { - fs::try_exists(self) + fs::exists(self) } /// Returns `true` if the path exists on disk and is pointing at a regular file. diff --git a/std/src/sys/pal/hermit/fs.rs b/std/src/sys/pal/hermit/fs.rs index a4a16e6e86b0c..b8de7643e9ffb 100644 --- a/std/src/sys/pal/hermit/fs.rs +++ b/std/src/sys/pal/hermit/fs.rs @@ -18,7 +18,7 @@ use crate::sys::time::SystemTime; use crate::sys::unsupported; use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; -pub use crate::sys_common::fs::{copy, try_exists}; +pub use crate::sys_common::fs::{copy, exists}; #[derive(Debug)] pub struct File(FileDesc); diff --git a/std/src/sys/pal/solid/fs.rs b/std/src/sys/pal/solid/fs.rs index a6c1336109ad7..dc83e4f4b4999 100644 --- a/std/src/sys/pal/solid/fs.rs +++ b/std/src/sys/pal/solid/fs.rs @@ -12,7 +12,7 @@ use crate::{ sys::unsupported, }; -pub use crate::sys_common::fs::try_exists; +pub use crate::sys_common::fs::exists; /// A file descriptor. #[derive(Clone, Copy)] diff --git a/std/src/sys/pal/unix/fs.rs b/std/src/sys/pal/unix/fs.rs index 1aaa8cc2a9d9a..55f849938e9b7 100644 --- a/std/src/sys/pal/unix/fs.rs +++ b/std/src/sys/pal/unix/fs.rs @@ -101,7 +101,7 @@ use libc::{ ))] use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64}; -pub use crate::sys_common::fs::try_exists; +pub use crate::sys_common::fs::exists; pub struct File(FileDesc); diff --git a/std/src/sys/pal/unix/thread.rs b/std/src/sys/pal/unix/thread.rs index 1ab54ec57c3b7..875b4193e4d0c 100644 --- a/std/src/sys/pal/unix/thread.rs +++ b/std/src/sys/pal/unix/thread.rs @@ -477,7 +477,7 @@ mod cgroups { //! output and we don't unescape use crate::borrow::Cow; use crate::ffi::OsString; - use crate::fs::{try_exists, File}; + use crate::fs::{exists, File}; use crate::io::Read; use crate::io::{BufRead, BufReader}; use crate::os::unix::ffi::OsStringExt; @@ -555,7 +555,7 @@ mod cgroups { path.push("cgroup.controllers"); // skip if we're not looking at cgroup2 - if matches!(try_exists(&path), Err(_) | Ok(false)) { + if matches!(exists(&path), Err(_) | Ok(false)) { return usize::MAX; }; @@ -612,7 +612,7 @@ mod cgroups { path.push(&group_path); // skip if we guessed the mount incorrectly - if matches!(try_exists(&path), Err(_) | Ok(false)) { + if matches!(exists(&path), Err(_) | Ok(false)) { continue; } diff --git a/std/src/sys/pal/unsupported/fs.rs b/std/src/sys/pal/unsupported/fs.rs index 6ac1b5d2bcfca..474c9fe97d18d 100644 --- a/std/src/sys/pal/unsupported/fs.rs +++ b/std/src/sys/pal/unsupported/fs.rs @@ -291,7 +291,7 @@ pub fn remove_dir_all(_path: &Path) -> io::Result<()> { unsupported() } -pub fn try_exists(_path: &Path) -> io::Result { +pub fn exists(_path: &Path) -> io::Result { unsupported() } diff --git a/std/src/sys/pal/wasi/fs.rs b/std/src/sys/pal/wasi/fs.rs index 529b82e019893..c58e6a08b374e 100644 --- a/std/src/sys/pal/wasi/fs.rs +++ b/std/src/sys/pal/wasi/fs.rs @@ -17,7 +17,7 @@ use crate::sys::time::SystemTime; use crate::sys::unsupported; use crate::sys_common::{AsInner, FromInner, IntoInner}; -pub use crate::sys_common::fs::try_exists; +pub use crate::sys_common::fs::exists; pub struct File { fd: WasiFd, diff --git a/std/src/sys/pal/windows/fs.rs b/std/src/sys/pal/windows/fs.rs index e92c5e80eac9c..85107a495951d 100644 --- a/std/src/sys/pal/windows/fs.rs +++ b/std/src/sys/pal/windows/fs.rs @@ -1531,7 +1531,7 @@ pub fn junction_point(original: &Path, link: &Path) -> io::Result<()> { } // Try to see if a file exists but, unlike `exists`, report I/O errors. -pub fn try_exists(path: &Path) -> io::Result { +pub fn exists(path: &Path) -> io::Result { // Open the file to ensure any symlinks are followed to their target. let mut opts = OpenOptions::new(); // No read, write, etc access rights are needed. diff --git a/std/src/sys_common/fs.rs b/std/src/sys_common/fs.rs index 617ac52e51ca8..acb6713cf1b14 100644 --- a/std/src/sys_common/fs.rs +++ b/std/src/sys_common/fs.rs @@ -42,7 +42,7 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { fs::remove_dir(path) } -pub fn try_exists(path: &Path) -> io::Result { +pub fn exists(path: &Path) -> io::Result { match fs::metadata(path) { Ok(_) => Ok(true), Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(false), From 5e7ce0bad2384fea48a70bc2d869a72bef1f63c2 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 16 Jun 2024 15:04:37 +0000 Subject: [PATCH 2/3] Remove `feature(effects)` from the standard library --- alloc/src/lib.rs | 1 - core/src/cmp.rs | 4 +--- core/src/escape.rs | 2 +- core/src/ffi/c_str.rs | 4 +++- core/src/lib.rs | 2 -- core/src/marker.rs | 1 - core/src/num/nonzero.rs | 6 ++---- core/src/ops/arith.rs | 4 +--- core/src/task/wake.rs | 4 ++-- std/src/lib.rs | 1 - 10 files changed, 10 insertions(+), 19 deletions(-) diff --git a/alloc/src/lib.rs b/alloc/src/lib.rs index 022a14b931a3c..43213dce243e8 100644 --- a/alloc/src/lib.rs +++ b/alloc/src/lib.rs @@ -175,7 +175,6 @@ #![feature(const_mut_refs)] #![feature(const_precise_live_drops)] #![feature(const_ptr_write)] -#![feature(const_trait_impl)] #![feature(const_try)] #![feature(decl_macro)] #![feature(dropck_eyepatch)] diff --git a/core/src/cmp.rs b/core/src/cmp.rs index f3f757ce69df7..cff75870790c5 100644 --- a/core/src/cmp.rs +++ b/core/src/cmp.rs @@ -245,7 +245,6 @@ use self::Ordering::*; append_const_msg )] #[rustc_diagnostic_item = "PartialEq"] -#[const_trait] pub trait PartialEq { /// This method tests for `self` and `other` values to be equal, and is used /// by `==`. @@ -1475,8 +1474,7 @@ mod impls { macro_rules! partial_eq_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] - impl const PartialEq for $t { + impl PartialEq for $t { #[inline] fn eq(&self, other: &$t) -> bool { (*self) == (*other) } #[inline] diff --git a/core/src/escape.rs b/core/src/escape.rs index f6ec30b9f793a..b213cc2b9167c 100644 --- a/core/src/escape.rs +++ b/core/src/escape.rs @@ -60,7 +60,7 @@ const fn escape_ascii(byte: u8) -> ([ascii::Char; N], Range) const fn escape_unicode(c: char) -> ([ascii::Char; N], Range) { const { assert!(N >= 10 && N < u8::MAX as usize) }; - let c = u32::from(c); + let c = c as u32; // OR-ing `1` ensures that for `c == 0` the code computes that // one digit should be printed. diff --git a/core/src/ffi/c_str.rs b/core/src/ffi/c_str.rs index 297f52e756bc6..fbc0c7232c4e5 100644 --- a/core/src/ffi/c_str.rs +++ b/core/src/ffi/c_str.rs @@ -515,7 +515,9 @@ impl CStr { #[inline] #[must_use] const fn as_non_null_ptr(&self) -> NonNull { - NonNull::from(&self.inner).as_non_null_ptr() + // FIXME(effects) replace with `NonNull::from` + // SAFETY: a reference is never null + unsafe { NonNull::new_unchecked(&self.inner as *const [c_char] as *mut [c_char]) }.as_non_null_ptr() } /// Returns the length of `self`. Like C's `strlen`, this does not include the nul terminator. diff --git a/core/src/lib.rs b/core/src/lib.rs index 94ad8fbd5df07..51452e3b7b02f 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -214,13 +214,11 @@ #![feature(const_mut_refs)] #![feature(const_precise_live_drops)] #![feature(const_refs_to_cell)] -#![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deprecated_suggestion)] #![feature(doc_cfg)] #![feature(doc_cfg_hide)] #![feature(doc_notable_trait)] -#![feature(effects)] #![feature(extern_types)] #![feature(f128)] #![feature(f16)] diff --git a/core/src/marker.rs b/core/src/marker.rs index 1d073a6d649b8..2e8be7bde4bc3 100644 --- a/core/src/marker.rs +++ b/core/src/marker.rs @@ -944,7 +944,6 @@ marker_impls! { #[lang = "destruct"] #[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)] #[rustc_deny_explicit_impl(implement_via_object = false)] -#[const_trait] pub trait Destruct {} /// A marker for tuple types. diff --git a/core/src/num/nonzero.rs b/core/src/num/nonzero.rs index 5956a08593ad4..0c6f06dc017e7 100644 --- a/core/src/num/nonzero.rs +++ b/core/src/num/nonzero.rs @@ -33,7 +33,6 @@ use super::{IntErrorKind, ParseIntError}; reason = "implementation detail which may disappear or be replaced at any time", issue = "none" )] -#[const_trait] pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed { #[doc(hidden)] type NonZeroInner: Sized + Copy; @@ -47,7 +46,6 @@ macro_rules! impl_zeroable_primitive { reason = "implementation detail which may disappear or be replaced at any time", issue = "none" )] - #[const_trait] pub trait Sealed {} $( @@ -70,14 +68,14 @@ macro_rules! impl_zeroable_primitive { reason = "implementation detail which may disappear or be replaced at any time", issue = "none" )] - impl const private::Sealed for $primitive {} + impl private::Sealed for $primitive {} #[unstable( feature = "nonzero_internals", reason = "implementation detail which may disappear or be replaced at any time", issue = "none" )] - unsafe impl const ZeroablePrimitive for $primitive { + unsafe impl ZeroablePrimitive for $primitive { type NonZeroInner = private::$NonZeroInner; } )+ diff --git a/core/src/ops/arith.rs b/core/src/ops/arith.rs index 5e77788d8ea36..133ae04f02618 100644 --- a/core/src/ops/arith.rs +++ b/core/src/ops/arith.rs @@ -73,7 +73,6 @@ append_const_msg )] #[doc(alias = "+")] -#[const_trait] pub trait Add { /// The resulting type after applying the `+` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -95,8 +94,7 @@ pub trait Add { macro_rules! add_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ops", issue = "90080")] - impl const Add for $t { + impl Add for $t { type Output = $t; #[inline] diff --git a/core/src/task/wake.rs b/core/src/task/wake.rs index 3d21b09fa8a02..86a965f68e085 100644 --- a/core/src/task/wake.rs +++ b/core/src/task/wake.rs @@ -282,7 +282,7 @@ impl<'a> Context<'a> { pub const fn ext(&mut self) -> &mut dyn Any { // FIXME: this field makes Context extra-weird about unwind safety // can we justify AssertUnwindSafe if we stabilize this? do we care? - match &mut *self.ext { + match &mut self.ext.0 { ExtData::Some(data) => *data, ExtData::None(unit) => unit, } @@ -356,7 +356,7 @@ impl<'a> ContextBuilder<'a> { #[rustc_const_unstable(feature = "const_waker", issue = "102012")] #[unstable(feature = "context_ext", issue = "123392")] pub const fn from(cx: &'a mut Context<'_>) -> Self { - let ext = match &mut *cx.ext { + let ext = match &mut cx.ext.0 { ExtData::Some(ext) => ExtData::Some(*ext), ExtData::None(()) => ExtData::None(()), }; diff --git a/std/src/lib.rs b/std/src/lib.rs index 80f67838ac002..caa8c7375ec45 100644 --- a/std/src/lib.rs +++ b/std/src/lib.rs @@ -284,7 +284,6 @@ #![feature(cfi_encoding)] #![feature(concat_idents)] #![feature(const_mut_refs)] -#![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deprecated_suggestion)] #![feature(doc_cfg)] From 1f1793634b497929e05448cb32128334d6388eb9 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 16 Jun 2024 15:12:22 +0000 Subject: [PATCH 3/3] update intrinsic const param counting --- core/src/ffi/c_str.rs | 3 ++- core/src/lib.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/ffi/c_str.rs b/core/src/ffi/c_str.rs index fbc0c7232c4e5..d2a408485d162 100644 --- a/core/src/ffi/c_str.rs +++ b/core/src/ffi/c_str.rs @@ -517,7 +517,8 @@ impl CStr { const fn as_non_null_ptr(&self) -> NonNull { // FIXME(effects) replace with `NonNull::from` // SAFETY: a reference is never null - unsafe { NonNull::new_unchecked(&self.inner as *const [c_char] as *mut [c_char]) }.as_non_null_ptr() + unsafe { NonNull::new_unchecked(&self.inner as *const [c_char] as *mut [c_char]) } + .as_non_null_ptr() } /// Returns the length of `self`. Like C's `strlen`, this does not include the nul terminator. diff --git a/core/src/lib.rs b/core/src/lib.rs index 51452e3b7b02f..2d0b8825f433b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -200,6 +200,7 @@ // Language features: // tidy-alphabetical-start #![cfg_attr(bootstrap, feature(c_unwind))] +#![cfg_attr(bootstrap, feature(effects))] #![feature(abi_unadjusted)] #![feature(adt_const_params)] #![feature(allow_internal_unsafe)]