libcore: Add range_step and range_rev functions.#4313
libcore: Add range_step and range_rev functions.#4313huonw wants to merge 2 commits intorust-lang:incomingfrom
Conversation
|
r+, though could probably use a handful of tests to guard against the ever-present "whoops, got my boundary conditions slightly wrong" bugs. I can write those if you don't feel like it though. Thanks! |
|
Yeah, I wasn't sure where they should go (i.e. at the bottom of the file or in the tests directory), are there any rules/conventions about this? (Also, I'm away for a week or so, and won't be able to do anything, so feel free to add the tests.) Graydon Hoare notifications@github.com wrote:
|
|
@dbaupp library tests go at the bottom of the file, language tests go in the tests directory. |
|
@graydon Added some tests, and found that I had met the "'negative' unsigned numbers act strangely" bug. Previously, calling I'm slightly uncomfortable about having a different API for signed vs unsigned (i.e. |
…unctions. Splits the range_step function into the two directions (up, low -> high, and down, high -> low) for the uint types, since there is no way to have `step < 0` for a backwards range.
|
@dbaupp Thanks. @graydon What do you think of these API changes? Is it ok to have two functions here? We could also just use |
|
Yeah, I'd just take an int for the step and have one variant. |
|
I'm unsure if it should be (Unless there is already a technique to get the type |
|
A whole new function for |
|
I vote for adding |
|
Considering Python's precedent, I vote for the following functions: Where reverse is just achieved by providing a negative step value to |
|
I'm adding the |
|
Yeah. +1, these are convenience functions to be used casually; step will almost always be 1, 2, -1, -2 or a similarly small number. Iterating by MAXINT-ish steps is rare and probably best done manually or by a user-written loop / iterator. |
|
Merged at last! 982cf90 |
|
(Oh, and thanks to @dbaupp :-) |
A code like
```rust
extern "C" {
fn f() {
fn g() {}
}
}
```
is incorrect and does not compile. Today rustfmt formats this in a way
that is correct:
```rust
extern "C" {
fn f();
}
```
But this loses information, and doesn't have to be done because we know
the content of the block if it is present. During development I don't
think rustfmt should drop the block in this context.
Closes rust-lang#4313
test suite: use CARGO_TARGET_TMPDIR for temporary build artifacts
Per #1817
Counting-down range is named
range_revrather thanrrangeto distinguish it from plainrangemore (obviously this can change).