Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for ! arm in tail match expr #117526

Merged
merged 1 commit into from
Nov 28, 2023
Merged

Commits on Nov 27, 2023

  1. Account for ! arm in tail match expr

    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 rust-lang#24157.
    estebank committed Nov 27, 2023
    Configuration menu
    Copy the full SHA
    8221f9c View commit details
    Browse the repository at this point in the history