rust-lang / rust-lang/rust-analyzer

"extract into function" inserts dereference for macro call

Open
#14,919 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I'm not knowledgeable enough to explain what's going on here, but here's an example which reproduces this:

let v = vec![1];
for _ in 0..1 {
    println!("len is {}", v.len());
}

highlight the println! statement, Extract into function...

fn fun_name(v: &Vec<i32>) {
    *println!("len is {}", v.len());
}

note the dereference, which prevents this from compiling (type () cannot be dereferenced)

rust-analyzer version: 0.3.1524-standalone (7ac161ce7 2023-05-21)

rustc version: (eg. output of rustc -V) 1.69.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue in rust-analyzer using the Rust snippet and the Extract into function action, then trace how extraction handles the println! macro call. Done means the generated function no longer inserts a dereference and the resulting Rust code compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.