diff options
| author | Ralf Jung <post@ralfj.de> | 2020-05-29 21:58:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-29 21:58:32 +0200 |
| commit | b965196ce0bb0b484336f1f2ba3a6a72cbfb4f76 (patch) | |
| tree | bb77385894d39b2154c8c6732e95c82d6f17900d /src/rustllvm/RustWrapper.cpp | |
| parent | de561a9d3d8d06969abc4f6851fd532f584ff52c (diff) | |
| parent | cd6a8cae2aa07bd456a1816196e3c9aa2fcb72d6 (diff) | |
| download | rust-b965196ce0bb0b484336f1f2ba3a6a72cbfb4f76.tar.gz rust-b965196ce0bb0b484336f1f2ba3a6a72cbfb4f76.zip | |
Rollup merge of #72413 - CAD97:char-range, r=dtolnay
impl Step for char (make Range*<char> iterable) [[irlo thread]](https://internals.rust-lang.org/t/mini-rfc-make-range-char-work/12392?u=cad97) [[godbolt asm example]](https://rust.godbolt.org/z/fdveKo) Add an implementation of the `Step` trait for `char`, which has the effect of making `RangeInclusive<char>` (and the other range types) iterable. I've used the surrogate range magic numbers as magic numbers here rather than e.g. a `const SURROGATE_RANGE = 0xD800..0xE000` because these numbers appear to be used as magic numbers elsewhere and there doesn't exist constants for them yet. These files definitely aren't where surrogate range constants should live. `ExactSizeIterator` is not implemented because `0x10FFFF` is bigger than fits in a `usize == u16`. However, given we already provide some `ExactSizeIterator` that are not correct on 16 bit targets, we might still want to consider providing it for `Range`[`Inclusive`]`<char>`, as it is definitely _very_ convenient. (At the very least, we want to make sure `.count()` doesn't bother iterating the range.) The second commit in this PR changes a call to `Step::forward` to use `Step::forward_unchecked` in `RangeInclusive::next`. This is because without this patch, iteration over all codepoints (`'\0'..=char::MAX`) does not successfully optimize out the panicking branch. This was mentioned in the PR that updated `Step` to its current design, but was deemed not yet necessary as it did not impact codegen for integral types. More of `Range*`'s implementations' calls to `Step` methods will probably want to see if they can use the `_unchecked` version as (if) we open up `Step` to being implemented on more types. --- cc @rust-lang/libs, this is insta-stable and a fairly significant addition to `Range*`'s capabilities; this is the first instance of a noncontinuous domain being iterable with `Range` (or, well, anything other than primitive integers). I don't think this needs a full RFC, but it should definitely get some decent eyes on it.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
