rust-lang / rust-lang/rust-analyzer

RA cannot defer the type from a macro

Open
#19,537 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-macro C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 13h
Merged PRs (30d)
69

Description

rust-analyzer version: rust-analyzer version: 0.4.2369-standalone (588948f267 2025-04-06)

rustc version: rustc 1.86.0 (05f9846f8 2025-03-31)

editor or extension: pre-release (release same problem): Version
0.4.2369
Last Updated
2025-04-07,

code snippet to reproduce:
cargo.toml

crabtime = "1.1.3"
fn main() {
    let x = {
        #[crabtime::eval_function()]
        fn boo2() {
            crabtime::output! {
                5u32
            }
        }
    };
}

RA reports x: () while with the expanded code from RA, it reports correctly u32
expanded:

let x = { 
#[doc = " # Compilation Stats"]
#[doc = " Start: 01:23:04 (771)"]
#[doc = " Duration: 0.50 s"]
#[doc = " Cached: false"]
#[doc = " Output Dir: /Users/indra/Code/git/flecs_rust/target/rust-analyzer/debug/build/crabtime/project_f940e44a8c006acd/pid_59609"]
#[doc = " Macro Options: MacroOptions {"]
#[doc = "     cache: true,"]
#[doc = "     content_base_name: false,"]
#[doc = " }"]
#[cfg(any())]
const _:() = ();
5u32
};
Image

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 report using the dependency in cargo.toml and the crabtime macro snippet, then compare rust-analyzer's inferred type for x with the expanded code shown in the issue. The work is done when rust-analyzer reports x as u32 for this case rather than ().

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.