about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2018-04-20 17:11:28 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2018-04-20 18:09:59 +0200
commitaaefa947ac507ff77049d27f927ddffe1b73cb18 (patch)
tree0298befc23541521ad321c42242217525b00195e /src
parentfadabd6fbbfe1a401bbdd4ba0919b21ba4f7c5d2 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/context.rs8
-rw-r--r--src/librustc_typeck/check/mod.rs5
-rw-r--r--src/test/compile-fail/defaulted-never-note.rs4
-rw-r--r--src/test/ui/associated-types-ICE-when-projecting-out-of-err.rs2
-rw-r--r--src/test/ui/associated-types-ICE-when-projecting-out-of-err.stderr4
5 files changed, 18 insertions, 5 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 28ad5edbd2d..f3a2aa51946 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -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)
     }
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index ca35153d571..acde10a6396 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -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);
diff --git a/src/test/compile-fail/defaulted-never-note.rs b/src/test/compile-fail/defaulted-never-note.rs
index 798544f1649..ac8ac85824e 100644
--- a/src/test/compile-fail/defaulted-never-note.rs
+++ b/src/test/compile-fail/defaulted-never-note.rs
@@ -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 {
diff --git a/src/test/ui/associated-types-ICE-when-projecting-out-of-err.rs b/src/test/ui/associated-types-ICE-when-projecting-out-of-err.rs
index 052575de4c2..75b60aa8d10 100644
--- a/src/test/ui/associated-types-ICE-when-projecting-out-of-err.rs
+++ b/src/test/ui/associated-types-ICE-when-projecting-out-of-err.rs
@@ -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
 }
diff --git a/src/test/ui/associated-types-ICE-when-projecting-out-of-err.stderr b/src/test/ui/associated-types-ICE-when-projecting-out-of-err.stderr
index c22a645385a..7924ab74444 100644
--- a/src/test/ui/associated-types-ICE-when-projecting-out-of-err.stderr
+++ b/src/test/ui/associated-types-ICE-when-projecting-out-of-err.stderr
@@ -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