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

Array repeat expressions with nested blocks do not recognize constants #85333

Open
RalfJung opened this issue May 15, 2021 · 2 comments
Open
Labels
A-array Area: `[T; N]`

Comments

@RalfJung
Copy link
Member

I tried the following code:

pub fn make_vecs() -> [Vec<i32>; 5] {
    [{
        const C: Vec<i32> = Vec::new();
        C
    }; 5]
}

I thought this would be accepted, since C is a constant.
But it does get rejected, probably because of the surrounding curly braces.

This code may look unnatural, but it is the kind of code that arises from a macro-based implementation of anonymous/inline constants.
Cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented May 15, 2021

hmm... it feels odd to allow this, I mean it's pretty much the reason we have inline consts as a feature and allowing it would require special casing blocks just for this use case

@RalfJung
Copy link
Member Author

That's fair, I cannot seem to come up with any reasonable way this would arise unless one tries to re-implement inline consts as a macro...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-array Area: `[T; N]`
Projects
None yet
Development

No branches or pull requests

3 participants