Skip to content

use foo::{self, ...} doesn't import macro foo! #63842

Closed
@valff

Description

@valff

When there is a macro and a module with the same name, use foo::{self, Bar} syntax imports the module foo, but not the macro foo!. So you are forced to use this:

use crate::foo;
use crate::foo::Bar;

It is especially annoying because rustfmt automatically merges it like this:

use crate::foo::{self, Bar};

And the macro is no longer imported. Both procedural and declarative macros are affected. Here is the full example:

pub mod foo {
    pub struct Bar;
}

mod inner {
    use crate::foo::{self, Bar};
    foo!();
}

#[macro_export]
macro_rules! foo {
    () => {};
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: cannot find macro `foo!` in this scope
 --> src/lib.rs:7:5
  |
7 |     foo!();
  |     ^^^
  |
  = help: have you added the `#[macro_use]` on the module/import?

warning: unused imports: `Bar`, `self`
 --> src/lib.rs:6:22
  |
6 |     use crate::foo::{self, Bar};
  |                      ^^^^  ^^^
  |
  = note: #[warn(unused_imports)] on by default

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions