rust-lang / rust-lang/rust

target_feature leads to confusing note in rustdoc

Open
#131,735 1 comment 1 reaction 1 assignee View on GitHub

@lolbinarycat is already working on this.

Since Oct 19, 2024.

A-rustdoc-ui C-bug T-rustdoc T-rustdoc-frontend
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.