Commit graph

268 commits

Author SHA1 Message Date
Amanieu d'Antras
7060a9e683 Disable try_reserve tests on Android 2020-04-09 15:55:12 +01:00
Linus Färnstrand
e4fc04b6df Use usize::MAX as assoc const in liballoc 2020-04-06 23:07:38 +02:00
Linus Färnstrand
65e10e3436 Use assoc const f32::NAN in liballoc 2020-04-06 22:44:04 +02:00
Dylan DPC
c2595539e7
Rollup merge of #70777 - faern:use-assoc-int-consts2, r=dtolnay
Don't import integer and float modules, use assoc consts

Stop importing the standard library integer and float modules to reach the `MIN`, `MAX` and other constants. They are available directly on the primitive types now.

This PR is a follow up of #69860 which made sure we use the new constants in documentation.

This type of change touches a lot of files, and previously all my assoc int consts PRs had collisions and were accepted only after a long delay. So I'd prefer to do it in smaller steps now. Just removing these imports seem like a good next step.

r? @dtolnay
2020-04-05 18:47:45 +02:00
Dylan DPC
7e4ed72d64
Rollup merge of #70558 - RalfJung:vec-extend-aliasing, r=Amanieu
Fix some aliasing issues in Vec

`Vec::extend` and `Vec::truncate` invalidated references into the vector even without reallocation, because they (implicitly) created a mutable reference covering the *entire* initialized part of the vector.

Fixes https://github.com/rust-lang/rust/issues/70301
I verified the fix by adding some new tests here that I ran in Miri.
2020-04-05 13:13:08 +02:00
Linus Färnstrand
fff4f08398 Stop importing integer modules in liballoc 2020-04-05 11:22:01 +02:00
bors
127a11a344 Auto merge of #70362 - TimDiekmann:alloc-overhaul, r=Amanieu
Overhaul of the `AllocRef` trait to match allocator-wg's latest consens; Take 2

GitHub won't let me reopen #69889 so I make a new PR.

In addition to #69889 this fixes the unsoundness of `RawVec::into_box` when using allocators supporting overallocating. Also it uses `MemoryBlock` in `AllocRef` to unify `_in_place` methods by passing `&mut MemoryBlock`. Additionally, `RawVec` now checks for `size_of::<T>()` again and ignore every ZST. The internal capacity of `RawVec` isn't used by ZSTs anymore, as `into_box` now requires a length to be specified.

r? @Amanieu

fixes rust-lang/wg-allocators#38
fixes rust-lang/wg-allocators#41
fixes rust-lang/wg-allocators#44
fixes rust-lang/wg-allocators#51
2020-04-02 06:08:35 +00:00
Dylan DPC
718ba0d23b
Rollup merge of #68770 - ssomers:btree_drain_filter, r=Amanieu
BTreeMap/BTreeSet: implement drain_filter

Provide an implementation of drain_filter for BTreeMap and BTreeSet. Should be optimal when the predicate picks only elements in leaf nodes with at least MIN_LEN remaining elements, which is a common case, at least when draining only a fraction of the map/set, and also when the predicate picks elements stored in internal nodes where the right subtree can easily let go of a replacement element.

The first commit adds benchmarks with an external, naive implementation. to compare how much this claimed optimality-in-some-cases is actually worth.
2020-04-01 00:27:18 +02:00
Ralf Jung
5bbaac357d fix and test aliasing in swap_remove 2020-03-30 13:34:03 +02:00
Ralf Jung
8f479e362f fix aliasing in remove()
also add smoke test to detect relocation even in rustc runs
2020-03-30 13:24:55 +02:00
Ralf Jung
4eacf45c9c also cover next() path of draining iterators 2020-03-30 13:01:15 +02:00
Ralf Jung
3411ade32e test more mutating vector methods 2020-03-30 12:24:02 +02:00
Ralf Jung
032d3cd553 fix BTreeMap test compilation with Miri 2020-03-30 12:04:05 +02:00
Ralf Jung
4393923168 add some tests 2020-03-30 11:58:16 +02:00
Stein Somers
0405db3a34 BTreeMap/BTreeSet: implement and test drain_filter 2020-03-29 16:05:53 +02:00
Stein Somers
e92d740b35 BTreeMap testing: introduce symbolic constants and refer to height consistently. 2020-03-28 23:30:43 +01:00
Tim Diekmann
bf6a46db31 Make fields in MemoryBlock public 2020-03-28 20:22:07 +01:00
Tim Diekmann
03b055b0b4 Remove alignment from MemoryBlock 2020-03-26 17:14:12 +01:00
Tim Diekmann
2526accdd3 Fix issues from review and unsoundness of RawVec::into_box 2020-03-26 17:11:47 +01:00
Tim Diekmann
56cbf2f22a Overhaul of the AllocRef trait to match allocator-wg's latest consens 2020-03-26 17:10:54 +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