Change:
I tried this code: I expected to see this happen: Instead, this happened: Note that this problem still does not occur at the top-most level. That is, removing above makes it work: It most recently worked on: +nightly-2024-04-27 : _ modify labels: +regression-from-stable-to-nightly -regression-untriaged
IIUC this is also on beta 1.79 but I don't think it's in 1.78, which becomes stable on Thursday.
Good point, in three (?) days it will become a !
beta 1.79 is already out IIRC?
Why did it work at all? The doc comment is defined earlier in the source order than the macro, so it shouldn't be able to see the macro.
This is from cc
The AST visiting order (mutable and immutable) was tweaked in , yes. Not sure which exactly pass is responsible for the change though. The new behavior looks correct to me, is not in scope at the doc comment's location. I wonder how widespread this breakage is.
I agree it could be sensible not to try to keep backcompat too much, and "tank" the breakage. Especially since adding a after the macro definition (as it is already customarily done so that a macro become nameable before its definition) does make the error go away: I am fine doing this for my crate which runs into this; I was just worried about doc strings potentially ending up, eventually, fully unable to refer to macros defined within the module. _ I do think something ought to be done w.r.t. the root/top-level module, since that one has not regressed, meaning it is currently still possible to have: working, which given the current issue, hints at some future regression eventually happening in the future: it could thus warrant a FCW, or a fully-fledged breakage here and now?
Note, that name resolution for inner attributes is not well defined, and that's why non-builtin inner attributes are unstable. For the same reasons it would be reasonable to keep unstable as well, but apparently nobody thought about this in time. The situation with is better than with inner attributes in general though, because at least it cannot transform content of the module it's applied to into something different. So in we can resolve inside without it going from under our feet.
I think my preference would be fixing the root module case, auditing the implementation for other possible interesting cases, and then running crater to see what code is affected.
I've encountered this very issue (with , but I guess it's the same thing), but the error messages seem a bit different, so it took me quite a while to find this issue here... I'll paste my minimal repro here so that it might help someone after me: If the approach is recommended, then the message could use some improvements here.
Fixed in
Reopening to track beta backport
Closing, backported in

Discussion:
ctxt: AssocCtxt, ) -> V::Result { let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item; <del> walk_list!(visitor, visit_attribute, attrs); </del> try_visit!(visitor.visit_vis(vis)); try_visit!(visitor.visit_ident(ident)); try_visit!(kind.walk(item, ctxt, visitor)); <ins> walk_list!(visitor, visit_attribute, attrs); </ins> V::Result::output() }

error: using tabs in doc comments is not recommended <del> --> tests/ui/tabs_in_doc_comments.rs:6:5 </del> <ins> --> tests/ui/tabs_in_doc_comments.rs:10:9 </ins> | <del> LL | ///     - first        one |     ^^^^ help: consider using four spaces per tab </del> <ins> LL |     ///     - First String: |         ^^^^ help: consider using four spaces per tab </ins> | = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` error: using tabs in doc comments is not recommended <del> --> tests/ui/tabs_in_doc_comments.rs:6:13 </del> <ins> --> tests/ui/tabs_in_doc_comments.rs:11:9 </ins> | <del> LL | ///     - first        one |                ^^^^^^^^ help: consider using four spaces per tab </del> <ins> LL |     ///         - needs to be inside here |         ^^^^^^^^ help: consider using four spaces per tab </ins> error: using tabs in doc comments is not recommended <del> --> tests/ui/tabs_in_doc_comments.rs:7:5 </del> <ins> --> tests/ui/tabs_in_doc_comments.rs:14:9 </ins> | <del> LL | ///     - second    one |     ^^^^ help: consider using four spaces per tab </del> <ins> LL |     ///     - Second String: |         ^^^^ help: consider using four spaces per tab </ins> error: using tabs in doc comments is not recommended <del> --> tests/ui/tabs_in_doc_comments.rs:7:14 </del> <ins> --> tests/ui/tabs_in_doc_comments.rs:15:9 </ins> | <del> LL | ///     - second    one |                 ^^^^ help: consider using four spaces per tab </del> <ins> LL |     ///         - needs to be inside here |         ^^^^^^^^ help: consider using four spaces per tab </ins> error: using tabs in doc comments is not recommended <del> --> tests/ui/tabs_in_doc_comments.rs:10:9 </del> <ins> --> tests/ui/tabs_in_doc_comments.rs:6:5 </ins> | <del> LL |     ///     - First String: |         ^^^^ help: consider using four spaces per tab </del> <ins> LL | ///     - first        one |     ^^^^ help: consider using four spaces per tab </ins> error: using tabs in doc comments is not recommended <del> --> tests/ui/tabs_in_doc_comments.rs:11:9 </del> <ins> --> tests/ui/tabs_in_doc_comments.rs:6:13 </ins> | <del> LL |     ///         - needs to be inside here |         ^^^^^^^^ help: consider using four spaces per tab </del> <ins> LL | ///     - first        one |                ^^^^^^^^ help: consider using four spaces per tab </ins> error: using tabs in doc comments is not recommended <del> --> tests/ui/tabs_in_doc_comments.rs:14:9 </del> <ins> --> tests/ui/tabs_in_doc_comments.rs:7:5 </ins> | <del> LL |     ///     - Second String: |         ^^^^ help: consider using four spaces per tab </del> <ins> LL | ///     - second    one |     ^^^^ help: consider using four spaces per tab </ins> error: using tabs in doc comments is not recommended <del> --> tests/ui/tabs_in_doc_comments.rs:15:9 </del> <ins> --> tests/ui/tabs_in_doc_comments.rs:7:14 </ins> | <del> LL |     ///         - needs to be inside here |         ^^^^^^^^ help: consider using four spaces per tab </del> <ins> LL | ///     - second    one |                 ^^^^ help: consider using four spaces per tab </ins> error: aborting due to 8 previous errors

<ins> #![doc = in_root!()] // FIXME, this is a bug #![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope #![doc = in_mod_escape!()] // FIXME, this is a bug #![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope #[doc = in_root!()] //~ ERROR cannot find macro `in_root` in this scope #[doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope #[doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape` in this scope #[doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope fn before() { #![doc = in_root!()] //~ ERROR cannot find macro `in_root` in this scope #![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope #![doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape` in this scope #![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope } macro_rules! in_root { () => { "" } } mod macros_stay { #![doc = in_mod!()] // FIXME, this is a bug macro_rules! in_mod { () => { "" } } #[doc = in_mod!()] // OK fn f() { #![doc = in_mod!()] // OK } } #[macro_use] mod macros_escape { #![doc = in_mod_escape!()] // FIXME, this is a bug macro_rules! in_mod_escape { () => { "" } } #[doc = in_mod_escape!()] // OK fn f() { #![doc = in_mod_escape!()] // OK } } fn block() { #![doc = in_block!()]  //~ ERROR cannot find macro `in_block` in this scope macro_rules! in_block { () => { "" } } #[doc = in_block!()] // OK fn f() { #![doc = in_block!()] // OK } } #[doc = in_root!()] // OK #[doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope #[doc = in_mod_escape!()] // OK #[doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope fn after() { #![doc = in_root!()] // OK #![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope #![doc = in_mod_escape!()] // OK #![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope } fn main() {} </ins>

<ins> error: cannot find macro `in_mod` in this scope --> $DIR/key-value-expansion-scope.rs:2:10 | LL | #![doc = in_mod!()] |          ^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_block` in this scope --> $DIR/key-value-expansion-scope.rs:4:10 | LL | #![doc = in_block!()] |          ^^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_root` in this scope --> $DIR/key-value-expansion-scope.rs:6:9 | LL | #[doc = in_root!()] |         ^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_mod` in this scope --> $DIR/key-value-expansion-scope.rs:7:9 | LL | #[doc = in_mod!()] |         ^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_mod_escape` in this scope --> $DIR/key-value-expansion-scope.rs:8:9 | LL | #[doc = in_mod_escape!()] |         ^^^^^^^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_block` in this scope --> $DIR/key-value-expansion-scope.rs:9:9 | LL | #[doc = in_block!()] |         ^^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_root` in this scope --> $DIR/key-value-expansion-scope.rs:11:14 | LL |     #![doc = in_root!()] |              ^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_mod` in this scope --> $DIR/key-value-expansion-scope.rs:12:14 | LL |     #![doc = in_mod!()] |              ^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_mod_escape` in this scope --> $DIR/key-value-expansion-scope.rs:13:14 | LL |     #![doc = in_mod_escape!()] |              ^^^^^^^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_block` in this scope --> $DIR/key-value-expansion-scope.rs:14:14 | LL |     #![doc = in_block!()] |              ^^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_block` in this scope --> $DIR/key-value-expansion-scope.rs:43:14 | LL |     #![doc = in_block!()] |              ^^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_mod` in this scope --> $DIR/key-value-expansion-scope.rs:54:9 | LL | #[doc = in_mod!()] |         ^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_block` in this scope --> $DIR/key-value-expansion-scope.rs:56:9 | LL | #[doc = in_block!()] |         ^^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_mod` in this scope --> $DIR/key-value-expansion-scope.rs:59:14 | LL |     #![doc = in_mod!()] |              ^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: cannot find macro `in_block` in this scope --> $DIR/key-value-expansion-scope.rs:61:14 | LL |     #![doc = in_block!()] |              ^^^^^^^^ | = help: have you added the `#[macro_use]` on the module/import? error: aborting due to 15 previous errors </ins>

error[E0658]: the `#[optimize]` attribute is an experimental feature <del> --> $DIR/feature-gate-optimize_attribute.rs:4:1 | LL | #[optimize(size)] | ^^^^^^^^^^^^^^^^^ | = note: see issue #54882 <https://github.com/rust-lang/rust/issues/54882> for more information = help: add `#![feature(optimize_attribute)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: the `#[optimize]` attribute is an experimental feature </del> --> $DIR/feature-gate-optimize_attribute.rs:7:1 | LL | #[optimize(size)]

= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: the `#[optimize]` attribute is an experimental feature <ins> --> $DIR/feature-gate-optimize_attribute.rs:4:1 | LL | #[optimize(size)] | ^^^^^^^^^^^^^^^^^ | = note: see issue #54882 <https://github.com/rust-lang/rust/issues/54882> for more information = help: add `#![feature(optimize_attribute)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: the `#[optimize]` attribute is an experimental feature </ins> --> $DIR/feature-gate-optimize_attribute.rs:2:1 | LL | #![optimize(speed)]

error[E0734]: stability attributes may not be used outside of the standard library <del> --> $DIR/issue-43106-gating-of-stable.rs:10:1 | LL | #[stable()] | ^^^^^^^^^^^ error[E0734]: stability attributes may not be used outside of the standard library </del> --> $DIR/issue-43106-gating-of-stable.rs:14:9 | LL |         #![stable()]

|     ^^^^^^^^^^^ error[E0734]: stability attributes may not be used outside of the standard library <ins> --> $DIR/issue-43106-gating-of-stable.rs:10:1 | LL | #[stable()] | ^^^^^^^^^^^ error[E0734]: stability attributes may not be used outside of the standard library </ins> --> $DIR/issue-43106-gating-of-stable.rs:7:1 | LL | #![stable()]

error[E0734]: stability attributes may not be used outside of the standard library <del> --> $DIR/issue-43106-gating-of-unstable.rs:10:1 | LL | #[unstable()] | ^^^^^^^^^^^^^ error[E0734]: stability attributes may not be used outside of the standard library </del> --> $DIR/issue-43106-gating-of-unstable.rs:14:9 | LL |         #![unstable()]

|     ^^^^^^^^^^^^^ error[E0734]: stability attributes may not be used outside of the standard library <ins> --> $DIR/issue-43106-gating-of-unstable.rs:10:1 | LL | #[unstable()] | ^^^^^^^^^^^^^ error[E0734]: stability attributes may not be used outside of the standard library </ins> --> $DIR/issue-43106-gating-of-unstable.rs:7:1 | LL | #![unstable()]