]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Auto merge of #75207 - dylni:add-slice-check-range, r=KodrAus
authorbors <bors@rust-lang.org>
Fri, 4 Sep 2020 12:21:43 +0000 (12:21 +0000)
committerbors <bors@rust-lang.org>
Fri, 4 Sep 2020 12:21:43 +0000 (12:21 +0000)
commitef55a0a92f3cb6572ef67d99f4aefbdeb7b6b804
treef811be6020731d8ff158e0e4d6b0265c9662370d
parent4ffb5c5954a304daf47a567b34e74e421db86d98
parentd9e877fb98212a47dd425e145b8b3e4283e6b487
Auto merge of #75207 - dylni:add-slice-check-range, r=KodrAus

Add `slice::check_range`

This method is useful for [`RangeBounds`] parameters. It's even been [rewritten](https://github.com/rust-lang/rust/blob/22ee68dc586440f96b76b32fbd6087507c6afdb9/src/librustc_data_structures/sorted_map.rs#L214) [many](https://github.com/rust-lang/rust/blob/22ee68dc586440f96b76b32fbd6087507c6afdb9/library/alloc/src/vec.rs#L1299) [times](https://github.com/rust-lang/rust/blob/22ee68dc586440f96b76b32fbd6087507c6afdb9/library/core/src/slice/mod.rs#L2441) in the standard library, sometimes assuming that the bounds won't be [`usize::MAX`].

For example, [`Vec::drain`] creates an empty iterator when [`usize::MAX`] is used as an inclusive end bound:

```rust
assert!(vec![1].drain(..=usize::max_value()).eq(iter::empty()));
```

If this PR is merged, I'll create another to use it for those methods.

[`RangeBounds`]: https://doc.rust-lang.org/std/ops/trait.RangeBounds.html
[`usize::MAX`]: https://doc.rust-lang.org/std/primitive.usize.html#associatedconstant.MAX
[`Vec::drain`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain
library/alloc/src/collections/vec_deque.rs
library/alloc/src/lib.rs
library/alloc/src/string.rs
library/alloc/src/vec.rs
library/core/src/slice/mod.rs
library/core/tests/slice.rs
src/tools/linkchecker/main.rs