Skip to content

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

Closed
gnzlbg opened this issue Nov 10, 2018 · 4 comments
Closed

std::arch documentation examples fail to compile on nightly #55848

gnzlbg opened this issue Nov 10, 2018 · 4 comments

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Nov 10, 2018

/// ```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() {}

fails with

---- src/../../../stdsimd/mod.rs - stdsimd::arch (line 214) stdout ----
error: incorrect close delimiter: `)`
 --> src/../../../stdsimd/mod.rs:218:1
  |
2 | #![cfg_attr(
  |            - close delimiter possibly meant for this
3 | extern crate stdsimd;
4 | fn main() {
  |           - un-closed delimiter
...
7 | )]
  | ^ incorrect close delimiter

error: unexpected close delimiter: `}`
  --> src/../../../stdsimd/mod.rs:253:1
   |
42 | }
   | ^ unexpected close delimiter

thread 'src/../../../stdsimd/mod.rs - stdsimd::arch (line 214)' panicked at 'couldn't compile the test', librustdoc/test.rs:323:13
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Nov 10, 2018

cc @QuietMisdreavus

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Nov 10, 2018

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);
    }
}

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Nov 10, 2018

Putting the first config on its own line fixes this:

/// #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature, stdsimd))]

@QuietMisdreavus
Copy link
Member

Duplicate of #55713

@QuietMisdreavus QuietMisdreavus marked this as a duplicate of #55713 Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants