Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rustfmt
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c0d899db6946946823046b8d3a58e10cb86e9adb
Choose a base ref
..
head repository: rust-lang/rustfmt
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a80e63ad73cec02540ba721c426ec61b49717c04
Choose a head ref
Showing with 47 additions and 2 deletions.
  1. +21 −1 tests/source/let_else.rs
  2. +26 −1 tests/target/let_else.rs
22 changes: 21 additions & 1 deletion tests/source/let_else.rs
Original file line number Diff line number Diff line change
@@ -2,9 +2,14 @@ fn main() {
// Although this won't compile it still parses so make sure we can format empty else blocks
let Some(x) = opt else {};

// let-else may be formatted on a single line if they are "short" and only contain a single expression
// let-else may be formatted on a single line if they are "short"
// and only contain a single expression
let Some(x) = opt else { return };

let Some(x) = opt else {
return
};

let Some(x) = opt else { return; };

let Some(x) = opt else {
@@ -125,3 +130,18 @@ fn unbreakable_initializer_expr_pre_formatting_length_through_initializer_expr_n
// because the Shape is accounting for the `;` at the end of the `let-else` statement.
let Some(x) = some_really_really_really_really_really_really_really_really_really_really_really_long_nameJ else {return};
}

fn long_patterns() {
let Foo {x: Bar(..), y: FooBar(..), z: Baz(..)} = opt else {
return;
};

// with version=One we don't wrap long array patterns
let [aaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd] = opt else {
return;
};

let Some(Ok((Message::ChangeColor(super::color::Color::Rgb(r, g, b)), Point { x, y, z }))) = opt else {
return;
};
}
27 changes: 26 additions & 1 deletion tests/target/let_else.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,10 @@ fn main() {
// Although this won't compile it still parses so make sure we can format empty else blocks
let Some(x) = opt else {};

// let-else may be formatted on a single line if they are "short" and only contain a single expression
// let-else may be formatted on a single line if they are "short"
// and only contain a single expression
let Some(x) = opt else { return };

let Some(x) = opt else { return };

let Some(x) = opt else {
@@ -192,3 +195,25 @@ fn unbreakable_initializer_expr_pre_formatting_length_through_initializer_expr_n
// because the Shape is accounting for the `;` at the end of the `let-else` statement.
let Some(x) = some_really_really_really_really_really_really_really_really_really_really_really_long_nameJ else {return};
}

fn long_patterns() {
let Foo {
x: Bar(..),
y: FooBar(..),
z: Baz(..),
} = opt
else {
return;
};

// with version=One we don't wrap long array patterns
let [aaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd] = opt else {
return;
};

let Some(Ok((Message::ChangeColor(super::color::Color::Rgb(r, g, b)), Point { x, y, z }))) =
opt
else {
return;
};
}