Commit graph

251 commits

Author SHA1 Message Date
Ralf Jung
3411ade32e test more mutating vector methods 2020-03-30 12:24:02 +02:00
Ralf Jung
4393923168 add some tests 2020-03-30 11:58:16 +02:00
Stein Somers
e92d740b35 BTreeMap testing: introduce symbolic constants and refer to height consistently. 2020-03-28 23:30:43 +01:00
Kornel
42b10e51c1 must_use on split_off
#70194
2020-03-24 17:35:40 +00:00
Mark Rousskov
4d85314a00 Update test commentary for shared root removal 2020-03-20 09:43:41 -04:00
Mazdak Farrokhzad
f497325b13
Rollup merge of #69776 - ssomers:fix69769, r=Mark-Simulacrum
Fix & test leak of some BTreeMap nodes on panic during `into_iter`

Fixes #69769
2020-03-08 11:51:17 +01:00
Stein Somers
44c97c43b5 Fix & test leak of some BTreeMap nodes on panic during into_iter 2020-03-06 14:50:09 +01:00
Ralf Jung
2770f300b1 reduce test size for Miri 2020-03-05 23:41:17 +01:00
Yuki Okushi
4699b29a04
Rollup merge of #69609 - TimDiekmann:excess, r=Amanieu
Remove `usable_size` APIs

This removes the usable size APIs:
- remove `usable_size` (obv)
- change return type of allocating methods to include the allocated size
- remove `_excess` API

r? @Amanieu
closes rust-lang/wg-allocators#17
2020-03-03 17:50:06 +09:00
Tim Diekmann
d8e3557dba Remove usable_size APIs 2020-03-03 00:08:24 +01:00
bors
892cb143e5 Auto merge of #67290 - jonas-schievink:leak-audit, r=KodrAus
Audit liballoc for leaks in `Drop` impls when user destructor panics

Inspired by https://github.com/rust-lang/rust/pull/67243 and https://github.com/rust-lang/rust/pull/67235, this audits and hopefully fixes the remaining `Drop` impls in liballoc for resource leaks in the presence of panics in destructors called by the affected `Drop` impl.

This does not touch `Hash{Map,Set}` since they live in hashbrown. They have similar issues though.

r? @KodrAus
2020-02-26 12:48:53 +00:00
bors
87e494c4cd Auto merge of #67330 - golddranks:split_inclusive, r=kodraus
Implement split_inclusive for slice and str

# Overview
* Implement `split_inclusive` for `slice` and `str` and `split_inclusive_mut` for `slice`
* `split_inclusive` is a substring/subslice splitting iterator that includes the matched part in the iterated substrings as a terminator.
* EDIT: The behaviour has now changed, as per @KodrAus 's input, to the same semantics with the `split_terminator` function. I updated the examples below.
* Two examples below:
```Rust
    let data = "\nMäry häd ä little lämb\nLittle lämb\n";
    let split: Vec<&str> = data.split_inclusive('\n').collect();
    assert_eq!(split, ["\n", "Märy häd ä little lämb\n", "Little lämb\n"]);
```

```Rust
    let uppercase_separated = "SheePSharKTurtlECaT";
    let mut first_char = true;
    let split: Vec<&str> = uppercase_separated.split_inclusive(|c: char| {
        let split = !first_char && c.is_uppercase();
        first_char = split;
        split
    }).collect();
    assert_eq!(split, ["SheeP", "SharK", "TurtlE", "CaT"]);
```

# Justification for the API
* I was surprised to find that stdlib currently only has splitting iterators that leave out the matched part. In my experience, wanting to leave a substring terminator as a part of the substring is a pretty common usecase.
* This API is strictly more expressive than the standard `split` API: it's easy to get the behaviour of `split` by mapping a subslicing operation that drops the terminator. On the other hand it's impossible to derive this behaviour from `split` without using hacky and brittle `unsafe` code. The normal way to achieve this functionality would be implementing the iterator yourself.
* Especially when dealing with mutable slices, the only way currently is to use `split_at_mut`. This API provides an ergonomic alternative that plays to the strengths of the iterating capabilities of Rust. (Using `split_at_mut` iteratively used to be a real pain before NLL, fortunately the situation is a bit better now.)

# Discussion items
* <s>Does it make sense to mimic `split_terminator` in that the final empty slice would be left off in case of the string/slice ending with a terminator? It might do, as this use case is naturally geared towards considering the matching part as a terminator instead of a separator.</s>
  * EDIT: The behaviour was changed to mimic `split_terminator`.
* Does it make sense to have `split_inclusive_mut` for `&mut str`?
2020-02-22 03:54:50 +00:00
Stein Somers
da226dd9dc Lighten tests, in particular for Miri, yet test and explain more 2020-02-16 22:35:44 +01:00
Jonas Schievink
0b50319af6
Rollup merge of #68738 - kennytm:derive-clone-eq-for-fromutf8error, r=sfackler
Derive Clone + Eq for std::string::FromUtf8Error

Implement `Clone` and `Eq` for `std::string::FromUtf8Error`.

Both the inner `Vec<u8>` and `std::str::Utf8Error` are also `Clone + Eq`, so I don't see why we shouldn't derive them on `FromUtf8Error` as well.

(impl are insta-stable, requiring FCP from T-libs.)
2020-02-09 18:23:28 +01:00
Pyry Kontio
5c9dc57cb5 Don't return empty slice on last iteration with matched terminator. Test reverse iteration. 2020-02-09 23:49:44 +09:00
Pyry Kontio
86bf96291d Implement split_inclusive for slice and str, an splitting iterator that includes the matched part in the iterated substrings as a terminator. 2020-02-09 23:48:52 +09:00
Stein Somers
fa9bfebfc9 Fix and test implementation of BTreeMap's first_entry, last_entry, pop_first, pop_last 2020-02-04 22:35:43 +01:00
kennytm
847d5b4d13
Derive Clone + PartialEq + Eq for std::string::FromUtf8Error 2020-02-02 02:29:28 +08:00
Dylan DPC
12c9562486
Rollup merge of #66648 - crgl:btree-clone-from, r=Amanieu
Implement clone_from for BTreeMap and BTreeSet

See #28481. This results in up to 90% speedups on simple data types when `self` and `other` are the same size, and is generally comparable or faster. Some concerns:

1. This implementation requires an `Ord` bound on the `Clone` implementation for `BTreeMap` and `BTreeSet`. Since these structs can only be created externally for keys with `Ord` implemented, this should be fine? If not, there's certainly a less safe way to do this.
2. Changing `next_unchecked` on `RangeMut` to return mutable key references allows for replacing the entire overlapping portion of both maps without changing the external interface in any way. However, if `clone_from` fails it can leave the `BTreeMap` in an invalid state, which might be unacceptable.

~This probably needs an FCP since it changes a trait bound, but (as far as I know?) that change cannot break any external code.~
2020-01-30 01:46:38 +01:00
Charles Gleason
60a7c9421e Include empty BTreeMap in clone_from tests 2020-01-28 11:39:48 -05:00
Tim Diekmann
7ca25db816
Rename Alloc to AllocRef 2020-01-27 21:39:51 +01:00
Jonas Schievink
e5987a062f Format 2020-01-19 20:50:00 +01:00
Jonas Schievink
1f373f4aeb Add test for panic in LL DrainFilter predicate 2020-01-19 20:24:36 +01:00
Jonas Schievink
0ae16b47ff Avoid leak in DrainFilter when a drop panics 2020-01-19 20:24:36 +01:00
Jonas Schievink
163ed23f00 Fix leak in vec::IntoIter when a destructor panics 2020-01-19 20:24:08 +01:00
Jonas Schievink
b04ca13873 Fix leak in VecDeque::drain when drop panics 2020-01-19 20:24:08 +01:00
Jonas Schievink
dc492452da Fix leak in btree_map::IntoIter when drop panics 2020-01-19 20:24:08 +01:00
Jonas Schievink
5d04790dd2 Avoid leak in vec::Drain when item drop panics 2020-01-19 20:23:41 +01:00
Jonas Schievink
3e5eb2634c Fix VecDeque::truncate leak on drop panic 2020-01-19 20:23:07 +01:00
Jonas Schievink
a859ca5c87 Fix binary_heap::DrainSorted drop leak on panics 2020-01-19 20:23:07 +01:00
bors
6250d56355 Auto merge of #67758 - ssomers:testing_range, r=Mark-Simulacrum
More thorough testing of BTreeMap::range

Test more of the paths in the `range_search` function in map.rs
2020-01-19 04:40:21 +00:00
Lzu Tao
7ba25acd7a Revert "Rollup merge of #67727 - Dylan-DPC:stabilise/remove_item, r=alexcrichton"
This reverts commit 4ed415b547, reversing
changes made to 3cce950743.
2020-01-11 03:04:39 +00:00
dylan_DPC
503d06b90d oh the one that was left behind 2020-01-06 23:28:47 +05:30
dylan_DPC
e03d1c4204 add feature gate 2020-01-05 15:42:35 +05:30
dylan_DPC
f744ea03b4 ef em ti ... :P 2020-01-04 23:57:34 +05:30
dylan_DPC
eb36688a01 add tests 2020-01-04 23:41:17 +05:30
Lzu Tao
dd8f072233 Use drop instead of the toilet closure |_| () 2020-01-02 08:56:12 +00:00
Stein Somers
8314b7fd27 More thorough testing of BTreeMap::range 2019-12-31 18:21:57 +01:00
Stein Somers
e3c814e623 prune ill-conceived BTreeMap iter_mut assertion and test more 2019-12-26 18:26:57 +01:00
Charles Gleason
8651aa066f Add test for BTreeMap::clone_from 2019-12-23 11:03:30 -05:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mazdak Farrokhzad
48164f8a17
Rollup merge of #67235 - jonas-schievink:vecdeque-leak, r=KodrAus
VecDeque: drop remaining items on destructor panic

Closes https://github.com/rust-lang/rust/issues/67232
2019-12-13 20:35:30 +01:00
Mazdak Farrokhzad
87f3b16e0b
Rollup merge of #67243 - jonas-schievink:linkedlist-drop, r=KodrAus
LinkedList: drop remaining items when drop panics

https://github.com/rust-lang/rust/pull/67235, but for `LinkedList`, which has the same issue.

I've also copied over the other drop-related tests from `VecDeque` since AFAICT `LinkedList` didn't have any.
2019-12-13 04:21:27 +01:00
Jonas Schievink
5e32da1849 LinkedList: drop remaining items when drop panics 2019-12-12 00:14:09 +01:00
Andre Bogus
2422797785 Small Cow improvements 2019-12-11 21:01:33 +01:00
Jonas Schievink
189ccf20a2 VecDeque: drop remaining items on destructor panic 2019-12-11 19:38:45 +01:00
Ralf Jung
ca2ffe3a80 liballoc: ignore tests in Miri instead of removing them entirely 2019-12-07 12:42:19 +01:00
Mazdak Farrokhzad
3db3f156f1
Rollup merge of #66890 - dtolnay:fmt4, r=Dylan-DPC
Format liballoc with rustfmt

Same strategy as #66691 -- as with my previous formatting PRs, I am avoiding causing merge conflicts in other PRs by only touches those files that are not involved in any currently open PR. Files that appear in new PRs between when this PR is opened and when it makes it to the top of the bors queue will be reverted from this PR.

The list of files involved in open PRs is determined by querying GitHub's GraphQL API [with this script](https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8).

With the list of files from the script in outstanding_files, the relevant commands were:

```
$ find src/liballoc -name '*.rs' \
    | xargs rustfmt --edition=2018 --unstable-features --skip-children
$ rg liballoc outstanding_files | xargs git checkout --
```

To confirm no funny business:

```
$ git checkout $THIS_COMMIT^
$ git show --pretty= --name-only $THIS_COMMIT \
    | xargs rustfmt --edition=2018 --unstable-features --skip-children
$ git diff $THIS_COMMIT  # there should be no difference
```

r? @Dylan-DPC
2019-12-01 04:49:31 +01:00
Mazdak Farrokhzad
cb43d82fd6
Rollup merge of #66662 - RalfJung:miri-test-liballoc, r=dtolnay
Miri: run panic-catching tests in liballoc

I also converted two tests from using `thread::spawn(...).join()` just for catching panics, to `catch_panic`, so that Miri can run them.
2019-12-01 04:49:21 +01:00
David Tolnay
1c4d453969
Format liballoc with rustfmt 2019-11-29 20:25:07 -08:00