Closed
Description
Using the as
syntax does not work as a generic to an impl Trait in return position.
trait A { type Foo; }
impl<T> A for T { type Foo = (); }
fn foo() -> impl std::borrow::Borrow<<u8 as A>::Foo> {
()
}
Error
error[E0277]: the trait bound `(): std::borrow::Borrow<<u8 as A>::Foo>` is not satisfied
--> src/lib.rs:4:13
|
4 | fn foo() -> impl std::borrow::Borrow<<u8 as A>::Foo> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::borrow::Borrow<<u8 as A>::Foo>` is not implemented for `()`
|
= help: consider adding a `where (): std::borrow::Borrow<<u8 as A>::Foo>` bound
= note: the return type of a function must have a statically known size
As a parameter it does work:
trait A { type Foo; }
impl<T> A for T { type Foo = (); }
fn foo(p: impl std::borrow::Borrow<<u8 as A>::Foo>) {}
fn call_foo() {
foo(())
}
This issue looks related, but specifically calls out type equality constraints. #53984
Metadata
Metadata
Assignees
Labels
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Lazy normalization (tracking issue: #60471)Area: Trait systemCategory: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Relevant to the compiler team, which will review and decide on the PR/issue.