Skip to content

Cannot find impl of trait with literal &'static str const parameter #66596

Closed
@rodrimati1992

Description

@rodrimati1992

This code ran in the latest nightly(2019-11-19) in the playground does not compile:

#![feature(const_generics)]

trait FieldType<const NAME: &'static str> {
    type FieldType;
}

impl<T> FieldType<"0"> for (T,) {
    type FieldType = T;
}

fn main() {
    let _: <(Vec<u32>,) as FieldType<"0">>::FieldType = vec![100];
}

And it prints this error message

error[E0277]: the trait bound `(std::vec::Vec<u32>,): FieldType<"0">` is not satisfied
  --> src/main.rs:12:12
   |
12 |     let _: <(Vec<u32>,) as FieldType<"0">>::FieldType = vec![100];
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FieldType<"0">` is not implemented for `(std::vec::Vec<u32>,)`
   |
   = help: the following implementations were found:
             <(T,) as FieldType<"0">>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions