Open
Description
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
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Remove `#[rustfmt::skip]` to circumvent rustc bug
fmease commentedon Jan 26, 2024
Triage: No longer triggers
macro_expanded_macro_exports_accessed_by_absolute_paths
.Current output:
macro_rule
s that have attribute tags ([rustfmt::skip]
) #121219fmease commentedon Feb 17, 2024
Related reproducer from #121219 (different error):
fmease commentedon Feb 17, 2024
@bvanjoi, perhaps you're interested in looking into the root cause for this. Pinging you since I know that you love to work on
A-resolve
issues :)bvanjoi commentedon Feb 17, 2024
It's noteworthy that this case had previously induced an ice:
rustc version:
Backtrace
I plan to delve into this in the near future. @rustbot claim
edit: no ice in
rustc 1.78.0-nightly (bccb9bbb4 2024-02-16)
bvanjoi commentedon Feb 26, 2024
This issue encompasses two problems:
firstly
And it will resolved by #121589.
bvanjoi commentedon Feb 26, 2024
And secondly:
I will delve into this case at a later point.
Auto merge of rust-lang#121589 - bvanjoi:fix-98291, r=<try>
Auto merge of rust-lang#121589 - bvanjoi:fix-98291, r=<try>
Auto merge of rust-lang#121589 - bvanjoi:fix-98291, r=petrochenkov
...
in this scope" does not compile #136140nyurik commentedon Feb 21, 2025
I ran into this issue when I tried to add a new
#[clippy::format_args]
to a large project's logging macros. Reproducible with this on Rust v1.85. I have no idea how to even approach it, let alone the reason for this.#[clippy::format_args]
#137364nyurik commentedon Feb 23, 2025
CC: @bvanjoi and @petrochenkov I saw you had a relevant PR #121589, but it seems the bug is still there. Moreover, it is now more visible because v1.85 introduced an ability for Clippy to lint code when the 3rd party crates include an attribute on a macro. I tried adding the new attribute to both stdlib and 3rd party crates, and only the
log
crate worked ok.FORMAT_MACRO_DIAG_ITEMS
, and tag the macros in stdlib rust-lang/rust-clippy#14267