Skip to content

Commit 88a1e81

Browse files
committed
try to fixup code examples
1 parent 509ac7d commit 88a1e81

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/rust-2024/never-type-fallback.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
When the compiler sees a value of type ! in a [coercion site],
1212
it implicitly inserts a coercion to allow the type checker to infer any type:
1313

14-
```rust
14+
```rust,ignore (has placeholders)
1515
// this
1616
let x: u8 = panic!();
1717
@@ -25,7 +25,7 @@ fn absurd<T>(_: !) -> T { ... }
2525

2626
This can lead to compilation errors if the type cannot be inferred:
2727

28-
```rust
28+
```rust,ignore (uses code from previous example)
2929
// this
3030
{ panic!() };
3131
@@ -36,7 +36,7 @@ This can lead to compilation errors if the type cannot be inferred:
3636
To prevent such errors, the compiler remembers where it inserted absurd calls,
3737
and if it can’t infer the type, it uses the fallback type instead:
3838

39-
```rust
39+
```rust,ignore (has placeholders, uses code from previous example)
4040
type Fallback = /* An arbitrarily selected type! */;
4141
{ absurd::<Fallback>(panic!()) }
4242
```
@@ -67,7 +67,7 @@ The complication is that it might not be trivial to see which type needs to be s
6767
One of the most common patterns which are broken by this change is using `f()?;` where `f` is
6868
generic over the ok-part of the return type:
6969

70-
```rust
70+
```rust,ignore (can't compile outside of a result-returning function)
7171
fn f<T: Default>() -> Result<T, ()> {
7272
Ok(T::default())
7373
}
@@ -80,19 +80,19 @@ desugaring of `?` operator it used to be inferred to `()`, but it will be inferr
8080

8181
To fix the issue you need to specify the `T` type explicitly:
8282

83-
```rust
83+
```rust,ignore (can't compile outside of a result-returning function, mentions function from previous example)
8484
f::<()>()?;
8585
// OR
8686
() = f()?;
8787
```
8888

8989
Another relatively common case is `panic`king in a closure:
9090

91-
```rust
91+
```rust,edition2015
9292
trait Unit {}
9393
impl Unit for () {}
9494
95-
fn run(f: impl FnOnce() -> impl Unit) {
95+
fn run<R: Unit>(f: impl FnOnce() -> R) {
9696
f();
9797
}
9898

0 commit comments

Comments
 (0)