-
Notifications
You must be signed in to change notification settings - Fork 13.4k
std::arch documentation examples fail to compile on nightly #55848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Particularly, this crate compiles, but then the doc tests fail: #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature, stdsimd))]
#[cfg(not(dox))]
#[macro_use]
extern crate stdsimd;
fn main() {
let mut dst = [0];
add_quickly(&[1], &[2], &mut dst);
assert_eq!(dst[0], 3);
}
fn add_quickly(a: &[u8], b: &[u8], c: &mut [u8]) {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
// Note that this `unsafe` block is safe because we're testing
// that the `avx2` feature is indeed available on our CPU.
if is_x86_feature_detected!("avx2") {
return unsafe { add_quickly_avx2(a, b, c) };
}
}
add_quickly_fallback(a, b, c)
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[target_feature(enable = "avx2")]
unsafe fn add_quickly_avx2(a: &[u8], b: &[u8], c: &mut [u8]) {
add_quickly_fallback(a, b, c) // the function below is inlined here
}
fn add_quickly_fallback(a: &[u8], b: &[u8], c: &mut [u8]) {
for ((a, b), c) in a.iter().zip(b).zip(c) {
*c = *a + *b;
}
}
/// ```rust
/// # #![cfg_attr(
/// # not(dox),
/// # feature(cfg_target_feature, target_feature, stdsimd)
/// # )]
/// # #[cfg(not(dox))]
/// # #[macro_use]
/// # extern crate stdsimd;
///
/// fn main() {
/// let mut dst = [0];
/// add_quickly(&[1], &[2], &mut dst);
/// assert_eq!(dst[0], 3);
/// }
///
/// fn add_quickly(a: &[u8], b: &[u8], c: &mut [u8]) {
/// #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
/// {
/// // Note that this `unsafe` block is safe because we're testing
/// // that the `avx2` feature is indeed available on our CPU.
/// if is_x86_feature_detected!("avx2") {
/// return unsafe { add_quickly_avx2(a, b, c) };
/// }
/// }
///
/// add_quickly_fallback(a, b, c)
/// }
///
/// #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
/// #[target_feature(enable = "avx2")]
/// unsafe fn add_quickly_avx2(a: &[u8], b: &[u8], c: &mut [u8]) {
/// add_quickly_fallback(a, b, c) // the function below is inlined here
/// }
///
/// fn add_quickly_fallback(a: &[u8], b: &[u8], c: &mut [u8]) {
/// for ((a, b), c) in a.iter().zip(b).zip(c) {
/// *c = *a + *b;
/// }
/// }
/// ```
///
fn foo() {}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
} |
Putting the first config on its own line fixes this:
|
Duplicate of #55713 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fails with
The text was updated successfully, but these errors were encountered: