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

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

Closed
rodrimati1992 opened this issue Nov 21, 2019 · 3 comments · Fixed by #70939
Closed

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

rodrimati1992 opened this issue Nov 21, 2019 · 3 comments · Fixed by #70939
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rodrimati1992
Copy link
Contributor

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">>
@rodrimati1992 rodrimati1992 changed the title Cannot find impl of trait with literal &'static str const parameter Cannot find impl of trait with literal &'static str const parameter Nov 21, 2019
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 21, 2019
@Centril
Copy link
Contributor

Centril commented Nov 21, 2019

Reduced:

#![feature(const_generics)]

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

impl FieldType<"0"> for i32 {}

fn main() {
    let _: <i32 as FieldType<"0">>::FieldType;
}

@varkor
Copy link
Member

varkor commented Nov 21, 2019

@Centril: that gives a different error, because FieldType isn't defined. Perhaps you meant something like:

#![feature(const_generics)]

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

impl Trait<"0"> for () {
    type Assoc = ();
}

fn main() {
    let _: <() as Trait<"0">>::Assoc = ();
}

@varkor
Copy link
Member

varkor commented Apr 8, 2020

This appears to be working now.

@varkor varkor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 8, 2020
@Centril Centril added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Apr 8, 2020
varkor added a commit to varkor/rust that referenced this issue Apr 9, 2020
@bors bors closed this as completed in 7944f39 Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants