rust-lang / rust-lang/rust-analyzer

Request hover support for constants defined with `const fn`

Open
#18,685 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I would like to ask for textDocument/hover support for constants defined with const fn. In my example below, you can see that an add function works, but not usize.ilog2().

Works as expected

pub const fn add(a: u32, b: u32) -> u32 { a + b }
pub const ADD_EXAMPLE: u32 = add(2, 3);

Hovering over ADD_EXAMPLE shows 5 as expected...

Image

Feature request

pub const fn ilog2(n: u32) -> u32 { n.ilog2() }
pub const ILOG2_EXAMPLE: u32 = ilog2(16);

But hovering over ILOG2_EXAMPLE currently shows: ilog2(16) instead of 4...

Image

Background

I have an application where I define constants based on usize.ilog2() and I like to sanity check the results in my editor.

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 by reproducing the two Rust examples through textDocument/hover and trace the hover handling for constant expressions. Compare the existing result for add(2, 3) with the unresolved ilog2(16) result. Done means hovering over ILOG2_EXAMPLE displays 4, while the existing ADD_EXAMPLE behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.