Skip to content

fix: handle usages in macro for extract_function#22344

Open
A4-Tacks wants to merge 1 commit into
rust-lang:masterfrom
A4-Tacks:extract-fn-ref-in-macro
Open

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

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants