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 retain for VecDeque #24879

Merged
merged 1 commit into from
May 6, 2015
Merged

Implement retain for VecDeque #24879

merged 1 commit into from
May 6, 2015

Conversation

Stebalien
Copy link
Contributor

According to rust-lang/rfcs#235, VecDeque should have this method (VecDeque was called RingBuf at the time) but it was never implemented.

I marked this stable since "1.0.0" because it's stable in Vec.

@rust-highfive
Copy link
Collaborator

r? @huonw

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

/// buf.retain(|&x| x%2 == 0);
/// assert_eq!(buf, [2, 4]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Copy link
Member

Choose a reason for hiding this comment

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

At this point anything to be included in 1.0 needs to be cherry-picked backwards, and this isn't necessarily a serious enough change to be cherry-picked backwards, so if we're going to insta-stabilize it this should be since = "1.1.0" with a unique feature name like vec_deque_retain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

@alexcrichton
Copy link
Member

cc @aturon, @gankro

I think I'm ok insta-stabilizing this method as it's just following a convention, but I'm also not sure if we want to hold off adding these kinds of methods piecemeal for a point where a comprehensive review of all collections is done to ensure they reflect the expected API.

#[test]
fn test_retain() {
let mut buf = VecDeque::new();
buf.extend(1..4);
Copy link
Member

Choose a reason for hiding this comment

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

I think this test will also need to be updated for 1..5 instead of 1..4

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's bad. I ran the tests (make -j4 check) and they passed...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An unrelated test was failing causing the tests to abort early. However, the abort was lost well past my scrollback buffer and the old test logs were still there so I figured that my test passed...

@aturon
Copy link
Member

aturon commented Apr 28, 2015

@alexcrichton I don't have a strong feeling re: stabilization, but given that there's not a lot of urgency here, I would lean more toward landing as unstable and then including in a later stabilization pass, per standard policy.

@Gankra
Copy link
Contributor

Gankra commented Apr 28, 2015

I thought this was delayed/blocked on proper predicate support?

@Stebalien
Copy link
Contributor Author

I thought this was delayed/blocked on proper predicate support?

Vec already has retain. Anyways, Iterator::filter etc. will also need to be changed to support predicates so the change will probably have to be backwards compatible.

@alexcrichton
Copy link
Member

@gankro I think we ended up abandoning generic predicates due to coherence problems, but I don't know the precise details.

@Stebalien could you alter this to be introduced as #[unstable]?

@Stebalien
Copy link
Contributor Author

Done. I switched it to the collections feature to avoid adding a new one.

As for predicates, I'm guessing that the problem was that FnMut is a trait you'd need to implement Predicate for all FnMuts:

impl<T, V> Predicate<V> for T where T: FnMut { .. }
impl<V> Predicate<V> for SomeMatcher<V> { .. } // What if `SomeMatcher<V>` implements `FnMut`?

(Although you could cheat and auto-implement Predicate for all lambdas.)

@alexcrichton
Copy link
Member

Can you actually use a more descriptive feature name instead? We're trying to move away from large blanket feature names.

@alexcrichton
Copy link
Member

Something like vec_deque_retain should do just fine.

@Stebalien
Copy link
Contributor Author

Done (forgot that GitHub doesn't ping on commits).

@alexcrichton
Copy link
Member

@bors: r+ e8957aa

@bors
Copy link
Contributor

bors commented May 1, 2015

⌛ Testing commit e8957aa with merge b129686...

@bors
Copy link
Contributor

bors commented May 1, 2015

💔 Test failed - auto-mac-64-opt

@Stebalien
Copy link
Contributor Author

Sorry about that. It should work now (I think).

@alexcrichton
Copy link
Member

Could you also squash the commits?

@Stebalien
Copy link
Contributor Author

Done.

@alexcrichton
Copy link
Member

@bors: r+ 292193b

@bors
Copy link
Contributor

bors commented May 5, 2015

⌛ Testing commit 292193b with merge 1636d82...

@bors
Copy link
Contributor

bors commented May 5, 2015

💔 Test failed - auto-mac-64-opt

@Stebalien
Copy link
Contributor Author

Now it should actually be fixed. Is there any way to get rust to not stop testing on failure? The debug tests are broken on my system due to grsecurity and make NO_REBUILD=1 never seems to work (it always complains about missing symbols) so going back and running specific tests using make takes quite a while...

@Gankra
Copy link
Contributor

Gankra commented May 5, 2015

@bors r=alexcrichton

I can ask bors to run the tests on the try tester first if you're not sure?

@bors
Copy link
Contributor

bors commented May 5, 2015

📌 Commit decf395 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented May 5, 2015

⌛ Testing commit decf395 with merge 465fc8f...

@bors
Copy link
Contributor

bors commented May 5, 2015

💔 Test failed - auto-linux-64-nopt-t

@Stebalien
Copy link
Contributor Author

Is there any way to get rust to not stop testing on failure?

Nevermind, I figured out how to disable the faulty test (unset CFG_GDB in config.mk). However, the latest failure is unrelated to these changes (tcp rebind failure).

Sorry for wasting so much of your time on a simple patch.

@alexcrichton
Copy link
Member

@bors: retry

No worries! (we should fix these tests...)

@bors
Copy link
Contributor

bors commented May 6, 2015

⌛ Testing commit decf395 with merge 5b04c16...

bors added a commit that referenced this pull request May 6, 2015
According to rust-lang/rfcs#235, `VecDeque` should have this method (`VecDeque` was called `RingBuf` at the time) but it was never implemented.

I marked this stable since "1.0.0" because it's stable in `Vec`.
@bors bors merged commit decf395 into rust-lang:master May 6, 2015
@Stebalien Stebalien deleted the vec_deque branch June 11, 2015 16:09
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.

7 participants