# Pre-RFC: Extended array literal syntax

**URL:** <https://internals.rust-lang.org/t/pre-rfc-extended-array-literal-syntax/10446>\
**Category:** language design\
**Created:** [June 22, 2019, 4:39am UTC](https://internals.rust-lang.org/t/pre-rfc-extended-array-literal-syntax/10446 "2019-06-22T04:39:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshlf](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/joshlf/32/3815_2.png) [@joshlf](https://internals.rust-lang.org/u/joshlf)\
**Post date:** [June 22, 2019, 4:39am UTC](https://internals.rust-lang.org/t/pre-rfc-extended-array-literal-syntax/10446/1 "2019-06-22T04:39:49Z")

</div>

Calling this a pre-RFC is a bit of a stretch, but…

Wouldn’t it be cool if you could write `[0, 14, 3, 72, 8; 10]` and have the last element repeated 10 times? It’s a generalization of the already-supported `[0, 14, 3, 72, 8]` and `[8; 10]` literal syntaxes.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [June 22, 2019, 5:14am UTC](https://internals.rust-lang.org/t/pre-rfc-extended-array-literal-syntax/10446/2 "2019-06-22T05:14:25Z")

</div>

Definitely more of an “Idea” than a “Pre-RFC” 😛

I suppose it could even extend to `[0;3, 1, 0;6]` for `[0, 0, 0, 1, 0, 0, 0, 0, 0, 0]`, though I don’t know if that’s a good idea.

---

<div class="post-metadata">

**Author:** ![H2CO3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/h2co3/32/2849_2.png) [@H2CO3](https://internals.rust-lang.org/u/H2CO3)\
**Post date:** [June 22, 2019, 5:27am UTC](https://internals.rust-lang.org/t/pre-rfc-extended-array-literal-syntax/10446/3 "2019-06-22T05:27:48Z")

</div>

> [@joshlf](#):
>
> Wouldn’t it be cool if

No, I think not. Its semantics is _highly_ non-obvious. For example, having used various kinds of scientific and numerical software and libraries (e.g. R and Numpy) I'm used to repetition applying to a whole sequence instead of just one element. But that has its own problems too (and I don't like it _either_); for example, what to do when the number of specified elements doesn't evenly divide the repeat count?

Unless this solves a real and significant problem that is impossible or prohibitively hard to solve otherwise, I'd not like to see this kind of clever but ultimately confusing shorthand syntax in Rust.

---

<div class="post-metadata">

**Author:** ![joshlf](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/joshlf/32/3815_2.png) [@joshlf](https://internals.rust-lang.org/u/joshlf)\
**Post date:** [June 22, 2019, 6:33am UTC](https://internals.rust-lang.org/t/pre-rfc-extended-array-literal-syntax/10446/4 "2019-06-22T06:33:24Z")

</div>

Ah that’s a good point. I hadn’t considered that interpretation. Probably best not to then 🙂

---

<div class="post-metadata">

**Author:** ![mcy](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mcy/32/6512_2.png) [@mcy](https://internals.rust-lang.org/u/mcy)\
**Post date:** [June 23, 2019, 8:35pm UTC](https://internals.rust-lang.org/t/pre-rfc-extended-array-literal-syntax/10446/5 "2019-06-23T20:35:24Z")

</div>

This is definitely the kind of thing that’s better off as a proc-macro.

That said, I’d definitely like more flexible ways to declare large tables. I’d be nice to have e.g.

```rust
x[1..3] = [1, 2, 3];

```

available… though I don’t think this generalizes nicely (you need to synthesize bounds checks for slices… and size/alignment checks for trait objects, which seems super confusing).

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [September 21, 2019, 8:36pm UTC](https://internals.rust-lang.org/t/pre-rfc-extended-array-literal-syntax/10446/6 "2019-09-21T20:36:48Z")

</div>

Closed on September 21, 2019, 8:36pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
