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

Confusing error message: "Expected Foo, found Foo" #121944

Closed
pacak opened this issue Mar 3, 2024 · 2 comments
Closed

Confusing error message: "Expected Foo, found Foo" #121944

pacak opened this issue Mar 3, 2024 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pacak
Copy link
Contributor

pacak commented Mar 3, 2024

Code

struct Foo<'a> {
    value: &'a str,
}

impl<'a> Bar for Foo<'a> {
    fn get(&self) -> &'a str {
        self.value
    }
}

fn make<'b>(s: &'b str) -> Foo<'b> {
    Foo { value: s }
}

trait Bar {
    fn get(&self) -> &str;
}

fn gmake<T, F>(_build: F)
where
    F: Fn(&str) -> T,
    T: Bar,
{
    todo!()
}

fn foo() {
    gmake(make);
}

Current output

error[E0308]: mismatched types
  --> src/lib.rs:28:5
   |
28 |     gmake(make);
   |     ^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected struct `Foo<'_>`
              found struct `Foo<'_>`
note: the lifetime requirement is introduced here
  --> src/lib.rs:21:20
   |
21 |     F: Fn(&str) -> T,
   |                    ^

Desired output

Anything that would explain the difference between expected `Foo` and actual `Foo`

Rationale and extra context

Expected "XXX", found "XXX" is wrong when XXX is exactly the same.

Other cases

No response

Rust Version

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Or most recent nightly as of today

Anything else?

No response

@pacak pacak added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 3, 2024
@fmease fmease added A-lifetimes Area: Lifetimes / regions D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Mar 3, 2024
@pacak
Copy link
Contributor Author

pacak commented Mar 3, 2024

30+ duplicates

Ouch. I guess we can close this one then, I should try to search more carefully next time.

@fmease
Copy link
Member

fmease commented Mar 3, 2024

No worries! It helps to remind me that I'd really like to see this general issue fixed / fix it myself.
Let's close it but I'll keep it in the list of #112985,
so we can double-check if the future fix 🤞 does fix this instance, too.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants