Skip to content

fix: add semicolon for postfix format unit like snippets#21955

Merged
A4-Tacks merged 2 commits intorust-lang:masterfrom
A4-Tacks:postfix-format-semi
Apr 6, 2026
Merged

fix: add semicolon for postfix format unit like snippets#21955
A4-Tacks merged 2 commits intorust-lang:masterfrom
A4-Tacks:postfix-format-semi

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks commented Apr 4, 2026

Example

fn main() {
    "{ 2+2 } { SomeStruct { val: 1, other: 32 } :?}".println
}

Before this PR

fn main() {
    println!("{} {:?}", 2 + 2, SomeStruct { val: 1, other: 32 })
}

After this PR

fn main() {
    println!("{} {:?}", 2 + 2, SomeStruct { val: 1, other: 32 });
}

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 4, 2026
Example
---
```rust
fn main() {
    "{ 2+2 } { SomeStruct { val: 1, other: 32 } :?}".println
}
```

**Before this PR**

```rust
fn main() {
    println!("{} {:?}", 2 + 2, SomeStruct { val: 1, other: 32 })
}
```

**After this PR**

```rust
fn main() {
    println!("{} {:?}", 2 + 2, SomeStruct { val: 1, other: 32 });
}
```
@A4-Tacks A4-Tacks force-pushed the postfix-format-semi branch from eba3543 to 42cffd3 Compare April 4, 2026 13:45
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor nit, then LGTM.

View changes since this review

("logw", "log::warn!"),
("loge", "log::error!"),
];
static HAS_VALUE: &[&str] = &["format"];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is a bit unclear. Perhaps FORMAT_SNIPPET_RETURNS_UNIT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's not public, I think SNIPPET_RETURNS_NON_UNIT is enough

&& let Some(literal_text) = ast::String::cast(literal.token())
{
add_format_like_completions(acc, ctx, &dot_receiver_including_refs, cap, &literal_text);
add_format_like_completions(acc, ctx, dot_receiver, cap, &literal_text, semi);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also handle match arms here and insert a comma.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will test this in the new PR

@A4-Tacks A4-Tacks added this pull request to the merge queue Apr 6, 2026
Merged via the queue into rust-lang:master with commit 46c7112 Apr 6, 2026
17 checks passed
@A4-Tacks A4-Tacks deleted the postfix-format-semi branch April 6, 2026 05:06
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants