Skip to content

Commit 0f31fc6

Browse files
committed
Update examples for never type stabilization
Some of these examples can be simplified with using the never type.
1 parent 1efe67f commit 0f31fc6

4 files changed

Lines changed: 6 additions & 18 deletions

File tree

src/attributes/diagnostics.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,10 @@ As an exception to [attributes.diagnostics.must_use.type], the lint does not fir
401401
```rust
402402
#![deny(unused_must_use)]
403403
# use core::ops::ControlFlow;
404-
enum Empty {}
405-
fn f1() -> Result<(), Empty> { Ok(()) }
406-
f1(); // OK: `Empty` is uninhabited.
407-
fn f2() -> ControlFlow<Empty, ()> { ControlFlow::Continue(()) }
408-
f2(); // OK: `Empty` is uninhabited.
404+
fn f1() -> Result<(), !> { Ok(()) }
405+
f1(); // OK: `!` is uninhabited.
406+
fn f2() -> ControlFlow<!, ()> { ControlFlow::Continue(()) }
407+
f2(); // OK: `!` is uninhabited.
409408
```
410409

411410
r[attributes.diagnostics.must_use.fn]

src/expressions/block-expr.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ r[expr.block.diverging]
9191
A block is considered to be [diverging][divergence] if all reachable control flow paths contain a diverging expression, unless that expression is a [place expression] that is not read from.
9292
9393
```rust,no_run
94-
# #![ feature(never_type) ]
9594
fn no_control_flow() -> ! {
9695
// There are no conditional statements, so this entire function body is diverging.
9796
loop {}
@@ -115,10 +114,6 @@ fn control_flow_not_diverging() -> () {
115114
}
116115
}
117116
118-
// Note: This makes use of the unstable never type which is only available on
119-
// Rust's nightly channel. This is done for illustration purposes. It is
120-
// possible to encounter this scenario in stable Rust, but requires a more
121-
// convoluted example.
122117
struct Foo {
123118
x: !,
124119
}
@@ -133,7 +128,6 @@ fn diverging_place_read() -> ! {
133128
```
134129
135130
```rust,compile_fail,E0308
136-
# #![ feature(never_type) ]
137131
# fn make<T>() -> T { loop {} }
138132
# struct Foo {
139133
# x: !,

src/expressions/match-expr.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ If there are no match arms, then the `match` expression is [diverging] and the t
119119

120120
> [!EXAMPLE]
121121
> ```rust
122-
> # fn make<T>() -> T { loop {} }
123-
> enum Empty {}
124-
>
125-
> fn diverging_match_no_arms() -> ! {
126-
> let e: Empty = make();
122+
> fn diverging_match_no_arms(e: !) -> ! {
127123
> match e {}
128124
> }
129125
> ```

src/types/closure.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ r[type.closure.capture.precision.discriminants.uninhabited-variants]
340340
Even if all variants but the one being matched against are uninhabited, making the pattern [irrefutable][patterns.refutable], the discriminant is still read if it otherwise would be.
341341

342342
```rust,compile_fail,E0502
343-
enum Empty {}
344-
let mut x = Ok::<_, Empty>(42);
343+
let mut x = Ok::<_, !>(42);
345344
let c = || {
346345
let Ok(_) = x; // Captures `x` by `ImmBorrow`.
347346
};

0 commit comments

Comments
 (0)