Compiler can't unify arg-position impl Trait
into an HRTB #119045
Open
Description
opened on Dec 17, 2023
It looks like using arg: impl Trait
makes the compiler unable to generalize the entire function-type into HRTB (?), that is:
fn foo(_: &str) {
//
}
fn bar(_: impl AsRef<str>) {
//
}
fn zar<T>(_: T) {
//
}
fn check(_: impl Fn(&str)) {
//
}
fn main() {
check(foo); // ok
check(bar); // err (implementation not general enough)
check(zar::<&str>); // err (ditto)
}
Using a no-op closure helps:
fn main() {
check(|x| bar(x));
}
... but is somewhat inconvenient (spotted in the wild at clap-rs/clap#4939).
Note that I'm reporting this is a bug, but I'm not really sure on the category here - it just feels like this code should pass type-checking, but maybe there's some deeper reason why it can't.
Activity