From d11ff2a06e7977685c9f093ec667301d3e5f63c8 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 22 Jun 2022 22:01:21 +1000 Subject: [PATCH 01/14] Impl `io::error::repr_unpacked::Repr::new` that accepts `ErrorData>` Signed-off-by: Jiahao XU --- library/std/src/io/error/repr_unpacked.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/std/src/io/error/repr_unpacked.rs b/library/std/src/io/error/repr_unpacked.rs index 3729c039c42d7..d6ad55b99f5c0 100644 --- a/library/std/src/io/error/repr_unpacked.rs +++ b/library/std/src/io/error/repr_unpacked.rs @@ -10,6 +10,10 @@ type Inner = ErrorData>; pub(super) struct Repr(Inner); impl Repr { + #[inline] + pub(super) fn new(dat: ErrorData>) -> Self { + Self(dat) + } pub(super) fn new_custom(b: Box) -> Self { Self(Inner::Custom(b)) } From 1713e25a411c3854e85baa5fe076d5e3e8cffe35 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 22 Jun 2022 22:01:51 +1000 Subject: [PATCH 02/14] Impl `io::error::repr_bitpacked::Repr::new` that accepts `ErrorData>` Signed-off-by: Jiahao XU --- library/std/src/io/error/repr_bitpacked.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/std/src/io/error/repr_bitpacked.rs b/library/std/src/io/error/repr_bitpacked.rs index e80068b46abb9..292bf4826fd23 100644 --- a/library/std/src/io/error/repr_bitpacked.rs +++ b/library/std/src/io/error/repr_bitpacked.rs @@ -132,6 +132,15 @@ unsafe impl Send for Repr {} unsafe impl Sync for Repr {} impl Repr { + pub(super) fn new(dat: ErrorData>) -> Self { + match dat { + ErrorData::Os(code) => Self::new_os(code), + ErrorData::Simple(kind) => Self::new_simple(kind), + ErrorData::SimpleMessage(simple_message) => Self::new_simple_message(simple_message), + ErrorData::Custom(b) => Self::new_custom(b), + } + } + pub(super) fn new_custom(b: Box) -> Self { let p = Box::into_raw(b).cast::(); // Should only be possible if an allocator handed out a pointer with From e0ea0c25341a34bbaa96a8173096e7713d472131 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 22 Jun 2022 22:43:54 +1000 Subject: [PATCH 03/14] Add new unstable API `Error::try_downgrade_inner` Signed-off-by: Jiahao XU --- library/std/src/io/error.rs | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 4a50e647c640e..b1931a522909a 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -795,6 +795,63 @@ impl Error { } } + /// Attempt to downgrade the inner error to `E` if any. + /// + /// If this [`Error`] was constructed via [`new`] then this function will + /// attempt to perform downgrade on it, otherwise it will return [`Err`]. + /// + /// If downgrade succeeds, it will return [`Ok`], otherwise it will also + /// return [`Err`]. + /// + /// [`new`]: Error::new + /// + /// # Examples + /// + /// ``` + /// #![feature(io_error_try_downcast_inner)] + /// + /// use std::fmt; + /// use std::io; + /// use std::error::Error; + /// + /// #[derive(Debug)] + /// enum E { + /// Io(io::Error), + /// SomeOtherVariant, + /// } + /// + /// impl fmt::Display for E { + /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + /// todo!() + /// } + /// } + /// impl Error for E {} + /// + /// impl From for E { + /// fn from(err: io::Error) -> E { + /// err.try_downcast_inner::() + /// .map(|b| *b) + /// .unwrap_or_else(E::Io) + /// } + /// } + /// ``` + #[unstable(feature = "io_error_try_downcast_inner", issue = "none")] + pub fn try_downcast_inner(self) -> result::Result, Self> + where + E: error::Error + Send + Sync + 'static, + { + match self.repr.into_data() { + ErrorData::Custom(b) if b.error.is::() => { + let res = (*b).error.downcast::(); + + // Safety: b.error.is::() returns true, + // which means that res must be Ok(e). + Ok(unsafe { res.unwrap_unchecked() }) + } + repr_data => Err(Self { repr: Repr::new(repr_data) }), + } + } + /// Returns the corresponding [`ErrorKind`] for this error. /// /// # Examples From d2211c9fdc8fd49bdbd17e92a16a9f304eda1d8c Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 22 Jun 2022 23:09:30 +1000 Subject: [PATCH 04/14] Add new unit test `test_try_downcast_inner` Signed-off-by: Jiahao XU --- library/std/src/io/error/tests.rs | 53 ++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs index 8d7877bcad35d..558594c816e16 100644 --- a/library/std/src/io/error/tests.rs +++ b/library/std/src/io/error/tests.rs @@ -1,4 +1,4 @@ -use super::{const_io_error, Custom, Error, ErrorData, ErrorKind, Repr}; +use super::{const_io_error, Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage}; use crate::assert_matches::assert_matches; use crate::error; use crate::fmt; @@ -141,3 +141,54 @@ fn test_custom_error_packing() { }) if error.downcast_ref::().as_deref() == Some(&Bojji(true)), ); } + +#[derive(Debug)] +struct E; + +impl fmt::Display for E { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { + Ok(()) + } +} + +impl error::Error for E {} + +#[test] +fn test_try_downcast_inner() { + // Case 1: custom error, downcast succeeds + let io_error = Error::new(ErrorKind::Other, Bojji(true)); + let e: Box = io_error.try_downcast_inner().unwrap(); + assert!(e.0); + + // Case 2: custom error, downcast fails + let io_error = Error::new(ErrorKind::Other, Bojji(true)); + let io_error = io_error.try_downcast_inner::().unwrap_err(); + + // ensures that the custom error is intact + assert_eq!(ErrorKind::Other, io_error.kind()); + let e: Box = io_error.try_downcast_inner().unwrap(); + assert!(e.0); + + // Case 3: os error + let errno = 20; + let io_error = Error::from_raw_os_error(errno); + let io_error = io_error.try_downcast_inner::().unwrap_err(); + + assert_eq!(errno, io_error.raw_os_error().unwrap()); + + // Case 4: simple + let kind = ErrorKind::OutOfMemory; + let io_error: Error = kind.into(); + let io_error = io_error.try_downcast_inner::().unwrap_err(); + + assert_eq!(kind, io_error.kind()); + + // Case 5: simple message + const SIMPLE_MESSAGE: SimpleMessage = + SimpleMessage { kind: ErrorKind::Other, message: "simple message error test" }; + let io_error = Error::from_static_message(&SIMPLE_MESSAGE); + let io_error = io_error.try_downcast_inner::().unwrap_err(); + + assert_eq!(SIMPLE_MESSAGE.kind, io_error.kind()); + assert_eq!(SIMPLE_MESSAGE.message, &*format!("{io_error}")); +} From 516da4c93f804f27b1a5f664ae06b9054532f095 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 23 Jun 2022 12:58:33 +1000 Subject: [PATCH 05/14] Use `unwrap` instead of `unwrap_unchecked` Signed-off-by: Jiahao XU --- library/std/src/io/error.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index b1931a522909a..4c6fd55ad13a3 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -844,9 +844,13 @@ impl Error { ErrorData::Custom(b) if b.error.is::() => { let res = (*b).error.downcast::(); - // Safety: b.error.is::() returns true, - // which means that res must be Ok(e). - Ok(unsafe { res.unwrap_unchecked() }) + // downcast is a really trivial and is marked as inline, so + // it's likely be inlined here. + // + // And the compiler should be able to eliminate the branch + // that produces `Err` here since b.error.is::() + // returns true. + Ok(res.unwrap()) } repr_data => Err(Self { repr: Repr::new(repr_data) }), } From 07a0fd2c1ee79faafafed2cfe60e640ca106fdb4 Mon Sep 17 00:00:00 2001 From: Lucas Dumont Date: Wed, 29 Jun 2022 06:29:10 +0200 Subject: [PATCH 06/14] Add std::fs::write documentation precision As mentioned in #97947, the documentation is updated --- library/std/src/fs.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index f46997b807ab2..d799776548a65 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -295,6 +295,9 @@ pub fn read_to_string>(path: P) -> io::Result { /// This function will create a file if it does not exist, /// and will entirely replace its contents if it does. /// +/// Depending on the platform, this function may fail if the +/// full directory path does not exist. +/// /// This is a convenience function for using [`File::create`] and [`write_all`] /// with fewer imports. /// @@ -349,6 +352,9 @@ impl File { /// This function will create a file if it does not exist, /// and will truncate it if it does. /// + /// Depending on the platform, this function may fail if the + /// full directory path does not exist. + /// /// See the [`OpenOptions::open`] function for more details. /// /// # Examples From 111253c519adc17f5bbfa41b7368512ac7e1effd Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 14 Jul 2022 11:24:44 +1000 Subject: [PATCH 07/14] Rename `std::io::Error::try_downcast_inner` to `downcast` Signed-off-by: Jiahao XU --- library/std/src/io/error.rs | 8 ++++---- library/std/src/io/error/tests.rs | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 4c6fd55ad13a3..8f2119425d112 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -808,7 +808,7 @@ impl Error { /// # Examples /// /// ``` - /// #![feature(io_error_try_downcast_inner)] + /// #![feature(io_error_downcast)] /// /// use std::fmt; /// use std::io; @@ -829,14 +829,14 @@ impl Error { /// /// impl From for E { /// fn from(err: io::Error) -> E { - /// err.try_downcast_inner::() + /// err.downcast::() /// .map(|b| *b) /// .unwrap_or_else(E::Io) /// } /// } /// ``` - #[unstable(feature = "io_error_try_downcast_inner", issue = "none")] - pub fn try_downcast_inner(self) -> result::Result, Self> + #[unstable(feature = "io_error_downcast", issue = "none")] + pub fn downcast(self) -> result::Result, Self> where E: error::Error + Send + Sync + 'static, { diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs index 558594c816e16..c897a5e8701c4 100644 --- a/library/std/src/io/error/tests.rs +++ b/library/std/src/io/error/tests.rs @@ -154,32 +154,32 @@ impl fmt::Display for E { impl error::Error for E {} #[test] -fn test_try_downcast_inner() { +fn test_std_io_error_downcast() { // Case 1: custom error, downcast succeeds let io_error = Error::new(ErrorKind::Other, Bojji(true)); - let e: Box = io_error.try_downcast_inner().unwrap(); + let e: Box = io_error.downcast().unwrap(); assert!(e.0); // Case 2: custom error, downcast fails let io_error = Error::new(ErrorKind::Other, Bojji(true)); - let io_error = io_error.try_downcast_inner::().unwrap_err(); + let io_error = io_error.downcast::().unwrap_err(); // ensures that the custom error is intact assert_eq!(ErrorKind::Other, io_error.kind()); - let e: Box = io_error.try_downcast_inner().unwrap(); + let e: Box = io_error.downcast().unwrap(); assert!(e.0); // Case 3: os error let errno = 20; let io_error = Error::from_raw_os_error(errno); - let io_error = io_error.try_downcast_inner::().unwrap_err(); + let io_error = io_error.downcast::().unwrap_err(); assert_eq!(errno, io_error.raw_os_error().unwrap()); // Case 4: simple let kind = ErrorKind::OutOfMemory; let io_error: Error = kind.into(); - let io_error = io_error.try_downcast_inner::().unwrap_err(); + let io_error = io_error.downcast::().unwrap_err(); assert_eq!(kind, io_error.kind()); @@ -187,7 +187,7 @@ fn test_try_downcast_inner() { const SIMPLE_MESSAGE: SimpleMessage = SimpleMessage { kind: ErrorKind::Other, message: "simple message error test" }; let io_error = Error::from_static_message(&SIMPLE_MESSAGE); - let io_error = io_error.try_downcast_inner::().unwrap_err(); + let io_error = io_error.downcast::().unwrap_err(); assert_eq!(SIMPLE_MESSAGE.kind, io_error.kind()); assert_eq!(SIMPLE_MESSAGE.message, &*format!("{io_error}")); From 0d45977aa552d0d1c8ec89ac470206f8a38a1e1b Mon Sep 17 00:00:00 2001 From: pierwill Date: Thu, 14 Jul 2022 15:30:36 -0500 Subject: [PATCH 08/14] Remove FIXME from MIR `always_storage_live_locals` --- compiler/rustc_mir_dataflow/src/storage.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/storage.rs b/compiler/rustc_mir_dataflow/src/storage.rs index 566c9d2d5054e..c909648ea017e 100644 --- a/compiler/rustc_mir_dataflow/src/storage.rs +++ b/compiler/rustc_mir_dataflow/src/storage.rs @@ -4,9 +4,6 @@ use rustc_middle::mir::{self, Local}; /// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations. /// /// These locals have fixed storage for the duration of the body. -// -// FIXME: Currently, we need to traverse the entire MIR to compute this. We should instead store it -// as a field in the `LocalDecl` for each `Local`. pub fn always_storage_live_locals(body: &mir::Body<'_>) -> BitSet { let mut always_live_locals = BitSet::new_filled(body.local_decls.len()); From d8aba1002a222d2a826c6c35fbb03dd4c1594a05 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 15 Jul 2022 13:04:06 +1000 Subject: [PATCH 09/14] Improve example of `downcast` Co-authored-by: Jane Losare-Lusby --- library/std/src/io/error.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 8f2119425d112..811688175e091 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -821,9 +821,10 @@ impl Error { /// } /// /// impl fmt::Display for E { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// todo!() - /// } + /// // ... + /// # fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + /// # todo!() + /// # } /// } /// impl Error for E {} /// From 67a6c0a7ee15dd464f4c917726c40978c7a857e3 Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Fri, 15 Jul 2022 12:57:46 +0900 Subject: [PATCH 10/14] Fix typo in mod.rs constuct -> construct --- library/std/src/thread/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index c70ac8c9806d6..d28c7b58b20ba 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1114,7 +1114,7 @@ impl Thread { // Used only internally to construct a thread object without spawning // Panics if the name contains nuls. pub(crate) fn new(name: Option) -> Thread { - // We have to use `unsafe` here to constuct the `Parker` in-place, + // We have to use `unsafe` here to construct the `Parker` in-place, // which is required for the UNIX implementation. // // SAFETY: We pin the Arc immediately after creation, so its address never From fa3156ec427192d3ebe3992f1c49b542d3d1179a Mon Sep 17 00:00:00 2001 From: rhysd Date: Fri, 15 Jul 2022 17:05:50 +0900 Subject: [PATCH 11/14] add `#[must_use]` to `Box::from_raw` --- library/alloc/src/boxed.rs | 1 + src/test/ui/lint/unused/must-use-box-from-raw.rs | 11 +++++++++++ .../ui/lint/unused/must-use-box-from-raw.stderr | 15 +++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/test/ui/lint/unused/must-use-box-from-raw.rs create mode 100644 src/test/ui/lint/unused/must-use-box-from-raw.stderr diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index d83bab7bbbdad..c1ceeb0deb837 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -949,6 +949,7 @@ impl Box { /// [`Layout`]: crate::Layout #[stable(feature = "box_raw", since = "1.4.0")] #[inline] + #[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `Box`"] pub unsafe fn from_raw(raw: *mut T) -> Self { unsafe { Self::from_raw_in(raw, Global) } } diff --git a/src/test/ui/lint/unused/must-use-box-from-raw.rs b/src/test/ui/lint/unused/must-use-box-from-raw.rs new file mode 100644 index 0000000000000..9ea7726894cbc --- /dev/null +++ b/src/test/ui/lint/unused/must-use-box-from-raw.rs @@ -0,0 +1,11 @@ +// #99269 + +// check-pass + +#![warn(unused_must_use)] + +unsafe fn free(ptr: *mut T) { + Box::from_raw(ptr); //~ WARNING unused return value +} + +fn main() {} diff --git a/src/test/ui/lint/unused/must-use-box-from-raw.stderr b/src/test/ui/lint/unused/must-use-box-from-raw.stderr new file mode 100644 index 0000000000000..7769f09aa5203 --- /dev/null +++ b/src/test/ui/lint/unused/must-use-box-from-raw.stderr @@ -0,0 +1,15 @@ +warning: unused return value of `Box::::from_raw` that must be used + --> $DIR/must-use-box-from-raw.rs:8:5 + | +LL | Box::from_raw(ptr); + | ^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/must-use-box-from-raw.rs:5:9 + | +LL | #![warn(unused_must_use)] + | ^^^^^^^^^^^^^^^ + = note: call `drop(from_raw(ptr))` if you intend to drop the `Box` + +warning: 1 warning emitted + From d6b7480c2a086d9284cfd4ed3f3e3612880a75d7 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 15 Jul 2022 03:10:35 -0700 Subject: [PATCH 12/14] Stabilize `core::ffi::CStr`, `alloc::ffi::CString`, and friends Stabilize the `core_c_str` and `alloc_c_string` feature gates. Change `std::ffi` to re-export these types rather than creating type aliases, since they now have matching stability. --- library/alloc/src/ffi/c_str.rs | 8 ++++---- library/alloc/src/ffi/mod.rs | 6 +++--- library/alloc/src/lib.rs | 2 -- library/alloc/tests/lib.rs | 1 - library/core/src/ffi/c_str.rs | 4 ++-- library/core/src/ffi/mod.rs | 2 +- library/std/src/ffi/mod.rs | 22 ++++------------------ library/std/src/lib.rs | 3 --- 8 files changed, 14 insertions(+), 34 deletions(-) diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index cde4219be84c2..ae61b1f1e8ed5 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -108,7 +108,7 @@ use crate::sync::Arc; /// and other memory errors. #[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)] #[cfg_attr(not(test), rustc_diagnostic_item = "cstring_type")] -#[unstable(feature = "alloc_c_string", issue = "94079")] +#[stable(feature = "alloc_c_string", since = "1.64.0")] pub struct CString { // Invariant 1: the slice ends with a zero byte and has a length of at least one. // Invariant 2: the slice contains only one zero byte. @@ -132,7 +132,7 @@ pub struct CString { /// let _: NulError = CString::new(b"f\0oo".to_vec()).unwrap_err(); /// ``` #[derive(Clone, PartialEq, Eq, Debug)] -#[unstable(feature = "alloc_c_string", issue = "94079")] +#[stable(feature = "alloc_c_string", since = "1.64.0")] pub struct NulError(usize, Vec); #[derive(Clone, PartialEq, Eq, Debug)] @@ -157,7 +157,7 @@ enum FromBytesWithNulErrorKind { /// let _: FromVecWithNulError = CString::from_vec_with_nul(b"f\0oo".to_vec()).unwrap_err(); /// ``` #[derive(Clone, PartialEq, Eq, Debug)] -#[unstable(feature = "alloc_c_string", issue = "94079")] +#[stable(feature = "alloc_c_string", since = "1.64.0")] pub struct FromVecWithNulError { error_kind: FromBytesWithNulErrorKind, bytes: Vec, @@ -223,7 +223,7 @@ impl FromVecWithNulError { /// This `struct` is created by [`CString::into_string()`]. See /// its documentation for more. #[derive(Clone, PartialEq, Eq, Debug)] -#[unstable(feature = "alloc_c_string", issue = "94079")] +#[stable(feature = "alloc_c_string", since = "1.64.0")] pub struct IntoStringError { inner: CString, error: Utf8Error, diff --git a/library/alloc/src/ffi/mod.rs b/library/alloc/src/ffi/mod.rs index fec2bec566a8b..e8530fbc1f08f 100644 --- a/library/alloc/src/ffi/mod.rs +++ b/library/alloc/src/ffi/mod.rs @@ -78,11 +78,11 @@ //! [`String`]: crate::string::String //! [`CStr`]: core::ffi::CStr -#![unstable(feature = "alloc_ffi", issue = "94079")] +#![stable(feature = "alloc_ffi", since = "1.64.0")] -#[unstable(feature = "alloc_c_string", issue = "94079")] +#[stable(feature = "alloc_c_string", since = "1.64.0")] pub use self::c_str::FromVecWithNulError; -#[unstable(feature = "alloc_c_string", issue = "94079")] +#[stable(feature = "alloc_c_string", since = "1.64.0")] pub use self::c_str::{CString, IntoStringError, NulError}; mod c_str; diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 541de5c902970..315469387e5ae 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -86,7 +86,6 @@ #![allow(explicit_outlives_requirements)] // // Library features: -#![cfg_attr(not(no_global_oom_handling), feature(alloc_c_string))] #![feature(alloc_layout_extra)] #![feature(allocator_api)] #![feature(array_chunks)] @@ -106,7 +105,6 @@ #![feature(const_maybe_uninit_write)] #![feature(const_maybe_uninit_as_mut_ptr)] #![feature(const_refs_to_cell)] -#![feature(core_c_str)] #![feature(core_intrinsics)] #![feature(const_eval_select)] #![feature(const_pin)] diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index bf5d0c941e934..c29e7b9c81efb 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -11,7 +11,6 @@ #![feature(const_nonnull_slice_from_raw_parts)] #![feature(const_ptr_write)] #![feature(const_try)] -#![feature(core_c_str)] #![feature(core_intrinsics)] #![feature(drain_filter)] #![feature(exact_size_is_empty)] diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 10bf95abd3959..ee9baf811e29c 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -76,7 +76,7 @@ use crate::str; /// [str]: prim@str "str" #[derive(Hash)] #[cfg_attr(not(test), rustc_diagnostic_item = "CStr")] -#[unstable(feature = "core_c_str", issue = "94079")] +#[stable(feature = "core_c_str", since = "1.64.0")] #[rustc_has_incoherent_inherent_impls] // FIXME: // `fn from` in `impl From<&CStr> for Box` current implementation relies @@ -108,7 +108,7 @@ pub struct CStr { /// let _: FromBytesWithNulError = CStr::from_bytes_with_nul(b"f\0oo").unwrap_err(); /// ``` #[derive(Clone, PartialEq, Eq, Debug)] -#[unstable(feature = "core_c_str", issue = "94079")] +#[stable(feature = "core_c_str", since = "1.64.0")] pub struct FromBytesWithNulError { kind: FromBytesWithNulErrorKind, } diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index 3b711c6b72d6d..ec1eaa99f0b8e 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -14,7 +14,7 @@ use crate::marker::PhantomData; use crate::num::*; use crate::ops::{Deref, DerefMut}; -#[unstable(feature = "core_c_str", issue = "94079")] +#[stable(feature = "core_c_str", since = "1.64.0")] pub use self::c_str::{CStr, FromBytesUntilNulError, FromBytesWithNulError}; mod c_str; diff --git a/library/std/src/ffi/mod.rs b/library/std/src/ffi/mod.rs index 484f42dafc3df..d987bf69b2576 100644 --- a/library/std/src/ffi/mod.rs +++ b/library/std/src/ffi/mod.rs @@ -146,24 +146,10 @@ #![stable(feature = "rust1", since = "1.0.0")] -/// See [alloc::ffi::FromVecWithNulError]. -#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")] -pub type FromVecWithNulError = alloc::ffi::FromVecWithNulError; -/// See [alloc::ffi::CString]. -#[stable(feature = "rust1", since = "1.0.0")] -pub type CString = alloc::ffi::CString; -/// See [alloc::ffi::IntoStringError]. -#[stable(feature = "rust1", since = "1.0.0")] -pub type IntoStringError = alloc::ffi::IntoStringError; -/// See [alloc::ffi::NulError]. -#[stable(feature = "rust1", since = "1.0.0")] -pub type NulError = alloc::ffi::NulError; -/// See [core::ffi::CStr]. -#[stable(feature = "rust1", since = "1.0.0")] -pub type CStr = core::ffi::CStr; -/// See [core::ffi::FromBytesWithNulError]. -#[stable(feature = "cstr_from_bytes", since = "1.10.0")] -pub type FromBytesWithNulError = core::ffi::FromBytesWithNulError; +#[stable(feature = "alloc_c_string", since = "1.64.0")] +pub use alloc::ffi::{CString, FromVecWithNulError, IntoStringError, NulError}; +#[stable(feature = "core_c_str", since = "1.64.0")] +pub use core::ffi::{CStr, FromBytesWithNulError}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::os_str::{OsStr, OsString}; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 8fbc5e27d02b8..ab50845e2b208 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -264,7 +264,6 @@ #![feature(atomic_mut_ptr)] #![feature(char_error_internals)] #![feature(char_internals)] -#![feature(core_c_str)] #![feature(core_intrinsics)] #![feature(cstr_from_bytes_until_nul)] #![feature(cstr_internals)] @@ -297,8 +296,6 @@ // // Library features (alloc): #![feature(alloc_layout_extra)] -#![feature(alloc_c_string)] -#![feature(alloc_ffi)] #![feature(allocator_api)] #![feature(get_mut_unchecked)] #![feature(map_try_insert)] From 8e8a3be22f1082da965f6a696be93fbbd7b5d4ba Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Fri, 15 Jul 2022 13:17:44 -0700 Subject: [PATCH 13/14] Apply suggestions from code review --- library/std/src/io/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 811688175e091..ff7fdcae16f53 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -836,7 +836,7 @@ impl Error { /// } /// } /// ``` - #[unstable(feature = "io_error_downcast", issue = "none")] + #[unstable(feature = "io_error_downcast", issue = "99262")] pub fn downcast(self) -> result::Result, Self> where E: error::Error + Send + Sync + 'static, From 64659804fcab73dc75b6582f1d46f8a9715e8542 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 16 Jul 2022 10:25:00 +0900 Subject: [PATCH 14/14] Add regression test for #64401 Signed-off-by: Yuki Okushi --- src/test/ui/codegen/issue-64401.rs | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/test/ui/codegen/issue-64401.rs diff --git a/src/test/ui/codegen/issue-64401.rs b/src/test/ui/codegen/issue-64401.rs new file mode 100644 index 0000000000000..53f85c63b5336 --- /dev/null +++ b/src/test/ui/codegen/issue-64401.rs @@ -0,0 +1,51 @@ +// build-pass +// The ICE didn't happen with `cargo check` but `cargo build`. + +use std::marker::PhantomData; + +trait Owned<'a> { + type Reader; +} + +impl<'a> Owned<'a> for () { + type Reader = (); +} + +trait Handler { + fn handle(&self); +} + +struct CtxHandlerWithoutState { + message_type: PhantomData, + _function: F, +} + +impl CtxHandlerWithoutState { + pub fn new(_function: F) -> Self { + Self { + message_type: PhantomData, + _function, + } + } +} + +impl<'a, M, F> Handler for CtxHandlerWithoutState +where + F: Fn(>::Reader), + M: Owned<'a>, +{ + fn handle(&self) {} +} + +fn e_to_i Owned<'a>>(_: >::Reader) {} + +fn send_external_to_internal() +where + M: for<'a> Owned<'a>, +{ + let _: Box = Box::new(CtxHandlerWithoutState::::new(e_to_i::)); +} + +fn main() { + send_external_to_internal::<()>() +}