Skip to content

Integral type mismatch error messages should use "expression" instead of "variable" #56115

Closed
@dooblad

Description

@dooblad

Type mismatch error messages involving integral expressions use the word "variable", when the problematic term is an expression.

I tried this code:

fn main() {
    let f = if true {
        ()
    } else {
        1
    };
}

I expected to see this happen:

<code sample that causes the bug>
error[E0308]: if and else have incompatible types
 --> src/main.rs:2:13
  |
2 |       let f = if true {
  |  _____________^
3 | |         ()
4 | |     } else {
5 | |         1
6 | |     };
  | |_____^ expected (), found integral expression
  |
  = note: expected type `()`
             found type `{integer}`

Instead, this happened:

<code sample that causes the bug>
error[E0308]: if and else have incompatible types
 --> src/main.rs:2:13
  |
2 |       let f = if true {
  |  _____________^
3 | |         ()
4 | |     } else {
5 | |         1
6 | |     };
  | |_____^ expected (), found integral variable
  |
  = note: expected type `()`
             found type `{integer}`

Meta

rustc --version --verbose:

rustc 1.31.0-nightly (3e6f30ec3 2018-10-26)
binary: rustc
commit-hash: 3e6f30ec3e6bda159063fcd126dcb14725fef92d
commit-date: 2018-10-26
host: x86_64-apple-darwin
release: 1.31.0-nightly
LLVM version: 8.0

Backtrace: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions