Skip to content

fn() -> impl T { todo!() } not compiling #116003

@axos88

Description

@axos88

I tried this code:

trait Foo {}


fn not_implemented() -> impl Foo {
    todo!()
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=55e475624b24e243aef53a2ace435156

I expected to see this happen: compiles.

Instead, this happened:

Compiling playground v0.0.1 (/playground)
error[[E0277]](https://doc.rust-lang.org/stable/error_codes/E0277.html): the trait bound `(): Foo` is not satisfied
 --> src/lib.rs:4:25
  |
4 | fn not_implemented() -> impl Foo {
  |                         ^^^^^^^^ the trait `Foo` is not implemented for `()`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to previous error

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.73.0-nightly (180dffba1 2023-08-14)
binary: rustc
commit-hash: 180dffba142c47240ca0d93096ce90b9fd97c8d7
commit-date: 2023-08-14
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 17.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions