Skip to content

Adding an attribute to a macro_exported macro and reexporting it incorrectly triggers the macro_expanded_macro_exports_accessed_by_absolute_paths error #98291

Open
@jakobrs

Description

@jakobrs

I tried this code:

#[rustfmt::skip]    // <- The code compiles if this attribute is removed
#[macro_export]
macro_rules! _a {
    () => {
        "Hello world"
    };
}

pub use _a as a;

fn main() {
    println!(a!());
}

(https://gist.github.com/jakobrs/8bcaf3448431126005e16ac678f769c5)

I expected to see this happen: The code should compile successfully.

Instead, this happened: The macro_expanded_macro_exports_accessed_by_absolute_paths error is triggered.

Full error message
error: cannot determine resolution for the macro `a`
  --> ./b.rs:12:14
   |
12 |     println!(a!());
   |              ^
   |
   = note: import resolution is stuck, try simplifying macro imports

error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
 --> ./b.rs:9:9
  |
9 | pub use _a as a;
  |         ^^^^^^^
  |
  = note: `#[deny(macro_expanded_macro_exports_accessed_by_absolute_paths)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #52234 <https://github.com/rust-lang/rust/issues/52234>
note: the macro is defined here
 --> ./b.rs:3:1
  |
3 | / macro_rules! _a {
4 | |     () => {
5 | |         "Hello world"
6 | |     };
7 | | }
  | |_^

error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
  --> ./b.rs:12:14
   |
12 |     println!(a!());
   |              ^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #52234 <https://github.com/rust-lang/rust/issues/52234>
note: the macro is defined here
  --> ./b.rs:3:1
   |
3  | / macro_rules! _a {
4  | |     () => {
5  | |         "Hello world"
6  | |     };
7  | | }
   | |_^

error: aborting due to 3 previous errors

Meta

This happens with Rust 1.60, 1.61 and nightly (bb8c2f4 2022-06-19)
rustc --version --verbose:

# Nightly

rustc 1.63.0-nightly (bb8c2f411 2022-06-19)
binary: rustc
commit-hash: bb8c2f41174caceec00c28bc6c5c20ae9f9a175c
commit-date: 2022-06-19
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5

# Stable

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.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