Skip to content

Fix incorrect rustdoc JSON representation of #[doc(test(..))] attrs.#153465

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
obi1kenobi:pg/trailing-bracket-fix
Mar 7, 2026
Merged

Fix incorrect rustdoc JSON representation of #[doc(test(..))] attrs.#153465
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
obi1kenobi:pg/trailing-bracket-fix

Conversation

@obi1kenobi
Copy link
Member

@obi1kenobi obi1kenobi commented Mar 6, 2026

Attributes like #[doc(test(attr(deny(rust_2018_idioms))))] are accidentally emitted without the final ].

Also, the #[doc(test(no_crate_inject))] attribute is mistakenly emitted as #[doc(no_crate_inject)] — note the missing test wrapper.

This PR adds the missing ] and fixes the no_crate_inject, and adds regression tests for both.

Thanks to the folks working on tonic and pyo3 for reporting a cargo-semver-checks crash on Rust 1.94 in their projects, which led me to finding this bug. Refs:

r? @aDotInTheVoid

@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2026

These commits modify tests/rustdoc-json.
rustdoc-json is a public (but unstable) interface.

Please ensure that if you've changed the output:

  • It's intentional.
  • The FORMAT_VERSION in src/librustdoc-json-types is bumped if necessary.

cc @aDotInTheVoid

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 6, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2026

aDotInTheVoid is currently at their maximum review capacity.
They may take a while to respond.

@obi1kenobi obi1kenobi force-pushed the pg/trailing-bracket-fix branch from 706e07d to 7abb750 Compare March 6, 2026 05:12
@obi1kenobi obi1kenobi changed the title Fix missing trailing in rustdoc JSON of attr. Fix incorrect rustdoc JSON representation of #[doc(test(..))] attrs. Mar 6, 2026
@obi1kenobi
Copy link
Member Author

I wasn't sure if this deserves a version bump, since the bug is only present in some v57 versions and not others. I was leaning "no" but that opinion is loosely held.

Copy link
Member

@aDotInTheVoid aDotInTheVoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing.

FORMAT_VERSION doesn't need to be bumped here, as AttributeKind::Other explicitly isn't versioned. You could bump it if you want, so you could detect if you needed to deal with broken attrs,

View changes since this review

ret.push(Attribute::Other(format!("#[doc(test(attr({snippet})))]")));
}
}
toggle_attr(&mut ret, "no_crate_inject", no_crate_inject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this be toggle_attr with "test(no_crate_inject)"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It absolutely could, and I'll switch it. Two things kept me from it initially. I didn't see any examples of a parenthesized arg to toggle_attr. I also wasn't sure if the // FIXME should apply to this test attr too, and mirroring that block's pattern seemed to rhyme with its FIXME comment better.

I'll change it though!

// https://github.com/rust-lang/rust/pull/153465

//@ count "$.index[?(@.inner.module.is_crate)].attrs[*]" 1
//@ has "$.index[?(@.inner.module.is_crate)].attrs[*].other" '"#[doc(test(no_crate_inject))]"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: This can use is (for a slightly nicer error)

// https://github.com/rust-lang/rust/pull/153465

//@ count "$.index[?(@.inner.module.is_crate)].attrs[*]" 1
//@ has "$.index[?(@.inner.module.is_crate)].attrs[*].other" '"#[doc(test(attr(deny(rust_2018_idioms))))]"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@aDotInTheVoid
Copy link
Member

@bors delegate+

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 6, 2026

✌️ @obi1kenobi, you can now approve this pull request!

If @aDotInTheVoid told you to "r=me" after making some further change, then please make that change and post @bors r=aDotInTheVoid.

@obi1kenobi obi1kenobi force-pushed the pg/trailing-bracket-fix branch from 7abb750 to d3149ca Compare March 7, 2026 02:14
@obi1kenobi
Copy link
Member Author

@bors r=aDotInTheVoid

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 7, 2026

📌 Commit d3149ca has been approved by aDotInTheVoid

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 7, 2026
@aDotInTheVoid
Copy link
Member

@bors rollup=always

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 7, 2026
…, r=aDotInTheVoid

Fix incorrect rustdoc JSON representation of `#[doc(test(..))]` attrs.

Attributes like `#[doc(test(attr(deny(rust_2018_idioms))))]` are accidentally emitted without the final `]`.

Also, the `#[doc(test(no_crate_inject))]` attribute is mistakenly emitted as `#[doc(no_crate_inject)]` — note the missing `test` wrapper.

This PR adds the missing `]` and fixes the `no_crate_inject`, and adds regression tests for both.

Thanks to the folks working on `tonic` and `pyo3` for reporting a `cargo-semver-checks` crash on Rust 1.94 in their projects, which led me to finding this bug. Refs:
- https://github.com/hyperium/tonic/actions/runs/22732044107/job/65957306230?pr=2536
- https://github.com/PyO3/pyo3/actions/runs/22745106403/job/65967167797
- obi1kenobi/cargo-semver-checks#1590

r? @aDotInTheVoid
rust-bors bot pushed a commit that referenced this pull request Mar 7, 2026
…uwer

Rollup of 2 pull requests

Successful merges:

 - #153494 (Replace Box<[TraitCandidate]> with &'hir [TraitCandidate<'hir>])
 - #153465 (Fix incorrect rustdoc JSON representation of `#[doc(test(..))]` attrs.)
@rust-bors rust-bors bot merged commit 1f12441 into rust-lang:main Mar 7, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Mar 7, 2026
Rollup merge of #153465 - obi1kenobi:pg/trailing-bracket-fix, r=aDotInTheVoid

Fix incorrect rustdoc JSON representation of `#[doc(test(..))]` attrs.

Attributes like `#[doc(test(attr(deny(rust_2018_idioms))))]` are accidentally emitted without the final `]`.

Also, the `#[doc(test(no_crate_inject))]` attribute is mistakenly emitted as `#[doc(no_crate_inject)]` — note the missing `test` wrapper.

This PR adds the missing `]` and fixes the `no_crate_inject`, and adds regression tests for both.

Thanks to the folks working on `tonic` and `pyo3` for reporting a `cargo-semver-checks` crash on Rust 1.94 in their projects, which led me to finding this bug. Refs:
- https://github.com/hyperium/tonic/actions/runs/22732044107/job/65957306230?pr=2536
- https://github.com/PyO3/pyo3/actions/runs/22745106403/job/65967167797
- obi1kenobi/cargo-semver-checks#1590

r? @aDotInTheVoid
@rustbot rustbot added this to the 1.96.0 milestone Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants