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_generics with default arguments #70471

Closed
lcnr opened this issue Mar 27, 2020 · 2 comments · Fixed by #74654
Closed

const_generics with default arguments #70471

lcnr opened this issue Mar 27, 2020 · 2 comments · Fixed by #74654
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 27, 2020

Should the following code be accepted?

// compiles rn
#![feature(const_generics)]

struct A<T = u32, const N: usize> {
    arg: T,
}

type C = A<u32, 7>;

if so, we probably also want to accept the following:

// this currently fails
type B = A<7>;
//~^ ERROR constant provided when a type was expected

playground

cc @varkor @eddyb

@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)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Mar 27, 2020
@rodrimati1992
Copy link
Contributor

rodrimati1992 commented Mar 29, 2020

So,how would the following be handled?

#![feature(const_generics)]

struct A<T = u32, const N: usize> {
    arg: T,
}

type C = u64;
const C: usize = 7;

const _: [A<C>; 0] = [];

That is Foo<C> (passing an identifier as a const argument).

@lcnr
Copy link
Contributor Author

lcnr commented Mar 29, 2020

@rodrimati1992 A<C> should be equal to A<u32; C> imo.

rn literals which are in both the type and the value namespace are always used as type params though (see #66615). So this would fail to compile even if we get A<10> to work.

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. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants