Skip to content

Commit 2e081db

Browse files
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.
1 parent bbf31f9 commit 2e081db

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

crates/core_simd/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ categories = ["hardware-support", "no-std"]
99
license = "MIT OR Apache-2.0"
1010

1111
[features]
12-
default = []
12+
default = ["as_crate"]
13+
as_crate = []
1314
std = []
1415
generic_const_exprs = []
1516

crates/core_simd/src/elements/float.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ pub trait SimdFloat: Copy + Sealed {
113113
///
114114
/// ```
115115
/// # #![feature(portable_simd)]
116-
/// # use core::simd::f32x2;
116+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
117+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
118+
/// # use simd::{f32x2, SimdFloat};
117119
/// let v = f32x2::from_array([1., 2.]);
118120
/// assert_eq!(v.reduce_sum(), 3.);
119121
/// ```
@@ -125,7 +127,9 @@ pub trait SimdFloat: Copy + Sealed {
125127
///
126128
/// ```
127129
/// # #![feature(portable_simd)]
128-
/// # use core::simd::f32x2;
130+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
131+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
132+
/// # use simd::{f32x2, SimdFloat};
129133
/// let v = f32x2::from_array([3., 4.]);
130134
/// assert_eq!(v.reduce_product(), 12.);
131135
/// ```
@@ -142,7 +146,9 @@ pub trait SimdFloat: Copy + Sealed {
142146
///
143147
/// ```
144148
/// # #![feature(portable_simd)]
145-
/// # use core::simd::f32x2;
149+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
150+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
151+
/// # use simd::{f32x2, SimdFloat};
146152
/// let v = f32x2::from_array([1., 2.]);
147153
/// assert_eq!(v.reduce_max(), 2.);
148154
///
@@ -167,7 +173,9 @@ pub trait SimdFloat: Copy + Sealed {
167173
///
168174
/// ```
169175
/// # #![feature(portable_simd)]
170-
/// # use core::simd::f32x2;
176+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
177+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
178+
/// # use simd::{f32x2, SimdFloat};
171179
/// let v = f32x2::from_array([3., 7.]);
172180
/// assert_eq!(v.reduce_min(), 3.);
173181
///

crates/core_simd/src/elements/int.rs

+27-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ pub trait SimdInt: Copy + Sealed {
1616
/// # Examples
1717
/// ```
1818
/// # #![feature(portable_simd)]
19-
/// # use core::simd::Simd;
19+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
20+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
21+
/// # use simd::{Simd, SimdInt};
2022
/// use core::i32::{MIN, MAX};
2123
/// let x = Simd::from_array([MIN, 0, 1, MAX]);
2224
/// let max = Simd::splat(MAX);
@@ -32,7 +34,9 @@ pub trait SimdInt: Copy + Sealed {
3234
/// # Examples
3335
/// ```
3436
/// # #![feature(portable_simd)]
35-
/// # use core::simd::Simd;
37+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
38+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
39+
/// # use simd::{Simd, SimdInt};
3640
/// use core::i32::{MIN, MAX};
3741
/// let x = Simd::from_array([MIN, -2, -1, MAX]);
3842
/// let max = Simd::splat(MAX);
@@ -48,7 +52,9 @@ pub trait SimdInt: Copy + Sealed {
4852
/// # Examples
4953
/// ```
5054
/// # #![feature(portable_simd)]
51-
/// # use core::simd::Simd;
55+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
56+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
57+
/// # use simd::{Simd, SimdInt};
5258
/// use core::i32::{MIN, MAX};
5359
/// let xs = Simd::from_array([MIN, MIN +1, -5, 0]);
5460
/// assert_eq!(xs.abs(), Simd::from_array([MIN, MAX, 5, 0]));
@@ -61,7 +67,9 @@ pub trait SimdInt: Copy + Sealed {
6167
/// # Examples
6268
/// ```
6369
/// # #![feature(portable_simd)]
64-
/// # use core::simd::Simd;
70+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
71+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
72+
/// # use simd::{Simd, SimdInt};
6573
/// use core::i32::{MIN, MAX};
6674
/// let xs = Simd::from_array([MIN, -2, 0, 3]);
6775
/// let unsat = xs.abs();
@@ -77,7 +85,9 @@ pub trait SimdInt: Copy + Sealed {
7785
/// # Examples
7886
/// ```
7987
/// # #![feature(portable_simd)]
80-
/// # use core::simd::Simd;
88+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
89+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
90+
/// # use simd::{Simd, SimdInt};
8191
/// use core::i32::{MIN, MAX};
8292
/// let x = Simd::from_array([MIN, -2, 3, MAX]);
8393
/// let unsat = -x;
@@ -105,7 +115,9 @@ pub trait SimdInt: Copy + Sealed {
105115
///
106116
/// ```
107117
/// # #![feature(portable_simd)]
108-
/// # use core::simd::i32x4;
118+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
119+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
120+
/// # use simd::{i32x4, SimdInt};
109121
/// let v = i32x4::from_array([1, 2, 3, 4]);
110122
/// assert_eq!(v.reduce_sum(), 10);
111123
///
@@ -121,7 +133,9 @@ pub trait SimdInt: Copy + Sealed {
121133
///
122134
/// ```
123135
/// # #![feature(portable_simd)]
124-
/// # use core::simd::i32x4;
136+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
137+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
138+
/// # use simd::{i32x4, SimdInt};
125139
/// let v = i32x4::from_array([1, 2, 3, 4]);
126140
/// assert_eq!(v.reduce_product(), 24);
127141
///
@@ -137,7 +151,9 @@ pub trait SimdInt: Copy + Sealed {
137151
///
138152
/// ```
139153
/// # #![feature(portable_simd)]
140-
/// # use core::simd::i32x4;
154+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
155+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
156+
/// # use simd::{i32x4, SimdInt};
141157
/// let v = i32x4::from_array([1, 2, 3, 4]);
142158
/// assert_eq!(v.reduce_max(), 4);
143159
/// ```
@@ -149,7 +165,9 @@ pub trait SimdInt: Copy + Sealed {
149165
///
150166
/// ```
151167
/// # #![feature(portable_simd)]
152-
/// # use core::simd::i32x4;
168+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
169+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
170+
/// # use simd::{i32x4, SimdInt};
153171
/// let v = i32x4::from_array([1, 2, 3, 4]);
154172
/// assert_eq!(v.reduce_min(), 1);
155173
/// ```

crates/core_simd/src/elements/uint.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ pub trait SimdUint: Copy + Sealed {
1111
/// # Examples
1212
/// ```
1313
/// # #![feature(portable_simd)]
14-
/// # use core::simd::Simd;
14+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
15+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
16+
/// # use simd::{Simd, SimdUint};
1517
/// use core::u32::MAX;
1618
/// let x = Simd::from_array([2, 1, 0, MAX]);
1719
/// let max = Simd::splat(MAX);
@@ -27,7 +29,9 @@ pub trait SimdUint: Copy + Sealed {
2729
/// # Examples
2830
/// ```
2931
/// # #![feature(portable_simd)]
30-
/// # use core::simd::Simd;
32+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
33+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
34+
/// # use simd::{Simd, SimdUint};
3135
/// use core::u32::MAX;
3236
/// let x = Simd::from_array([2, 1, 0, MAX]);
3337
/// let max = Simd::splat(MAX);

crates/core_simd/src/vector.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ where
173173
///
174174
/// ```
175175
/// # #![feature(portable_simd)]
176-
/// # use core::simd::{Simd, u32x4};
176+
/// # use core::simd::u32x4;
177177
/// let source = vec![1, 2, 3, 4, 5, 6];
178178
/// let v = u32x4::from_slice(&source);
179179
/// assert_eq!(v.as_array(), &[1, 2, 3, 4]);
@@ -332,7 +332,9 @@ where
332332
/// # Examples
333333
/// ```
334334
/// # #![feature(portable_simd)]
335-
/// # use core_simd::simd::{Simd, SimdPartialOrd, Mask};
335+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
336+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
337+
/// # use simd::{Simd, SimdPartialOrd, Mask};
336338
/// let vec: Vec<i32> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
337339
/// let idxs = Simd::from_array([9, 3, 0, 5]);
338340
/// let alt = Simd::from_array([-5, -4, -3, -2]);
@@ -389,7 +391,9 @@ where
389391
/// # Examples
390392
/// ```
391393
/// # #![feature(portable_simd)]
392-
/// # use core_simd::simd::{Simd, Mask};
394+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
395+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
396+
/// # use simd::{Simd, Mask};
393397
/// let mut vec: Vec<i32> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
394398
/// let idxs = Simd::from_array([9, 3, 0, 0]);
395399
/// let vals = Simd::from_array([-27, 82, -41, 124]);
@@ -423,7 +427,9 @@ where
423427
/// # Examples
424428
/// ```
425429
/// # #![feature(portable_simd)]
426-
/// # use core_simd::simd::{Simd, SimdPartialOrd, Mask};
430+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
431+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
432+
/// # use simd::{Simd, SimdPartialOrd, Mask};
427433
/// let mut vec: Vec<i32> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
428434
/// let idxs = Simd::from_array([9, 3, 0, 0]);
429435
/// let vals = Simd::from_array([-27, 82, -41, 124]);

0 commit comments

Comments
 (0)