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

Add take_... functions to slices #62282

Closed
wants to merge 1 commit into from

Conversation

cramertj
Copy link
Member

@cramertj cramertj commented Jul 1, 2019

This adds the following associated functions to [T]:

  • take_front
  • take_front_mut
  • take_end
  • take_end_mut
  • take_first
  • take_first_mut
  • take_last
  • take_last_mut

A previous PR that would have added some of this functionality was closed due to inactivity: #49173

I personally use these functions fairly often, and I often feel guilty re-hand-rolling them.

One thing to note is that these are just associated functions, rather than methods, because they use &&Self rather than &Self, which isn't yet a stable Self type. It should be backwards-compatible to change this, however, so long as there aren't major method resolution conflicts or similar. AFAIK there aren't any technical blockers to stabilizing &&Self method receivers-- it was just left out in order to keep the stable arbitrary_self_types surface small.

@rust-highfive
Copy link
Collaborator

r? @Kimundi

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 1, 2019
@cramertj cramertj mentioned this pull request Jul 1, 2019
6 tasks
@cramertj
Copy link
Member Author

cramertj commented Jul 1, 2019

cc @nox

src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
@timvermeulen
Copy link
Contributor

timvermeulen commented Jul 2, 2019

take_end forwards the len parameter directly to split_at, but take_end(slice, n) should take the last n elements (according to its docs), not take the suffix starting at index n. So it should probably either split the slice at slice.len() - len, or be documented to take an index.

I personally think having it take an index is more useful. In my limited experience with slices I more frequently want to take (or discard) the elements starting at a given index, rather than taking the last n elements. Admittedly, the current semantics do play nicely with take_last.

@cramertj
Copy link
Member Author

cramertj commented Jul 2, 2019

Ah, good call! I did intend for it to take at an index, but I got lazy with copy/pasting. Will fix, thanks for pointing that out. It is a somewhat interesting asymmetry, though.

@timvermeulen
Copy link
Contributor

timvermeulen commented Jul 2, 2019

take_end(3) does sound to me like taking the last three elements, maybe something like take_from would be less confusing?

@Dylan-DPC-zz
Copy link

ping from triage @cramertj can you update this with changes requested by Centril before I get someone to review it? thanks (also failing tests)

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 15, 2019
@cramertj
Copy link
Member Author

Sure-- there's one open design question above, but I'll at least make this PR self-consistent and address the other issues. Thanks for the ping!

@rholderfield
Copy link

ping from triage... hi @cramertj, can you please provide a status?

@nox
Copy link
Contributor

nox commented Jul 26, 2019

I feel like all these functions should actually live as methods on std::slice::Iter.


/// Takes the first element out of the slice.
///
/// Returns a reference pointing to the first element of the old slice.
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no such thing as an old slice, given there is not really a new slice either.

@timvermeulen
Copy link
Contributor

@nox This was addressed:

One thing to note is that these are just associated functions, rather than methods, because they use &&Self rather than &Self, which isn't yet a stable Self type. It should be backwards-compatible to change this, however, so long as there aren't major method resolution conflicts or similar. AFAIK there aren't any technical blockers to stabilizing &&Self method receivers-- it was just left out in order to keep the stable arbitrary_self_types surface small.

@nox
Copy link
Contributor

nox commented Jul 27, 2019

One thing to note is that these are just associated functions, rather than methods, because they use &&Self rather than &Self, which isn't yet a stable Self type. It should be backwards-compatible to change this, however, so long as there aren't major method resolution conflicts or similar. AFAIK there aren't any technical blockers to stabilizing &&Self method receivers-- it was just left out in order to keep the stable arbitrary_self_types surface small.

There is no need for &&Self if the methods live on std::slice::Iter.

@timvermeulen
Copy link
Contributor

Sorry, I misread your comment.

@nox
Copy link
Contributor

nox commented Jul 27, 2019

Sorry, I misread your comment.

No worries, I should have given more details as to why I think that anyway:

  • Those methods all take a &mut, but slices are Copy, I could imagine badly using one of those methods in a way where you take the n first elements but the rest of the code continue to use the original slice instead of the mutated one because it was mistakenly copied somewhere.

  • Doing those operations on slices, you have to adjust the pointer and the length every time, whereas std::slice::Iter is implemented as a pair of start/end pointers, so you only need to readjust the start pointer.

@timvermeulen
Copy link
Contributor

@nox

  • Those methods all take a &mut, but slices are Copy, I could imagine badly using one of those methods in a way where you take the n first elements but the rest of the code continue to use the original slice instead of the mutated one because it was mistakenly copied somewhere.

Hmm, kinda like how Range isn't Copy because it's already an iterator? Do you have an example of when you might accidentally mutate a copy of the slice instead of the original slice? Calling any of these methods on an immutable slice variable will fortunately cause a compiler error rather than mutating a copy, so I'm not sure when this could cause any problems.

  • Doing those operations on slices, you have to adjust the pointer and the length every time, whereas std::slice::Iter is implemented as a pair of start/end pointers, so you only need to readjust the start pointer.

I happen to think that that's how slices should have been implemented to begin with 🙂 It would make stuff like split_at a lot simpler too in terms of the number of operations, and slice::Iter could then just wrap a slice without losing performance.

Whenever I needed any of these take_ methods, I don't think having them on slice::Iter would have been very useful for me. If it requires converting to an iterator and then back to a slice, you probably may as well call split_at instead.

@nox
Copy link
Contributor

nox commented Jul 27, 2019

Hmm, kinda like how Range isn't Copy because it's already an iterator? Do you have an example of when you might accidentally mutate a copy of the slice instead of the original slice? Calling any of these methods on an immutable slice variable will fortunately cause a compiler error rather than mutating a copy, so I'm not sure when this could cause any problems.

Forget about that, the cases I had in mind involved method calls on temporaries, but there are no method calls to begin with in this RFC.

I happen to think that that's how slices should have been implemented to begin with 🙂 It would make stuff like split_at a lot simpler too in terms of the number of operations, and slice::Iter could then just wrap a slice without losing performance.

A pair of pointers makes Index implementations more complicated though.

Whenever I needed any of these take_ methods, I don't think having them on slice::Iter would have been very useful for me. If it requires converting to an iterator and then back to a slice, you probably may as well call split_at instead.

The thing is, if there were those methods on slice::Iter, how often would you even need a slice again? I usually either need indexing, or extracting things out from the beginning of the slice, not both at once.

@JohnTitor
Copy link
Member

Ping from triage: @cramertj any updates on this?

@totsteps
Copy link
Member

totsteps commented Aug 13, 2019

Second ping from triage, @cramertj any updates on this? All checks are failing.

Note: Thanks for the PR. This will be closed and marked as S-inactive-closed next week. Feel free to re-open when you have time.

Thanks

@timvermeulen
Copy link
Contributor

@nox

A pair of pointers makes Index implementations more complicated though.

That's fair enough, although earlier I wasn't able to come up with a benchmark that uses indexing and is faster on normal slices than on two-pointer slices. I'm guessing the binary ended up reusing the length rather than computing it over and over, which may actually be true most real world usages of slices.

The thing is, if there were those methods on slice::Iter, how often would you even need a slice again? I usually either need indexing, or extracting things out from the beginning of the slice, not both at once.

I decided to give this a go in a programming exercise that required linear search in a part of the problem. I passed around slice iterators, and it worked pretty well until I decided to use binary search instead, which was quite a pain to change. I could have added a couple .as_slice() calls but that would defeat the point of passing around iterators in the first place.

I might change my mind on this later, but right now I think it's good to limit slice::Iter's functionality to (more or less) just iterator methods and .as_slice(). Then you know that all the other slice functionality is going to be on slice itself, and then you only need to bother with .iter() if you're directly iterating it.

If take_... methods were to be added to slice::Iter, then wouldn't we want to add the split methods as well, and possibly chunks? All of those also benefit from slice::Iter's representation, but it seems like going down that path would lead to a lot of duplicated methods. I wholeheartedly agree with your argument about having to adjust two values instead of one, so I'm hoping that giving slice the same representation as slice::Iter could give us the best of both worlds.

@cramertj
Copy link
Member Author

I believe I've addressed all outstanding comments, aside from the suggestion that the methods be moved to std::slice::Iter, which I disagree with-- my needs for these methods have required mutation of a slice, not a slice iterator.

I've also removed the take and take_mut helpers, since core::mem::take around :)

@timvermeulen
Copy link
Contributor

timvermeulen commented Aug 19, 2019

Ah, good call! I did intend for it to take at an index

take_back seems to take a number of elements now rather than an index, did you change your mind?

@rust-highfive

This comment has been minimized.

@cramertj
Copy link
Member Author

cramertj commented Mar 4, 2020

I think this is ready for review again.

src/libcore/ops/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/ops/range.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Show resolved Hide resolved
src/libcore/slice/mod.rs Show resolved Hide resolved
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-03-06T17:50:55.0123165Z ========================== Starting Command Output ===========================
2020-03-06T17:50:55.0125677Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/28b5af76-e0a7-4678-9d87-88f55beffefc.sh
2020-03-06T17:50:55.0125934Z 
2020-03-06T17:50:55.0129235Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-06T17:50:55.0147944Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-06T17:50:55.0151306Z Task         : Get sources
2020-03-06T17:50:55.0151597Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-06T17:50:55.0151875Z Version      : 1.0.0
2020-03-06T17:50:55.0152085Z Author       : Microsoft
---
2020-03-06T17:50:56.1861361Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-06T17:50:56.1870714Z ##[command]git config gc.auto 0
2020-03-06T17:50:56.1875206Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-06T17:50:56.1881691Z ##[command]git config --get-all http.proxy
2020-03-06T17:50:56.1892193Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/62282/merge:refs/remotes/pull/62282/merge
---
2020-03-06T18:54:25.3699286Z .................................................................................................... 1700/9732
2020-03-06T18:54:30.0330834Z .................................................................................................... 1800/9732
2020-03-06T18:54:41.9072781Z ..........................................................i......................................... 1900/9732
2020-03-06T18:54:49.5268385Z .................................................................................................... 2000/9732
2020-03-06T18:55:04.1594732Z ................................................iiiii............................................... 2100/9732
2020-03-06T18:55:14.5422371Z .................................................................................................... 2300/9732
2020-03-06T18:55:16.8491940Z .................................................................................................... 2400/9732
2020-03-06T18:55:20.4321584Z .................................................................................................... 2500/9732
2020-03-06T18:55:42.7902596Z .................................................................................................... 2600/9732
---
2020-03-06T18:58:25.0859830Z .........i...............i.......................................................................... 5000/9732
2020-03-06T18:58:35.2591833Z .................................................................................................... 5100/9732
2020-03-06T18:58:40.4699649Z ....................................................i............................................... 5200/9732
2020-03-06T18:58:49.0608028Z .................................................................................................... 5300/9732
2020-03-06T18:58:56.8409040Z ................................ii.ii........i...i.................................................. 5400/9732
2020-03-06T18:59:05.6896104Z .................................................................................................... 5600/9732
2020-03-06T18:59:15.7975127Z .................................................................................................... 5700/9732
2020-03-06T18:59:23.3963895Z .......................i............................................................................ 5800/9732
2020-03-06T18:59:29.4054626Z .................................................................................................... 5900/9732
2020-03-06T18:59:29.4054626Z .................................................................................................... 5900/9732
2020-03-06T18:59:40.9612119Z .................................................................................................... 6000/9732
2020-03-06T18:59:51.6040092Z ...............ii...i..ii...........i............................................................... 6100/9732
2020-03-06T19:00:08.3270109Z .................................................................................................... 6300/9732
2020-03-06T19:00:15.5573221Z .................................................................................................... 6400/9732
2020-03-06T19:00:15.5573221Z .................................................................................................... 6400/9732
2020-03-06T19:00:32.7172503Z ..............................................i..ii................................................. 6500/9732
2020-03-06T19:00:56.9941233Z .................................................................................................... 6700/9732
2020-03-06T19:00:59.0850753Z ......................................i............................................................. 6800/9732
2020-03-06T19:01:01.2564343Z .................................................................................................... 6900/9732
2020-03-06T19:01:03.5380277Z ....................................................................i............................... 7000/9732
---
2020-03-06T19:02:46.5354507Z .................................................................................................... 7700/9732
2020-03-06T19:02:51.9601755Z .................................................................................................... 7800/9732
2020-03-06T19:02:56.8217143Z .................................................................................................... 7900/9732
2020-03-06T19:03:05.1952687Z ..............i..................................................................................... 8000/9732
2020-03-06T19:03:14.1737227Z ...............................................................iiiiiiiii.i.......................... 8100/9732
2020-03-06T19:03:29.5872980Z ......i......i...................................................................................... 8300/9732
2020-03-06T19:03:35.0625235Z .................................................................................................... 8400/9732
2020-03-06T19:03:49.0539281Z .................................................................................................... 8500/9732
2020-03-06T19:03:58.4603735Z .................................................................................................... 8600/9732
---
2020-03-06T19:06:26.9168785Z  finished in 7.687
2020-03-06T19:06:26.9371895Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T19:06:27.1413201Z 
2020-03-06T19:06:27.1413461Z running 178 tests
2020-03-06T19:06:30.2322217Z iiii......i...........ii..iiii...i....i...........i............i..i..................i....i......... 100/178
2020-03-06T19:06:32.6070307Z ...i.i.i...iii..iiiiiiiiiiiiiiii.......................iii............ii......
2020-03-06T19:06:32.6073271Z 
2020-03-06T19:06:32.6081149Z  finished in 5.670
2020-03-06T19:06:32.6288295Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T19:06:32.8150706Z 
---
2020-03-06T19:06:34.8656666Z  finished in 2.237
2020-03-06T19:06:34.8844741Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T19:06:35.0451327Z 
2020-03-06T19:06:35.0451725Z running 9 tests
2020-03-06T19:06:35.0454219Z iiiiiiiii
2020-03-06T19:06:35.0455606Z 
2020-03-06T19:06:35.0458268Z  finished in 0.161
2020-03-06T19:06:35.0680225Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T19:06:35.2605432Z 
---
2020-03-06T19:06:56.7514343Z  finished in 21.684
2020-03-06T19:06:56.7742523Z Check compiletest suite=debuginfo mode=debuginfo (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T19:06:56.9841199Z 
2020-03-06T19:06:56.9841500Z running 116 tests
2020-03-06T19:07:10.8047267Z iiiii..i.....i..i...i..i.i.i..i..i..ii....i.i....ii..........iiii..........i.....i..i.......ii.i.ii. 100/116
2020-03-06T19:07:12.7938048Z ....iiii.....ii.
2020-03-06T19:07:12.7947126Z 
2020-03-06T19:07:12.7949877Z  finished in 16.020
2020-03-06T19:07:12.7959708Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T19:07:12.7960789Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2020-03-06T19:20:51.5849354Z 
2020-03-06T19:20:51.5855799Z    Doc-tests core
2020-03-06T19:20:56.4795373Z 
2020-03-06T19:20:56.4796387Z running 2490 tests
2020-03-06T19:21:05.8335097Z ......iiiii......................................................................................... 100/2490
2020-03-06T19:21:15.1428907Z ....................................................................................ii.............. 200/2490
2020-03-06T19:21:36.3948541Z ...................i................................................................................ 400/2490
2020-03-06T19:21:36.3948541Z ...................i................................................................................ 400/2490
2020-03-06T19:21:46.2800521Z ........................................................................i..i..................iiii.. 500/2490
2020-03-06T19:22:02.8426567Z .................................................................................................... 700/2490
2020-03-06T19:22:11.5967428Z .................................................................................................... 800/2490
2020-03-06T19:22:20.2545340Z .................................................................................................... 900/2490
2020-03-06T19:22:28.9060145Z .................................................................................................... 1000/2490
---
2020-03-06T19:24:47.5640758Z ---- slice/mod.rs - slice::[T]::take (line 2707) stdout ----
2020-03-06T19:24:47.5641055Z error[E0308]: mismatched types
2020-03-06T19:24:47.5641466Z   --> slice/mod.rs:2715:1
2020-03-06T19:24:47.5641907Z    |
2020-03-06T19:24:47.5642388Z 11 | assert_eq!(Some(&['a', 'b', 'c', 'd']), slice.take(..4));
2020-03-06T19:24:47.5642947Z    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected array `[char; 4]`, found slice `[char]`
2020-03-06T19:24:47.5643274Z    |
2020-03-06T19:24:47.5643526Z    = note: expected enum `std::option::Option<&[char; 4]>`
2020-03-06T19:24:47.5643892Z               found enum `std::option::Option<&[char]>`
2020-03-06T19:24:47.5644883Z 
2020-03-06T19:24:47.5645066Z error: aborting due to previous error
2020-03-06T19:24:47.5645246Z 
2020-03-06T19:24:47.5645669Z For more information about this error, try `rustc --explain E0308`.
2020-03-06T19:24:47.5645669Z For more information about this error, try `rustc --explain E0308`.
2020-03-06T19:24:47.5646091Z Couldn't compile the test.
2020-03-06T19:24:47.5646570Z ---- slice/mod.rs - slice::[T]::take_mut (line 2768) stdout ----
2020-03-06T19:24:47.5646986Z error[E0599]: no method named `take` found for mutable reference `&mut [char]` in the current scope
2020-03-06T19:24:47.5647682Z   |
2020-03-06T19:24:47.5647682Z   |
2020-03-06T19:24:47.5647870Z 8 | assert_eq!(None, slice.take(4..));
2020-03-06T19:24:47.5648161Z   |                        ^^^^ method not found in `&mut [char]`
2020-03-06T19:24:47.5648677Z   = note: the method `take` exists but the following trait bounds were not satisfied:
2020-03-06T19:24:47.5648677Z   = note: the method `take` exists but the following trait bounds were not satisfied:
2020-03-06T19:24:47.5649025Z           `[char]: std::iter::Iterator`
2020-03-06T19:24:47.5649378Z           which is required by `&mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5649726Z           `&mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5650086Z           which is required by `&mut &mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5650334Z 
2020-03-06T19:24:47.5650642Z error[E0599]: no method named `take` found for mutable reference `&mut [char]` in the current scope
2020-03-06T19:24:47.5651321Z   |
2020-03-06T19:24:47.5651321Z   |
2020-03-06T19:24:47.5651521Z 9 | assert_eq!(None, slice.take(..5));
2020-03-06T19:24:47.5651815Z   |                        ^^^^ method not found in `&mut [char]`
2020-03-06T19:24:47.5652331Z   = note: the method `take` exists but the following trait bounds were not satisfied:
2020-03-06T19:24:47.5652331Z   = note: the method `take` exists but the following trait bounds were not satisfied:
2020-03-06T19:24:47.5652677Z           `[char]: std::iter::Iterator`
2020-03-06T19:24:47.5653011Z           which is required by `&mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5653373Z           `&mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5653731Z           which is required by `&mut &mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5653977Z 
2020-03-06T19:24:47.5654267Z error[E0599]: no method named `take` found for mutable reference `&mut [char]` in the current scope
2020-03-06T19:24:47.5654957Z    |
2020-03-06T19:24:47.5654957Z    |
2020-03-06T19:24:47.5655140Z 10 | assert_eq!(None, slice.take(..=4));
2020-03-06T19:24:47.5655457Z    |                        ^^^^ method not found in `&mut [char]`
2020-03-06T19:24:47.5655969Z    = note: the method `take` exists but the following trait bounds were not satisfied:
2020-03-06T19:24:47.5655969Z    = note: the method `take` exists but the following trait bounds were not satisfied:
2020-03-06T19:24:47.5656338Z            `[char]: std::iter::Iterator`
2020-03-06T19:24:47.5656678Z            which is required by `&mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5657027Z            `&mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5657404Z            which is required by `&mut &mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5657652Z 
2020-03-06T19:24:47.5657940Z error[E0599]: no method named `take` found for mutable reference `&mut [char]` in the current scope
2020-03-06T19:24:47.5658635Z    |
2020-03-06T19:24:47.5658635Z    |
2020-03-06T19:24:47.5659054Z 11 | assert_eq!(Some(&mut ['a', 'b', 'c', 'd']), slice.take(..4));
2020-03-06T19:24:47.5659458Z    |                                                   ^^^^ method not found in `&mut [char]`
2020-03-06T19:24:47.5660143Z    = note: the method `take` exists but the following trait bounds were not satisfied:
2020-03-06T19:24:47.5660143Z    = note: the method `take` exists but the following trait bounds were not satisfied:
2020-03-06T19:24:47.5661227Z            `[char]: std::iter::Iterator`
2020-03-06T19:24:47.5661585Z            which is required by `&mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5661934Z            `&mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5662309Z            which is required by `&mut &mut [char]: std::iter::Iterator`
2020-03-06T19:24:47.5662744Z error: aborting due to 4 previous errors
2020-03-06T19:24:47.5662914Z 
2020-03-06T19:24:47.5663461Z For more information about this error, try `rustc --explain E0599`.
2020-03-06T19:24:47.5663895Z Couldn't compile the test.
---
2020-03-06T19:24:47.5929964Z   local time: Fri Mar  6 19:24:47 UTC 2020
2020-03-06T19:24:47.8848323Z   network time: Fri, 06 Mar 2020 19:24:47 GMT
2020-03-06T19:24:47.8849585Z == end clock drift check ==
2020-03-06T19:24:48.5278165Z 
2020-03-06T19:24:48.5351824Z ##[error]Bash exited with code '1'.
2020-03-06T19:24:48.5366139Z ##[section]Finishing: Run build
2020-03-06T19:24:48.5416155Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-06T19:24:48.5421650Z Task         : Get sources
2020-03-06T19:24:48.5422034Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-06T19:24:48.5422345Z Version      : 1.0.0
2020-03-06T19:24:48.5422563Z Author       : Microsoft
2020-03-06T19:24:48.5422563Z Author       : Microsoft
2020-03-06T19:24:48.5422937Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-06T19:24:48.5423358Z ==============================================================================
2020-03-06T19:24:48.8941122Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-06T19:24:48.8984191Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-06T19:24:48.9077233Z Cleaning up task key
2020-03-06T19:24:48.9078500Z Start cleaning up orphan processes.
2020-03-06T19:24:48.9268063Z Terminate orphan process: pid (3362) (python)
2020-03-06T19:24:48.9504710Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-03-06T22:15:50.7146129Z ========================== Starting Command Output ===========================
2020-03-06T22:15:50.7148928Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/6bdbf0b7-6a29-43c7-b361-c785ceb9d0a6.sh
2020-03-06T22:15:50.7149224Z 
2020-03-06T22:15:50.7153685Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-06T22:15:50.7174559Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-06T22:15:50.7178367Z Task         : Get sources
2020-03-06T22:15:50.7178690Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-06T22:15:50.7179020Z Version      : 1.0.0
2020-03-06T22:15:50.7179231Z Author       : Microsoft
---
2020-03-06T22:15:51.8469248Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-06T22:15:51.8479418Z ##[command]git config gc.auto 0
2020-03-06T22:15:51.8486775Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-06T22:15:51.8493232Z ##[command]git config --get-all http.proxy
2020-03-06T22:15:51.8503138Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/62282/merge:refs/remotes/pull/62282/merge
---
2020-03-06T23:14:59.2981966Z .................................................................................................... 1700/9733
2020-03-06T23:15:03.5587035Z .................................................................................................... 1800/9733
2020-03-06T23:15:14.4154703Z ...........................................................i........................................ 1900/9733
2020-03-06T23:15:21.5847266Z .................................................................................................... 2000/9733
2020-03-06T23:15:35.0194488Z .................................................iiiii.............................................. 2100/9733
2020-03-06T23:15:44.5543150Z .................................................................................................... 2300/9733
2020-03-06T23:15:46.6081755Z .................................................................................................... 2400/9733
2020-03-06T23:15:49.9194015Z .................................................................................................... 2500/9733
2020-03-06T23:16:10.9438268Z .................................................................................................... 2600/9733
---
2020-03-06T23:18:54.2025515Z ..........i...............i......................................................................... 5000/9733
2020-03-06T23:19:03.6890846Z .................................................................................................... 5100/9733
2020-03-06T23:19:08.5539184Z .....................................................i.............................................. 5200/9733
2020-03-06T23:19:16.9075218Z .................................................................................................... 5300/9733
2020-03-06T23:19:23.8970689Z .................................ii.ii........i...i................................................. 5400/9733
2020-03-06T23:19:31.9128144Z .................................................................................................... 5600/9733
2020-03-06T23:19:40.9628734Z .................................................................................................... 5700/9733
2020-03-06T23:19:47.6553710Z ........................i........................................................................... 5800/9733
2020-03-06T23:19:53.4396893Z .................................................................................................... 5900/9733
2020-03-06T23:19:53.4396893Z .................................................................................................... 5900/9733
2020-03-06T23:20:04.5698559Z .................................................................................................... 6000/9733
2020-03-06T23:20:14.8848427Z ................ii...i..ii...........i.............................................................. 6100/9733
2020-03-06T23:20:30.6625997Z .................................................................................................... 6300/9733
2020-03-06T23:20:37.2459239Z .................................................................................................... 6400/9733
2020-03-06T23:20:37.2459239Z .................................................................................................... 6400/9733
2020-03-06T23:20:54.9553269Z ...............................................i..ii................................................ 6500/9733
2020-03-06T23:21:17.8281686Z .................................................................................................... 6700/9733
2020-03-06T23:21:19.8542799Z .......................................i............................................................ 6800/9733
2020-03-06T23:21:21.8184798Z .................................................................................................... 6900/9733
2020-03-06T23:21:23.8855706Z .....................................................................i.............................. 7000/9733
---
2020-03-06T23:22:59.1881079Z .................................................................................................... 7700/9733
2020-03-06T23:23:03.9860860Z .................................................................................................... 7800/9733
2020-03-06T23:23:08.4754760Z .................................................................................................... 7900/9733
2020-03-06T23:23:16.3035240Z ...............i.................................................................................... 8000/9733
2020-03-06T23:23:24.5656059Z ................................................................iiiiiiiii.i......................... 8100/9733
2020-03-06T23:23:38.7449058Z .......i......i..................................................................................... 8300/9733
2020-03-06T23:23:43.5726779Z .................................................................................................... 8400/9733
2020-03-06T23:23:56.4600946Z .................................................................................................... 8500/9733
2020-03-06T23:24:05.3705622Z .................................................................................................... 8600/9733
---
2020-03-06T23:26:23.9882241Z  finished in 7.181
2020-03-06T23:26:24.0055784Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T23:26:24.1550102Z 
2020-03-06T23:26:24.1550325Z running 178 tests
2020-03-06T23:26:26.9213478Z iiii......i...........ii..iiii...i....i...........i............i..i..................i....i......... 100/178
2020-03-06T23:26:29.1258164Z ...i.i.i...iii..iiiiiiiiiiiiiiii.......................iii............ii......
2020-03-06T23:26:29.1260705Z 
2020-03-06T23:26:29.1267751Z  finished in 5.121
2020-03-06T23:26:29.1445649Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T23:26:29.2823758Z 
---
2020-03-06T23:26:31.1266052Z  finished in 1.982
2020-03-06T23:26:31.1450770Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T23:26:31.2835349Z 
2020-03-06T23:26:31.2835725Z running 9 tests
2020-03-06T23:26:31.2838378Z iiiiiiiii
2020-03-06T23:26:31.2840642Z 
2020-03-06T23:26:31.2841030Z  finished in 0.139
2020-03-06T23:26:31.2991254Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T23:26:31.4443610Z 
---
2020-03-06T23:26:50.4506911Z  finished in 19.151
2020-03-06T23:26:50.4696286Z Check compiletest suite=debuginfo mode=debuginfo (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T23:26:50.6171256Z 
2020-03-06T23:26:50.6171592Z running 116 tests
2020-03-06T23:27:03.9406042Z iiiii..i.....i..i...i..i.i.i..i..i..ii....i.i....ii..........iiii..........i.....i..i.......ii.i.ii. 100/116
2020-03-06T23:27:05.8190061Z ....iiii.....ii.
2020-03-06T23:27:05.8194783Z 
2020-03-06T23:27:05.8194961Z  finished in 15.349
2020-03-06T23:27:05.8195609Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2020-03-06T23:27:05.8196419Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2020-03-06T23:39:45.8065191Z 
2020-03-06T23:39:45.8070083Z    Doc-tests core
2020-03-06T23:39:50.3468052Z 
2020-03-06T23:39:50.3469083Z running 2490 tests
2020-03-06T23:39:59.4721122Z ......iiiii......................................................................................... 100/2490
2020-03-06T23:40:08.0684455Z ....................................................................................ii.............. 200/2490
2020-03-06T23:40:27.9512603Z ...................i................................................................................ 400/2490
2020-03-06T23:40:27.9512603Z ...................i................................................................................ 400/2490
2020-03-06T23:40:37.3434870Z ........................................................................i..i..................iiii.. 500/2490
2020-03-06T23:40:52.9289996Z .................................................................................................... 700/2490
2020-03-06T23:41:01.0638222Z .................................................................................................... 800/2490
2020-03-06T23:41:09.1204045Z .................................................................................................... 900/2490
2020-03-06T23:41:17.1089872Z .................................................................................................... 1000/2490
---
2020-03-06T23:43:30.0314174Z Test executable failed (exit code 101).
2020-03-06T23:43:30.0314555Z 
2020-03-06T23:43:30.0314910Z stderr:
2020-03-06T23:43:30.0315481Z thread 'main' panicked at 'assertion failed: `(left == right)`
2020-03-06T23:43:30.0315754Z   left: `None`,
2020-03-06T23:43:30.0319371Z  right: `Some([])`', slice/mod.rs:8:1
2020-03-06T23:43:30.0320552Z 
2020-03-06T23:43:30.0320665Z 
2020-03-06T23:43:30.0321555Z ---- slice/mod.rs - slice::[T]::take_mut (line 2769) stdout ----
2020-03-06T23:43:30.0322123Z error[E0716]: temporary value dropped while borrowed
2020-03-06T23:43:30.0322123Z error[E0716]: temporary value dropped while borrowed
2020-03-06T23:43:30.0322880Z   --> slice/mod.rs:2777:47
2020-03-06T23:43:30.0328747Z    |
2020-03-06T23:43:30.0329860Z 11 | let expected: Option<&mut [char]> = Some(&mut ['a', 'b', 'c', 'd']);
2020-03-06T23:43:30.0335667Z    |                                               ^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
2020-03-06T23:43:30.0337095Z    |                                               creates a temporary which is freed while still in use
2020-03-06T23:43:30.0337095Z    |                                               creates a temporary which is freed while still in use
2020-03-06T23:43:30.0337432Z 12 | assert_eq!(expected, slice.take_mut(..4));
2020-03-06T23:43:30.0338268Z    | ------------------------------------------ borrow later used here
2020-03-06T23:43:30.0338984Z    = note: consider using a `let` binding to create a longer lived value
2020-03-06T23:43:30.0339187Z 
2020-03-06T23:43:30.0339497Z error: aborting due to previous error
2020-03-06T23:43:30.0339670Z 
---
2020-03-06T23:43:30.0349508Z   local time: Fri Mar  6 23:43:28 UTC 2020
2020-03-06T23:43:30.0349926Z   network time: Fri, 06 Mar 2020 23:43:29 GMT
2020-03-06T23:43:30.0350309Z == end clock drift check ==
2020-03-06T23:43:30.0350502Z 
2020-03-06T23:43:30.0392244Z ##[error]Bash exited with code '1'.
2020-03-06T23:43:30.0407222Z ##[section]Finishing: Run build
2020-03-06T23:43:30.0469814Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-06T23:43:30.0475019Z Task         : Get sources
2020-03-06T23:43:30.0475333Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-06T23:43:30.0475636Z Version      : 1.0.0
2020-03-06T23:43:30.0475833Z Author       : Microsoft
2020-03-06T23:43:30.0475833Z Author       : Microsoft
2020-03-06T23:43:30.0476153Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-06T23:43:30.0476534Z ==============================================================================
2020-03-06T23:43:30.3692671Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-06T23:43:30.3696222Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-06T23:43:30.3772780Z Cleaning up task key
2020-03-06T23:43:30.3773868Z Start cleaning up orphan processes.
2020-03-06T23:43:30.3937064Z Terminate orphan process: pid (3450) (python)
2020-03-06T23:43:30.4181772Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

Copy link
Member

@LukasKalbertodt LukasKalbertodt left a comment

Choose a reason for hiding this comment

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

Could you add a few (non doc) tests still? Thinking about testing these cases:

  • take[_mut] with in bound index (with all three range types)
  • take[_mut] with out of bound index (with all three range types)
  • take[_mut] with usize::MAX index (you can create a [(); usize::MAX] array for that)
  • take_[first|last][_mut] with non-empty slice
  • take_[first|last][_mut] with empty slice
  • take_last[_mut] with the [(); usize::MAX] array

With these tests and the docs for the first/last methods adjusted, I'm happy to merge this!

Comment on lines +2801 to +2792
/// Takes the first element out of the slice.
///
/// Returns a reference pointing to the first element of the old slice.
///
/// Returns `None` if the slice is empty.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want to adopt the formulation from the take and take_mut docs for this and the three other methods below? I.e.:

Removes and returns the [first|last] element from the slice.

If the slice is empty, None is returned and the slice is not modified.

This would also resolve @nox's remark.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm a little confused about how to phrase this, because I want to make it clear that the element itself is staying in place, and the only thing being manipulated is what the slice refers to. That is, "Removes and returns the first element from the slice." sounds to me like it's taking an element out from the backing memory, which isn't the case. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you're right, it's a bit misleading. I don't have a good idea, but maybe something like:

Returns a reference to the first element and modifies self to now start at the second element.

or

Returns a reference to the first element and modifies self to not include that element anymore.

or

Returns a reference to the first element and sets self to &self[1..].

In all cases, the first "self" could be replaced by "this slice". And in all cases, I would add as a second paragraph:

If the slice is empty, None is returned and [self|the slice] is not modified. This function is essentially equivalent to self.take(1..), but returns &T instead of &[T].

And if we change the take_[first|last] versions of this method, we should probably also adjust the formulation for take[_mut]. It currently says "removes and returns" which, as you said, is misleading.

@joelpalmer joelpalmer added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 30, 2020
This adds the following associated functions to `[T]`:
- take
- take_mut
- take_first
- take_first_mut
- take_last
- take_last_mut
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-03-30T19:44:46.2013694Z ========================== Starting Command Output ===========================
2020-03-30T19:44:46.2018916Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/ec99754f-0be2-4ac3-8955-a8c55dfb31eb.sh
2020-03-30T19:44:46.2019421Z 
2020-03-30T19:44:46.2024387Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-30T19:44:46.2045792Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-30T19:44:46.2049728Z Task         : Get sources
2020-03-30T19:44:46.2050053Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-30T19:44:46.2050366Z Version      : 1.0.0
2020-03-30T19:44:46.2050600Z Author       : Microsoft
---
2020-03-30T19:44:47.8281292Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-30T19:44:47.8287860Z ##[command]git config gc.auto 0
2020-03-30T19:44:47.8292576Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-30T19:44:47.8296521Z ##[command]git config --get-all http.proxy
2020-03-30T19:44:47.8304951Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/62282/merge:refs/remotes/pull/62282/merge
---
2020-03-30T19:47:08.8965927Z  ---> 3fc1b512c57b
2020-03-30T19:47:08.8966412Z Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
2020-03-30T19:47:08.8968806Z  ---> Using cache
2020-03-30T19:47:08.8969480Z  ---> 5ee4295733f4
2020-03-30T19:47:08.8971080Z Step 7/7 : ENV SCRIPT python2.7 ../x.py test src/tools/expand-yaml-anchors &&            python2.7 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python2.7 ../x.py build --stage 0 src/tools/build-manifest &&            python2.7 ../x.py test --stage 0 src/tools/compiletest &&            python2.7 ../x.py test src/tools/tidy &&            /scripts/validate-toolstate.sh
2020-03-30T19:47:08.8973018Z  ---> 3d07a0fa42fe
2020-03-30T19:47:08.9011272Z Successfully built 3d07a0fa42fe
2020-03-30T19:47:08.9063706Z Successfully tagged rust-ci:latest
2020-03-30T19:47:08.9314330Z Built container sha256:3d07a0fa42feb5754fc13bb2f7010ebe13e4b8b8cdbebed0c75d8da320c8c8ad
---
2020-03-30T19:51:02.1282940Z     Checking rustc_feature v0.0.0 (/checkout/src/librustc_feature)
2020-03-30T19:51:02.2780181Z     Checking fmt_macros v0.0.0 (/checkout/src/libfmt_macros)
2020-03-30T19:51:02.4888614Z     Checking rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
2020-03-30T19:51:02.5352222Z     Checking rustc_hir v0.0.0 (/checkout/src/librustc_hir)
2020-03-30T19:51:03.1555993Z     Checking rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
2020-03-30T19:51:05.5972858Z     Checking rustc_attr v0.0.0 (/checkout/src/librustc_attr)
2020-03-30T19:51:06.0674529Z     Checking rustc_parse v0.0.0 (/checkout/src/librustc_parse)
2020-03-30T19:51:08.1453740Z     Checking rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
2020-03-30T19:51:08.5937017Z     Checking rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
2020-03-30T19:52:58.0780041Z configure: build.locked-deps    := True
2020-03-30T19:52:58.0780340Z configure: llvm.ccache          := sccache
2020-03-30T19:52:58.0781238Z configure: build.cargo-native-static := True
2020-03-30T19:52:58.0781900Z configure: dist.missing-tools   := True
2020-03-30T19:52:58.0782470Z configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
2020-03-30T19:52:58.0783254Z configure: writing `config.toml` in current directory
2020-03-30T19:52:58.0783613Z configure: 
2020-03-30T19:52:58.0784690Z configure: run `python /checkout/x.py --help`
2020-03-30T19:52:58.0784928Z configure: 
---
2020-03-30T19:54:28.5905151Z Hugepagesize:       2048 kB
2020-03-30T19:54:28.5905555Z DirectMap4k:      131008 kB
2020-03-30T19:54:28.5905932Z DirectMap2M:     4063232 kB
2020-03-30T19:54:28.5906307Z DirectMap1G:     5242880 kB
2020-03-30T19:54:28.5907123Z + python2.7 ../x.py test src/tools/expand-yaml-anchors
2020-03-30T19:54:29.3445090Z Ensuring the YAML anchors in the GitHub Actions config were expanded
2020-03-30T19:54:29.3445090Z Ensuring the YAML anchors in the GitHub Actions config were expanded
2020-03-30T19:54:29.3452988Z Building stage0 tool expand-yaml-anchors (x86_64-unknown-linux-gnu)
2020-03-30T19:54:29.6110889Z    Compiling unicode-xid v0.2.0
2020-03-30T19:54:29.7373134Z    Compiling syn v1.0.11
2020-03-30T19:54:30.6226694Z    Compiling linked-hash-map v0.5.2
2020-03-30T19:54:30.6402683Z    Compiling lazy_static v1.4.0
2020-03-30T19:54:30.6402683Z    Compiling lazy_static v1.4.0
2020-03-30T19:54:30.8682546Z    Compiling yaml-rust v0.4.3
2020-03-30T19:54:35.2812983Z    Compiling quote v1.0.2
2020-03-30T19:54:50.4317449Z    Compiling thiserror-impl v1.0.5
2020-03-30T19:54:55.3322733Z    Compiling thiserror v1.0.5
2020-03-30T19:54:55.3913899Z    Compiling yaml-merge-keys v0.4.0
2020-03-30T19:54:57.6355325Z    Compiling expand-yaml-anchors v0.1.0 (/checkout/src/tools/expand-yaml-anchors)
2020-03-30T19:54:59.9224062Z Build completed successfully in 0:00:31
2020-03-30T19:54:59.9233152Z + python2.7 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu
2020-03-30T19:55:00.2094595Z     Finished dev [unoptimized] target(s) in 0.20s
2020-03-30T19:55:01.3175714Z Checking rustdoc artifacts (x86_64-unknown-linux-gnu -> i686-pc-windows-gnu)
---
2020-03-30T19:57:09.4484771Z     Checking rustc_feature v0.0.0 (/checkout/src/librustc_feature)
2020-03-30T19:57:09.5319880Z     Checking fmt_macros v0.0.0 (/checkout/src/libfmt_macros)
2020-03-30T19:57:09.7513110Z     Checking rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
2020-03-30T19:57:09.8882928Z     Checking rustc_hir v0.0.0 (/checkout/src/librustc_hir)
2020-03-30T19:57:10.4162697Z     Checking rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
2020-03-30T19:57:12.7147768Z     Checking rustc_attr v0.0.0 (/checkout/src/librustc_attr)
2020-03-30T19:57:13.1838306Z     Checking rustc_parse v0.0.0 (/checkout/src/librustc_parse)
2020-03-30T19:57:15.2652440Z     Checking rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
2020-03-30T19:57:15.7316768Z     Checking rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
2020-03-30T20:01:32.4432751Z skip untracked path src/doc/rust-by-example/ during rustfmt invocations
2020-03-30T20:01:32.4436148Z skip untracked path src/llvm-project/ during rustfmt invocations
2020-03-30T20:01:35.0618120Z Diff in /checkout/src/libcore/tests/slice.rs at line 1800:
2020-03-30T20:01:35.0620722Z  
2020-03-30T20:01:35.0622918Z  // can't be a constant due to const mutability rules
2020-03-30T20:01:35.0624824Z  // see ***/issues/57349#issuecomment-597395059
2020-03-30T20:01:35.0626920Z -macro_rules! empty_max_mut { () => { &mut [(); std::usize::MAX] as _ } }
2020-03-30T20:01:35.0628431Z +macro_rules! empty_max_mut {
2020-03-30T20:01:35.0628806Z +    () => {
2020-03-30T20:01:35.0629827Z +        &mut [(); std::usize::MAX] as _
2020-03-30T20:01:35.0631295Z +}
2020-03-30T20:01:35.0631533Z  
2020-03-30T20:01:35.0631864Z  take_tests! {
2020-03-30T20:01:35.0631864Z  take_tests! {
2020-03-30T20:01:35.0632242Z      slice: &[(); ::std::usize::MAX], method: take,
2020-03-30T20:01:35.0643597Z Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2018" "--unstable-features" "--skip-children" "--check" "/checkout/src/libcore/tests/slice.rs"` failed.
2020-03-30T20:01:35.0644820Z If you're running `tidy`, try again with `--bless` flag. Or, you just want to format code, run `./x.py fmt` instead.
2020-03-30T20:01:35.0654219Z Build completed unsuccessfully in 0:00:39
2020-03-30T20:01:35.0700791Z == clock drift check ==
2020-03-30T20:01:35.0714317Z   local time: Mon Mar 30 20:01:35 UTC 2020
2020-03-30T20:01:35.2328150Z   network time: Mon, 30 Mar 2020 20:01:35 GMT
2020-03-30T20:01:35.2328150Z   network time: Mon, 30 Mar 2020 20:01:35 GMT
2020-03-30T20:01:35.2332985Z == end clock drift check ==
2020-03-30T20:01:36.7458383Z 
2020-03-30T20:01:36.7548713Z ##[error]Bash exited with code '1'.
2020-03-30T20:01:36.7563861Z ##[section]Finishing: Run build
2020-03-30T20:01:36.7617828Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-30T20:01:36.7623743Z Task         : Get sources
2020-03-30T20:01:36.7624156Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-30T20:01:36.7624519Z Version      : 1.0.0
2020-03-30T20:01:36.7624775Z Author       : Microsoft
2020-03-30T20:01:36.7624775Z Author       : Microsoft
2020-03-30T20:01:36.7625255Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-30T20:01:36.7625740Z ==============================================================================
2020-03-30T20:01:37.1055145Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-30T20:01:37.1116961Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/62282/merge to s
2020-03-30T20:01:37.1195890Z Cleaning up task key
2020-03-30T20:01:37.1197005Z Start cleaning up orphan processes.
2020-03-30T20:01:37.1367070Z Terminate orphan process: pid (3819) (python)
2020-03-30T20:01:37.1651514Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@LukasKalbertodt
Copy link
Member

@cramertj Ping, the CI is red. Seems to be a simple rustfmt error. No hurries thought; just wanted to ping you in case you didn't see the CI failure.

@joelpalmer joelpalmer added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 16, 2020
@bors
Copy link
Contributor

bors commented Apr 23, 2020

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

@crlf0710 crlf0710 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 2, 2020
@Dylan-DPC-zz
Copy link

Closing this due to inactivity.

@Dylan-DPC-zz Dylan-DPC-zz added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 2, 2020
@LukasKalbertodt
Copy link
Member

@cramertj Would love to get this merged some day. Just ping me if you have time again :)
Either open a new PR or I guess we could potentially open this one? (Note tho: force pushing on a closed PR makes it impossible to reopen.)

@nox
Copy link
Contributor

nox commented May 3, 2020

FWIW I've released tranche recently, which provides take_front.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 1, 2021
Add slice take methods

Revival of rust-lang#62282

This PR adds the following slice methods:

- `take`
- `take_mut`
- `take_first`
- `take_first_mut`
- `take_last`
- `take_last_mut`

r? `@LukasKalbertodt`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. 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.