Commit Graph

2470 Commits

Author SHA1 Message Date
bors 9d430cb351 Auto merge of #71204 - JohnTitor:into-vec, r=wesleywiser
perf: Remove inline attribute from `into_vec()`

It was introduced in #70565 and is likely related to this perf results: https://perf.rust-lang.org/compare.html?start=1edcfc83c6a08ddc5e63fc652b149baea0236e7c&end=d249d756374737eb014079901ac132f1e1ed905e&stat=instructions:u
Let's check if it's related to that.
r? @wesleywiser could you kick off perf check? I don't think I can do it.
2020-04-18 08:03:38 +00:00
Dylan DPC d5d9bf0406
Rollup merge of #71167 - RalfJung:big-o, r=shepmaster
big-O notation: parenthesis for function calls, explicit multiplication

I saw `O(n m log n)` in the docs and found that really hard to parse. In particular, I don't think we should use blank space as syntax for *both* multiplication and function calls, that is just confusing.

This PR makes both multiplication and function calls explicit using Rust-like syntax. If you prefer, I can also leave one of them implicit, but I believe explicit is better here.

While I was at it I also added backticks consistently.
2020-04-17 23:56:00 +02:00
Charles Lew 22e51cd78a Implement `Clone` for `liballoc::collections::linked_list::Cursor`. 2020-04-17 21:31:59 +08:00
Dylan DPC 28964b4ef2
Rollup merge of #71220 - cuviper:std_or_patterns, r=Mark-Simulacrum
Dogfood or_patterns in the standard library

We can start using `or_patterns` in the standard library as a step toward stabilization.

cc #54883 @Centril
2020-04-17 03:05:19 +02:00
Dylan DPC 53f3130bdb
Rollup merge of #71219 - JOE1994:patch-4, r=Mark-Simulacrum
Minor fixes to doc comments of 'VecDeque'

1. Changed descriptions of `fn get` & `fn get_mut`.
  Since both of these functions are returning references, and not the owned value, I thought the doc comments could be fixed to be consistent with doc comments of `fn front` & `fn front_mut`.

2. Other changes are minor fixes or additions for clarification.

Thank you for taking a look :)
2020-04-16 23:34:45 +02:00
Youngsuk Kim 9707bec3c5
Minor fixes to doc comments of 'VecDequeue'
1. Changed descriptions of `fn get` & `fn get_mut`.
  Since both of these functions are returning references, and not the owned value, I thought the doc comments could be fixed to be consistent with doc comments of `fn front` & `fn front_mut`.

2. Other changes are minor fixes or additions for clarification.

Thank you for taking a look :)
2020-04-16 16:26:14 -04:00
Josh Stone 2edd123a23 Dogfood or_patterns in the standard library 2020-04-16 12:44:57 -07:00
Yuki Okushi c2f24a1d94
Remove inline attribute from `into_vec()` 2020-04-17 00:23:44 +09:00
Simon Sapin 7709d205dd Implement `Box::into_raw` based on `Box::leak`
… instead of the other way around.
2020-04-16 17:20:53 +02:00
Matthias Krüger 139c646251 Fix clippy warnings
clippy::{filter_next,single_char_pattern,unit_arg,identity_conversion,nonminimal_bool}
2020-04-15 23:38:48 +02:00
Simon Sapin 9a1c7dba32
Apply suggestions from code review
Co-Authored-By: Ralf Jung <post@ralfj.de>
2020-04-15 18:32:56 +02:00
Ralf Jung 818bef5558 don't specify log base in big-O 2020-04-15 17:07:13 +02:00
Simon Sapin b359fe1eea Deprecate `Rc::into_raw_non_null` and `Arc::into_raw_non_null` 2020-04-15 16:18:33 +02:00
Simon Sapin cdb6bef4fb Deprecate `Box::into_raw_non_null`
Per https://github.com/rust-lang/rust/issues/47336#issuecomment-586589016
2020-04-15 16:18:33 +02:00
Ralf Jung 88612e3657 big-O notation: parenthesis, multiplication and backticks 2020-04-15 14:33:45 +02:00
Dylan DPC 54b160d764
Rollup merge of #71133 - MiSawa:fix-sort-by-key-doc, r=Dylan-DPC
Tighten time complexity on the doc of sort_by_key

Fixes #71132
2020-04-14 23:29:59 +02:00
Dylan DPC e2f24230a2
Rollup merge of #70949 - WaffleLapkin:simlify_vec_macro, r=petrochenkov
simplify `vec!` macro

Simplify `vec!` macro by replacing 2 following branches:
- `($($x:expr),*) => (...)`
- `($($x:expr,)*) => (...)`
with one:
- `($($x:expr),* $(,)?) => (...)`

This is a minor change, however, this will make the documentation cleaner
2020-04-14 23:29:53 +02:00
Ulrik Sverdrup 7612ad7797 Vec drop and truncate: drop using raw slice *mut [T]
By creating a *mut [T] directly (without going through &mut [T]), avoid
questions of validity of the contents of the slice.

Consider the following risky code:

```rust
unsafe {
    let mut v = Vec::<bool>::with_capacity(16);
    v.set_len(16);
}
```

The intention is that with this change, the above snippet will be
sound because Vec::drop does no longer produces a mutable slice of
the vector's contents.
2020-04-14 21:51:48 +02:00
mi_sawa 408dc36980 Tighten time complexity on the doc 2020-04-14 23:51:03 +09:00
Dylan DPC 340b7314e3
Rollup merge of #71121 - AnthonyMikh:fix_string_doc_link, r=Dylan-DPC
Fix broken link in documentation for String::from_utf8
2020-04-14 15:35:32 +02:00
AnthonyMikh 15ba31d010
Fix broken link in documentation for String::from_utf8 2020-04-14 15:07:57 +03:00
Waffle 2c23bd4914 make `vec![,]` uncompilable
Fix regression introduced in commit #3ae2d21
2020-04-14 10:27:55 +03:00
Michal 'vorner' Vaner 80ccddc0ed
weak-into-raw: as_raw -> as_ptr + dangling garbage
* Rename Weak::as_raw to Weak::as_ptr for consistency with some other
  types.
* The as_ptr for a dangling Weak pointer might return whatever garbage
  (and takes that advantage to avoid a conditional).
* Don't guarantee to be able to do `Weak::from_raw(weak.as_ptr())` (even
  though it'll still work fine).
2020-04-13 17:17:34 +02:00
Ivan Tham 7a22cf6415 Add examples to Pattern docs 2020-04-13 22:25:15 +08:00
Ivan Tham cbe96b04ad Add period to Pattern docs 2020-04-13 22:24:58 +08:00
Dylan DPC 03a724bd48
Rollup merge of #70996 - ChaiTRex:master, r=Amanieu
Add or_insert_with_key to Entry of HashMap/BTreeMap

Going along with `or_insert_with`, `or_insert_with_key` provides the `Entry`'s key to the lambda, avoiding the need to either clone the key or the need to reimplement this body of this method from scratch each time.

This is useful when the initial value for a map entry is derived from the key. For example, the introductory Rust book has an example Cacher struct that takes an expensive-to-compute lambda and then can, given an argument to the lambda, produce either the cached result or execute the lambda.

---

I'm fairly new to Rust, so any optimizations, corrections to types, better names, better documentation, or whatever else would be appreciated. I'd like to thank Arnavion on freenode for helping me to implement a very similar method when I found that `or_insert_with_key` was unavailable.

As a somewhat-related note, this implements https://github.com/rust-lang/rfcs/issues/1202 from 2015, so if this pull request is accepted, that should be closed.
2020-04-11 17:52:11 +02:00
Chai T. Rex db0c39fba5 Change issue number to point to tracking issue 2020-04-11 08:46:12 -04:00
Chai T. Rex 78102377d0 Fixed doc tests for added methods 2020-04-10 13:45:34 -04:00
Chai T. Rex 921579cc3c Add or_insert_with_key to Entry of HashMap/BTreeMap
Going along with or_insert_with, or_insert_with_key provides the
Entry's key to the lambda, avoiding the need to either clone the
key or the need to reimplement this body of this method from
scratch each time.

This is useful when the initial value for a map entry is derived
from the key. For example, the introductory Rust book has an
example Cacher struct that takes an expensive-to-compute lambda and
then can, given an argument to the lambda, produce either the
cached result or execute the lambda.
2020-04-10 12:54:09 -04:00
Mazdak Farrokhzad f699a55e4b
Rollup merge of #70981 - ssomers:btreemap_into_into_iter, r=Mark-Simulacrum
Rearrange BTreeMap::into_iter to match range_mut.

r? @Mark-Simulacrum
I wondered why you catered for the optional root differently in `into_iter` than in `range_mut`.
2020-04-10 18:15:24 +02:00
Mazdak Farrokhzad 277ce9e249
Rollup merge of #70979 - ssomers:btreemap_the_alice_merton_variations, r=Amanieu
Follow up on BTreeMap comments

r? @Amanieu (for the first commit)
2020-04-10 18:15:22 +02:00
Mazdak Farrokhzad 74e93bb8e6
Rollup merge of #70913 - eddyb:rc-arc-diagnostic-items, r=matthewjasper
Replace "rc"/"arc" lang items with Rc/Arc diagnostic items.

`Rc`/`Arc` should have no special semantics, so it seems appropriate for them to not be lang items.

r? @matthewjasper
2020-04-10 12:48:45 +02:00
Mazdak Farrokhzad 81a360fe9a
Rollup merge of #70843 - ssomers:btree_drain_filter_epilogue, r=Amanieu
Remove the Ord bound that was plaguing drain_filter

Now that  #70795 made it superfluous. Also removes superfluous lifetime specifiers (at least I think they are).
2020-04-10 12:48:44 +02:00
Stein Somers 4ade06bab8 Rearrange BTreeMap::into_iter to match range_mut. 2020-04-10 10:58:17 +02:00
Stein Somers de39a4f621 Respect the comment: no root unless the borrow type is `Mut` 2020-04-09 21:37:30 +02:00
Stein Somers 607315b2c3 Kill comment left behind by a last minute change in #70795 2020-04-09 20:16:30 +02:00
Mazdak Farrokhzad 2c3147f018
Rollup merge of #70958 - Amanieu:android_try_reserve, r=Mark-Simulacrum
Disable try_reserve tests on Android

Calling `realloc` with large sizes seems to be broken on older Android versions that use dlmalloc as the default allocator. This is not an issue for modern Android versions that use jemalloc.

Fixes #55861
2020-04-09 18:17:22 +02:00
Amanieu d'Antras 7060a9e683 Disable try_reserve tests on Android 2020-04-09 15:55:12 +01:00
Waffle 3ae2d21c12 simplify `vec!` macro
Simplify `vec!` macro by replacing 2 following branches:
- `($($x:expr),*) => (...)`
- `($($x:expr,)*) => (...)`
with one:
- `($($x:expr),* $(,)?) => (...)`
2020-04-09 11:03:57 +03:00
Dylan DPC 5848209b64
Rollup merge of #70930 - lcnr:patch-1, r=Dylan-DPC
add tracking issue to `VecDeque::make_contiguous`

The tracking issue is https://github.com/rust-lang/rust/issues/70929
2020-04-08 23:33:48 +02:00
Dylan DPC 3cae0e479e
Rollup merge of #70565 - Zoxc:inlines-query-system, r=davidtwco
Add inline attributes for functions used in the query system
2020-04-08 23:33:40 +02:00
Dylan DPC b9bb12640e
Rollup merge of #70850 - ssomers:btreemap_first_last, r=Amanieu
BTreeMap first last proposal tweaks

Clean-up and following up on a request in #62924.

Trying the reviewer of the original code #65637...
r? @scottmcm
2020-04-08 18:37:22 +02:00
Bastian Kauschke 839d229550
add `VecDeque::make_contiguous` tracking issue 2020-04-08 16:53:04 +02:00
Eduard-Mihai Burtescu 9d13520a6b Replace "rc"/"arc" lang items with Rc/Arc diagnostic items. 2020-04-08 10:47:41 +03:00
Dylan DPC 89d661f15d
Rollup merge of #70857 - faern:use-assoc-int-float-consts, r=dtolnay
Don't import integer and float modules, use assoc consts 2

Follow up to #70777. I missed quite a lot of places. Partially because I wanted to keep the size of the last PR down, and partially because my regexes were not good enough :)

r? @dtolnay
2020-04-07 14:46:59 +02:00
Josh Stone e8339e820b Use split_at in slice's ToOwned::clone_into
It appears to codegen slightly more efficiently with `split_at` taking
two slices at once, rather than slicing across different calls.
2020-04-06 15:50:59 -07: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
Stein Somers 8212b9772e BTreeMap first/last: add pop methods 2020-04-06 19:56:29 +02:00
Stein Somers c23ee767d9 BTreeMap first/last: make examples more to the point 2020-04-06 19:03:18 +02:00
Stein Somers bdbe56ecb8 BTreeMap first/last: simplify implementations 2020-04-06 19:00:43 +02:00
IgorPerikov 9fc77c0e15 add detailed panic messages for Vec functions 2020-04-06 17:53:56 +03:00
Stein Somers 6ee7e8c978 Remove the Ord bound that was plaguing drain_filter, and superfluous lifetimes 2020-04-06 15:45:19 +02:00
Dylan DPC 2ec0e148f1
Rollup merge of #70795 - Amanieu:btree_remove_tracking, r=Mark-Simulacrum
Keep track of position when deleting from a BTreeMap

This improves the performance of drain_filter and is needed for future Cursor support for BTreeMap.

cc @ssomers
r? @Mark-Simulacrum
2020-04-05 18:47:47 +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
Amanieu d'Antras 51357cf1cd Apply review feedback 2020-04-05 14:29:00 +01:00
Amanieu d'Antras 7365748c0c Keep track of position when deleting from a BTreeMap
This improves the performance of drain_filter and is needed for
future Cursor support for BTreeMap.
2020-04-05 12:18:46 +01:00
Dylan DPC c185c4fe47
Rollup merge of #70776 - RalfJung:raw-vec, r=Dylan-DPC,TimDiekmann
clarify comment in RawVec::into_box

On first reading I almost thought "len <= cap" would be all that there is to check here. Expand the comment to clarify that that is not the case.
2020-04-05 13:13:13 +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
Ralf Jung 6cbe1726a7 clarify safety in RawVec::into_box 2020-04-05 12:09:03 +02:00
Linus Färnstrand fff4f08398 Stop importing integer modules in liballoc 2020-04-05 11:22:01 +02:00
Ralf Jung 7e81c11aa8 tweak swap_remove 2020-04-05 08:40:40 +02:00
Trevor Spiteri 2b718e8d9c use ManuallyDrop instead of forget inside collections
This commit changes some usage of mem::forget into mem::ManuallyDrop
in some Vec, VecDeque, BTreeMap and Box methods.

Before the commit, the generated IR for some of the methods was
longer, and even after optimization, some unwinding artifacts were
still present.
2020-04-04 14:30:33 +02:00
Mazdak Farrokhzad 9b22fdc121
Rollup merge of #69860 - faern:use-assoc-int-consts, r=dtolnay
Use associated numeric consts in documentation

Now when the associated constants on int/float types are stabilized and the recommended way of accessing said constants (#68952). We can start using it in this repository, and recommend it via documentation example code.

This PR is the reincarnation of #67913 minus the actual adding + stabilization of said constants. (EDIT: Now it's only changing the documentation. So users will see the new consts, but we don't yet update the internal code)

Because of how fast bit rot happens to PRs that touch this many files, it does not try to replace 100% of the old usage of the constants in the entire repo, but a good chunk of them.
2020-04-03 22:55:02 +02:00
Yoshua Wuyts 3d17993f9f Fix link in task::Wake docs 2020-04-03 11:33:27 +02:00
Linus Färnstrand c0ec0a27b3 Replace max/min_value() with MAX/MIN assoc consts 2020-04-03 09:33:10 +02:00
DutchGhost 3f1a588a94 stabilize BTreeMap::remove_entry 2020-04-02 21:35:26 +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
Tim Diekmann 89ed59d884
Add missing allocation guard in `RawVec::grow` 2020-04-01 10:26:30 +02:00
Dylan DPC 8310320ebd
Rollup merge of #70632 - tspiteri:vec-new, r=sfackler
expand vec![] to Vec::new()

The current expansion of `vec![]` calls `into_vec` on a boxed slice, which results in longer IR, and even after optimization, some unwinding artifacts are still present in the IR. This PR uses `Vec::new()` for `vec![]`.

This also allows `vec![]` to be used in const expressions.
2020-04-01 00:27:26 +02: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
Trevor Spiteri 4d8273dea5 expand vec![] to Vec::new() 2020-03-31 21:37:13 +02:00
Dylan DPC f62cfa76c5
Rollup merge of #69425 - lcnr:make_contiguous, r=Amanieu
add fn make_contiguous to VecDeque

Adds the following method to VecDeque:

```rust
pub fn make_contiguous(&mut self) -> &mut [T];
```

Taken from https://github.com/rust-lang/rust/pull/69400, after a suggestion by @CryZe https://github.com/rust-lang/rust/pull/69400#issuecomment-590216089

I am in favor of merging this instead of https://github.com/rust-lang/rust/pull/69400.
2020-03-31 19:29:26 +02:00
Bastian Kauschke e1afd26c52 fix docs 2020-03-31 16:50:06 +02:00
Mazdak Farrokhzad 9ee373fd94
Rollup merge of #69784 - benesch:fast-strip-prefix-suffix, r=kennytm
Optimize strip_prefix and strip_suffix with str patterns

As mentioned in https://github.com/rust-lang/rust/issues/67302#issuecomment-585639226.
I'm not sure whether adding these methods to `Pattern` is desirable—but they have default implementations so the change is backwards compatible. Plus it seems like they're slated for wholesale replacement soon anyway? #56345

----

Constructing a Searcher in strip_prefix and strip_suffix is
unnecessarily slow when the pattern is a fixed-length string. Add
strip_prefix and strip_suffix methods to the Pattern trait, and add
optimized implementations of these methods in the str implementation.
The old implementation is retained as the default for these methods.
2020-03-31 15:59:40 +02:00
Bastian Kauschke b5223d2725 update `VecDeque::as_(mut)_slice` docs 2020-03-31 15:39:56 +02:00
Nikhil Benesch ac478f2f61
Optimize strip_prefix and strip_suffix with str patterns
Constructing a Searcher in strip_prefix and strip_suffix is
unnecessarily slow when the pattern is a fixed-length string. Add
strip_prefix and strip_suffix methods to the Pattern trait, and add
optimized implementations of these methods in the str implementation.
The old implementation is retained as the default for these methods.
2020-03-30 11:10:21 -04:00
John Kåre Alsaker 87cdfb6e71 Add inline attributes for functions used in the query system 2020-03-30 14:37:44 +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
Ralf Jung fa6c883074 fix ptr invalidation in Vec::truncate 2020-03-30 11:58:16 +02:00
Ralf Jung 86c1c43420 fix pointer invalidation when extnding a vector from an untrusted iterator 2020-03-30 11:58:16 +02:00
Ralf Jung 6556549fa6 fix Vec::extend invalidating unrelated pointers 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 a6cae3d5cf Add benchmarks of drain_filter-like behaviour 2020-03-29 16:05:53 +02:00
Mazdak Farrokhzad f31e56309a
Rollup merge of #70506 - ssomers:btreemap_testing_consts, r=RalfJung
BTreeMap testing: introduce symbolic constants and use height consistently

Doesn't change what or how much is tested, except for some exact integer types, just for convenience and because `node::CAPACITY` is a usize.

r? @RalfJung
2020-03-29 11:50:13 +02:00
Mazdak Farrokhzad c51fcb5f38
Rollup merge of #68692 - jyn514:vec-from-array, r=LukasKalbertodt
impl From<[T; N]> for Vec<T>

Closes https://github.com/rust-lang/rust/issues/67963
2020-03-29 11:50:10 +02:00
Tim Diekmann 3ade8ae660 Implement `init` and `init_offset` on `AllocInit` and mark it unsafe 2020-03-29 01:47:05 +01: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 fed3d6e646 Fix safety section of `RawVec::into_box` 2020-03-26 17:13:47 +01:00
Tim Diekmann cbbdca0594 Fix wording in `RawVec::from_raw_parts(_in)` 2020-03-26 17:13:31 +01:00
Tim Diekmann b02e53f197 Remove check for ZST in `RawVec::needs_to_grow` 2020-03-26 17:13:25 +01:00
Tim Diekmann ad7de67a32 Refine docs for `RawVec::from_raw_parts(_in)` 2020-03-26 17:13:11 +01:00
Tim Diekmann aae3c52c7a Remove the note on the internal capacity field in `RawVec` 2020-03-26 17:12:57 +01:00
Tim Diekmann ba26a9e957 Fix assertion in `shrink` to use `capacity()` instead 2020-03-26 17:12:45 +01:00
Tim Diekmann 42a8547038 Fix comment in `RawVec::into_box()` 2020-03-26 17:12:35 +01:00
Tim Diekmann c1fa02331a Fix ZST handling for `RawVec` 2020-03-26 17:12:27 +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
Niko Matsakis fda3378e3f introduce `negative_impls` feature gate and document
They used to be covered by `optin_builtin_traits` but negative impls
are now applicable to all traits, not just auto traits.

This also adds docs in the unstable book for the current state of auto traits.
2020-03-26 06:52:55 -04:00
Kornel 42b10e51c1 must_use on split_off
#70194
2020-03-24 17:35:40 +00:00
Saoirse Shipwreckt 32f5724e8a Apply suggestions from code review
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
2020-03-23 15:45:30 +01:00
Saoirse Shipwreckt caff9f92ab Update src/liballoc/task.rs
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
2020-03-23 15:45:30 +01:00
Without Boats 3ae74cafe4 More explicit; CFG on atomic pointer 2020-03-23 15:45:30 +01:00
Without Boats ede03a4175 typo 2020-03-23 15:45:30 +01:00
Without Boats c9acdb0bd4 Improve safety implementation, fix typos 2020-03-23 15:45:30 +01:00
Without Boats 06ede350c2 Add Wake trait for safe construction of Wakers.
Currently, constructing a waker requires calling the unsafe
`Waker::from_raw` API. This API requires the user to manually construct
a vtable for the waker themself - which is both cumbersome and very
error prone. This API would provide an ergonomic, straightforward and
guaranteed memory-safe way of constructing a waker.

It has been our longstanding intention that the `Waker` type essentially
function as an `Arc<dyn Wake>`, with a `Wake` trait as defined here. Two
considerations prevented the original API from being shipped as simply
an `Arc<dyn Wake>`:

- We want to support futures on embedded systems, which may not have an
  allocator, and in optimized executors for which this API may not be
  best-suited. Therefore, we have always explicitly supported the
  maximally-flexible (but also memory-unsafe) `RawWaker` API, and
  `Waker` has always lived in libcore.
- Because `Waker` lives in libcore and `Arc` lives in liballoc, it has
  not been feasible to provide a constructor for `Waker` from `Arc<dyn
  Wake>`.

Therefore, the Wake trait was left out of the initial version of the
task waker API.

However, as Rust 1.41, it is possible under the more flexible orphan
rules to implement `From<Arc<W>> for Waker where W: Wake` in liballoc.
Therefore, we can now define this constructor even though `Waker` lives
in libcore.

This PR adds these APIs:

- A `Wake` trait, which contains two methods
    - A required method `wake`, which is called by `Waker::wake`
    - A provided method `wake_by_ref`, which is called by
      `Waker::wake_by_ref` and which implementors can override if they
      can optimize this use case.
- An implementation of `From<Arc<W>> for Waker where W: Wake + Send +
  Sync + 'static`
- A similar implementation of `From<Arc<W>> for RawWaker`.
2020-03-23 15:44:58 +01:00
Mazdak Farrokhzad c984a96189
Rollup merge of #70269 - matthiaskrgr:clippy_closures, r=Dylan-DPC
remove redundant closures (clippy::redundant_closure)
2020-03-23 04:26:15 +01:00
Bastian Kauschke d068545bfb
update `make_contiguous` docs
Co-Authored-By: Amanieu d'Antras <amanieu@gmail.com>
2020-03-22 16:00:51 +01:00
Dylan DPC 8fe8bad96b
Rollup merge of #70254 - matthiaskrgr:cl4ppy, r=Centril
couple more clippy fixes (let_and_return, if_same_then_else)

* summarize if-else-code with identical blocks (clippy::if_same_then_else)
* don't create variable bindings just to return the bound value immediately (clippy::let_and_return)
2020-03-22 15:48:41 +01:00
Dylan DPC 0bc5fc99d3
Rollup merge of #68099 - lukaslueg:into_raw_unsafe, r=LukasKalbertodt
Amend Rc/Arc::from_raw() docs regarding unsafety

[This](https://stackoverflow.com/questions/59671647/is-it-safe-to-clone-a-type-erased-arc-via-raw-pointer) question on SO boils down to "is it safe to `::from_raw()` a `Rc<T>`/`Arc<T>` using a dummy `T` even if `T` is never dereferenced via the new `Rc`/`Arc`?". It almost never is.

This PR amends the docs of `from_raw()` regarding this point.
2020-03-22 15:48:28 +01:00
Bastian Kauschke ecf301d987 document invariant of `VecDeque::as_(mut)_slice` 2020-03-22 14:59:38 +01:00
Matthias Krüger 263cbd1bbe remove redundant closures (clippy::redundant_closure) 2020-03-22 12:43:19 +01:00
Bastian Kauschke 626fdbce8b add `fn make_contiguous` to VecDeque 2020-03-22 09:35:08 +01:00
Matthias Krüger 74d68ea7eb don't create variable bindings just to return the bound value immediately (clippy::let_and_return) 2020-03-22 00:35:25 +01:00
Mazdak Farrokhzad 54285db640
Rollup merge of #70194 - kornelski:must_split, r=joshtriplett
#[must_use] on split_off()

I've noticed this function used for truncation in the wild. `must_use` will clear that up.
2020-03-21 05:33:36 +01:00
Mazdak Farrokhzad 9d9e3813b2
Rollup merge of #70111 - Mark-Simulacrum:btree-no-shared, r=cuviper
BTreeMap: remove shared root

This replaces the shared root with `Option`s in the BTreeMap code, and then slightly cleans up the node manipulation code taking advantage of the removal of the shared root. I expect that further simplification is possible, but wanted to get this posted for initial review.

Note that `BTreeMap::new()` continues to not allocate.

Benchmarks seem within the margin of error/unaffected, as expected for an entirely predictable branch.

```
 name                                 alloc-bench-a ns/iter  alloc-bench-b ns/iter  diff ns/iter  diff %  speedup
 btree::map::iter_mut_20              20                     21                                1   5.00%   x 0.95
 btree::set::clone_100                1,360                  1,439                            79   5.81%   x 0.95
 btree::set::clone_100_and_into_iter  1,319                  1,434                           115   8.72%   x 0.92
 btree::set::clone_10k                143,515                150,991                       7,476   5.21%   x 0.95
 btree::set::clone_10k_and_clear      142,792                152,916                      10,124   7.09%   x 0.93
 btree::set::clone_10k_and_into_iter  146,019                154,561                       8,542   5.85%   x 0.94
```
2020-03-21 05:33:21 +01:00
Kornel 2f7d7c0333 must_use on split_off 2020-03-20 14:40:35 +00:00
Mark Rousskov 4d85314a00 Update test commentary for shared root removal 2020-03-20 09:43:41 -04:00
Mark Rousskov 13f6d771bb Simplify ensure_root_is_owned callers
This makes ensure_root_is_owned return a reference to the (now guaranteed to
exist) root, allowing callers to operate on it without going through another
unwrap.

Unfortunately this is only rarely useful as it's frequently the case that both
the length and the root need to be accessed and field-level borrows in methods
don't yet exist.
2020-03-20 09:43:41 -04:00
Mark Rousskov 54b7c38889 Drop NodeHeader type from BTree code
We no longer have a separate header because the shared root is gone; all code
can work solely with leafs now.
2020-03-20 09:43:41 -04:00
Mark Rousskov 3c04fda751 Make functions dependent only on shared root avoidance safe 2020-03-20 09:43:40 -04:00
Mark Rousskov 1c44f852df Remove shared root code and assertions from BTree nodes 2020-03-20 09:43:19 -04:00
Mark Rousskov e61f126fb4 Replace shared root with optional root
This simplifies the node manipulation, as we can (in later commits) always know
when traversing nodes that we are not in a shared root.
2020-03-20 09:42:10 -04:00
Tomasz Miąsko fd0e15bbcd Make std::sync::Arc compatible with ThreadSanitizer
The memory fences used previously in Arc implementation are not properly
understood by ThreadSanitizer as synchronization primitives. This had
unfortunate effect where running any non-trivial program compiled with
`-Z sanitizer=thread` would result in numerous false positives.

Replace acquire fences with acquire loads when using ThreadSanitizer to
address the issue.
2020-03-20 00:18:44 +01:00
Mazdak Farrokhzad f907598ba4
Rollup merge of #70029 - jonas-schievink:bootstrap, r=Centril
Bump the bootstrap compiler
2020-03-17 03:05:17 +01:00
Jonas Schievink f53f9a88f1 Bump the bootstrap compiler 2020-03-15 19:43:25 +01:00
Mazdak Farrokhzad cc1623267b
Rollup merge of #69661 - lopopolo:string-from-mut-str, r=sfackler
Implement From<&mut str> for String

I ran into this missing impl when trying to do `String::from` on the result returned from this API in the `uuid` crate:

https://docs.rs/uuid/0.8.1/uuid/adapter/struct.Hyphenated.html#method.encode_lower

I wasn't sure what to put in the stability annotation. I'd appreciate some help with that :)
2020-03-15 15:40:07 +01:00
Yuki Okushi c13548dccd
Rollup merge of #69809 - matthiaskrgr:lifetimes, r=eddyb
remove lifetimes that can be elided (clippy::needless_lifetimes)
2020-03-14 04:03:26 +09:00
Matthias Krüger 7b1b08cfee remove lifetimes that can be elided (clippy::needless_lifetimes) 2020-03-12 20:03:09 +01:00
Mazdak Farrokhzad d21320cbd9
Rollup merge of #69792 - LenaWil:try_reserve_error/impl-error, r=sfackler
Implement Error for TryReserveError

I noticed that the Error trait wasn't implemented for TryReserveError. (#48043)

Not sure if the error messages and code style are 100% correct, it's my first time contributing to the Rust std.
2020-03-12 16:32:21 +01:00
Lena Wildervanck 2c90a37969 Reformat match statement to make the check pass 2020-03-11 17:55:14 +01:00
Lena Wildervanck 599cd683ea Format the match statement 2020-03-11 17:30:04 +01:00
Mazdak Farrokhzad 080d41391d
Rollup merge of #69828 - RalfJung:vec-leak, r=kennytm
fix memory leak when vec::IntoIter panics during drop

Fixes https://github.com/rust-lang/rust/issues/69770
2020-03-11 14:03:47 +01:00
Ryan Lopopolo 533784d3a2 Add docs for From::<&mut str>::from String impl 2020-03-10 18:47:19 -07:00
Ryan Lopopolo 18feaa3fa2 Add stable feature name 2020-03-10 18:45:08 -07:00
Joshua Nelson 3477e67a92 Allow vec.rs to be over 3000 lines :( 2020-03-10 23:49:45 +00:00
Joshua Nelson 8212584c9e Bump release cutoff 2020-03-10 23:44:46 +00:00
Joshua Nelson 1ac4a46142 make the impl a little prettier 2020-03-10 23:44:46 +00:00
Joshua Nelson 96794d86f1 fix test failure 2020-03-10 23:44:46 +00:00
Joshua Nelson f267d9dc19 limit From impl to LengthAtMost32
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2020-03-10 23:44:46 +00:00
Joshua Nelson daeb8ece8c fix error compiling stage2
Co-Authored-By: lzutao <taolzu@gmail.com>
2020-03-10 23:44:46 +00:00
Joshua Nelson 62722735fb impl From<[T; N]> for Vec<T> 2020-03-10 23:44:46 +00:00
Mazdak Farrokhzad 3e9efbd8b4
Rollup merge of #69877 - CAD97:patch-1, r=dtolnay
Vec::new is const stable in 1.39 not 1.32

Changelog: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1390-2019-11-07

This really surprised me when a MSRV check for 1.35 failed with `Vec::new is not yet stable as a const fn` and the docs said that it was const stabilized in 1.32.
2020-03-10 06:47:59 +01:00