Skip to content

Compiler doesn't think that an associate type implements const trait #101982

Closed
@fee1-dead

Description

@fee1-dead

I tried this code: play

#![feature(const_trait_impl)]

#[const_trait]
trait Foo {
    type Assoc: ~const Foo;
    fn foo() {}
}

const fn foo<T: ~const Foo>() {
    <T as Foo>::Assoc::foo();
}

I expected to see this happen: Compiles

Instead, this happened: errors

error[E0277]: the trait bound `<T as Foo>::Assoc: ~const Foo` is not satisfied
  --> src/lib.rs:10:5
   |
10 |     <T as Foo>::Assoc::foo();
   |     ^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Foo` is not implemented for `<T as Foo>::Assoc`
   |
note: the trait `Foo` is implemented for `<T as Foo>::Assoc`, but that implementation is not `const`
  --> src/lib.rs:10:5
   |
10 |     <T as Foo>::Assoc::foo();
   |     ^^^^^^^^^^^^^^^^^^^^^^
help: consider further restricting the associated type
   |
9  | const fn foo<T: ~const Foo>() where <T as Foo>::Assoc: ~const Foo {
   |                               +++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]`

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions