From dd132214ed3e2415da4292fec21f564f4496baa5 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 31 Aug 2026 10:51:07 -0500 Subject: [PATCH] Dogfood never type in std --- library/alloc/src/bstr.rs | 4 ++-- library/alloc/src/string.rs | 10 ++++------ library/core/src/array/iter.rs | 2 +- library/core/src/array/mod.rs | 5 ++--- library/core/src/convert/mod.rs | 4 ++-- library/core/src/ops/control_flow.rs | 10 +++++----- library/core/src/ops/try_trait.rs | 8 ++++---- library/core/src/option.rs | 10 +++++----- library/core/src/result.rs | 12 +++++------- library/core/src/slice/cmp.rs | 2 +- library/core/src/task/poll.rs | 15 ++++++--------- library/std/src/ffi/os_str.rs | 4 ++-- library/std/src/path.rs | 4 ++-- tests/rustdoc-js/never-search.js | 2 ++ 14 files changed, 43 insertions(+), 49 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index a6c6377c8b2e1..8d993f6758a52 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -333,10 +333,10 @@ impl FromIterator for ByteString { #[unstable(feature = "bstr", issue = "134915")] impl FromStr for ByteString { - type Err = core::convert::Infallible; + type Err = !; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(ByteString(s.as_bytes().to_vec())) } } diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 170b94ba0c4b8..bf702875f3cad 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2895,20 +2895,18 @@ impl ops::DerefMut for String { } } -/// A type alias for [`Infallible`]. +/// A type alias for [`!`]. /// /// This alias exists for backwards compatibility, and may be eventually deprecated. -/// -/// [`Infallible`]: core::convert::Infallible "convert::Infallible" #[stable(feature = "str_parse_error", since = "1.5.0")] -pub type ParseError = core::convert::Infallible; +pub type ParseError = !; #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for String { - type Err = core::convert::Infallible; + type Err = !; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(String::from(s)) } } diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index d42e174283a7b..1129e8b6ceb2b 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -172,7 +172,7 @@ impl IntoIter { /// assert_eq!(empty.len(), 0); /// assert_eq!(empty.as_slice(), &[]); /// - /// let empty = IntoIter::::empty(); + /// let empty = IntoIter::::empty(); /// assert_eq!(empty.len(), 0); /// ``` /// diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 30af6450d19a9..fcd635a03c652 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -7,7 +7,6 @@ use crate::borrow::{Borrow, BorrowMut}; use crate::clone::TrivialClone; use crate::cmp::Ordering; -use crate::convert::Infallible; use crate::error::Error; use crate::hash::{self, Hash}; use crate::intrinsics::transmute_unchecked; @@ -195,8 +194,8 @@ impl Error for TryFromSliceError {} #[stable(feature = "try_from_slice_error", since = "1.36.0")] #[rustc_const_unstable(feature = "const_convert", issue = "143773")] -const impl From for TryFromSliceError { - fn from(x: Infallible) -> TryFromSliceError { +const impl From for TryFromSliceError { + fn from(x: !) -> TryFromSliceError { match x {} } } diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 7e675815edb2e..a57f3d58e3998 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -815,10 +815,10 @@ const impl TryFrom for T where U: [const] Into, { - type Error = Infallible; + type Error = !; #[inline] - fn try_from(value: U) -> Result { + fn try_from(value: U) -> Result { Ok(U::into(value)) } } diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index 227c9c43bea66..56c9d0cf0cba7 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -1,5 +1,5 @@ use crate::marker::Destruct; -use crate::{convert, ops}; +use crate::ops; /// Used to tell an operation whether it should exit early or go on as usual. /// @@ -104,7 +104,7 @@ pub enum ControlFlow { #[rustc_const_unstable(feature = "const_try", issue = "74935")] const impl ops::Try for ControlFlow { type Output = C; - type Residual = ControlFlow; + type Residual = ControlFlow; #[inline] fn from_output(output: Self::Output) -> Self { @@ -124,9 +124,9 @@ const impl ops::Try for ControlFlow { #[rustc_const_unstable(feature = "const_try", issue = "74935")] // Note: manually specifying the residual type instead of using the default to work around // https://github.com/rust-lang/rust/issues/99940 -const impl ops::FromResidual> for ControlFlow { +const impl ops::FromResidual> for ControlFlow { #[inline] - fn from_residual(residual: ControlFlow) -> Self { + fn from_residual(residual: ControlFlow) -> Self { match residual { ControlFlow::Break(b) => ControlFlow::Break(b), } @@ -135,7 +135,7 @@ const impl ops::FromResidual> for Cont #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try_residual", issue = "91285")] -const impl ops::Residual for ControlFlow { +const impl ops::Residual for ControlFlow { type TryType = ControlFlow; } diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index 614b104d9c2a2..d0dd6c8d5c8b7 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -148,12 +148,12 @@ pub const trait Try: [const] FromResidual { /// this type is typically a newtype of some sort to "color" the type /// so that it's distinguishable from the residuals of other types. /// - /// This is why `Result::Residual` is not `E`, but `Result`. + /// This is why `Result::Residual` is not `E`, but `Result`. /// That way it's distinct from `ControlFlow::Residual`, for example, /// and thus `?` on `ControlFlow` cannot be used in a method returning `Result`. /// /// If you're making a generic type `Foo` that implements `Try`, - /// then typically you can use `Foo` as its `Residual` + /// then typically you can use `Foo` as its `Residual` /// type: that type will have a "hole" in the correct place, and will maintain the /// "foo-ness" of the residual so other types need to opt-in to interconversion. #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] @@ -356,9 +356,9 @@ where /// and [`Try::Residual`] components, this allows putting them back together. /// /// For example, -/// `Result: Try>`, +/// `Result: Try>`, /// and in the other direction, -/// ` as Residual>::TryType = Result`. +/// ` as Residual>::TryType = Result`. #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try_residual", issue = "91285")] pub const trait Residual: Sized { diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 8ec0414cf6874..2fe7c8c305afe 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -585,7 +585,7 @@ use crate::num::NonZero; use crate::ops::{self, ControlFlow, Deref, DerefMut, Residual, Try}; use crate::panicking::{panic, panic_display}; use crate::pin::Pin; -use crate::{cmp, convert, hint, mem, slice}; +use crate::{cmp, hint, mem, slice}; /// The `Option` type. See [the module level documentation](self) for more. #[doc(search_unbox)] @@ -2864,7 +2864,7 @@ impl> FromIterator> for Option { #[rustc_const_unstable(feature = "const_try", issue = "74935")] const impl ops::Try for Option { type Output = T; - type Residual = Option; + type Residual = Option; #[inline] fn from_output(output: Self::Output) -> Self { @@ -2884,9 +2884,9 @@ const impl ops::Try for Option { #[rustc_const_unstable(feature = "const_try", issue = "74935")] // Note: manually specifying the residual type instead of using the default to work around // https://github.com/rust-lang/rust/issues/99940 -const impl ops::FromResidual> for Option { +const impl ops::FromResidual> for Option { #[inline] - fn from_residual(residual: Option) -> Self { + fn from_residual(residual: Option) -> Self { match residual { None => None, } @@ -2905,7 +2905,7 @@ const impl ops::FromResidual> for Option { #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -const impl ops::Residual for Option { +const impl ops::Residual for Option { type TryType = Option; } diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 6e76c3525b4cc..472d568c5cf66 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -544,7 +544,7 @@ use crate::iter::{self, FusedIterator, TrustedLen}; use crate::marker::Destruct; use crate::ops::{self, ControlFlow, Deref, DerefMut}; -use crate::{convert, fmt, hint}; +use crate::{fmt, hint}; /// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]). /// @@ -2164,7 +2164,7 @@ impl> FromIterator> for Result { #[rustc_const_unstable(feature = "const_try", issue = "74935")] const impl ops::Try for Result { type Output = T; - type Residual = Result; + type Residual = Result; #[inline] fn from_output(output: Self::Output) -> Self { @@ -2182,12 +2182,10 @@ const impl ops::Try for Result { #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -const impl> ops::FromResidual> - for Result -{ +const impl> ops::FromResidual> for Result { #[inline] #[track_caller] - fn from_residual(residual: Result) -> Self { + fn from_residual(residual: Result) -> Self { match residual { Err(e) => Err(From::from(e)), } @@ -2205,6 +2203,6 @@ const impl> ops::FromResidual> for Result< #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -const impl ops::Residual for Result { +const impl ops::Residual for Result { type TryType = Result; } diff --git a/library/core/src/slice/cmp.rs b/library/core/src/slice/cmp.rs index acb74c9916dfd..cd3fc889ecdd5 100644 --- a/library/core/src/slice/cmp.rs +++ b/library/core/src/slice/cmp.rs @@ -176,7 +176,7 @@ const trait SliceChain: Sized { fn chaining_ge(left: &[Self], right: &[Self]) -> ControlFlow; } -type AlwaysBreak = ControlFlow; +type AlwaysBreak = ControlFlow; #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] const impl SlicePartialOrd for A { diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 87f8830a6b176..bad3cbe83ed65 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -1,6 +1,5 @@ #![stable(feature = "futures_api", since = "1.36.0")] -use crate::convert; use crate::ops::{self, ControlFlow}; /// Indicates whether a value is available or if the current task has been @@ -233,7 +232,7 @@ const impl From for Poll { #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for Poll> { type Output = Poll; - type Residual = Result; + type Residual = Result; #[inline] fn from_output(c: Self::Output) -> Self { @@ -251,9 +250,9 @@ impl ops::Try for Poll> { } #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] -impl> ops::FromResidual> for Poll> { +impl> ops::FromResidual> for Poll> { #[inline] - fn from_residual(x: Result) -> Self { + fn from_residual(x: Result) -> Self { match x { Err(e) => Poll::Ready(Err(From::from(e))), } @@ -263,7 +262,7 @@ impl> ops::FromResidual> for Pol #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for Poll>> { type Output = Poll>; - type Residual = Result; + type Residual = Result; #[inline] fn from_output(c: Self::Output) -> Self { @@ -282,11 +281,9 @@ impl ops::Try for Poll>> { } #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] -impl> ops::FromResidual> - for Poll>> -{ +impl> ops::FromResidual> for Poll>> { #[inline] - fn from_residual(x: Result) -> Self { + fn from_residual(x: Result) -> Self { match x { Err(e) => Poll::Ready(Some(Err(From::from(e)))), } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 7ad313e1ed3ca..6be8f775b441d 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1804,10 +1804,10 @@ impl AsInner for OsStr { #[stable(feature = "osstring_from_str", since = "1.45.0")] impl FromStr for OsString { - type Err = core::convert::Infallible; + type Err = !; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(OsString::from(s)) } } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index f2fc148551d2e..141bc72fb2e42 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2025,10 +2025,10 @@ impl From for PathBuf { #[stable(feature = "path_from_str", since = "1.32.0")] impl FromStr for PathBuf { - type Err = core::convert::Infallible; + type Err = !; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(PathBuf::from(s)) } } diff --git a/tests/rustdoc-js/never-search.js b/tests/rustdoc-js/never-search.js index 9cc62a5ed04a5..7f626be7b64f6 100644 --- a/tests/rustdoc-js/never-search.js +++ b/tests/rustdoc-js/never-search.js @@ -12,6 +12,7 @@ const EXPECTED = [ 'query': '-> !', 'others': [ { 'path': 'never_search', 'name': 'loops' }, + { 'path': 'never_search::never', 'name': 'try_from' }, ], }, { @@ -19,6 +20,7 @@ const EXPECTED = [ 'others': [ { 'path': 'never_search', 'name': 'loops' }, { 'path': 'never_search', 'name': 'returns' }, + { 'path': 'never_search::never', 'name': 'try_from' }, ], }, {