Skip to content

target_feature leads to confusing note in rustdoc #131735

Open
@zopsicle

Description

@zopsicle

I tried this code:

#[target_feature(enable = "avx2")]
pub unsafe fn f() {}

I expected to see this happen:

Rustdoc says something along the lines of:

Requires target feature avx2 at runtime.

Instead, this happened:

Rustdoc says:

Available with target feature avx2 only.

It is not clear what “available” means here. I initially thought it meant the function would not be defined if not compiled with --codegen target-feature=+avx2 (and concluded it was always safe to call if the calling program compiles). Instead it means the function is always defined but must not be called if the target feature is not available at runtime. Rustdoc gives no other indication that the target_feature attribute is used, and the note looks a lot like the “available on create feature … only” notes.

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Metadata

Metadata

Assignees

Labels

A-rustdoc-uiArea: Rustdoc UI (generated HTML)C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions