Skip to content

non-#[macro_export]'ed macro_rules! macros are impossible to disambiguate from built-in attributes in use declarations #133708

Open
@kanashimia

Description

@kanashimia

I tried this code:

macro_rules! warn { () => {} }
pub(crate) use warn;
fn main() { }

I expected it to compile.

Instead, it produces an error like this:

error[E0659]: `warn` is ambiguous
 --> src/main.rs:3:16
  |
3 | pub(crate) use warn;
  |                ^^^^ ambiguous name
  |
  = note: ambiguous because of a name conflict with a builtin attribute
  = note: `warn` could refer to a built-in attribute
note: `warn` could also refer to the macro defined here
 --> src/main.rs:1:1
  |
1 | macro_rules! warn { () => {} }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

macro_rules are impossible to qualify it as self::warn or crate::warn or super::warn.
use r#warn doesn't do anything useful too.

The only thing you can do is something stupid like this:

macro_rules! warn_hack { ($($tt:tt)*) => { warn!($($tt)*) } }
pub(crate) use warn_hack as warn;

This will work, the fact that it works like that is why I consider this a bug.

Meta

Occurs on all versions with --edition 2018 or later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.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