Skip to content

diagnostics: rustc displays confusing Ok(#[stable(feature = "rust1", since = "1.0.0")] T) if wrong match binding is used #74673

@matthiaskrgr

Description

@matthiaskrgr

If I have a function that returns Result<(), i32> and try to match on it with Ok() instead of Ok(()) or Ok(_), I get an error:

error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 1 field
   --> src/main.rs:7:9
    |
7   |         Ok() => {}
    |         ^^^^ expected 1 field, found 0
    |
   ::: /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/result.rs:250:5
    |
250 |     Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
    |     --------------------------------------------------- tuple variant defined here
    |
help: missing parenthesis
    |
7   |         Ok(()) => {}
    |           ^  ^

error: aborting due to previous error

The Ok(#[stable(feature = "rust1", since = "1.0.0")] T), comes from std but I think it can look very confusing to beginners, a simple Ok(T) would be much clearer here imo.

code:

fn a() -> Result<(), i32> {
    Ok(())
}

fn main() {
    match a() {
        Ok() => {} // should be: Ok(()) or Ok(_)
        Err(_) => {}
    }
}
binary: rustc
commit-hash: 346aec9b02f3c74f3fce97fd6bda24709d220e49
commit-date: 2020-07-11
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions