From 60cf630e467d512a8a05797e2c07fbe968a43096 Mon Sep 17 00:00:00 2001 From: ia0 Date: Sat, 7 Feb 2026 22:33:23 +0100 Subject: [PATCH] style-guide: Add try blocks --- src/doc/style-guide/src/expressions.md | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/doc/style-guide/src/expressions.md b/src/doc/style-guide/src/expressions.md index 9df5d7d18edb5..d276b6f5ff364 100644 --- a/src/doc/style-guide/src/expressions.md +++ b/src/doc/style-guide/src/expressions.md @@ -154,6 +154,37 @@ move |arg1: i32, arg2: i32| -> i32 { } ``` +## Try blocks + +### Homogeneous + +Put a space between `try` and the block. Format on a single line if it fits. Otherwise format the +block as if it started with `try {` instead of `{`. + +```rust +try { foo()?; bar()? } + +try { + foo()?; + bar()? +} +``` + +### Heterogeneous + +Put a space between `try` and `bikeshed`, between `bikeshed` and the type, and between the type and +the block. Format on a single line if it fits. Otherwise format the block as if it started with `try +bikeshed Type {` instead of `{`, where `Type` is the type formatted on a single line. + +```rust +try bikeshed Option<()> { foo()?; bar()? } + +try bikeshed Result<(), _> { + foo()?; + bar()?; +} +``` + ## Struct literals If a struct literal is *small*, format it on a single line, and do not use a