Clippy wants a Safety section for functions marked with target_feature

When I run clippy on this:

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

I get a warning:

warning: unsafe function's docs are missing a `# Safety` section
 --> src/lib.rs:2:1
  |
2 | pub fn f() {}
  | ^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.99.0/index.html#missing_safety_doc
  = note: `#[warn(clippy::missing_safety_doc)]` on by default

Given that calling target_feature functions are no longer unsafe and can be safely called from other target_feature functions since Rust 1.86, it seems inappropriate to add such Safety comments. It would be the same comment for all target_feature functions, so it is redundant information.

A better solution would be that rustdoc shows required target_features. Unfortunately this is currently only available on nightly and behind a feature.

2 Likes

Seems like it's straightforwardly a bug in clippy?

This has been fixed/will be fixed in Don't report missing safety doc for `#[target_feature(enable)]` attributed functions by DJMcNab · Pull Request #17051 · rust-lang/rust-clippy · GitHub

2 Likes