multiversion icon indicating copy to clipboard operation
multiversion copied to clipboard

Clone API docs

Open jorgecarleitao opened this issue 4 years ago • 2 comments

It would be nice for the missing docs to not complain when compiling multiversion. I.e. we could make following compile by also cloning the docs:

#![deny(missing_docs)]

use multiversion::multiversion;

/// Sums values
#[multiversion]
#[clone(target = "x86_64+aes+sse3+ssse3+avx+avx2")]
/// Sums values
pub fn sum(array: &[i32]) -> i32 {
    let mut sum = 0;
    for i in array {
        sum += i;
    }
    sum
}

fn main() {
    let _ = sum(&[1, 2]);
}

cargo build yields

error: missing documentation for the crate
  --> examples/bla.rs:1:1
   |
1  | / #![deny(missing_docs)]
2  | |
3  | | use multiversion::multiversion;
4  | |
...  |
18 | |     let _ = sum(&[1, 2]);
19 | | }
   | |_^
   |
note: the lint level is defined here
  --> examples/bla.rs:1:9
   |
1  | #![deny(missing_docs)]
   |         ^^^^^^^^^^^^

error: missing documentation for a function
 --> examples/bla.rs:6:1
  |
6 | #[multiversion]
  | ^^^^^^^^^^^^^^^
  |
  = note: this error originates in the attribute macro `multiversion` (in Nightly builds, run with -Z macro-backtrace for more info)

jorgecarleitao avatar Sep 30 '21 14:09 jorgecarleitao

I'm working on a change that should place the clones within the scope of the multiversioned function, which I think should incidentally solve this as well.

calebzulawski avatar Mar 19 '22 19:03 calebzulawski

More broadly, though, I'm unsure how to handle attributes on the multiversioned function vs on the clones. Copying all attributes doesn't quite make sense, for example:

#[multiversion(...)]
#[export_name = "foo"]
pub fn some_multiversioned_function() { ... }

However sometimes you might want it copied, like the tracing::instrument macro. Maybe the default should be to not copy, and provide a mechanism to copy particular attributes.

calebzulawski avatar Mar 19 '22 19:03 calebzulawski

On master, the clones are now completely contained within the multiversioned function, which solves this issue. It also helps some more peculiar cases, like multiversioned trait implementations.

calebzulawski avatar Dec 04 '22 04:12 calebzulawski