rust-lang / rust-lang/rust-analyzer

"Generate constant" assist creates constant with function's type when invoked on a const generic argument.

Open
#11,034 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

  • serverVersion: '0.3.859'
  • nightlyReleaseId: 55412114

Example:

fn main() {
    fn foo<const X: usize>() { }
    foo::<BAR>();
}

Invoking the "Generate constant" assist on BAR results in:

fn main() {
    fn foo<const X: usize>() { }
    const BAR: fn foo() = ;
    foo::<BAR>();
}

It should instead use the argument's type and generate const BAR: usize = .

https://user-images.githubusercontent.com/1352092/146385585-7e7151f2-a287-4b99-9c50-6b43a216c99f.mp4

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

Start at the rust-analyzer “Generate constant” assist entry point and reproduce the issue with the const-generic Rust snippet in the report. Trace how the selected argument’s type is determined, then verify that invoking the assist on BAR produces const BAR: usize = rather than using the function type.

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
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.