Bring back old fallback semantics: Without feature(never_type), fallback to (), not !.

Note that this commit, since it is trying to be minimal in order to
ease backporting to the beta and release channels, does *not* include
the old future-proofing warnings that we used to have associated with
such fallback to `()`; see discussion at this comment:

https://github.com/rust-lang/rust/issues/49691#issuecomment-381266730
This commit is contained in:
Felix S. Klock II 2018-04-20 17:11:28 +02:00
parent fadabd6fbb
commit aaefa947ac
5 changed files with 18 additions and 5 deletions

View File

@ -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)
}

View File

@ -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.
@ -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);

View File

@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// We need to opt inot the `!` feature in order to trigger the
// requirement that this is testing.
#![feature(never_type)]
#![allow(unused)]
trait Deserialize: Sized {

View File

@ -31,5 +31,5 @@ trait Add<RHS=Self> {
fn ice<A>(a: A) {
let r = loop {};
r = r + a;
//~^ ERROR the trait bound `!: Add<A>` is not satisfied
//~^ ERROR the trait bound `(): Add<A>` is not satisfied
}

View File

@ -1,8 +1,8 @@
error[E0277]: the trait bound `!: Add<A>` is not satisfied
error[E0277]: the trait bound `(): Add<A>` is not satisfied
--> $DIR/associated-types-ICE-when-projecting-out-of-err.rs:33:11
|
LL | r = r + a;
| ^ the trait `Add<A>` is not implemented for `!`
| ^ the trait `Add<A>` is not implemented for `()`
error: aborting due to previous error