Skip to content

Rustc reports errors for macro_rules that have attribute tags ([rustfmt::skip]) #121219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Embers-of-the-Fire opened this issue Feb 17, 2024 · 2 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Embers-of-the-Fire
Copy link

I tried this code:

#[macro_export]
#[rustfmt::skip]
macro_rules! test_macro {
    (()) => { Some(()) };
    (non) => { None };
}

fn main() {
    let t = crate::test_macro!(());
    println!("{:?}", t);
}

This does work if there's no [rustfmt::skip].
However, if this attribute is added, the following compilation error occurs:

error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
 --> src/main.rs:9:13
  |
9 |     let t = crate::test_macro!(());
  |             ^^^^^^^^^^^^^^^^^
  |
  = 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
 --> src/main.rs:3:1
  |
3 | / macro_rules! test_macro {
4 | |     (()) => { Some(()) };
5 | |     (non) => { None };
6 | | }
  | |_^
  = note: `#[deny(macro_expanded_macro_exports_accessed_by_absolute_paths)]` on by default

And other commonly-used attributes do not fail, like feature or cfg.

Playground here: Rust Playground.

Note: the sequence of the two attributes does not make difference.

Meta

Stable(1.76.0), beta(1.77.0-beta.4 2/16) and nightly(1.78.0-nightly 2/15) all failed to compile this.

@Embers-of-the-Fire Embers-of-the-Fire added the C-bug Category: This is a bug. label Feb 17, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 17, 2024
@fmease fmease added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 17, 2024
@fmease
Copy link
Member

fmease commented Feb 17, 2024

Related: #98291.

@fmease fmease added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 17, 2024
@Embers-of-the-Fire
Copy link
Author

Related: #98291.

Looks like a duplicate, I'll close mine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants