[v; n] Is a List Literal of n Copies of a Value That Copies, Typed by Its Use as Every List Literal Is; a List Literal of One Range Is WarnedStatus: Accepted
Date: October 17, 2026
Answers: how a list or an array of n equal values is written, left open
by ADR-152 §4; what [0..181] deserves
Related:
ADR-152 D1, D2, D4 (Array[T, N], its copy rule, a literal
typed by its use); ADR-135 D2 (a literal with no use is a
Vec); ADR-293 (an index out of range aborts); ADR-287
(comptime); Part I 4.5, 8.3 (a value that copies, .clone()); Part III’s
NK1157, NK1191, NK1201
let safety_buffer = ??? // 181 elements, all 0
let buf: Array[u8, 4096] = ??? // a buffer with no allocation (ADR-152)
A Vec of n equal values takes a detour today -
(0..<n).map(fn(_i) { 0 }).collect(), or let mut xs = [] and
xs.resize(n, 0) - and an Array[T, N] takes none: its literal writes every
element, so a buffer of 4096 bytes cannot be written, though ADR-152 made
Array the container of the target with no allocator. [0..181], written for
the numbers, is a list of one element, the range.
| Language | n zeros |
Length | A value that does not copy |
|---|---|---|---|
| Rust | [0; 181], vec![0; n] |
array: a constant; Vec: any |
array: only Copy or a constant; vec! clones each |
| Zig | [_]u8{0} ** 4096 |
a constant | copied |
| Go | [4096]byte{}, make([]int, n) |
only the zero value | |
| Swift | Array(repeating: 0, count: n) |
any | the reference copied |
| Python | [0] * n |
any | the same object n times ([[]] * n) |
Rust’s Clippy warns on vec![0..n] (single_range_in_vec_init).
| Option | Example | Why it lost | See |
|---|---|---|---|
| A function | repeat(0, 181), filled(0) |
an array’s length would have to come from the result’s type; a length is inferred from arguments only (Part I 4.6) | D1 |
| An operator on a list | [0] * 181 |
arithmetic on lists is refused (NK1191); Python’s shared-object trap |
D1 |
| A new operator | [0 ** 181] |
an operator for one use | D1 |
| Nothing new | resize, map |
Array[T, N] stays unwritable |
D1 |
| Clone a value that does not copy | [name; 3] clones name three times |
a copy nobody wrote; Nikaia writes .clone() where a value is duplicated (Part I 8.3) |
D3 |
Refuse [0..181] |
an error | a list of one range is rare, not wrong | D5 |
[v; n] is a list literal of n copies of v.It is a list literal, and takes its type from its use as every list literal
does (ADR-152 D4): with no use it is a Vec[T], where an Array[T, N] is
wanted it is that array. It is Rust’s spelling, which the lowering hands on as
it is. Inside brackets the ; is unambiguous.
Where an Array[T, N] is wanted, n is a comptime integer (ADR-287) equal
to N; another number, or one the build does not know, is NK1157, naming
both. For a Vec, n is any whole number, worked out when the literal is
reached; a negative one aborts as an index out of range does (ADR-293).
v is worked out once. A value that copies - a number, a bool, a char, an
Array or a value struct of them (Part I 8.3) - is copied n times. A value
that does not copy, String, Vec or a type that owns one, is NK1280; the
help writes (0..<n).map(fn(_i) { v.clone() }).collect(), where each copy is
visible.
The len() of [v; n] is n, as a written literal’s is its count, and for an
array N.
A list literal whose only element is a range, [0..181], is the warning
NK1281: a list of one range; the help writes (0..181).collect() for the
numbers and [0; 182] for that many equal values. A type written for it
(let r: Vec[Range[i64]] = [0..181]) says the list is meant and silences it.
A literal of several ranges is not warned.
[v; n] is typed as [a, b, c] is, so Vec and
Array get it together and nothing about a literal’s type is new..clone()
says so. Refusing is the direction that can open later; cloning could not be
taken back.[0..181] reads as the numbers to
anyone who knows ranges, and the program it makes fails late (NK1201, or an
index out of range); a warning names both ways out.[v; n] under lists and under Array[T, N], and the
warning; Part III’s table has NK1280, NK1281 and the length under
NK1157.[v; n], the checker’s type and copy test,
the lowering to vec![v; n] and [v; N], the prover’s len(); the warning
later (low priority).; has a third meaning, after a statement’s end and
subject ; config; a large Array on the stack is Array’s question, not
this literal’s.Not decided here: cloning a value that does not copy, if programs ask for
it; Array beyond the stack.
Decided October 17, 2026.