8000 Rollup of 16 pull requests by Dylan-DPC · Pull Request #94784 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 16 pull requests #94784

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
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6620244
Make some `Clone` impls `const`
lilasta Dec 11, 2021
9054fbb
mirror mention of intent of From
asquared31415 Jan 3, 2022
04b3162
Add collect_into
frengor Feb 20, 2022
5941fef
Constify slice indexing
fee1-dead Feb 22, 2022
4654a91
Constify slice index for strings
fee1-dead Mar 6, 2022
b328688
Statically compile libstdc++ everywhere if asked
Mar 8, 2022
0d92752
Suggest `if let`/`let_else` for refutable pat in `let`
estebank Mar 8, 2022
c3a998e
Do not suggest `let_else` if no bindings would be introduced
estebank Mar 8, 2022
a5216cf
Unify inherent impl blocks by wrapping them into a div
GuillaumeGomez Mar 8, 2022
fbd9c28
Update GUI tests for impl blocks path changes
GuillaumeGomez Mar 8, 2022
4e067e8
Improve rustdoc book
Urgau Mar 8, 2022
40e4bd2
treat all mir::Constant values as ConstantKind::Val
b-naber Feb 16, 2022
8a811a1
bless tests
b-naber Feb 16, 2022
26fe550
normalization change and rebase
b-naber Mar 8, 2022
5226395
Fix soundness issue in scoped threads.
m-ou-se Mar 5, 2022
7a481ff
Properly abort when thread result panics on drop.
m-ou-se Mar 5, 2022
1c06eb7
Remove outdated comment.
m-ou-se Mar 9, 2022
b97d875
Add soundness test for dropping scoped thread results before joining.
m-ou-se Mar 9, 2022
491350c
Ignore `close_read_wakes_up` test on SGX platform
raoulstrackx Mar 9, 2022
18bb2dd
manually bless 32-bit stderr
b-naber Mar 9, 2022
e346920
Also take in account mdbook redirect in linkchecker
Urgau Mar 9, 2022
021c3b0
keep ERROR in message
b-naber Mar 9, 2022
e54d4ab
Use MaybeUninit in VecDeque to remove the undefined behavior of slice
JmPotato Mar 1, 2022
4d56c15
Add documentation about lifetimes to thread::scope.
m-ou-se Mar 9, 2022
6781016
Add miri to the well known conditional compilation names and values
Urgau Mar 9, 2022
915f9a5
Warn users about || in let chain expressions
c410-f3r Mar 9, 2022
8073a88
Implement macro meta-variable expressions
c410-f3r Mar 9, 2022
63eddb3
Add tracking issue
frengor Mar 9, 2022
ed0ed70
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
Dylan-DPC Mar 9, 2022
0754c96
Rollup merge of #92541 - asquared31415:from-docs, r=m-ou-se
Dylan-DPC Mar 9, 2022
3f13f0b
Rollup merge of #93057 - frengor:iter_collect_into, r=m-ou-se
Dylan-DPC Mar 9, 2022
de7a97c
Rollup merge of #94059 - b-naber:constantkind-val-transformation, r=lcnr
Dylan-DPC Mar 9, 2022
753d931
Rollup merge of #94368 - c410-f3r:metaaaaaaaaaaaaaaaaaaaaaaaaaaa, r=p…
Dylan-DPC Mar 9, 2022
3440019
Rollup merge of #94472 - JmPotato:use_maybeuninit_for_vecdeque, r=m-o…
Dylan-DPC Mar 9, 2022
e3c33bb
Rollup merge of #94644 - m-ou-se:scoped-threads-drop-soundness, r=jos…
Dylan-DPC Mar 9, 2022
30bb973
Rollup merge of #94657 - fee1-dead:const_slice_index, r=oli-obk
Dylan-DPC Mar 9, 2022
72d8cf1
Rollup merge of #94719 - jonhoo:enable-static-lld, r=Mark-Simulacrum
Dylan-DPC Mar 9, 2022
fca8dba
Rollup merge of #94739 - estebank:suggest-let-else, r=oli-obk
Dylan-DPC Mar 9, 2022
668c607
Rollup merge of #94740 - GuillaumeGomez:unify-impl-blocks, r=notriddle
Dylan-DPC Mar 9, 2022
f2baf2f
Rollup merge of #94753 - Urgau:rustdoc-book-improvements, r=Guillaume…
Dylan-DPC Mar 9, 2022
67fa033
Rollup merge of #94754 - c410-f3r:nice-error, r=lcnr
Dylan-DPC Mar 9, 2022
1ccd44f
Rollup merge of #94763 - m-ou-se:scoped-threads-lifetime-docs, r=Mark…
Dylan-DPC Mar 9, 2022
f7b1fcf
Rollup merge of #94768 - fortanix:raoul/fix_close_read_wakes_up_test_…
Dylan-DPC Mar 9, 2022
3257f81
Rollup merge of #94772 - Urgau:check-cfg-miri, r=petrochenkov
Dylan-DPC Mar 9, 2022
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
Add collect_into
  • Loading branch information
frengor committed Feb 20, 2022
commit 04b3162764516aa2295d4d549969bae60b5d0cf9
71 changes: 71 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,77 @@ pub trait Iterator {
try_process(self, |i| i.collect())
}

/// Collects all the items from an iterator into a collection.
///
/// This method consumes the iterator and adds all its items to the
/// passed collection. The collection is then returned, so the call chain
/// can be continued.
///
/// This is useful when you already have a collection and wants to add
/// the iterator items to it.
///
/// This method is a convenience method to call [Extend::extend](trait.Extend.html),
/// but instead of being called on a collection, it's called on an iterator.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(iter_collect_into)]
///
/// let a = [1, 2, 3];
/// let mut vec: Vec::<i32> = vec![0, 1];
///
/// a.iter().map(|&x| x * 2).collect_into(&mut vec);
/// a.iter().map(|&x| x * 10).collect_into(&mut vec);
///
/// assert_eq!(vec![0, 1, 2, 4, 6, 10, 20, 30], vec);
/// ```
///
/// `Vec` can have a manual set capacity to avoid reallocating it:
///
/// ```
/// #![feature(iter_collect_into)]
///
/// let a = [1, 2, 3];
/// let mut vec: Vec::<i32> = Vec::with_capacity(6);
///
/// a.iter().map(|&x| x * 2).collect_into(&mut vec);
/// a.iter().map(|&x| x * 10).collect_into(&mut vec);
///
/// assert_eq!(6, vec.capacity());
/// println!("{:?}", vec);
/// ```
///
/// The returned mutable reference can be used to continue the call chain:
///
/// ```
/// #![feature(iter_collect_into)]
///
/// let a = [1, 2, 3];
/// let mut vec: Vec::<i32> = Vec::with_capacity(6);
///
/// let count = a.iter().collect_into(&mut vec).iter().count();
///
/// assert_eq!(count, vec.len());
/// println!("Vec len is {}", count);
///
/// let count = a.iter().collect_into(&mut vec).iter().count();
///
/// assert_eq!(count, vec.len());
/// println!("Vec len now is {}", count);
/// ```
#[inline]
#[unstable(feature = "iter_collect_into", reason = "new API", issue = "none")]
fn collect_into<E: Extend<Self::Item>>(self, collection: &mut E) -> &mut E
where
Self: Sized,
{
collection.extend(self);
collection
}

/// Consumes an iterator, creating two collections from it.
///
/// The predicate passed to `partition()` can return `true`, or `false`.
Expand Down
8 changes: 8 additions & 0 deletions library/core/tests/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@ fn test_try_collect() {
assert_eq!(v, Continue(vec![4, 5]));
}

#[test]
fn test_collect_into() {
let a = vec![1, 2, 3, 4, 5];
let mut b = Vec::new();
a.iter().cloned().collect_into(&mut b);
assert!(a == b);
}

// just tests by whether or not this compiles
fn _empty_impl_all_auto_traits<T>() {
use std::panic::{RefUnwindSafe, UnwindSafe};
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 @@ -63,6 +63,7 @@
#![feature(slice_partition_dedup)]
#![feature(int_log)]
#![feature(iter_advance_by)]
#![feature(iter_collect_into)]
#![feature(iter_partition_in_place)]
#![feature(iter_intersperse)]
#![feature(iter_is_partitioned)]
Expand Down
0