Skip to content

Add documentation for the target_feature attribute - #160218

Open
valentynkit wants to merge 2 commits into
rust-lang:mainfrom
valentynkit:docs-target-feature-attribute
Open

Add documentation for the target_feature attribute#160218
valentynkit wants to merge 2 commits into
rust-lang:mainfrom
valentynkit:docs-target-feature-attribute

Conversation

@valentynkit

Copy link
Copy Markdown
Contributor

Documents the target_feature attribute, the next one from my claim on the tracking issue.

The example is wrapped in a hidden #[cfg(target_arch = "x86_64")] block, since feature names are architecture specific and the example has to compile everywhere the doctests run.

Part of #157604

r? @GuillaumeGomez

Tested with ./x test library/core --doc --test-args attribute_docs and the same for library/std.

Document the built-in `target_feature` attribute in the standard library using
the `#[doc(attribute = "...")]` mechanism, following the existing `inline` and
`cold` attribute documentation.
The Reference already lists where the attribute may appear, and these
entries are meant to stay guide-level rather than exhaustive.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 30, 2026
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jul 30, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

I don't know too much about this attribute so I prefer letting someone else review it.

r? @RalfJung

@rustbot rustbot assigned RalfJung and unassigned GuillaumeGomez Jul 30, 2026
@rustbot

rustbot commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@RalfJung

Copy link
Copy Markdown
Member

The attribute is already documented in the Reference. Is it a good idea to duplicate that documentation here?

@RalfJung RalfJung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems correct from the opsem side but the writing needs work.

Unfortunately I don't have the time to shepherd this all the way through.
r? @workingjubilee

View changes since this review

//
/// Enables extra CPU instructions for a single function.
///
/// A program is compiled for a baseline CPU, so instructions that only newer CPUs support go

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where does the baseline come from?

Comment on lines +592 to +593
/// baseline. The `-C target-feature` and `-C target-cpu` compiler flags enable features for the
/// whole crate instead, which raises the minimum CPU the binary runs on.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is an oddly dangling remark without flow.

It seems better to first mention the -C flags, and then pivot from there to the per-function version. Also, -Ctarget-cpu is very different from -Ctarget-fature, so throwing them into one bag here is quite confusing. -Ctarget-feature and #[target_feature] are closely related, they work on the same set of features; that should be mentioned.

@rustbot rustbot assigned workingjubilee and unassigned RalfJung Jul 31, 2026
@rustbot

rustbot commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

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

@RalfJung

Copy link
Copy Markdown
Member

Also, given the context in #160219, I would like to emphasize that in my view, we should not land AI-generated docs. I don't know if these docs were AI-generated, and this is just my opinion as the official policy banning AI-generated docs has not landed yet. But to inform my own judgment as a reviewer I'd like to know whether you wrote these docs entirely yourself or whether you edited a draft that was generated by AI. This is relevant because AI-generated text and code needs to be reviewed in a very different way than human-written text and code (because the kinds of mistakes AIs make are different from the mistakes humans make).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants