rust-lang / rust-lang/rust

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

Open
#136,670 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the minimized program from the issue on stable 1.84.1 and the noted nightly, focusing on the E0277 diagnostic at src/main.rs:22. Done when the compiler no longer reports that &() both does and does not implement Foo, while still explaining the unsatisfied bound.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.