Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected error when resolving bounds involving associated types #133314

Open
klkvr opened this issue Nov 21, 2024 · 1 comment
Open

Unexpected error when resolving bounds involving associated types #133314

klkvr opened this issue Nov 21, 2024 · 1 comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@klkvr
Copy link

klkvr commented Nov 21, 2024

I am trying to compile the following code

struct MyBlock;

trait Block {
    type Header;
}
impl Block for MyBlock {
    type Header = ();
}

trait Header {}
impl Header for () {}

trait FullBlock: Block<Header: Header> {}
impl<T> FullBlock for T where T: Block<Header: Header> {}

trait Primitives {
    type Block;
}

trait FullPrimitives: Primitives<Block: FullBlock<Header = Self::Header>> {
    type Header;
}

impl<T> FullPrimitives for T where T: Primitives<Block: FullBlock> {
    type Header = <<T as Primitives>::Block as Block>::Header;
}

fn test<P: FullPrimitives<Block = MyBlock>>() {}

The compilation is failing with:

error[E0283]: type annotations needed: cannot satisfy `MyBlock: FullBlock`
  --> src/main.rs:30:12
   |
30 | fn test<P: FullPrimitives<Block = MyBlock>>() {}
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: cannot satisfy `MyBlock: FullBlock`
note: required by a bound in `FullPrimitives`
  --> src/main.rs:22:41
   |
22 | trait FullPrimitives: Primitives<Block: FullBlock<Header = Self::Header>> {
   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `FullPrimitives`

For more information about this error, try `rustc --explain E0283`.
error: could not compile `my_project` (bin "my") due to 1 previous error

However, if I relax the FullBlock trait requirements it compiles fine

-trait FullBlock: Block<Header: Header> {}
-impl<T> FullBlock for T where T: Block<Header: Header> {}
+trait FullBlock: Block {}
+impl<T> FullBlock for T where T: Block {}

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (c1db4dc24 2024-10-25)
binary: rustc
commit-hash: c1db4dc24267a707409c9bf2e67cf3c7323975c8
commit-date: 2024-10-25
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.1

@klkvr klkvr added the C-bug Category: This is a bug. label Nov 21, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 21, 2024
@lolbinarycat lolbinarycat added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. labels Nov 25, 2024
@lolbinarycat
Copy link
Contributor

triage: -Znext-solver fixes this and causes the code to compile.

@lolbinarycat lolbinarycat removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants