Skip to content

Conversation

frewsxcv
Copy link
Contributor

Fixes #37046.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (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.

@frewsxcv
Copy link
Contributor Author

I think my changes are an improvement, but I'm not super satisfied with them. Please let me know if anyone has ideas for improvement.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum Dec 23, 2016

Choose a reason for hiding this comment

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

Could we just reuse the Vec comment: "Inserts an element at position index within the vector, shifting all elements after it to the right."? I don't know whether that has different meaning for VecDeque, but seems simpler.

Edit: Link to Vec documentation: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.insert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My hesitation with that comment is that (at least behind the scenes in memory), VecDeque::insert doesn't necessarily shift all the following items to the back like it does with Vec::insert. Though, if we're not talking about what happens in-memory it is true as far as indices/positions go, if that makes any sense. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps "Inserts an element at position index within the vector, incrementing all indices after index by one."

That avoids the problem with somewhat implying the underlying memory operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I incorporated it in the latest force push.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though on second thought, your suggestion doesn't really address #37046.

@shepmaster
Copy link
Member

shepmaster commented Dec 23, 2016

Looks like your PR / commit message title has a typo: VecDequeue instead of VecDeque.

@frewsxcv frewsxcv changed the title Clarify behavior of VecDequeue::insert. Clarify behavior of VecDeque::insert. Dec 24, 2016
@frewsxcv
Copy link
Contributor Author

Looks like your PR / commit message title has a typo: VecDequeue instead of VecDeque.

@shepmaster Thanks for pointing that out. It's been fixed now.

@frewsxcv frewsxcv force-pushed the vecdequeue-insert branch 2 times, most recently from deec978 to 971a019 Compare December 24, 2016 20:15
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

Looks good, left two minor nits.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just "at index"? "index index" feels a little odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest force push.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this will compile, but perhaps we can omit the & in front of each char in the array? Perhaps removing those and making it a slice will work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That didn't work for me:

error[E0277]: the trait bound `&char: std::cmp::PartialEq<char>` is not satisfied
  --> <anon>:12:4
   |
12 |    assert_eq!(vec, &['a', 'd', 'b', 'c']);
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::PartialEq<char>` is not implemented for `&char`
   |
   = help: the following implementations were found:
   = help:   <char as std::cmp::PartialEq>
   = note: required because of the requirements on the impl of `std::cmp::PartialEq<&[char; 4]>` for `std::vec::Vec<&char>`
   = note: this error originates in a macro outside of the current crate

error: aborting due to previous error

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see the problem. Can you try changing vec_deque.iter().collect::<Vec<_>>(); to vec_deque.into_iter().collect::<Vec<_>>();? That should fix the compile error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! Fixed in the latest force push.

@GuillaumeGomez
Copy link
Member

Thanks!

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Jan 4, 2017

📌 Commit 0ab7812 has been approved by GuillaumeGomez

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 4, 2017
…aumeGomez

Clarify behavior of `VecDeque::insert`.

Fixes rust-lang#37046.
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jan 4, 2017
…aumeGomez

Clarify behavior of `VecDeque::insert`.

Fixes rust-lang#37046.
@bors
Copy link
Collaborator

bors commented Jan 9, 2017

⌛ Testing commit 0ab7812 with merge 96d3123...

@bors
Copy link
Collaborator

bors commented Jan 9, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

alexcrichton commented Jan 9, 2017 via email

@bors
Copy link
Collaborator

bors commented Jan 9, 2017

⌛ Testing commit 0ab7812 with merge 5c1472a...

bors added a commit that referenced this pull request Jan 9, 2017
Clarify behavior of `VecDeque::insert`.

Fixes #37046.
@bors
Copy link
Collaborator

bors commented Jan 9, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: GuillaumeGomez
Pushing 5c1472a to master...

@bors bors merged commit 0ab7812 into rust-lang:master Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants