Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0698922
Deprecate compare_and_swap on all atomic types
faern Nov 20, 2020
7bd770c
Add documentation on migrating away from compare_and_swap
faern Nov 20, 2020
df2ef1d
Migrate standard library away from compare_and_swap
faern Nov 20, 2020
90e6eeb
Add doc aliases to compare_exchange[_weak]
faern Nov 22, 2020
ed7b244
Fix documentation typo
faern Nov 22, 2020
7a40b6d
Improve documentation on `success` and `failure` arguments
faern Nov 22, 2020
50b2ade
Revert the usage of compare_exchange_weak
faern Nov 22, 2020
3b8617b
Added [T; N]::zip()
usbalbin Nov 26, 2020
2f35fb1
Remove redundant tests
usbalbin Nov 27, 2020
06ca6bb
Add tests
Nadrieril Nov 22, 2020
d1a50ff
Rename the `overlapping_patterns` lint to `overlapping_range_endpoints`
Nadrieril Oct 22, 2020
c89d439
Be consistent about linting singletons
Nadrieril Oct 22, 2020
94ad5e1
Improve error message
Nadrieril Oct 22, 2020
5687c16
`overlapping_range_endpoints` does not belong in the `unused` lint group
Nadrieril Nov 22, 2020
0e0ae47
Add a new lint to rustdoc for invalid codeblocks
poliorcetics Dec 15, 2020
be2c8f2
Update zip for better codegen, see discussion
usbalbin Dec 16, 2020
baa5e47
Update doc comment
usbalbin Dec 16, 2020
8b37259
Added reference to tracking issue
usbalbin Dec 16, 2020
830ceaa
Remap instrument-coverage line numbers in doctests
Swatinem Dec 6, 2020
5b6c175
Tweak diagnostics
Nadrieril Dec 19, 2020
52b717f
Edit rustc_middle::lint::LintSource docs
pierwill Dec 19, 2020
4fffa74
docs: Edit rustc_middle::ty::query::on_disk_cache
pierwill Dec 19, 2020
41c4330
Make doc-test pass with the new rustdoc
poliorcetics Dec 19, 2020
c127530
Fix labels for 'Library Tracking Issue' template
camelid Dec 20, 2020
e614a72
Fix rustc-std-workspace-core documentation
GreenRecycleBin Dec 20, 2020
f9fa3fe
add an attribute to inner doctest fn
Swatinem Dec 20, 2020
087101e
make path normalization compatible with mac python2
Swatinem Dec 21, 2020
a272d62
Implemented a compiler diagnostic for move async mistake
diondokter Dec 18, 2020
a219cb7
Rollup merge of #78242 - Nadrieril:rename-overlapping_endpoints-lint,…
Dylan-DPC Dec 22, 2020
f373fe3
Rollup merge of #79261 - faern:deprecate-compare-and-swap, r=Amanieu
Dylan-DPC Dec 22, 2020
dae90aa
Rollup merge of #79451 - usbalbin:array_zip, r=m-ou-se
Dylan-DPC Dec 22, 2020
028b0cc
Rollup merge of #79762 - Swatinem:remap-doctest-coverage, r=Swatinem
Dylan-DPC Dec 22, 2020
c9e897a
Rollup merge of #79816 - poliorcetics:rustdoc-fail-on-deny, r=jyn514
Dylan-DPC Dec 22, 2020
c809da4
Rollup merge of #80160 - diondokter:move_async_fix, r=davidtwco
Dylan-DPC Dec 22, 2020
51338fa
Rollup merge of #80203 - pierwill:pierwill-rustcmiddle-lint, r=oli-obk
Dylan-DPC Dec 22, 2020
731c7ec
Rollup merge of #80204 - pierwill:pierwill-rustcmiddle-ondisk, r=varkor
Dylan-DPC Dec 22, 2020
f36d9ee
Rollup merge of #80219 - camelid:library_tracking_issue-labels, r=m-o…
Dylan-DPC Dec 22, 2020
cac7101
Rollup merge of #80222 - GreenRecycleBin:daniel/fix-rustc-std-workspa…
Dylan-DPC Dec 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added [T; N]::zip()
  • Loading branch information
usbalbin committed Nov 26, 2020
commit 3b8617b9b6718f04d412ffae52337053e79c3c6b
28 changes: 28 additions & 0 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,34 @@ impl<T, const N: usize> [T; N] {
unsafe { crate::mem::transmute_copy::<_, [U; N]>(&dst) }
}

/// 'Zips up' two arrays into a single array of pairs.
/// `zip()` returns a new array where every element is a tuple where the first element comes from the first array, and the second element comes from the second array.
/// In other words, it zips two arrays together, into a single one.
///
/// # Examples
///
/// ```
/// #![feature(array_zip)]
/// let x = [1, 2, 3];
/// let y = [4, 5, 6];
/// let z = x.zip(y);
/// assert_eq!(z, [(1, 4), (2, 5), (3, 6)]);
/// ```
#[unstable(feature = "array_zip", issue = "none")]
pub fn zip<U>(self, rhs: [U; N]) -> [(T, U); N] {
use crate::mem::MaybeUninit;

let mut dst = MaybeUninit::uninit_array::<N>();
for ((lhs, rhs), dst) in IntoIter::new(self).zip(IntoIter::new(rhs)).zip(&mut dst) {
dst.write((lhs, rhs));
}
// FIXME: Convert to crate::mem::transmute once it works with generics.
// unsafe { crate::mem::transmute::<[MaybeUninit<U>; N], [U; N]>(dst) }
// SAFETY: At this point we've properly initialized the whole array
// and we just need to cast it to the correct type.
unsafe { crate::mem::transmute_copy::<_, [(T, U); N]>(&dst) }
}

/// Returns a slice containing the entire array. Equivalent to `&s[..]`.
#[unstable(feature = "array_methods", issue = "76118")]
pub fn as_slice(&self) -> &[T] {
Expand Down
8 changes: 8 additions & 0 deletions library/core/tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ fn array_map() {
assert_eq!(b, [1, 2, 3]);
}

#[test]
fn array_zip() {
let a = [1, 2, 3];
let b = [4, 5, 6];
let c = a.zip(b);
assert_eq!(c, [(1, 4), (2, 5), (3, 6)]);
}

// See note on above test for why `should_panic` is used.
#[test]
#[should_panic(expected = "test succeeded")]
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![feature(array_from_ref)]
#![feature(array_methods)]
#![feature(array_map)]
#![feature(array_zip)]
#![feature(array_windows)]
#![feature(bool_to_option)]
#![feature(bound_cloned)]
Expand Down