Skip to content

Wrong error if a crate exports a macro with the same name as itself #47361

Closed
@dtolnay

Description

@dtolnay

If a crate or module defines a macro with the same name as the crate or module, any type error suggests that you invoke a non-existent macro instead of what you meant to write.

mod syn {
    #[allow(unused_macros)]
    macro_rules! syn {
        () => {}
    }
}

fn main() {
    let _: syn::Foo;
}
error[E0573]: expected type, found macro `syn::Foo`
  --> src/main.rs:22:9
   |
22 |     let _: syn::Foo;
   |            ^^^^^^^^ did you mean `syn::Foo!(...)`?

If the macro name is different from the module name then the error is reasonable.

error[E0412]: cannot find type `Foo` in module `syn`
  --> src/main.rs:22:14
   |
22 |     let _: syn::Foo;
   |                 ^^^ not found in `syn`

This currently affects the Syn crate. @Arnavion

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-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language 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