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 with member parametrized by const generic #60801

Closed
imbrem opened this issue May 13, 2019 · 2 comments
Closed

Compiler error with member parametrized by const generic #60801

imbrem opened this issue May 13, 2019 · 2 comments

Comments

@imbrem
Copy link
Contributor

imbrem commented May 13, 2019

When you parameterize struct members by const generics you get the same sort of errors as when parametrizing impls by const generics (#60800)

#![feature(const_generics)]

struct Member<const N : usize>();

#[allow(dead_code)]
struct Foo<const N : usize> {
    member : Member<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[E0465]: multiple rlib candidates for `debug_unreachable` found
  |
  = note: candidate #1: /playground/target/debug/deps/libdebug_unreachable-b6bbaea13290bfa4.rlib
  = note: candidate #2: /playground/target/debug/deps/libdebug_unreachable-597d184d1c38b826.rlib

error[E0573]: expected type, found const parameter `N`
 --> src/lib.rs:7:21
  |
7 |     member : Member<N>
  |                     ^ not a type

error[E0107]: wrong number of const arguments: expected 1, found 0
 --> src/lib.rs:7:14
  |
7 |     member : Member<N>
  |              ^^^^^^^^^ expected 1 const argument

error[E0107]: wrong number of type arguments: expected 0, found 1
 --> src/lib.rs:7:21
  |
7 |     member : Member<N>
  |                     ^ unexpected type argument

error: aborting due to 4 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

At the moment, you need to surround const generic arguments in curly brackets: e.g.{N}, because they can't be disambiguated from type parameters yet.

@varkor
Copy link
Member

varkor commented May 13, 2019

I've just created a catch-all issue for this: #60804. Thanks for reporting!

@varkor varkor closed this as completed May 13, 2019
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