diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index fd4b2daae9c13c236c85c7c52412067a5aa6b78d..b21ff0e90836d3ece90bcc0b1840a4ec3c9a49a0 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -1,6 +1,5 @@ #![feature(let_chains)] #![feature(once_cell)] -#![feature(path_try_exists)] #![feature(rustc_attrs)] #![feature(type_alias_impl_trait)] diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 55bd2c59406df9a3ac8db1fd5bedfe029f933162..f46997b807ab230653d361ab92de59d16cc7ddef 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -2317,10 +2317,14 @@ fn as_inner_mut(&mut self) -> &mut fs_imp::DirBuilder { /// unrelated to the path not existing. (E.g. it will return `Err(_)` in case of permission /// denied on some of the parent directories.) /// +/// Note that while this avoids some pitfalls of the `exists()` method, it still can not +/// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios +/// where those bugs are not an issue. +/// /// # Examples /// /// ```no_run -/// #![feature(path_try_exists)] +/// #![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")); @@ -2330,7 +2334,7 @@ fn as_inner_mut(&mut self) -> &mut fs_imp::DirBuilder { /// [`Path::exists`]: crate::path::Path::exists // FIXME: stabilization should modify documentation of `exists()` to recommend this method // instead. -#[unstable(feature = "path_try_exists", issue = "83186")] +#[unstable(feature = "fs_try_exists", issue = "83186")] #[inline] pub fn try_exists>(path: P) -> io::Result { fs_imp::try_exists(path.as_ref()) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 36d6469c02d31e1f46e4c3e1686879e357ffa468..c56d5aa9b2e8d008c238623cea73958d64ba557e 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2705,6 +2705,9 @@ pub fn read_dir(&self) -> io::Result { /// Returns `true` if the path points at an existing entity. /// + /// Warning: this method may be error-prone, consider using [`try_exists()`] instead! + /// It also has a risk of introducing time-of-check to time-of-use (TOCTOU) bugs. + /// /// This function will traverse symbolic links to query information about the /// destination file. /// @@ -2721,7 +2724,9 @@ pub fn read_dir(&self) -> io::Result { /// # See Also /// /// This is a convenience function that coerces errors to false. If you want to - /// check errors, call [`fs::metadata`]. + /// check errors, call [`Path::try_exists`]. + /// + /// [`try_exists()`]: Self::try_exists #[stable(feature = "path_ext", since = "1.5.0")] #[must_use] #[inline] @@ -2738,20 +2743,20 @@ pub fn exists(&self) -> bool { /// unrelated to the path not existing. (E.g. it will return `Err(_)` in case of permission /// denied on some of the parent directories.) /// + /// Note that while this avoids some pitfalls of the `exists()` method, it still can not + /// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios + /// where those bugs are not an issue. + /// /// # Examples /// /// ```no_run - /// #![feature(path_try_exists)] - /// /// use std::path::Path; /// assert!(!Path::new("does_not_exist.txt").try_exists().expect("Can't check existence of file does_not_exist.txt")); /// assert!(Path::new("/root/secret_file.txt").try_exists().is_err()); /// ``` /// /// [`exists()`]: Self::exists - // FIXME: stabilization should modify documentation of `exists()` to recommend this method - // instead. - #[unstable(feature = "path_try_exists", issue = "83186")] + #[stable(feature = "path_try_exists", since = "1.63.0")] #[inline] pub fn try_exists(&self) -> io::Result { fs::try_exists(self)