Skip to content

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

Open
@rusty-snake

Description

@rusty-snake

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions