From 2e081db92aa3ee0a4563bc28ce01bdad5b1b2efd Mon Sep 17 00:00:00 2001 From: The Atelier Date: Wed, 20 Jul 2022 17:23:46 -0700 Subject: [PATCH] Fix doctest imports using as_crate feature Within core, `use self::` does not work to import these items. And because core is not core_simd, neither does the existing `use`. So, use this quirky hack instead, switching the import on a feature. --- crates/core_simd/Cargo.toml | 3 ++- crates/core_simd/src/elements/float.rs | 16 +++++++++--- crates/core_simd/src/elements/int.rs | 36 +++++++++++++++++++------- crates/core_simd/src/elements/uint.rs | 8 ++++-- crates/core_simd/src/vector.rs | 14 +++++++--- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/crates/core_simd/Cargo.toml b/crates/core_simd/Cargo.toml index 8877c6df66ed..8a29cf15696e 100644 --- a/crates/core_simd/Cargo.toml +++ b/crates/core_simd/Cargo.toml @@ -9,7 +9,8 @@ categories = ["hardware-support", "no-std"] license = "MIT OR Apache-2.0" [features] -default = [] +default = ["as_crate"] +as_crate = [] std = [] generic_const_exprs = [] diff --git a/crates/core_simd/src/elements/float.rs b/crates/core_simd/src/elements/float.rs index 67e4454e5e12..d60223270556 100644 --- a/crates/core_simd/src/elements/float.rs +++ b/crates/core_simd/src/elements/float.rs @@ -113,7 +113,9 @@ pub trait SimdFloat: Copy + Sealed { /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::f32x2; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{f32x2, SimdFloat}; /// let v = f32x2::from_array([1., 2.]); /// assert_eq!(v.reduce_sum(), 3.); /// ``` @@ -125,7 +127,9 @@ pub trait SimdFloat: Copy + Sealed { /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::f32x2; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{f32x2, SimdFloat}; /// let v = f32x2::from_array([3., 4.]); /// assert_eq!(v.reduce_product(), 12.); /// ``` @@ -142,7 +146,9 @@ pub trait SimdFloat: Copy + Sealed { /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::f32x2; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{f32x2, SimdFloat}; /// let v = f32x2::from_array([1., 2.]); /// assert_eq!(v.reduce_max(), 2.); /// @@ -167,7 +173,9 @@ pub trait SimdFloat: Copy + Sealed { /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::f32x2; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{f32x2, SimdFloat}; /// let v = f32x2::from_array([3., 7.]); /// assert_eq!(v.reduce_min(), 3.); /// diff --git a/crates/core_simd/src/elements/int.rs b/crates/core_simd/src/elements/int.rs index 787a07411467..9b8c37ed466e 100644 --- a/crates/core_simd/src/elements/int.rs +++ b/crates/core_simd/src/elements/int.rs @@ -16,7 +16,9 @@ pub trait SimdInt: Copy + Sealed { /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::Simd; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdInt}; /// use core::i32::{MIN, MAX}; /// let x = Simd::from_array([MIN, 0, 1, MAX]); /// let max = Simd::splat(MAX); @@ -32,7 +34,9 @@ pub trait SimdInt: Copy + Sealed { /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::Simd; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdInt}; /// use core::i32::{MIN, MAX}; /// let x = Simd::from_array([MIN, -2, -1, MAX]); /// let max = Simd::splat(MAX); @@ -48,7 +52,9 @@ pub trait SimdInt: Copy + Sealed { /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::Simd; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdInt}; /// use core::i32::{MIN, MAX}; /// let xs = Simd::from_array([MIN, MIN +1, -5, 0]); /// assert_eq!(xs.abs(), Simd::from_array([MIN, MAX, 5, 0])); @@ -61,7 +67,9 @@ pub trait SimdInt: Copy + Sealed { /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::Simd; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdInt}; /// use core::i32::{MIN, MAX}; /// let xs = Simd::from_array([MIN, -2, 0, 3]); /// let unsat = xs.abs(); @@ -77,7 +85,9 @@ pub trait SimdInt: Copy + Sealed { /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::Simd; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdInt}; /// use core::i32::{MIN, MAX}; /// let x = Simd::from_array([MIN, -2, 3, MAX]); /// let unsat = -x; @@ -105,7 +115,9 @@ pub trait SimdInt: Copy + Sealed { /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::i32x4; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{i32x4, SimdInt}; /// let v = i32x4::from_array([1, 2, 3, 4]); /// assert_eq!(v.reduce_sum(), 10); /// @@ -121,7 +133,9 @@ pub trait SimdInt: Copy + Sealed { /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::i32x4; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{i32x4, SimdInt}; /// let v = i32x4::from_array([1, 2, 3, 4]); /// assert_eq!(v.reduce_product(), 24); /// @@ -137,7 +151,9 @@ pub trait SimdInt: Copy + Sealed { /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::i32x4; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{i32x4, SimdInt}; /// let v = i32x4::from_array([1, 2, 3, 4]); /// assert_eq!(v.reduce_max(), 4); /// ``` @@ -149,7 +165,9 @@ pub trait SimdInt: Copy + Sealed { /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::i32x4; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{i32x4, SimdInt}; /// let v = i32x4::from_array([1, 2, 3, 4]); /// assert_eq!(v.reduce_min(), 1); /// ``` diff --git a/crates/core_simd/src/elements/uint.rs b/crates/core_simd/src/elements/uint.rs index f9d43a1d19b0..21e7e76eb3de 100644 --- a/crates/core_simd/src/elements/uint.rs +++ b/crates/core_simd/src/elements/uint.rs @@ -11,7 +11,9 @@ pub trait SimdUint: Copy + Sealed { /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::Simd; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdUint}; /// use core::u32::MAX; /// let x = Simd::from_array([2, 1, 0, MAX]); /// let max = Simd::splat(MAX); @@ -27,7 +29,9 @@ pub trait SimdUint: Copy + Sealed { /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::Simd; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdUint}; /// use core::u32::MAX; /// let x = Simd::from_array([2, 1, 0, MAX]); /// let max = Simd::splat(MAX); diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index 761151ab8b28..8661be938d5b 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs @@ -173,7 +173,7 @@ where /// /// ``` /// # #![feature(portable_simd)] - /// # use core::simd::{Simd, u32x4}; + /// # use core::simd::u32x4; /// let source = vec![1, 2, 3, 4, 5, 6]; /// let v = u32x4::from_slice(&source); /// assert_eq!(v.as_array(), &[1, 2, 3, 4]); @@ -332,7 +332,9 @@ where /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core_simd::simd::{Simd, SimdPartialOrd, Mask}; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdPartialOrd, Mask}; /// let vec: Vec = vec![10, 11, 12, 13, 14, 15, 16, 17, 18]; /// let idxs = Simd::from_array([9, 3, 0, 5]); /// let alt = Simd::from_array([-5, -4, -3, -2]); @@ -389,7 +391,9 @@ where /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core_simd::simd::{Simd, Mask}; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, Mask}; /// let mut vec: Vec = vec![10, 11, 12, 13, 14, 15, 16, 17, 18]; /// let idxs = Simd::from_array([9, 3, 0, 0]); /// let vals = Simd::from_array([-27, 82, -41, 124]); @@ -423,7 +427,9 @@ where /// # Examples /// ``` /// # #![feature(portable_simd)] - /// # use core_simd::simd::{Simd, SimdPartialOrd, Mask}; + /// # #[cfg(feature = "as_crate")] use core_simd::simd; + /// # #[cfg(not(feature = "as_crate"))] use core::simd; + /// # use simd::{Simd, SimdPartialOrd, Mask}; /// let mut vec: Vec = vec![10, 11, 12, 13, 14, 15, 16, 17, 18]; /// let idxs = Simd::from_array([9, 3, 0, 0]); /// let vals = Simd::from_array([-27, 82, -41, 124]);