Skip to content

The todo! macro does not play well with RPIT #121449

@sillykelvin

Description

@sillykelvin

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

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.S-has-mcveStatus: 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions