From d9089245fefdc4179c1d61839e78131c5e5a5a45 Mon Sep 17 00:00:00 2001 From: Geoffrey Copin Date: Sat, 11 Apr 2020 20:32:58 +0200 Subject: [PATCH] Generate doc --- crates/ra_assists/src/doc_tests/generated.rs | 15 +++++++++++++++ docs/user/assists.md | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs index 64444ee3aa..6dc049715d 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs @@ -606,6 +606,21 @@ impl Walrus { ) } +#[test] +fn doctest_reorder_fields() { + check( + "reorder_fields", + r#####" +struct Foo {foo: i32, bar: i32}; +const test: Foo = <|>Foo {bar: 0, foo: 1} +"#####, + r#####" +struct Foo {foo: i32, bar: i32}; +const test: Foo = Foo {foo: 1, bar: 0} +"#####, + ) +} + #[test] fn doctest_replace_if_let_with_match() { check( diff --git a/docs/user/assists.md b/docs/user/assists.md index 754131f6fe..75404e2890 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -582,6 +582,21 @@ impl Walrus { } ``` +## `reorder_fields` + +Reorder the fields of record literals and record patterns in the same order as in +the definition. + +```rust +// BEFORE +struct Foo {foo: i32, bar: i32}; +const test: Foo = ┃Foo {bar: 0, foo: 1} + +// AFTER +struct Foo {foo: i32, bar: i32}; +const test: Foo = Foo {foo: 1, bar: 0} +``` + ## `replace_if_let_with_match` Replaces `if let` with an else branch with a `match` expression.