Skip to content
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

Implement Vec::splice and String::splice (RFC 1432) #40434

Merged
merged 6 commits into from
Apr 25, 2017

Conversation

mattico
Copy link
Contributor

@mattico mattico commented Mar 11, 2017

RFC: rust-lang/rfcs#1432, tracking issue: #32310
A rebase of #32355 with a few more tests.

Let me know if you have any ideas for more tests.

cc @SimonSapin

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@mattico
Copy link
Contributor Author

mattico commented Mar 11, 2017

I suppose I should duplicate the Vec tests in String and test the return value of splice()...

/// The given string doesn’t need to be the same length as the range.
///
/// Note: The element range is removed even if the iterator is not
/// consumed until the end.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is contradicted by the comment under "Memory safety" below.

Copy link
Contributor Author

@mattico mattico Mar 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

/// Note: The element range is removed when the Splice is dropped,
/// even if the iterator is not consumed until the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this applies to Drain as well

/// consumed until the end.
///
/// Note 2: It is unspecified how many elements are removed from the vector,
/// if the `Splice` value is leaked.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this comma is unnecessary.

@durka
Copy link
Contributor

durka commented Mar 11, 2017 via email

@durka
Copy link
Contributor

durka commented Mar 11, 2017 via email

@SimonSapin
Copy link
Contributor

Thank you for picking this up!

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 14, 2017
@mattico
Copy link
Contributor Author

mattico commented Mar 19, 2017

Let's get this landed once the beta-madness settles down 😉.

@mattico mattico changed the title Implement Vec::splice and String::splice Implement Vec::splice and String::splice (RFC 1432) Mar 22, 2017
@mattico
Copy link
Contributor Author

mattico commented Mar 28, 2017

@bors r? @alexcrichton

(Feel free to reassign, I just know you're around)

@alexcrichton
Copy link
Member

sorry for being slow to review @mattico! I wanted to be sure to thank you for the PR, and just wanted to give you a heads up that I'll be traveling for the next week so it'll take some time to get around to reviewing this.

@mattico
Copy link
Contributor Author

mattico commented Apr 1, 2017

No problem, @alexcrichton. This RFC has waited a year, what's another week or so 😉.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok got a chance to look this over and it looks fantastic to me, thanks @mattico!

Just one minor nit but other than that I'd be ready to r+

impl<'a, 'b> Drop for Splice<'a, 'b> {
fn drop(&mut self) {
unsafe {
let vec = (*self.string).as_mut_vec();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for this to use Vec::splice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean using the Vec implementation for String in general, or using Vec::splice() in the string splice drop impl?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it may be pretty hard due to char decoding and whatnot, but here in drop it seems like it'd be a one-liner to call the vec impl for splicing I think, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into it after I rebase

@bors
Copy link
Contributor

bors commented Apr 6, 2017

☔ The latest upstream changes (presumably #41102) made this pull request unmergeable. Please resolve the merge conflicts.

@mattico mattico force-pushed the splice-update branch 2 times, most recently from 50cfe26 to 9878aa0 Compare April 8, 2017 21:48
@mattico
Copy link
Contributor Author

mattico commented Apr 10, 2017

I broke something during rebase, I'll ping you once I've fixed it.

@alexcrichton
Copy link
Member

@mattico ok just ping me whenever it's green and I'll take a final pass before r+

@mattico
Copy link
Contributor Author

mattico commented Apr 10, 2017

I found these comments interesting re: sharing drop impl https://github.com/rust-lang/rust/pull/32355/files#r57401834

@mattico
Copy link
Contributor Author

mattico commented Apr 10, 2017

Note to self: add forget() test: https://github.com/rust-lang/rust/pull/32355/files#r57402156

@alexcrichton
Copy link
Member

I think we don't need to worry about leaks in this case b/c we're already in a destructor and we're just dropping the splice value that we ourselves are creating, so I don't think there's leak issues? If the split iterator is leaked then I think the string is just safely truncated, right?

@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 14, 2017
@carols10cents
Copy link
Member

Hi @mattico! Friendly ping to keep this on your radar!

@mattico
Copy link
Contributor Author

mattico commented Apr 17, 2017

Haven't forgotten about this, just haven't had much time. Will try to get back to this this week sometime.

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 24, 2017
Implement Vec::splice and String::splice (RFC 1432)

RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310
A rebase of rust-lang#32355 with a few more tests.

Let me know if you have any ideas for more tests.

cc @SimonSapin
@mattico
Copy link
Contributor Author

mattico commented Apr 24, 2017

Oh whoops, I just pushed a forget() test, which codifies the current behavior. Technically for Vec it's unspecified what happens if you forget the Splice, but the test will at least make sure it doesn't change behavior accidentally.

@mattico
Copy link
Contributor Author

mattico commented Apr 24, 2017

These new tests pass locally so it should be safe to r+

@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Contributor

bors commented Apr 24, 2017

📌 Commit feae5a0 has been approved by alexcrichton

bors added a commit that referenced this pull request Apr 24, 2017
Rollup of 3 pull requests

- Successful merges: #40434, #41370, #41500
- Failed merges:
@bors
Copy link
Contributor

bors commented Apr 24, 2017

⌛ Testing commit feae5a0 with merge 05a2d62...

@bors
Copy link
Contributor

bors commented Apr 24, 2017

💔 Test failed - status-travis

@frewsxcv
Copy link
Member

@bors retry #40474

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 24, 2017
Implement Vec::splice and String::splice (RFC 1432)

RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310
A rebase of rust-lang#32355 with a few more tests.

Let me know if you have any ideas for more tests.

cc @SimonSapin
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 24, 2017
Implement Vec::splice and String::splice (RFC 1432)

RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310
A rebase of rust-lang#32355 with a few more tests.

Let me know if you have any ideas for more tests.

cc @SimonSapin
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 25, 2017
Implement Vec::splice and String::splice (RFC 1432)

RFC: rust-lang/rfcs#1432, tracking issue: rust-lang#32310
A rebase of rust-lang#32355 with a few more tests.

Let me know if you have any ideas for more tests.

cc @SimonSapin
@alexcrichton
Copy link
Member

@bors: retry

@arielb1 arielb1 added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 25, 2017
@bors
Copy link
Contributor

bors commented Apr 25, 2017

⌛ Testing commit feae5a0 with merge c7e724a...

bors added a commit that referenced this pull request Apr 25, 2017
Implement Vec::splice and String::splice (RFC 1432)

RFC: rust-lang/rfcs#1432, tracking issue: #32310
A rebase of #32355 with a few more tests.

Let me know if you have any ideas for more tests.

cc @SimonSapin
@bors
Copy link
Contributor

bors commented Apr 25, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing c7e724a to master...

@bors bors merged commit feae5a0 into rust-lang:master Apr 25, 2017
@mattico mattico deleted the splice-update branch April 28, 2017 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.