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

Compiler error on impl with const generic #60800

Closed
imbrem opened this issue May 13, 2019 · 1 comment
Closed

Compiler error on impl with const generic #60800

imbrem opened this issue May 13, 2019 · 1 comment

Comments

@imbrem
Copy link
Contributor

imbrem commented May 13, 2019

Impls which are generic over a const parameter don't seem to work properly, generating a bunch of compiler errors

#![feature(const_generics)]

trait Fooable<const N : usize> {}

struct Foo<const N : usize>();

impl<const N : usize> Fooable<N> for Foo<N> {}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/lib.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^

error[E0573]: expected type, found const parameter `N`
 --> src/lib.rs:7:31
  |
7 | impl<const N : usize> Fooable<N> for Foo<N> {}
  |                               ^ not a type

error[E0573]: expected type, found const parameter `N`
 --> src/lib.rs:7:42
  |
7 | impl<const N : usize> Fooable<N> for Foo<N> {}
  |                                          ^ not a type

error[E0107]: wrong number of const arguments: expected 1, found 0
 --> src/lib.rs:7:38
  |
7 | impl<const N : usize> Fooable<N> for Foo<N> {}
  |                                      ^^^^^^ expected 1 const argument

error[E0107]: wrong number of type arguments: expected 0, found 1
 --> src/lib.rs:7:42
  |
7 | impl<const N : usize> Fooable<N> for Foo<N> {}
  |                                          ^ unexpected type argument

error[E0107]: wrong number of const arguments: expected 1, found 0
 --> src/lib.rs:7:23
  |
7 | impl<const N : usize> Fooable<N> for Foo<N> {}
  |                       ^^^^^^^^^^ expected 1 const argument

error[E0107]: wrong number of type arguments: expected 0, found 1
 --> src/lib.rs:7:31
  |
7 | impl<const N : usize> Fooable<N> for Foo<N> {}
  |                               ^ unexpected type argument

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0107`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

@varkor
Copy link
Member

varkor commented May 13, 2019

I've just created a catch-all issue for this: #60804. For now, you can get around it by surrounding const argument with curly brackets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants