Skip to content

Commit

Permalink
Auto merge of #50121 - pnkfelix:revert-stabilization-of-never-type-et…
Browse files Browse the repository at this point in the history
…-al, r=alexcrichton

Revert stabilization of never_type (!) et al

Fix #49691

I *think* this correctly adopts @nikomatsakis 's desired fix of:
 * reverting stabilization of `!` and `TryFrom`, and
 * returning to the previous fallback semantics (i.e. it is once again dependent on whether the crate has opted into `#[feature(never_type)]`,
 * **without** attempting to put back in the previous future-proofing warnings regarding the change in fallback semantics.

(I'll be away from computers for a week starting now, so any updates to this PR should be either pushed into it, or someone else should adopt the task of polishing this fix and put up their own PR.)
  • Loading branch information
bors committed Apr 21, 2018
2 parents 699eb95 + 42b6d46 commit aa7ce89
Show file tree
Hide file tree
Showing 63 changed files with 188 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/libcore/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
}

/// The error type returned when a conversion from a slice to an array fails.
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
#[derive(Debug, Copy, Clone)]
pub struct TryFromSliceError(());

Expand Down Expand Up @@ -148,7 +148,7 @@ macro_rules! array_impls {
}
}

#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl<'a, T> TryFrom<&'a [T]> for &'a [T; $N] {
type Error = TryFromSliceError;

Expand All @@ -162,7 +162,7 @@ macro_rules! array_impls {
}
}

#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl<'a, T> TryFrom<&'a mut [T]> for &'a mut [T; $N] {
type Error = TryFromSliceError;

Expand Down
6 changes: 3 additions & 3 deletions src/libcore/char/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl FromStr for char {
}


#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<u32> for char {
type Error = CharTryFromError;

Expand All @@ -219,11 +219,11 @@ impl TryFrom<u32> for char {
}

/// The error type returned when a conversion from u32 to char fails.
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct CharTryFromError(());

#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl fmt::Display for CharTryFromError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
"converted integer out of range for `char`".fmt(f)
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/char/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use self::convert::{from_u32, from_digit};
pub use self::convert::from_u32_unchecked;
#[stable(feature = "char_from_str", since = "1.20.0")]
pub use self::convert::ParseCharError;
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
pub use self::convert::CharTryFromError;
#[stable(feature = "decode_utf16", since = "1.9.0")]
pub use self::decode::{decode_utf16, DecodeUtf16, DecodeUtf16Error};
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod impls {
bool char
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Clone for ! {
#[inline]
fn clone(&self) -> Self {
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,24 +881,24 @@ mod impls {

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

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl PartialEq for ! {
fn eq(&self, _: &!) -> bool {
*self
}
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Eq for ! {}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl PartialOrd for ! {
fn partial_cmp(&self, _: &!) -> Option<Ordering> {
*self
}
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Ord for ! {
fn cmp(&self, _: &!) -> Ordering {
*self
Expand Down
12 changes: 4 additions & 8 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,22 @@ pub trait From<T>: Sized {
///
/// [`TryFrom`]: trait.TryFrom.html
/// [`Into`]: trait.Into.html
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
pub trait TryInto<T>: Sized {
/// The type returned in the event of a conversion error.
#[stable(feature = "try_from", since = "1.26.0")]
type Error;

/// Performs the conversion.
#[stable(feature = "try_from", since = "1.26.0")]
fn try_into(self) -> Result<T, Self::Error>;
}

/// Attempt to construct `Self` via a conversion.
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
pub trait TryFrom<T>: Sized {
/// The type returned in the event of a conversion error.
#[stable(feature = "try_from", since = "1.26.0")]
type Error;

/// Performs the conversion.
#[stable(feature = "try_from", since = "1.26.0")]
fn try_from(value: T) -> Result<Self, Self::Error>;
}

Expand Down Expand Up @@ -409,7 +405,7 @@ impl<T> From<T> for T {


// TryFrom implies TryInto
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl<T, U> TryInto<U> for T where U: TryFrom<T>
{
type Error = U::Error;
Expand All @@ -421,7 +417,7 @@ impl<T, U> TryInto<U> for T where U: TryFrom<T>

// Infallible conversions are semantically equivalent to fallible conversions
// with an uninhabited error type.
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl<T, U> TryFrom<U> for T where T: From<U> {
type Error = !;

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,14 +1780,14 @@ macro_rules! fmt_refs {

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

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Debug for ! {
fn fmt(&self, _: &mut Formatter) -> Result {
*self
}
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Display for ! {
fn fmt(&self, _: &mut Formatter) -> Result {
*self
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#![feature(iterator_repeat_with)]
#![feature(lang_items)]
#![feature(link_llvm_intrinsics)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(macro_at_most_once_rep)]
#![feature(no_core)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ mod copy_impls {
bool char
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Copy for ! {}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4192,7 +4192,7 @@ macro_rules! from_str_radix_int_impl {
from_str_radix_int_impl! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }

/// The error type returned when a checked integral type conversion fails.
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
#[derive(Debug, Copy, Clone)]
pub struct TryFromIntError(());

Expand All @@ -4207,14 +4207,14 @@ impl TryFromIntError {
}
}

#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl fmt::Display for TryFromIntError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.__description().fmt(fmt)
}
}

#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl From<!> for TryFromIntError {
fn from(never: !) -> TryFromIntError {
never
Expand All @@ -4224,7 +4224,7 @@ impl From<!> for TryFromIntError {
// only negative bounds
macro_rules! try_from_lower_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<$source> for $target {
type Error = TryFromIntError;

Expand All @@ -4243,7 +4243,7 @@ macro_rules! try_from_lower_bounded {
// unsigned to signed (only positive bound)
macro_rules! try_from_upper_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<$source> for $target {
type Error = TryFromIntError;

Expand All @@ -4262,7 +4262,7 @@ macro_rules! try_from_upper_bounded {
// all other cases
macro_rules! try_from_both_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<$source> for $target {
type Error = TryFromIntError;

Expand Down
1 change: 1 addition & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#![feature(str_internals)]
#![feature(test)]
#![feature(trusted_len)]
#![feature(try_from)]
#![feature(try_trait)]
#![feature(exact_chunks)]
#![cfg_attr(stage0, feature(atomic_nand))]
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#![cfg_attr(windows, feature(libc))]
#![feature(macro_lifetime_matcher)]
#![feature(macro_vis_matcher)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(non_exhaustive)]
#![feature(nonzero)]
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.intern_tup(&[])
}

pub fn mk_diverging_default(self) -> Ty<'tcx> {
if self.features().never_type {
self.types.never
} else {
self.intern_tup(&[])
}
}

pub fn mk_bool(self) -> Ty<'tcx> {
self.mk_ty(TyBool)
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_apfloat/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![forbid(unsafe_code)]

#![feature(try_from)]
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
#[allow(unused_extern_crates)]
extern crate rustc_cratesio_shim;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/build/matches/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
PatternKind::Variant { adt_def, substs, variant_index, ref subpatterns } => {
let irrefutable = adt_def.variants.iter().enumerate().all(|(i, v)| {
i == variant_index || {
self.hir.tcx().features().never_type &&
self.hir.tcx().features().exhaustive_patterns &&
self.hir.tcx().is_variant_uninhabited_from_all_modules(v, substs)
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(nonzero)]
#![feature(inclusive_range_fields)]
#![feature(crate_visibility_modifier)]
#![feature(never_type)]
#![cfg_attr(stage0, feature(try_trait))]

extern crate arena;
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}

// Tries to apply a fallback to `ty` if it is an unsolved variable.
// Non-numerics get replaced with !, unconstrained ints with i32,
// Non-numerics get replaced with ! or () (depending on whether
// feature(never_type) is enabled, unconstrained ints with i32,
// unconstrained floats with f64.
// Fallback becomes very dubious if we have encountered type-checking errors.
// In that case, fallback to TyError.
Expand All @@ -2231,7 +2232,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
_ if self.is_tainted_by_errors() => self.tcx().types.err,
UnconstrainedInt => self.tcx.types.i32,
UnconstrainedFloat => self.tcx.types.f64,
Neither if self.type_var_diverges(ty) => self.tcx.types.never,
Neither if self.type_var_diverges(ty) => self.tcx.mk_diverging_default(),
Neither => return false,
};
debug!("default_type_parameters: defaulting `{:?}` to `{:?}`", ty, fallback);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ This API is completely unstable and subject to change.
#![feature(slice_patterns)]
#![feature(slice_sort_by_cached_key)]
#![feature(dyn_trait)]
#![feature(never_type)]

#[macro_use] extern crate log;
#[macro_use] extern crate syntax;
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl<'a> From<Cow<'a, str>> for Box<Error> {
}
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Error for ! {
fn description(&self) -> &str { *self }
}
Expand Down Expand Up @@ -284,14 +284,14 @@ impl Error for num::ParseIntError {
}
}

#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl Error for num::TryFromIntError {
fn description(&self) -> &str {
self.__description()
}
}

#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl Error for array::TryFromSliceError {
fn description(&self) -> &str {
self.__description()
Expand Down Expand Up @@ -365,7 +365,7 @@ impl Error for cell::BorrowMutError {
}
}

#[stable(feature = "try_from", since = "1.26.0")]
#[unstable(feature = "try_from", issue = "33417")]
impl Error for char::CharTryFromError {
fn description(&self) -> &str {
"converted integer out of range for `char`"
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
#![feature(macro_reexport)]
#![feature(macro_vis_matcher)]
#![feature(needs_panic_runtime)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(nonzero)]
#![feature(num_bits_bytes)]
Expand Down Expand Up @@ -306,6 +307,7 @@
#![feature(test, rustc_private)]
#![feature(thread_local)]
#![feature(toowned_clone_into)]
#![feature(try_from)]
#![feature(try_reserve)]
#![feature(unboxed_closures)]
#![feature(untagged_unions)]
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ mod prim_bool { }
/// write:
///
/// ```
/// #![feature(never_type)]
/// # fn foo() -> u32 {
/// let x: ! = {
/// return 123
Expand Down Expand Up @@ -155,6 +156,7 @@ mod prim_bool { }
/// for example:
///
/// ```
/// #![feature(never_type)]
/// # use std::fmt;
/// # trait Debug {
/// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result;
Expand Down
Loading

0 comments on commit aa7ce89

Please sign in to comment.