Skip to content

Commit 6eb0627

Browse files
committed
Gate fallback via #![feature(never_type_fallback)].
1 parent 8f6197f commit 6eb0627

18 files changed

+64
-19
lines changed

src/librustc/ty/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,11 @@ impl<'tcx> TyCtxt<'tcx> {
24402440

24412441
#[inline]
24422442
pub fn mk_diverging_default(self) -> Ty<'tcx> {
2443-
self.types.never
2443+
if self.features().never_type_fallback {
2444+
self.types.never
2445+
} else {
2446+
self.types.unit
2447+
}
24442448
}
24452449

24462450
#[inline]

src/librustc_typeck/check/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,8 +3129,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31293129
}
31303130

31313131
// Tries to apply a fallback to `ty` if it is an unsolved variable.
3132-
// Non-numerics get replaced with `!`, unconstrained ints with `i32`,
3133-
// unconstrained floats with `f64`.
3132+
//
3133+
// - Unconstrained ints are replaced with `i32`.
3134+
//
3135+
// - Unconstrained floats are replaced with with `f64`.
3136+
//
3137+
// - Non-numerics get replaced with `!` when `#![feature(never_type_fallback)]`
3138+
// is enabled. Otherwise, they are replaced with `()`.
3139+
//
31343140
// Fallback becomes very dubious if we have encountered type-checking errors.
31353141
// In that case, fallback to Error.
31363142
// The return value indicates whether fallback has occurred.

src/libsyntax/feature_gate/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ declare_features! (
520520
/// Allows using the `efiapi` ABI.
521521
(active, abi_efiapi, "1.40.0", Some(65815), None),
522522

523+
/// Allows diverging expressions to fall back to `!` rather than `()`.
524+
(active, never_type_fallback, "1.41.0", Some(65992), None),
525+
523526
/// Allows using the `#[register_attr]` attribute.
524527
(active, register_attr, "1.41.0", Some(66080), None),
525528

src/libsyntax_pos/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ symbols! {
444444
negate_unsigned,
445445
never,
446446
never_type,
447+
never_type_fallback,
447448
new,
448449
next,
449450
__next,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ trait Add<RHS=Self> {
2121
fn ice<A>(a: A) {
2222
let r = loop {};
2323
r = r + a;
24-
//~^ ERROR the trait bound `!: Add<A>` is not satisfied
24+
//~^ ERROR the trait bound `(): Add<A>` is not satisfied
2525
}

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

Lines changed: 2 additions & 2 deletions
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:23: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

src/test/ui/binding/empty-types-in-patterns.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-pass
2+
#![feature(never_type_fallback)]
23
#![feature(exhaustive_patterns)]
34
#![feature(slice_patterns)]
45
#![allow(unreachable_patterns)]

src/test/ui/coercion/coerce-issue-49593-box-never.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
2+
#![feature(never_type_fallback)]
33
#![allow(unreachable_code)]
44

55
use std::error::Error;

src/test/ui/never_type/defaulted-never-note.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// We need to opt into the `never_type_fallback` feature
2+
// to trigger the requirement that this is testing.
3+
#![feature(never_type_fallback)]
4+
15
#![allow(unused)]
26

37
trait Deserialize: Sized {

src/test/ui/never_type/defaulted-never-note.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `!: ImplementedForUnitButNotNever` is not satisfied
2-
--> $DIR/defaulted-never-note.rs:23:5
2+
--> $DIR/defaulted-never-note.rs:27:5
33
|
44
LL | fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
55
| --- ----------------------------- required by this bound in `foo`

0 commit comments

Comments
 (0)