mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 16:57:03 +00:00
8221f9c837
On functions with a default return type that influences the coerced type of `match` arms, check if the failing arm is actually of type `!`. If so, suggest changing the return type so the coercion against the prior arms is successful. ``` error[E0308]: `match` arms have incompatible types --> $DIR/match-tail-expr-never-type-error.rs:9:13 | LL | fn bar(a: bool) { | - help: try adding a return type: `-> i32` LL | / match a { LL | | true => 1, | | - this is found to be of type `{integer}` LL | | false => { LL | | never() | | ^^^^^^^ | | | | | expected integer, found `()` | | this expression is of type `!`, but it get's coerced to `()` due to its surrounding expression LL | | } LL | | } | |_____- `match` arms have incompatible types ``` Fix #24157.
22 lines
760 B
Plaintext
22 lines
760 B
Plaintext
error[E0308]: `match` arms have incompatible types
|
|
--> $DIR/match-tail-expr-never-type-error.rs:9:13
|
|
|
|
|
LL | fn bar(a: bool) {
|
|
| - help: try adding a return type: `-> i32`
|
|
LL | / match a {
|
|
LL | | true => 1,
|
|
| | - this is found to be of type `{integer}`
|
|
LL | | false => {
|
|
LL | | never()
|
|
| | ^^^^^^^
|
|
| | |
|
|
| | expected integer, found `()`
|
|
| | this expression is of type `!`, but it is coerced to `()` due to its surrounding expression
|
|
LL | | }
|
|
LL | | }
|
|
| |_____- `match` arms have incompatible types
|
|
|
|
error: aborting due to 1 previous error
|
|
|
|
For more information about this error, try `rustc --explain E0308`.
|