Skip to content

Rust says that a type both implements and doesn't implement a trait. #136670

@theemathas

Description

@theemathas

Code

struct Dummy;
trait WithLifetime {
    type Output<'a>;
}
impl WithLifetime for Dummy {
    type Output<'a> = &'a ();
}

trait Unimplemented {}

trait Foo {}
impl<T> Foo for T where T: Unimplemented {}
impl<'a> Foo for &'a () where for<'b> Dummy: WithLifetime<Output<'b> = &'a ()> {}

fn what<'a>()
where
    &'a (): Foo,
{
}

fn main() {
    what();
}

Current output

error[E0277]: the trait bound `&(): Foo` is not satisfied
  --> src/main.rs:22:5
   |
22 |     what();
   |     ^^^^^^ the trait `Foo` is not implemented for `&()`
   |
   = help: the trait `Foo` is not implemented for `&()`
           but trait `Foo` is implemented for it
note: required by a bound in `what`
  --> src/main.rs:17:13
   |
15 | fn what<'a>()
   |    ---- required by a bound in this function
16 | where
17 |     &'a (): Foo,
   |             ^^^ required by this bound in `what`

For more information about this error, try `rustc --explain E0277`.

Desired output

Probably don't claim that `&()` both implements and doesn't implement `Foo`

Rationale and extra context

This issue is discovered while minimizing the code from #136666, which ICEs instead.

Other cases

Rust Version

Reproducible on the rust playground with stable rust 1.84.1 and nightly rust `1.86.0-nightly (2025-02-06 942db6782f4a28c55b0b)`

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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