Skip to content

Commit

Permalink
Merge pull request #762 from tweag/nb/rust_misc
Browse files Browse the repository at this point in the history
fix: [Rust] various formatting errors
  • Loading branch information
nbacquey authored Oct 10, 2024
2 parents 1a88ead + f287e11 commit dde8c48
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ This name should be decided amongst the team before the release.
- [#760](https://github.com/tweag/topiary/pull/760) Introduce optional `query_name` predicate, to help with query logging and debugging.

### Fixed
- [#720](https://github.com/tweag/topiary/pull/720) [#722](https://github.com/tweag/topiary/pull/722) [#723](https://github.com/tweag/topiary/pull/723) [#724](https://github.com/tweag/topiary/pull/724) [#735](https://github.com/tweag/topiary/pull/735)
[#738](https://github.com/tweag/topiary/pull/738) [#739](https://github.com/tweag/topiary/pull/739) [#745](https://github.com/tweag/topiary/pull/745) [#755](https://github.com/tweag/topiary/pull/755) [#759](https://github.com/tweag/topiary/pull/759) Various OCaml improvements
- [#720](https://github.com/tweag/topiary/pull/720) [#722](https://github.com/tweag/topiary/pull/722) [#723](https://github.com/tweag/topiary/pull/723) [#724](https://github.com/tweag/topiary/pull/724) [#735](https://github.com/tweag/topiary/pull/735) [#738](https://github.com/tweag/topiary/pull/738) [#739](https://github.com/tweag/topiary/pull/739) [#745](https://github.com/tweag/topiary/pull/745) [#755](https://github.com/tweag/topiary/pull/755) [#759](https://github.com/tweag/topiary/pull/759) Various OCaml improvements
- [#762](https://github.com/tweag/topiary/pull/762) Various Rust improvements
- [#744](https://github.com/tweag/topiary/pull/744) Nickel: fix the indentation of `in` for annotated multiline let-bindings
- [#761](https://github.com/tweag/topiary/pull/761) No longer use error code 1 for unspecified errors

Expand Down
23 changes: 23 additions & 0 deletions topiary-cli/tests/samples/expected/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,26 @@ enum Mode6 {
mode unchanged */
Either,
}

// Inline with let stmt
fn inline_let() { let hi = 1; }

// While loop spacing
while i == true {
let i = 42;
}

// Scoped blocks
{
let i = 42;
}
{
let i = 43;
}

// Empty block inside of impl function
impl MyTrait for MyStruct {
fn foo() {
// ... logic ...
}
}
24 changes: 24 additions & 0 deletions topiary-cli/tests/samples/input/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,27 @@ enum Mode6 {
mode unchanged */
Either,
}

// Inline with let stmt
fn inline_let() { let hi = 1; }

// While loop spacing
while i == true {
let i = 42;
}


// Scoped blocks
{
let i = 42;
}
{
let i = 43;
}

// Empty block inside of impl function
impl MyTrait for MyStruct {
fn foo() {
// ... logic ...
}
}
30 changes: 27 additions & 3 deletions topiary-queries/queries/rust.scm
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
; Sometimes we want to indicate that certain parts of our source text should
; not be formatted, but taken as is. We use the leaf capture name to inform the
; tool of this.
(string_literal) @leaf
[
(block_comment)
(line_comment)
(string_literal)
] @leaf

; Allow blank line before
[
Expand Down Expand Up @@ -37,6 +41,7 @@
"type"
"unsafe"
(visibility_modifier)
"while"
"="
"=="
"-"
Expand Down Expand Up @@ -73,14 +78,15 @@
(attribute_item)
(enum_item)
(extern_crate_declaration)
(expression_statement)
(function_item)
(impl_item)
(let_declaration)
(mod_item)
(struct_item)
(type_item)
(use_declaration)
] @append_hardline
] @append_spaced_softline
.
[
(block_comment)
Expand All @@ -92,6 +98,13 @@

(block_comment) @multi_line_indent_all

; Allow line break after block comments
(
(block_comment)
.
_ @prepend_input_softline
)

; Append softlines, unless followed by comments.
(
[
Expand Down Expand Up @@ -161,7 +174,6 @@
(block
.
"{" @append_spaced_softline @append_indent_start
_
"}" @prepend_spaced_softline @prepend_indent_end
.
)
Expand All @@ -176,8 +188,20 @@
"{" @prepend_space
)

(declaration_list
.
"{" @append_empty_softline @append_indent_start
"}" @prepend_empty_softline @prepend_indent_end
.
)

; PhantomData<&'a ()>
(_
(lifetime) @append_space
[(array_type) (generic_type) (primitive_type) (unit_type)]
)

; Never put a space before a comma
(
"," @prepend_antispace
)

0 comments on commit dde8c48

Please sign in to comment.