Skip to content

Commit e7c614b

Browse files
pnkfelixalexcrichton
authored andcommitted
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: #49691 (comment)
1 parent 1bc6989 commit e7c614b

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
@@ -2181,6 +2181,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
21812181
self.intern_tup(&[])
21822182
}
21832183

2184+
pub fn mk_diverging_default(self) -> Ty<'tcx> {
2185+
if self.features().never_type {
2186+
self.types.never
2187+
} else {
2188+
self.intern_tup(&[])
2189+
}
2190+
}
2191+
21842192
pub fn mk_bool(self) -> Ty<'tcx> {
21852193
self.mk_ty(TyBool)
21862194
}

src/librustc_typeck/check/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
22002200
}
22012201

22022202
// Tries to apply a fallback to `ty` if it is an unsolved variable.
2203-
// Non-numerics get replaced with !, unconstrained ints with i32,
2203+
// Non-numerics get replaced with ! or () (depending on whether
2204+
// feature(never_type) is enabled, unconstrained ints with i32,
22042205
// unconstrained floats with f64.
22052206
// Fallback becomes very dubious if we have encountered type-checking errors.
22062207
// In that case, fallback to TyError.
@@ -2214,7 +2215,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
22142215
_ if self.is_tainted_by_errors() => self.tcx().types.err,
22152216
UnconstrainedInt => self.tcx.types.i32,
22162217
UnconstrainedFloat => self.tcx.types.f64,
2217-
Neither if self.type_var_diverges(ty) => self.tcx.types.never,
2218+
Neither if self.type_var_diverges(ty) => self.tcx.mk_diverging_default(),
22182219
Neither => return false,
22192220
};
22202221
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)