Skip to content

Cannot compile todo!() in functions returning impl Trait with associated types #117293

@nicklimmm

Description

@nicklimmm

I tried this code:

trait Trait {
    type Type;
}

fn foo() -> impl Trait<Type = ()> {
    todo!()
}

Expected:

  • Compile without errors, similar to when returning other types such as i32, etc.

Instead, this happened:

error[E0277]: the trait bound `(): Trait` is not satisfied
 --> src/main.rs:5:13
  |
5 | fn foo() -> impl Trait<Type = ()> {
  |             ^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `()`
  |

Question:

  • Could this be caused by the behavior of having the ! type in the function body?

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (aa1a71e9e 2023-10-26)
binary: rustc
commit-hash: aa1a71e9e90f6eb3aed8cf79fc80bea304c17ecb
commit-date: 2023-10-26
host: aarch64-apple-darwin
release: 1.75.0-nightly
LLVM version: 17.0.3
Backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions