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

Const generic arguments require brackets (although #60804 is fixed) #66624

Closed
qwerty19106 opened this issue Nov 22, 2019 · 1 comment
Closed

Comments

@qwerty19106
Copy link

The #60804 issue is closed.
But brackets is required yet in my case:

#![feature(const_generics)]

struct Array<const SIZE: usize> {
    data: [u32; SIZE],
}

unsafe impl<const SIZE: usize> Sync for Array<SIZE>
{
}


struct Config {
    size: usize
}

const CONFIG: Config = Config {
    size: 5
};

static SINGLETON: Array<CONFIG.size> = Array {
    data: [0; CONFIG.size]
};

Gives error:

error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `.`
  --> src/lib.rs:20:31
   |
20 | static SINGLETON: Array<CONFIG.size> = Array {
   |                               ^ expected one of 7 possible tokens

playground

This code is compiled succesful:

static SINGLETON: Array<{CONFIG.size}> = Array {
    data: [0; CONFIG.size]
};
@qwerty19106 qwerty19106 changed the title Const generic arguments require brackets (although #60804 is landed) Const generic arguments require brackets (although #60804 is fixed) Nov 22, 2019
@jonas-schievink
Copy link
Contributor

This is expected, only literals and const parameters do not require braces (I believe)

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