Skip to content

Commit

Permalink
Bring back old fallback semantics: Without feature(never_type), fallb…
Browse files Browse the repository at this point in the history
…ack 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:

rust-lang#49691 (comment)
  • Loading branch information
pnkfelix committed Apr 20, 2018
1 parent fadabd6 commit aaefa94
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
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
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
4 changes: 4 additions & 0 deletions src/test/compile-fail/defaulted-never-note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit aaefa94

Please sign in to comment.