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

min_const_generics allows defining new types in const argument #75864

Closed
Aaron1011 opened this issue Aug 24, 2020 · 3 comments
Closed

min_const_generics allows defining new types in const argument #75864

Aaron1011 opened this issue Aug 24, 2020 · 3 comments
Labels
A-const-generics Area: const generics (parameters and arguments)

Comments

@Aaron1011
Copy link
Member

I recently discovered that the following code compiles:

#![feature(min_const_generics)]
struct Bar<const C: bool>;

struct Foo {
    outer: Bar<{
        struct Inner {
            field: bool
        }
        true
    }>,
}

It looks like an AnonConst is allowed to contain arbitrary expressions (as long as no const or type parameters are used), which means that new types can be defined.

I'm not certain whether this should be allowed or not. However, I haven't seen this discussed before, so I thought it was worth bringing up.

@Aaron1011 Aaron1011 added the A-const-generics Area: const generics (parameters and arguments) label Aug 24, 2020
@scottmcm
Copy link
Member

Feels to me like this, at the very least, shouldn't be min_const_generics.

(I'd personally be happy to block it from const_generics too, but there are consistency arguments that's it's not unreasonable to allow types in there, since they're allowed in other blocks.)

@petrochenkov
Copy link
Contributor

Items were allowed in constants expressions since forever, not sure why const generic arguments should be any different.

#![allow(unused)]

type A = [u8; { struct S; 1 }]; // OK since 1.0

fn main() {}

https://rust.godbolt.org/z/Ts6YT1

@Aaron1011
Copy link
Member Author

@petrochenkov: Wow, I didn't realize that we already supported that.

I'm going to close this issue - since we already supprt this in the array repeat position, there's nothing to gain from banning it in other positions.

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)
Projects
None yet
Development

No branches or pull requests

4 participants