rust-lang / rust-lang/rust

Suggested fix for "cannot find macro `...` in this scope" does not compile

Open
#136,140 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-macros A-suggestion-diagnostics C-bug D-invalid-suggestion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a095133990477eb48c9b42343e5593f4

fn main() {}

// STEP 1: Try to compile, will fail with "error: cannot find macro `nothing` in this scope".
// STEP 2: Uncomment line 18 as per suggestion.
// STEP 3: Try to compile, will fail with "macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths".
// STEP 4: Comment line 9.

mod a {
    #[rustfmt::skip]
    #[macro_export]
    macro_rules! nothing {
        () => {};
    }
}

mod b {
    fn foo() {
        //use crate::nothing;
        nothing!();
    }
}

I expected to see this happen: Using a suggestion "just works".

Instead, this happened: Unexpected and even more confusing error message caused because of #98291.

Meta

Tested on playground with 1.84.0 (stable) and 1.86.0-nightly (2025-01-26 f85c6de55206dbee5ffe).

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 linked Rust Playground example on the stated stable and nightly versions, then read issue #98291 for the related behavior. Trace the suggested use crate::nothing import and the macro_export definition in the example; done means the diagnostic suggestion no longer leads directly to the reported absolute-path error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.