Issue #3020: HashSet takes room ahead as a constructor option: HashSet(capacity: n)

Open and answer this issue on GitHub.

ready · opened 2026-12-01 · updated 2026-12-01 · 0 comments

collections::HashMap(capacity: n) reserves room ahead (“Vec, String and HashMap take room ahead as a constructor option: Vec(capacity: n)”, #2114), but the same option on collections::HashSet is refused, and the help points at a struct literal that does not exist.

Probe

use std::collections

fn main() throws {
	let mut s: collections::HashSet[i64] = collections::HashSet(capacity: 8)
	s.insert(1)
	println(s.len())
}

Expected: prints 1, the same as the HashMap(capacity: 8) version of the program.

Actual:

error[NK1146]: Build a `collections::HashSet` with braces, not parentheses.
   = help: Write `collections::HashSet { capacity: … }`.
error[NK1103]: This value is `collections::HashSet`, but the `let` declares `collections::HashSet[i64]`.

Found while reducing the cost of the kept-question dedupe in bounding_kept_texts (crates/nikaia-std/src/compiler/bounds_walk.nika). That code uses HashSet() for now and does not depend on this.

To build

  1. collections::HashSet(capacity: n) is accepted as a constructor option, the way #2114 did it for HashMap, and lowers to HashSet::with_capacity(n).
  2. NK1146 does not suggest a brace literal for a std collection that has none.
  3. Add a test in tests/compiler/tests/ with its .stdout.

Done when: the probe prints 1.


Generated by Claude Code

Back to Open Issues