Confusing error message: "Expected Foo, found Foo" #121944
Closed as not planned
Description
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