-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed as not planned
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
trait T {}
fn foo() -> impl T {
todo!()
}
fn bar<U: T>() -> U {
todo!()
}
Function foo
fails to compile, while bar
is ok. The compiler reports the following error:
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `(): T` is not satisfied
--> src/lib.rs:3:13
|
3 | fn foo() -> impl T {
| ^^^^^^ the trait `T` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> src/lib.rs:1:1
|
1 | trait T {}
| ^^^^^^^
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 1 previous error
I'm using rustc
1.76.0, however, the nightly version (2024-02-21 3406ada) also produces the same error.
PS: It's the same result for returning impl Future
and async functions, I think it might be the same problem (in the following code, foo
fails to compile, while bar
is ok):
use std::future::Future;
fn foo() -> impl Future {
todo!()
}
async fn bar() {
todo!()
}
Metadata
Metadata
Assignees
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.