Skip to content

fix: Improve add some on block like expression#21953

Merged
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
A4-Tacks:add-some-instead-wrap-some
Apr 7, 2026
Merged

fix: Improve add some on block like expression#21953
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
A4-Tacks:add-some-instead-wrap-some

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

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

After #21952, make the PR also support macros

Example

fn foo() -> Result<(), ()> {
    for _ in 0..5 {}$0
}

Before this PR

fn foo() -> Result<(), ()> {
    Ok(for _ in 0..5 {})
}

After this PR

fn foo() -> Result<(), ()> {
    for _ in 0..5 {}
    Ok(())
}

@ChayimFriedman2 ChayimFriedman2 marked this pull request as ready for review April 6, 2026 23:07
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2026
.insert(expr.syntax().text_range().end(), format!("\n{indent}{variant_name}(())"));

let source_change = SourceChange::from_text_edit(
expr_ptr.file_id.original_file(ctx.sema.db).file_id(ctx.sema.db),
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.

You can't expect the expanded node to be in the original file.

@A4-Tacks A4-Tacks force-pushed the add-some-instead-wrap-some branch from 1c24686 to 8ba16f5 Compare April 7, 2026 06:39
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 7, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

let mut builder = TextEdit::builder();
let indent = expr.indent_level();
builder
.insert(expr.syntax().text_range().end(), format!("\n{indent}{variant_name}(())"));
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.

This should be the upmapped range.

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.

Oh, sorry, I forgot

Example
---
```rust
fn foo() -> Result<(), ()> {
    for _ in 0..5 {}$0
}
```

**Before this PR**

```rust
fn foo() -> Result<(), ()> {
    Ok(for _ in 0..5 {})
}
```

**After this PR**

```rust
fn foo() -> Result<(), ()> {
    for _ in 0..5 {}
    Ok(())
}
```
@A4-Tacks A4-Tacks force-pushed the add-some-instead-wrap-some branch from 8ba16f5 to e7444c0 Compare April 7, 2026 09:01
@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Apr 7, 2026
Merged via the queue into rust-lang:master with commit 512db74 Apr 7, 2026
17 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 7, 2026
@A4-Tacks A4-Tacks deleted the add-some-instead-wrap-some branch April 7, 2026 10:17
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