Skip to content

Empty "tuple variant defined here" note #105241

Closed

Description

@jruderman

Code

playground

fn f() -> Option<()> {
    Some(0_u32)
}

fn main() {}

Current output

error[E0308]: mismatched types
 --> tvdh.rs:2:10
  |
2 |     Some(0_u32)
  |     ---- ^^^^^ expected `()`, found `u32`
  |     |
  |     arguments to this enum variant are incorrect
  |
note: tuple variant defined here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

The note starting with "note: tuple variant defined here" is confusing. Where is "here"?

I suspect it's trying to to show part of the definition of the Option type, but failing because the definition is in a different crate (or because it's part of std).

Ideal output

Don't try to show the enum-variant definition when it can't be shown, I guess?

For cases like this one that involve generics, see #105240 for a proposed alternative.

Regression

The empty note first appears in nightly-2022-06-12

Version

rustc 1.67.0-nightly (32e613bba 2022-12-02)
binary: rustc
commit-hash: 32e613bbaafee1bcabba48a2257b838f8d1c03d3
commit-date: 2022-12-02
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Dec 4, 2022
  2. jieyouxu commented on May 30, 2023

    @jieyouxu
    Member

    This seems to have been fixed, on stable (1.69.0) it produces

    error[E0308]: mismatched types
       --> test.rs:2:10
        |
    2   |     Some(0_u32)
        |     ---- ^^^^^ expected `()`, found `u32`
        |     |
        |     arguments to this enum variant are incorrect
        |
    help: the type constructed contains `u32` due to the type of the argument passed
       --> test.rs:2:5
        |
    2   |     Some(0_u32)
        |     ^^^^^-----^
        |          |
        |          this argument influences the type of `Some`
    note: tuple variant defined here
       --> /home/jieyouxu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:571:5
        |
    571 |     Some(#[stable(feature = "rust1", since = "1.0.0")] T),
        |    
    rustc 1.69.0 (84c898d65 2023-04-16)
    binary: rustc
    commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
    commit-date: 2023-04-16
    host: x86_64-unknown-linux-gnu
    release: 1.69.0
    LLVM version: 15.0.7
    
  3. jruderman commented on Nov 5, 2023

    @jruderman
    ContributorAuthor

    The filename option.rs is now shown (fixed in #104449)

    The new hint "... due to the type of the argument passed" was added in #106752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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