Skip to content

rustdoc-json: Add test for #[optimize(..)] #142916

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

Merged
merged 1 commit into from
Jun 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/rustdoc-json/attrs/optimize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(optimize_attribute)]

//@ is "$.index[?(@.name=='speed')].attrs" '["#[attr = Optimize(Speed)]"]'
Copy link
Member

Choose a reason for hiding this comment

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

Is the display of the inner value supposed to be like that? Shouldn't it be speed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

See also

//@ is "$.index[?(@.name=='just_inline')].attrs" '["#[attr = Inline(Hint)]"]'
#[inline]
pub fn just_inline() {}

Copy link
Member

Choose a reason for hiding this comment

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

I see. How attributes are displayed is incoherent though, which isn't great. For example:

attrs/repr_align.rs:3://@ is "$.index[?(@.name=='Aligned')].attrs" '["#[repr(align(4))]"]'
attrs/export_name_2024.rs:7://@ is "$.index[?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
attrs/repr_c.rs:13://@ is "$.index[?(@.name=='ReprCUnion')].attrs" '["#[repr(C)]"]'
attrs/repr_packed.rs:6://@ is "$.index[?(@.name=='Packed')].attrs" '["#[repr(packed(1))]"]'
keyword_private.rs:8://@ is   "$.index[?(@.name=='foo')].attrs" '["#[doc(keyword = \"match\")]"]'

Some of them are "code-like" and other represent the internal type representation in rustc, which is subject to change. Do we plan to uniform it at some point?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The code-like ones are either unstructured attributes, or have special handling in rustdoc.

#142936 moves to rustdoc-json not representing attributes as strings, but with a enum.

As part of #131229, all attributes are moving to being structured, but this is a gradual process.

Copy link
Member

Choose a reason for hiding this comment

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

Went through #142936. Feel very relieved. Attributes are declared in rustdoc-json-types so they can't change unexpectedly. Very good idea!

#[optimize(speed)]
pub fn speed() {}

//@ is "$.index[?(@.name=='size')].attrs" '["#[attr = Optimize(Size)]"]'
#[optimize(size)]
pub fn size() {}

//@ is "$.index[?(@.name=='none')].attrs" '["#[attr = Optimize(DoNotOptimize)]"]'
Copy link
Member

Choose a reason for hiding this comment

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

Especially in this case.

#[optimize(none)]
pub fn none() {}
Loading