11
11
When the compiler sees a value of type ! in a [ coercion site] ,
12
12
it implicitly inserts a coercion to allow the type checker to infer any type:
13
13
14
- ``` rust
14
+ ``` rust,ignore (has placeholders)
15
15
// this
16
16
let x: u8 = panic!();
17
17
@@ -25,7 +25,7 @@ fn absurd<T>(_: !) -> T { ... }
25
25
26
26
This can lead to compilation errors if the type cannot be inferred:
27
27
28
- ``` rust
28
+ ``` rust,ignore (uses code from previous example)
29
29
// this
30
30
{ panic!() };
31
31
@@ -36,7 +36,7 @@ This can lead to compilation errors if the type cannot be inferred:
36
36
To prevent such errors, the compiler remembers where it inserted absurd calls,
37
37
and if it can’t infer the type, it uses the fallback type instead:
38
38
39
- ``` rust
39
+ ``` rust,ignore (has placeholders, uses code from previous example)
40
40
type Fallback = /* An arbitrarily selected type! */;
41
41
{ absurd::<Fallback>(panic!()) }
42
42
```
@@ -67,7 +67,7 @@ The complication is that it might not be trivial to see which type needs to be s
67
67
One of the most common patterns which are broken by this change is using ` f()?; ` where ` f ` is
68
68
generic over the ok-part of the return type:
69
69
70
- ``` rust
70
+ ``` rust,ignore (can't compile outside of a result-returning function)
71
71
fn f<T: Default>() -> Result<T, ()> {
72
72
Ok(T::default())
73
73
}
@@ -80,19 +80,19 @@ desugaring of `?` operator it used to be inferred to `()`, but it will be inferr
80
80
81
81
To fix the issue you need to specify the ` T ` type explicitly:
82
82
83
- ``` rust
83
+ ``` rust,ignore (can't compile outside of a result-returning function, mentions function from previous example)
84
84
f::<()>()?;
85
85
// OR
86
86
() = f()?;
87
87
```
88
88
89
89
Another relatively common case is ` panic ` king in a closure:
90
90
91
- ``` rust
91
+ ``` rust,edition2015
92
92
trait Unit {}
93
93
impl Unit for () {}
94
94
95
- fn run (f : impl FnOnce () -> impl Unit ) {
95
+ fn run<R: Unit> (f: impl FnOnce() -> R ) {
96
96
f();
97
97
}
98
98
0 commit comments