What syntax should struct patterns use?
Author: zygoloidCreated Aug 26, 2026Updated Sep 1, 2026
Labelsleads question
Summary of issue:
When a struct pattern has a default, it can look like this: {.a = b: T = c}. The two =s are problematic and visually confusing. In #7530 we decided we wanted to replace the first = with something else. We need to decide what replaces it.
Details:
The = here is problematic both because it conflicts with = for defaults, and also because it's the only context in Carbon where we use = where we don't (conditionally or unconditionally) assign or bind the value on the right to the thing on the left. This = signifies a nested match.
Candidate alternatives suggested so far:
{.a: b}: unify struct literal and struct type literal syntax;{.a: b}is always a struct value, but has an implicit conversion totypeif all thebvalues do, analogous to the behavior of tuples.{.a: b: i32 = 0}still has repeated punctuation, but seems much more readable than the current syntax. Also removes the possibility of getting the:vs=syntax wrong.{.a ~ b}with infix~meaning "matches". We would also consider allowing things likeexpr ~ patternas a bool-valued expression to perform pattern matching. We want prefix~to mean destructive move, which this doesn't conflict with, but it's not ideal to use the same symbol for two unrelated things.{.a keyword b}, withkeywordbeingis,match,matches, orlike. A keyword may be too much ceremony here, especially in a large pattern with many field matches.ismight be expected to be analogous toas, and isn't.{.a |> b}: feasible, although a little awkward to type on US keyboard layouts.
Any other information that you want to share?
See #7530 for more information, including discussion of several options.
Source: carbon-language/carbon-lang