Skip to content

30+ duplicates on E0308 with expected and found being literally identical #112985

Open
@hartwork

Description

Hi! 👋

I was about to report a compiler diagnostics bug and then noticed that this things has 30+ duplicates here going back until January 2019 that are 99% open as of the moment, and not strongly interlinked. The pattern is this:

  1. Diagnostic "one type is more general than the other"
  2. The details saying that the compiler literally got what they expected a la "note: expected " and "found ".
  3. Often a reference to E0308 also

There is one concrete visual example with code further down.

After going through the first six pages of of matches for "one type is more general than the other" I stopped. Excluding unrelated ones, so far I found all of these as likely duplicates of this symptom:

Should one of these become the master issue?

Before you mass-close all the others, please verify that they are actual duplicates and didn't just fool me to believe they are.

Thank you!


PS: For completeness, my very broken diagnostics output was this, verbose rustc version included:

# cargo build
   Compiling issueXXX v0.1.0 (/tmp/tmp.5dilaGzlwK/issueXXX)
error[E0308]: mismatched types
   --> src/main.rs:9:14
    |
9   |         .arg(Arg::new("services").value_parser(parse_value))
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
    = note: expected trait `for<'a> <for<'a> fn(&'a str) -> Result<&'a str, &'a str> {parse_value} as FnOnce<(&'a str,)>>`
               found trait `for<'a> <for<'a> fn(&'a str) -> Result<&'a str, &'a str> {parse_value} as FnOnce<(&'a str,)>>`
note: the lifetime requirement is introduced here
   --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/clap_builder-4.3.8/src/builder/arg.rs:975:48
    |
975 |     pub fn value_parser(mut self, parser: impl IntoResettable<super::ValueParser>) -> Self {
    |                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `issueXXX` due to previous error

# rustc --version --verbose
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

And the related minimal reproducer code is this:

use clap::{Arg, Command};

fn parse_value(_text: &str) -> Result<&str, &str> {
    todo!()
}

fn main() {
    Command::new("rust-for-it")
        .arg(Arg::new("services").value_parser(parse_value))
        .get_matches();
}

Activity

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

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-lifetimesArea: Lifetimes / regionsD-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.metabugIssues about issues themselves ("bugs about bugs")

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions