From 0fb8104e9f98d565a9dc6d98df9cfda3cd343816 Mon Sep 17 00:00:00 2001 From: Amanda Graven Date: Fri, 28 Nov 2025 17:51:48 +0100 Subject: [PATCH] Add style guide for default field values --- src/doc/style-guide/src/expressions.md | 14 ++++++++++++-- src/doc/style-guide/src/items.md | 11 ++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/doc/style-guide/src/expressions.md b/src/doc/style-guide/src/expressions.md index 9df5d7d18edb5..431669625dfb7 100644 --- a/src/doc/style-guide/src/expressions.md +++ b/src/doc/style-guide/src/expressions.md @@ -173,8 +173,18 @@ let f = Foo { }; ``` -Functional record update syntax is treated like a field, but it must never have -a trailing comma. Do not put a space after `..`. +Default intialization syntax is treated like a field, but it must never have a +trailing comma. + +```rust +let f = Foo { + field1, + .. +}; +``` + +Functional record update syntax is treated the same. Do not put a space after +`..`. ```rust let f = Foo { diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index 090dc00844802..afd6c7fef7ccf 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -105,18 +105,23 @@ indented and appears on its own line. ```rust struct Foo { a: A, - b: B, + b: B = expr, } ``` If and only if the type of a field does not fit within the right margin, it is -pulled down to its own line and indented again. +pulled down to its own line and indented again. If and only if the default value +does not not fit within the right margin, split the line after the =. Also apply +a block indent if this was not already done by pulling down the type. ```rust struct Foo { a: A, + b: B = + long_expr, long_name: - LongType, + LongType = + long_expr, } ```