Skip to content

Commit aaefa94

Browse files
committed
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: rust-lang#49691 (comment)
1 parent fadabd6 commit aaefa94

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

src/librustc/ty/context.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23742374
self.intern_tup(&[])
23752375
}
23762376

2377+
pub fn mk_diverging_default(self) -> Ty<'tcx> {
2378+
if self.features().never_type {
2379+
self.types.never
2380+
} else {
2381+
self.intern_tup(&[])
2382+
}
2383+
}
2384+
23772385
pub fn mk_bool(self) -> Ty<'tcx> {
23782386
self.mk_ty(TyBool)
23792387
}

src/librustc_typeck/check/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
22172217
}
22182218

22192219
// Tries to apply a fallback to `ty` if it is an unsolved variable.
2220-
// Non-numerics get replaced with !, unconstrained ints with i32,
2220+
// Non-numerics get replaced with ! or () (depending on whether
2221+
// feature(never_type) is enabled, unconstrained ints with i32,
22212222
// unconstrained floats with f64.
22222223
// Fallback becomes very dubious if we have encountered type-checking errors.
22232224
// In that case, fallback to TyError.
@@ -2231,7 +2232,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
22312232
_ if self.is_tainted_by_errors() => self.tcx().types.err,
22322233
UnconstrainedInt => self.tcx.types.i32,
22332234
UnconstrainedFloat => self.tcx.types.f64,
2234-
Neither if self.type_var_diverges(ty) => self.tcx.types.never,
2235+
Neither if self.type_var_diverges(ty) => self.tcx.mk_diverging_default(),
22352236
Neither => return false,
22362237
};
22372238
debug!("default_type_parameters: defaulting `{:?}` to `{:?}`", ty, fallback);

src/test/compile-fail/defaulted-never-note.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// We need to opt inot the `!` feature in order to trigger the
12+
// requirement that this is testing.
13+
#![feature(never_type)]
14+
1115
#![allow(unused)]
1216

1317
trait Deserialize: Sized {

src/test/ui/associated-types-ICE-when-projecting-out-of-err.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ trait Add<RHS=Self> {
3131
fn ice<A>(a: A) {
3232
let r = loop {};
3333
r = r + a;
34-
//~^ ERROR the trait bound `!: Add<A>` is not satisfied
34+
//~^ ERROR the trait bound `(): Add<A>` is not satisfied
3535
}

src/test/ui/associated-types-ICE-when-projecting-out-of-err.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `!: Add<A>` is not satisfied
1+
error[E0277]: the trait bound `(): Add<A>` is not satisfied
22
--> $DIR/associated-types-ICE-when-projecting-out-of-err.rs:33:11
33
|
44
LL | r = r + a;
5-
| ^ the trait `Add<A>` is not implemented for `!`
5+
| ^ the trait `Add<A>` is not implemented for `()`
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)