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

Add VecDeque::resize_with #56016

Merged
merged 1 commit into from Nov 19, 2018

Conversation

Projects
None yet
5 participants
@scottmcm
Member

scottmcm commented Nov 17, 2018

This already exists on Vec; I'm just adding it to VecDeque.

I wanted to resize a VecDeque<Vec<T>> when I didn't know T: Clone, so I couldn't use .resize(n, Vec::new()). With this I could do .resize_with(n, Vec::new) instead, which doesn't need T: Clone.

Tracking issue: #41758

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 17, 2018

r? @joshtriplett

(rust_highfive has picked a reviewer for you, use r? to override)

@scottmcm scottmcm force-pushed the scottmcm:vecdeque-resize-with branch from 33c3ec1 to f14a86d Nov 17, 2018

@scottmcm scottmcm force-pushed the scottmcm:vecdeque-resize-with branch from f14a86d to cdb1a79 Nov 18, 2018

@joshtriplett

This comment has been minimized.

Member

joshtriplett commented Nov 18, 2018

@bors r+

@bors

This comment has been minimized.

Contributor

bors commented Nov 18, 2018

📌 Commit cdb1a79 has been approved by joshtriplett

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Nov 18, 2018

Rollup merge of rust-lang#56016 - scottmcm:vecdeque-resize-with, r=jo…
…shtriplett

Add VecDeque::resize_with

This already exists on `Vec`; I'm just adding it to `VecDeque`.

I wanted to resize a `VecDeque<Vec<T>>` when I didn't know `T: Clone`, so I couldn't use `.resize(n, Vec::new())`.  With this I could do `.resize_with(n, Vec::new)` instead, which doesn't need `T: Clone`.

Tracking issue: rust-lang#41758

bors added a commit that referenced this pull request Nov 19, 2018

Auto merge of #56051 - pietroalbini:rollup, r=pietroalbini
Rollup of 25 pull requests

Successful merges:

 - #55562 (Add powerpc- and powerpc64-unknown-linux-musl targets)
 - #55564 (test/linkage-visibility: Ignore on musl targets)
 - #55827 (A few tweaks to iterations/collecting)
 - #55834 (Forward the ABI of the non-zero sized fields of an union if they have the same ABI)
 - #55857 (remove unused dependency)
 - #55862 (in which the E0618 "expected function" diagnostic gets a makeover)
 - #55867 (do not panic just because cargo failed)
 - #55894 (miri enum discriminant handling: Fix treatment of pointers, better error when it is undef)
 - #55916 (Make miri value visitor usfeful for mutation)
 - #55919 (core/tests/num: Simplify `test_int_from_str_overflow()` test code)
 - #55923 (reword #[test] attribute error on fn items)
 - #55935 (appveyor: Use VS2017 for all our images)
 - #55949 (ty: return impl Iterator from Predicate::walk_tys)
 - #55952 (Update to Clang 7 on CI.)
 - #55953 (#53488 Refactoring UpvarId)
 - #55962 (rustdoc: properly calculate spans for intra-doc link resolution errors)
 - #55963 (Stress test for MPSC)
 - #55968 (Clean up some non-mod-rs stuff.)
 - #55970 (Miri backtrace improvements)
 - #56007 (CTFE: dynamically make sure we do not call non-const-fn)
 - #56011 (Replace data.clone() by Arc::clone(&data) in mutex doc.)
 - #56012 (avoid shared ref in UnsafeCell::get)
 - #56016 (Add VecDeque::resize_with)
 - #56027 (docs: Add missing backtick in object_safety.rs docs)
 - #56043 (remove "approx env bounds" if we already know from trait)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Nov 19, 2018

Auto merge of #56051 - pietroalbini:rollup, r=pietroalbini
Rollup of 25 pull requests

Successful merges:

 - #55562 (Add powerpc- and powerpc64-unknown-linux-musl targets)
 - #55564 (test/linkage-visibility: Ignore on musl targets)
 - #55827 (A few tweaks to iterations/collecting)
 - #55834 (Forward the ABI of the non-zero sized fields of an union if they have the same ABI)
 - #55857 (remove unused dependency)
 - #55862 (in which the E0618 "expected function" diagnostic gets a makeover)
 - #55867 (do not panic just because cargo failed)
 - #55894 (miri enum discriminant handling: Fix treatment of pointers, better error when it is undef)
 - #55916 (Make miri value visitor usfeful for mutation)
 - #55919 (core/tests/num: Simplify `test_int_from_str_overflow()` test code)
 - #55923 (reword #[test] attribute error on fn items)
 - #55935 (appveyor: Use VS2017 for all our images)
 - #55949 (ty: return impl Iterator from Predicate::walk_tys)
 - #55952 (Update to Clang 7 on CI.)
 - #55953 (#53488 Refactoring UpvarId)
 - #55962 (rustdoc: properly calculate spans for intra-doc link resolution errors)
 - #55963 (Stress test for MPSC)
 - #55968 (Clean up some non-mod-rs stuff.)
 - #55970 (Miri backtrace improvements)
 - #56007 (CTFE: dynamically make sure we do not call non-const-fn)
 - #56011 (Replace data.clone() by Arc::clone(&data) in mutex doc.)
 - #56012 (avoid shared ref in UnsafeCell::get)
 - #56016 (Add VecDeque::resize_with)
 - #56027 (docs: Add missing backtick in object_safety.rs docs)
 - #56043 (remove "approx env bounds" if we already know from trait)

Failed merges:

r? @ghost
/// assert_eq!(buf, [5, 10, 101, 102, 103]);
/// ```
#[unstable(feature = "vec_resize_with", issue = "41758")]
pub fn resize_with(&mut self, new_len: usize, generator: impl FnMut()->T) {

This comment has been minimized.

@Centril

Centril Nov 19, 2018

Contributor
Suggested change Beta
pub fn resize_with(&mut self, new_len: usize, generator: impl FnMut()->T) {
pub fn resize_with(&mut self, new_len: usize, generator: impl FnMut() -> T) {

Also, we generally don't use arg: impl Trait in the standard library so I think this should be a type param instead.

bors added a commit that referenced this pull request Nov 19, 2018

Auto merge of #56051 - pietroalbini:rollup, r=pietroalbini
Rollup of 26 pull requests

Successful merges:

 - #55562 (Add powerpc- and powerpc64-unknown-linux-musl targets)
 - #55564 (test/linkage-visibility: Ignore on musl targets)
 - #55827 (A few tweaks to iterations/collecting)
 - #55834 (Forward the ABI of the non-zero sized fields of an union if they have the same ABI)
 - #55857 (remove unused dependency)
 - #55862 (in which the E0618 "expected function" diagnostic gets a makeover)
 - #55867 (do not panic just because cargo failed)
 - #55894 (miri enum discriminant handling: Fix treatment of pointers, better error when it is undef)
 - #55916 (Make miri value visitor useful for mutation)
 - #55919 (core/tests/num: Simplify `test_int_from_str_overflow()` test code)
 - #55923 (reword #[test] attribute error on fn items)
 - #55935 (appveyor: Use VS2017 for all our images)
 - #55949 (ty: return impl Iterator from Predicate::walk_tys)
 - #55952 (Update to Clang 7 on CI.)
 - #55953 (#53488 Refactoring UpvarId)
 - #55962 (rustdoc: properly calculate spans for intra-doc link resolution errors)
 - #55963 (Stress test for MPSC)
 - #55968 (Clean up some non-mod-rs stuff.)
 - #55970 (Miri backtrace improvements)
 - #56007 (CTFE: dynamically make sure we do not call non-const-fn)
 - #56011 (Replace data.clone() by Arc::clone(&data) in mutex doc.)
 - #56012 (avoid shared ref in UnsafeCell::get)
 - #56016 (Add VecDeque::resize_with)
 - #56027 (docs: Add missing backtick in object_safety.rs docs)
 - #56043 (remove "approx env bounds" if we already know from trait)
 - #56059 (Increase `Duration` approximate equal threshold to 1us)

bors added a commit that referenced this pull request Nov 19, 2018

Auto merge of #56051 - pietroalbini:rollup, r=pietroalbini
Rollup of 26 pull requests

Successful merges:

 - #55562 (Add powerpc- and powerpc64-unknown-linux-musl targets)
 - #55564 (test/linkage-visibility: Ignore on musl targets)
 - #55827 (A few tweaks to iterations/collecting)
 - #55834 (Forward the ABI of the non-zero sized fields of an union if they have the same ABI)
 - #55857 (remove unused dependency)
 - #55862 (in which the E0618 "expected function" diagnostic gets a makeover)
 - #55867 (do not panic just because cargo failed)
 - #55894 (miri enum discriminant handling: Fix treatment of pointers, better error when it is undef)
 - #55916 (Make miri value visitor useful for mutation)
 - #55919 (core/tests/num: Simplify `test_int_from_str_overflow()` test code)
 - #55923 (reword #[test] attribute error on fn items)
 - #55935 (appveyor: Use VS2017 for all our images)
 - #55949 (ty: return impl Iterator from Predicate::walk_tys)
 - #55952 (Update to Clang 7 on CI.)
 - #55953 (#53488 Refactoring UpvarId)
 - #55962 (rustdoc: properly calculate spans for intra-doc link resolution errors)
 - #55963 (Stress test for MPSC)
 - #55968 (Clean up some non-mod-rs stuff.)
 - #55970 (Miri backtrace improvements)
 - #56007 (CTFE: dynamically make sure we do not call non-const-fn)
 - #56011 (Replace data.clone() by Arc::clone(&data) in mutex doc.)
 - #56012 (avoid shared ref in UnsafeCell::get)
 - #56016 (Add VecDeque::resize_with)
 - #56027 (docs: Add missing backtick in object_safety.rs docs)
 - #56043 (remove "approx env bounds" if we already know from trait)
 - #56059 (Increase `Duration` approximate equal threshold to 1us)

kennytm added a commit to pietroalbini/rust that referenced this pull request Nov 19, 2018

Rollup merge of rust-lang#56016 - scottmcm:vecdeque-resize-with, r=jo…
…shtriplett

Add VecDeque::resize_with

This already exists on `Vec`; I'm just adding it to `VecDeque`.

I wanted to resize a `VecDeque<Vec<T>>` when I didn't know `T: Clone`, so I couldn't use `.resize(n, Vec::new())`.  With this I could do `.resize_with(n, Vec::new)` instead, which doesn't need `T: Clone`.

Tracking issue: rust-lang#41758

bors added a commit that referenced this pull request Nov 19, 2018

Auto merge of #56051 - pietroalbini:rollup, r=pietroalbini
Rollup of 25 pull requests

Successful merges:

 - #55562 (Add powerpc- and powerpc64-unknown-linux-musl targets)
 - #55564 (test/linkage-visibility: Ignore on musl targets)
 - #55827 (A few tweaks to iterations/collecting)
 - #55834 (Forward the ABI of the non-zero sized fields of an union if they have the same ABI)
 - #55857 (remove unused dependency)
 - #55862 (in which the E0618 "expected function" diagnostic gets a makeover)
 - #55867 (do not panic just because cargo failed)
 - #55894 (miri enum discriminant handling: Fix treatment of pointers, better error when it is undef)
 - #55916 (Make miri value visitor useful for mutation)
 - #55919 (core/tests/num: Simplify `test_int_from_str_overflow()` test code)
 - #55923 (reword #[test] attribute error on fn items)
 - #55949 (ty: return impl Iterator from Predicate::walk_tys)
 - #55952 (Update to Clang 7 on CI.)
 - #55953 (#53488 Refactoring UpvarId)
 - #55962 (rustdoc: properly calculate spans for intra-doc link resolution errors)
 - #55963 (Stress test for MPSC)
 - #55968 (Clean up some non-mod-rs stuff.)
 - #55970 (Miri backtrace improvements)
 - #56007 (CTFE: dynamically make sure we do not call non-const-fn)
 - #56011 (Replace data.clone() by Arc::clone(&data) in mutex doc.)
 - #56012 (avoid shared ref in UnsafeCell::get)
 - #56016 (Add VecDeque::resize_with)
 - #56027 (docs: Add missing backtick in object_safety.rs docs)
 - #56043 (remove "approx env bounds" if we already know from trait)
 - #56059 (Increase `Duration` approximate equal threshold to 1us)

@bors bors merged commit cdb1a79 into rust-lang:master Nov 19, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@scottmcm scottmcm deleted the scottmcm:vecdeque-resize-with branch Nov 30, 2018

Centril added a commit to Centril/rust that referenced this pull request Dec 1, 2018

Rollup merge of rust-lang#56401 - scottmcm:vecdeque-resize-with, r=dt…
…olnay

Move VecDeque::resize_with out of the impl<T:Clone> block

I put this in the wrong `impl` block in rust-lang#56016, so fixing.

Tracking issue for the unstable method: rust-lang#41758 (comment)

Centril added a commit to Centril/rust that referenced this pull request Dec 2, 2018

Rollup merge of rust-lang#56401 - scottmcm:vecdeque-resize-with, r=dt…
…olnay

Move VecDeque::resize_with out of the impl<T:Clone> block

I put this in the wrong `impl` block in rust-lang#56016, so fixing.

Tracking issue for the unstable method: rust-lang#41758 (comment)

Centril added a commit to Centril/rust that referenced this pull request Dec 2, 2018

Rollup merge of rust-lang#56401 - scottmcm:vecdeque-resize-with, r=dt…
…olnay

Move VecDeque::resize_with out of the impl<T:Clone> block

I put this in the wrong `impl` block in rust-lang#56016, so fixing.

Tracking issue for the unstable method: rust-lang#41758 (comment)

Centril added a commit to Centril/rust that referenced this pull request Dec 2, 2018

Rollup merge of rust-lang#56401 - scottmcm:vecdeque-resize-with, r=dt…
…olnay

Move VecDeque::resize_with out of the impl<T:Clone> block

I put this in the wrong `impl` block in rust-lang#56016, so fixing.

Tracking issue for the unstable method: rust-lang#41758 (comment)

Centril added a commit to Centril/rust that referenced this pull request Dec 2, 2018

Rollup merge of rust-lang#56401 - scottmcm:vecdeque-resize-with, r=dt…
…olnay

Move VecDeque::resize_with out of the impl<T:Clone> block

I put this in the wrong `impl` block in rust-lang#56016, so fixing.

Tracking issue for the unstable method: rust-lang#41758 (comment)

Centril added a commit to Centril/rust that referenced this pull request Dec 2, 2018

Rollup merge of rust-lang#56401 - scottmcm:vecdeque-resize-with, r=dt…
…olnay

Move VecDeque::resize_with out of the impl<T:Clone> block

I put this in the wrong `impl` block in rust-lang#56016, so fixing.

Tracking issue for the unstable method: rust-lang#41758 (comment)

kennytm added a commit to kennytm/rust that referenced this pull request Dec 3, 2018

Rollup merge of rust-lang#56401 - scottmcm:vecdeque-resize-with, r=dt…
…olnay

Move VecDeque::resize_with out of the impl<T:Clone> block

I put this in the wrong `impl` block in rust-lang#56016, so fixing.

Tracking issue for the unstable method: rust-lang#41758 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment