-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Regression when doc string invokes a macro which is defined within the same module #124535
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
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 #124382 cc @petrochenkov |
The AST visiting order (mutable and immutable) was tweaked in #124382, yes. The new behavior looks correct to me, |
I agree it could be sensible not to try to keep backcompat too much, and "tank" the breakage. Especially since adding a mod module {
#![doc = foo!()]
macro_rules! foo {() => (
""
)}
+ use foo;
} I am fine doing this for my I do think something ought to be done w.r.t. the root/top-level #![doc = foo!()]
macro_rules! foo {() => (
""
)} 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. #![my::attribute] // ERROR: custom inner attributes are unstable For the same reasons it would be reasonable to keep The situation with |
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 src/lib.rsmod foo {
#![doc = foo!()]
macro_rules! foo { () => { "foo" } }
#[doc = foo!()] struct Foo;
} Before> cargo doc --all-features --document-private-items --no-deps
Documenting foo v0.1.0 (/Users/rami3l/Downloads/foo)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.18s
Generated /Users/rami3l/Downloads/foo/target/doc/foo/index.html
> rustdoc --version
rustdoc 1.78.0 (9b00956e5 2024-04-29) After> cargo +beta doc --all-features --document-private-items --no-deps
Documenting foo v0.1.0 (/Users/rami3l/Downloads/foo)
error: cannot find macro `foo` in this scope
--> src/lib.rs:2:12
|
2 | #![doc = foo!()]
| ^^^
|
= help: have you added the `#[macro_use]` on the module/import?
error: could not document `foo`
> rustdoc +beta --version
rustdoc 1.79.0-beta.2 (4bf9354b9 2024-05-02) ConclusionIf the |
Fixed in #125734. |
ast: Revert a breaking attribute visiting order change Fixes rust-lang#124535 Fixes rust-lang#125201
Rollup merge of rust-lang#125734 - petrochenkov:macinattr, r=wesleywiser ast: Revert a breaking attribute visiting order change Fixes rust-lang#124535 Fixes rust-lang#125201
Reopening to track beta backport |
Closing, backported in #126093. |
ast: Standardize visiting order for attributes and node IDs This should only affect `macro_rules` scopes and order of diagnostics. Also add a deprecation lint for `macro_rules` called outside of their scope, like in rust-lang#124535.
ast: Standardize visiting order for attributes and node IDs This should only affect `macro_rules` scopes and order of diagnostics. Also add a deprecation lint for `macro_rules` called outside of their scope, like in rust-lang/rust#124535.
ast: Standardize visiting order for attributes and node IDs This should only affect `macro_rules` scopes and order of diagnostics. Also add a deprecation lint for `macro_rules` called outside of their scope, like in rust-lang/rust#124535.
ast: Revert a breaking attribute visiting order change Fixes rust-lang/rust#124535 Fixes rust-lang/rust#125201
ast: Standardize visiting order for attributes and node IDs This should only affect `macro_rules` scopes and order of diagnostics. Also add a deprecation lint for `macro_rules` called outside of their scope, like in rust-lang/rust#124535.
``` warning: cannot find macro `self_test` in this scope --> lib.rs:44:10 | 44 | #![doc = self_test!(/** | ^^^^^^^^^ | = 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 #124535 <rust-lang/rust#124535> = help: import `macro_rules` with `use` to make it callable above its definition = note: `#[warn(out_of_scope_macro_calls)]` on by default ```
``` warning: cannot find macro `in_root` in the crate root --> $DIR/key-value-expansion-scope.rs:1:10 | LL | #![doc = in_root!()] | ^^^^^^^ not found in the crate root | = 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 rust-lang#124535 <rust-lang#124535> = help: import `macro_rules` with `use` to make it callable above its definition = note: `#[warn(out_of_scope_macro_calls)]` on by default ```
Following my previous comment in #124535 (comment), I'm experiencing a very weird situation right now with my project warning: cannot find macro `doc_self` in this scope
--> src/pm/dnf.rs:1:10
|
1 | #![doc = doc_self!()]
| ^^^^^^^^
|
= 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 #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition https://github.com/rami3l/pacaptr/actions/runs/11752606941/job/32744390895?pr=746 ... although I've already applied the fix in the file: #![doc = doc_self!()]
use std::sync::LazyLock;
use async_trait::async_trait;
use indoc::indoc;
use tap::prelude::*;
use super::{NoCacheStrategy, Pm, PmHelper, PmMode, PromptStrategy, Strategy};
use crate::{config::Config, error::Result, exec::Cmd};
macro_rules! doc_self {
() => {
indoc! {"
The [Dandified YUM](https://github.com/rpm-software-management/dnf).
"}
};
}
use doc_self;
#[doc = doc_self!()]
#[derive(Debug)]
pub struct Dnf {
cfg: Config,
} Should I be worried? 🤔 |
Code
I tried this code:
I expected to see this happen:
Instead, this happened:
Remark
Note that this problem still does not occur at the top-most level.
That is, removing
mod module {
above makes it work:Version it worked on
It most recently worked on: +nightly-2024-04-27
Version with regression
rustc --version --verbose
:@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged
The text was updated successfully, but these errors were encountered: