Skip to content

fix: handle usages in macro for extract_function#22344

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
A4-Tacks:extract-fn-ref-in-macro
May 15, 2026
Merged

fix: handle usages in macro for extract_function#22344
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
A4-Tacks:extract-fn-ref-in-macro

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented May 12, 2026

Copy link
Copy Markdown
Member

Example

#21053 is a fake fix

struct Foo(&'static str);

impl Foo {
    fn text(&self) -> &str { self.0 }
}

fn main() {
    let s = Foo("");
    $0print!("{}{}", s, s);$0
    let _ = s.text() == "";
}

Before this PR

fn $0fun_name(s: &Foo) {
    *print!("{}{}", s, s);
}

After this PR

fn $0fun_name(s: &Foo) {
    print!("{}{}", *s, *s);
}

macro_rules! refmut { ($e:expr) => { &mut $e }; }
fn foo() {
    let mut n = 1;
    $0let v = refmut!(n);
    *v += 1;$0
    let k = n;
}

Before this PR

fn $0fun_name(n: &mut i32) {
    let v = refmut!(n);
    *v += 1;
}

After this PR

fn $0fun_name(n: &mut i32) {
    let v = refmut!(*n);
    *v += 1;
}

Example
---
```rust
struct Foo(&'static str);

impl Foo {
    fn text(&self) -> &str { self.0 }
}

fn main() {
    let s = Foo("");
    $0print!("{}{}", s, s);$0
    let _ = s.text() == "";
}
```

**Before this PR**

```rust
fn $0fun_name(s: &Foo) {
    *print!("{}{}", s, s);
}
```

**After this PR**

```rust
fn $0fun_name(s: &Foo) {
    print!("{}{}", *s, *s);
}
```

---

```rust
macro_rules! refmut { ($e:expr) => { &mut $e }; }
fn foo() {
    let mut n = 1;
    $0let v = refmut!(n);
    *v += 1;$0
    let k = n;
}
```

**Before this PR**

```rust
fn $0fun_name(n: &mut i32) {
    let v = refmut!(n);
    *v += 1;
}
```

**After this PR**

```rust
fn $0fun_name(n: &mut i32) {
    let v = refmut!(*n);
    *v += 1;
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 12, 2026
@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue May 15, 2026
Merged via the queue into rust-lang:master with commit 3fdfad3 May 15, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 15, 2026
@A4-Tacks A4-Tacks deleted the extract-fn-ref-in-macro branch May 15, 2026 04: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