Skip to content

Commit 6f82984

Browse files
committed
Auto merge of #67224 - nikomatsakis:revert-stabilization-of-never-type, r=centril
Revert stabilization of never type Fixes #66757 I decided to keep the separate `never-type-fallback` feature gate, but tried to otherwise revert #65355. Seemed pretty clean. ( cc @Centril, author of #65355, you may want to check this over briefly )
2 parents c8ea4ac + 775076f commit 6f82984

File tree

125 files changed

+451
-159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+451
-159
lines changed

src/libcore/clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ mod impls {
195195
bool char
196196
}
197197

198-
#[stable(feature = "never_type", since = "1.41.0")]
198+
#[unstable(feature = "never_type", issue = "35121")]
199199
impl Clone for ! {
200200
#[inline]
201201
fn clone(&self) -> Self {

src/libcore/cmp.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1141,24 +1141,24 @@ mod impls {
11411141

11421142
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
11431143

1144-
#[stable(feature = "never_type", since = "1.41.0")]
1144+
#[unstable(feature = "never_type", issue = "35121")]
11451145
impl PartialEq for ! {
11461146
fn eq(&self, _: &!) -> bool {
11471147
*self
11481148
}
11491149
}
11501150

1151-
#[stable(feature = "never_type", since = "1.41.0")]
1151+
#[unstable(feature = "never_type", issue = "35121")]
11521152
impl Eq for ! {}
11531153

1154-
#[stable(feature = "never_type", since = "1.41.0")]
1154+
#[unstable(feature = "never_type", issue = "35121")]
11551155
impl PartialOrd for ! {
11561156
fn partial_cmp(&self, _: &!) -> Option<Ordering> {
11571157
*self
11581158
}
11591159
}
11601160

1161-
#[stable(feature = "never_type", since = "1.41.0")]
1161+
#[unstable(feature = "never_type", issue = "35121")]
11621162
impl Ord for ! {
11631163
fn cmp(&self, _: &!) -> Ordering {
11641164
*self

src/libcore/convert/mod.rs

+88-7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
4141
#![stable(feature = "rust1", since = "1.0.0")]
4242

43+
use crate::fmt;
44+
4345
mod num;
4446

4547
#[unstable(feature = "convert_float_to_int", issue = "67057")]
@@ -430,7 +432,9 @@ pub trait TryInto<T>: Sized {
430432
/// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T`
431433
/// - [`try_from`] is reflexive, which means that `TryFrom<T> for T`
432434
/// is implemented and cannot fail -- the associated `Error` type for
433-
/// calling `T::try_from()` on a value of type `T` is [`!`].
435+
/// calling `T::try_from()` on a value of type `T` is [`Infallible`].
436+
/// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be
437+
/// equivalent.
434438
///
435439
/// `TryFrom<T>` can be implemented as follows:
436440
///
@@ -479,6 +483,7 @@ pub trait TryInto<T>: Sized {
479483
/// [`TryInto`]: trait.TryInto.html
480484
/// [`i32::MAX`]: ../../std/i32/constant.MAX.html
481485
/// [`!`]: ../../std/primitive.never.html
486+
/// [`Infallible`]: enum.Infallible.html
482487
#[stable(feature = "try_from", since = "1.34.0")]
483488
pub trait TryFrom<T>: Sized {
484489
/// The type returned in the event of a conversion error.
@@ -634,9 +639,9 @@ impl AsRef<str> for str {
634639
// THE NO-ERROR ERROR TYPE
635640
////////////////////////////////////////////////////////////////////////////////
636641

637-
/// A type alias for [the `!` “never” type][never].
642+
/// The error type for errors that can never happen.
638643
///
639-
/// `Infallible` represents types of errors that can never happen since `!` has no valid values.
644+
/// Since this enum has no variant, a value of this type can never actually exist.
640645
/// This can be useful for generic APIs that use [`Result`] and parameterize the error type,
641646
/// to indicate that the result is always [`Ok`].
642647
///
@@ -653,15 +658,91 @@ impl AsRef<str> for str {
653658
/// }
654659
/// ```
655660
///
656-
/// # Eventual deprecation
661+
/// # Future compatibility
662+
///
663+
/// This enum has the same role as [the `!` “never” type][never],
664+
/// which is unstable in this version of Rust.
665+
/// When `!` is stabilized, we plan to make `Infallible` a type alias to it:
666+
///
667+
/// ```ignore (illustrates future std change)
668+
/// pub type Infallible = !;
669+
/// ```
670+
///
671+
/// … and eventually deprecate `Infallible`.
672+
///
673+
///
674+
/// However there is one case where `!` syntax can be used
675+
/// before `!` is stabilized as a full-fleged type: in the position of a function’s return type.
676+
/// Specifically, it is possible implementations for two different function pointer types:
677+
///
678+
/// ```
679+
/// trait MyTrait {}
680+
/// impl MyTrait for fn() -> ! {}
681+
/// impl MyTrait for fn() -> std::convert::Infallible {}
682+
/// ```
657683
///
658-
/// Previously, `Infallible` was defined as `enum Infallible {}`.
659-
/// Now that it is merely a type alias to `!`, we will eventually deprecate `Infallible`.
684+
/// With `Infallible` being an enum, this code is valid.
685+
/// However when `Infallible` becomes an alias for the never type,
686+
/// the two `impl`s will start to overlap
687+
/// and therefore will be disallowed by the language’s trait coherence rules.
660688
///
661689
/// [`Ok`]: ../result/enum.Result.html#variant.Ok
662690
/// [`Result`]: ../result/enum.Result.html
663691
/// [`TryFrom`]: trait.TryFrom.html
664692
/// [`Into`]: trait.Into.html
665693
/// [never]: ../../std/primitive.never.html
666694
#[stable(feature = "convert_infallible", since = "1.34.0")]
667-
pub type Infallible = !;
695+
#[derive(Copy)]
696+
pub enum Infallible {}
697+
698+
#[stable(feature = "convert_infallible", since = "1.34.0")]
699+
impl Clone for Infallible {
700+
fn clone(&self) -> Infallible {
701+
match *self {}
702+
}
703+
}
704+
705+
#[stable(feature = "convert_infallible", since = "1.34.0")]
706+
impl fmt::Debug for Infallible {
707+
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
708+
match *self {}
709+
}
710+
}
711+
712+
#[stable(feature = "convert_infallible", since = "1.34.0")]
713+
impl fmt::Display for Infallible {
714+
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
715+
match *self {}
716+
}
717+
}
718+
719+
#[stable(feature = "convert_infallible", since = "1.34.0")]
720+
impl PartialEq for Infallible {
721+
fn eq(&self, _: &Infallible) -> bool {
722+
match *self {}
723+
}
724+
}
725+
726+
#[stable(feature = "convert_infallible", since = "1.34.0")]
727+
impl Eq for Infallible {}
728+
729+
#[stable(feature = "convert_infallible", since = "1.34.0")]
730+
impl PartialOrd for Infallible {
731+
fn partial_cmp(&self, _other: &Self) -> Option<crate::cmp::Ordering> {
732+
match *self {}
733+
}
734+
}
735+
736+
#[stable(feature = "convert_infallible", since = "1.34.0")]
737+
impl Ord for Infallible {
738+
fn cmp(&self, _other: &Self) -> crate::cmp::Ordering {
739+
match *self {}
740+
}
741+
}
742+
743+
#[stable(feature = "convert_infallible", since = "1.34.0")]
744+
impl From<!> for Infallible {
745+
fn from(x: !) -> Self {
746+
x
747+
}
748+
}

src/libcore/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1940,14 +1940,14 @@ macro_rules! fmt_refs {
19401940

19411941
fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }
19421942

1943-
#[stable(feature = "never_type", since = "1.41.0")]
1943+
#[unstable(feature = "never_type", issue = "35121")]
19441944
impl Debug for ! {
19451945
fn fmt(&self, _: &mut Formatter<'_>) -> Result {
19461946
*self
19471947
}
19481948
}
19491949

1950-
#[stable(feature = "never_type", since = "1.41.0")]
1950+
#[unstable(feature = "never_type", issue = "35121")]
19511951
impl Display for ! {
19521952
fn fmt(&self, _: &mut Formatter<'_>) -> Result {
19531953
*self

src/libcore/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
#![feature(iter_once_with)]
8888
#![feature(lang_items)]
8989
#![feature(link_llvm_intrinsics)]
90-
#![cfg_attr(bootstrap, feature(never_type))]
90+
#![feature(never_type)]
9191
#![feature(nll)]
9292
#![feature(exhaustive_patterns)]
9393
#![feature(no_core)]

src/libcore/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ mod copy_impls {
776776
bool char
777777
}
778778

779-
#[stable(feature = "never_type", since = "1.41.0")]
779+
#[unstable(feature = "never_type", issue = "35121")]
780780
impl Copy for ! {}
781781

782782
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/num/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
#![stable(feature = "rust1", since = "1.0.0")]
66

7+
use crate::convert::Infallible;
78
use crate::fmt;
89
use crate::intrinsics;
910
use crate::mem;
@@ -5032,8 +5033,18 @@ impl fmt::Display for TryFromIntError {
50325033
}
50335034

50345035
#[stable(feature = "try_from", since = "1.34.0")]
5036+
impl From<Infallible> for TryFromIntError {
5037+
fn from(x: Infallible) -> TryFromIntError {
5038+
match x {}
5039+
}
5040+
}
5041+
5042+
#[unstable(feature = "never_type", issue = "35121")]
50355043
impl From<!> for TryFromIntError {
50365044
fn from(never: !) -> TryFromIntError {
5045+
// Match rather than coerce to make sure that code like
5046+
// `From<Infallible> for TryFromIntError` above will keep working
5047+
// when `Infallible` becomes an alias to `!`.
50375048
match never {}
50385049
}
50395050
}

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#![feature(core_intrinsics)]
3838
#![feature(drain_filter)]
3939
#![cfg_attr(windows, feature(libc))]
40-
#![cfg_attr(bootstrap, feature(never_type))]
40+
#![feature(never_type)]
4141
#![feature(exhaustive_patterns)]
4242
#![feature(overlapping_marker_traits)]
4343
#![feature(extern_types)]

src/librustc_codegen_utils/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![feature(box_patterns)]
99
#![feature(box_syntax)]
1010
#![feature(core_intrinsics)]
11-
#![cfg_attr(bootstrap, feature(never_type))]
11+
#![feature(never_type)]
1212
#![feature(nll)]
1313
#![feature(in_band_lifetimes)]
1414

src/librustc_error_codes/error_codes/E0725.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ command line flags.
44
Erroneous code example:
55

66
```ignore (can't specify compiler flags from doctests)
7-
#![feature(specialization)] // error: the feature `specialization` is not in
8-
// the list of allowed features
7+
#![feature(never_type)] // error: the feature `never_type` is not in
8+
// the list of allowed features
99
```
1010

1111
Delete the offending feature attribute, or add it to the list of allowed

src/librustc_feature/accepted.rs

-2
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ declare_features! (
253253
(accepted, const_constructor, "1.40.0", Some(61456), None),
254254
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.
255255
(accepted, cfg_doctest, "1.40.0", Some(62210), None),
256-
/// Allows the `!` type. Does not imply 'exhaustive_patterns' any more.
257-
(accepted, never_type, "1.41.0", Some(35121), None),
258256
/// Allows relaxing the coherence rules such that
259257
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
260258
(accepted, re_rebalance_coherence, "1.41.0", Some(55437), None),

src/librustc_feature/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ declare_features! (
303303
/// Allows `X..Y` patterns.
304304
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
305305

306+
/// Allows the `!` type. Does not imply 'exhaustive_patterns' (below) any more.
307+
(active, never_type, "1.13.0", Some(35121), None),
308+
306309
/// Allows exhaustive pattern matching on types that contain uninhabited types.
307310
(active, exhaustive_patterns, "1.13.0", Some(51085), None),
308311

src/librustc_mir/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1818
#![feature(drain_filter)]
1919
#![feature(exhaustive_patterns)]
2020
#![feature(iter_order_by)]
21-
#![cfg_attr(bootstrap, feature(never_type))]
21+
#![feature(never_type)]
2222
#![feature(specialization)]
2323
#![feature(try_trait)]
2424
#![feature(unicode_internals)]

src/librustc_typeck/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ This API is completely unstable and subject to change.
6767
#![feature(in_band_lifetimes)]
6868
#![feature(nll)]
6969
#![feature(slice_patterns)]
70-
#![cfg_attr(bootstrap, feature(never_type))]
70+
#![feature(never_type)]
7171

7272
#![recursion_limit="256"]
7373

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![feature(crate_visibility_modifier)]
1515
#![feature(const_fn)]
1616
#![feature(drain_filter)]
17-
#![cfg_attr(bootstrap, feature(never_type))]
17+
#![feature(never_type)]
1818
#![feature(unicode_internals)]
1919

2020
#![recursion_limit="256"]

src/libserialize/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Core encoding and decoding interfaces.
1111
#![feature(box_syntax)]
1212
#![feature(core_intrinsics)]
1313
#![feature(specialization)]
14-
#![cfg_attr(bootstrap, feature(never_type))]
14+
#![feature(never_type)]
1515
#![feature(nll)]
1616
#![feature(associated_type_bounds)]
1717
#![cfg_attr(test, feature(test))]

src/libstd/error.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl<'a> From<Cow<'a, str>> for Box<dyn Error> {
465465
}
466466
}
467467

468-
#[stable(feature = "never_type", since = "1.41.0")]
468+
#[unstable(feature = "never_type", issue = "35121")]
469469
impl Error for ! {
470470
fn description(&self) -> &str { *self }
471471
}
@@ -551,6 +551,13 @@ impl Error for string::FromUtf16Error {
551551
}
552552
}
553553

554+
#[stable(feature = "str_parse_error2", since = "1.8.0")]
555+
impl Error for string::ParseError {
556+
fn description(&self) -> &str {
557+
match *self {}
558+
}
559+
}
560+
554561
#[stable(feature = "decode_utf16", since = "1.9.0")]
555562
impl Error for char::DecodeUtf16Error {
556563
fn description(&self) -> &str {

src/libstd/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
#![feature(maybe_uninit_ref)]
282282
#![feature(maybe_uninit_slice)]
283283
#![feature(needs_panic_runtime)]
284-
#![cfg_attr(bootstrap, feature(never_type))]
284+
#![feature(never_type)]
285285
#![feature(nll)]
286286
#![cfg_attr(bootstrap, feature(on_unimplemented))]
287287
#![feature(optin_builtin_traits)]

src/libstd/primitive_docs.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ mod prim_bool { }
7171
/// write:
7272
///
7373
/// ```
74+
/// #![feature(never_type)]
7475
/// # fn foo() -> u32 {
7576
/// let x: ! = {
7677
/// return 123
@@ -200,6 +201,7 @@ mod prim_bool { }
200201
/// for example:
201202
///
202203
/// ```
204+
/// #![feature(never_type)]
203205
/// # use std::fmt;
204206
/// # trait Debug {
205207
/// # fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result;
@@ -237,7 +239,7 @@ mod prim_bool { }
237239
/// [`Default`]: default/trait.Default.html
238240
/// [`default()`]: default/trait.Default.html#tymethod.default
239241
///
240-
#[stable(feature = "never_type", since = "1.41.0")]
242+
#[unstable(feature = "never_type", issue = "35121")]
241243
mod prim_never { }
242244

243245
#[doc(primitive = "char")]

0 commit comments

Comments
 (0)