Skip to content

Complaint about trait not being implemented #61935

Closed

Description

Rustc complains about the trait not being implemented for [(); _], but actually it's given a [(); 1] literal and for that one, the trait is implemented. Turbofishing foo::<[(); 0]>([]) doesn't help.

cc @varkor @rodrimati1992

see also #61383

Code ↓

#![feature(const_generics)]
trait Foo {}

impl<const N: usize> Foo for [(); N]
where
    Self:FooImpl<{N==0}>
{}

trait FooImpl<const IS_ZERO: bool>{}

impl FooImpl<{0u8==0u8}> for [();0] {}

impl<const N:usize> FooImpl<{0u8!=0u8}> for [();N] {}

fn foo<T: Foo>(v: T) {}

fn main() {
    foo([]);
    foo([()]);
}

Error ↓

error[E0277]: the trait bound `[(); _]: FooImpl<{N==0}>` is not satisfied
  --> src/lib.rs:18:5
   |
18 |     foo([]);
   |     ^^^ the trait `FooImpl<{N==0}>` is not implemented for `[(); _]`
   |
   = help: the following implementations were found:
             <[(); 0] as FooImpl<true>>
             <[(); _] as FooImpl<false>>
   = note: required because of the requirements on the impl of `Foo` for `[(); 0]`
note: required by `foo`
  --> src/lib.rs:15:1
   |
15 | fn foo<T: Foo>(v: T) {}
   | ^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `[(); _]: FooImpl<{N==0}>` is not satisfied
  --> src/lib.rs:19:5
   |
19 |     foo([()]);
   |     ^^^ the trait `FooImpl<{N==0}>` is not implemented for `[(); _]`
   |
   = help: the following implementations were found:
             <[(); 0] as FooImpl<true>>
             <[(); _] as FooImpl<false>>
   = note: required because of the requirements on the impl of `Foo` for `[(); 1]`
note: required by `foo`
  --> src/lib.rs:15:1
   |
15 | fn foo<T: Foo>(v: T) {}
   | ^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-const_generics`#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions