Commit graph

799 commits

Author SHA1 Message Date
Guillaume Gomez
53af11651b
Rollup merge of #80022 - ssomers:btree_cleanup_8, r=Mark-Simulacrum
BTreeSet: simplify implementation of pop_first/pop_last

…and stop it interfering in #79245.
r? ```````@Mark-Simulacrum```````
2020-12-17 11:36:49 +01:00
Guillaume Gomez
6b83013d1f
Rollup merge of #80006 - ssomers:btree_cleanup_6, r=Mark-Simulacrum
BTreeMap: more expressive local variables in merge

r? ```````@Mark-Simulacrum```````
2020-12-17 11:36:47 +01:00
bors
e261649593 Auto merge of #78682 - glandium:issue78471, r=lcnr
Do not inline finish_grow

Fixes #78471.

Looking at libgkrust.a in Firefox, the sizes for the `gkrust.*.o` file is:
- 18584816 (text) 582418 (data) with unmodified master
- 17937659 (text) 582554 (data) with #72227 reverted
- 17968228 (text) 582858 (data) with `#[inline(never)]` on `grow_amortized` and `grow_exact`, but that has some performance consequences
- 17927760 (text) 582322 (data) with this change

So in terms of size, at least in the case of Firefox, this patch more than undoes the regression. I don't think it should affect performance, but we'll see.
2020-12-15 06:32:10 +00:00
Guillaume Gomez
5d8b2a5bf1
Rollup merge of #79918 - woodruffw-forks:ww/doc-initializer-side-effects, r=dtolnay
doc(array,vec): add notes about side effects when empty-initializing

Copying some context from a conversation in the Rust discord:

* Both `vec![T; 0]` and `[T; 0]` are syntactically valid, and produce empty containers of their respective types

* Both *also* have side effects:

```rust
fn side_effect() -> String {
    println!("side effect!");

    "foo".into()
}

fn main() {
    println!("before!");

    let x = vec![side_effect(); 0];

    let y = [side_effect(); 0];

    println!("{:?}, {:?}", x, y);
}
```

produces:

```
before!
side effect!
side effect!
[], []
```

This PR just adds two small notes to each's documentation, warning users that side effects can occur.

I've also submitted a clippy proposal: https://github.com/rust-lang/rust-clippy/issues/6439
2020-12-14 14:43:44 +01:00
Stein Somers
6c7835e441 BTreeSet: simplify implementation of pop_first/pop_last 2020-12-14 11:25:34 +01:00
bors
7feab000b2 Auto merge of #80005 - ssomers:btree_cleanup_3, r=Mark-Simulacrum
BTreeMap: declare clear_parent_link directly on the root it needs

r? `@Mark-Simulacrum`
2020-12-13 22:13:02 +00:00
bors
69ff39ee32 Auto merge of #79987 - ssomers:btree_cleanup_4, r=Mark-Simulacrum
BTreeMap: detect bulk_steal's count-1 underflow in release builds too

r? `@Mark-Simulacrum`
2020-12-13 17:09:41 +00:00
bors
cbab347e68 Auto merge of #79376 - ssomers:btree_choose_parent_kv, r=Mark-Simulacrum
BTreeMap: clarify comments and panics around choose_parent_kv

Fixes a lie in recent code: `unreachable!("empty non-root node")` should shout "empty internal node", but it might as well be good and keep quiet

r? `@Mark-Simulacrum`
2020-12-13 14:42:37 +00:00
Justus K
09d528ec15
fix typo 2020-12-13 15:18:38 +01:00
Stein Somers
94fd1d325c BTreeMap: more expressive local variables in merge 2020-12-13 11:27:24 +01:00
Stein Somers
bdc6adfb3b BTreeMap: declare clear_parent_link directly on the root it needs 2020-12-13 11:13:54 +01:00
Justus K
d75618e7a2
replace assert! with assert_eq! 2020-12-13 10:21:24 +01:00
Justus K
0f30b7dd87
fix panic if converting ZST Vec to VecDeque 2020-12-13 10:02:36 +01:00
bors
12813159a9 Auto merge of #79994 - JohnTitor:rollup-43wl2uj, r=JohnTitor
Rollup of 12 pull requests

Successful merges:

 - #79360 (std::iter: document iteration over `&T` and `&mut T`)
 - #79398 (Link loop/for keyword)
 - #79834 (Remove deprecated linked_list_extras methods.)
 - #79845 (Fix rustup support in default_build_triple for python3)
 - #79940 (fix more clippy::complexity findings)
 - #79942 (Add post-init hook for static memory for miri.)
 - #79954 (Fix building compiler docs with stage 0)
 - #79963 (Fix typo in `DebruijnIndex` documentation)
 - #79970 (Misc rustbuild improvements when the LLVM backend isn't used)
 - #79973 (rustdoc light theme: Fix CSS for selected buttons)
 - #79984 (Remove an unused dependency that made `rustdoc` crash)
 - #79985 (Fixes submit event of the search input)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-13 04:02:26 +00:00
Yuki Okushi
89051d81b9
Rollup merge of #79834 - m-ou-se:bye-linked-list-extras, r=Mark-Simulacrum
Remove deprecated linked_list_extras methods.

https://github.com/rust-lang/rust/issues/27794#issuecomment-667524201:
> I'd say give it about 2 weeks then remove them.

It's been 18 weeks. Time to remove them. :)

Closes #27794.
2020-12-13 11:05:32 +09:00
Stein Somers
0ae4c95eff BTreeMap: capture a recurring use pattern as replace_kv 2020-12-13 00:44:00 +01:00
Stein Somers
ad75a96b34 BTreeMap: detect bulk_steal's count-1 underflow in release builds too 2020-12-13 00:37:30 +01:00
Stein Somers
50576420f5 BTreeMap: clarify comments and panics surrounding choose_parent_kv 2020-12-12 20:35:15 +01:00
William Woodruff
d986924eb1
doc: apply suggestions 2020-12-11 10:09:40 -05:00
Tyler Mandry
c0cc91008a
Rollup merge of #79860 - rust-lang:frewsxcv-patch-2, r=jyn514
Clarify that String::split_at takes a byte index.

To someone skimming through the `String` docs and only reads the first line, the person could interpret "index" to be "char index". Later on in the docs it clarifies, but by adding "byte" it removes that ambiguity.
2020-12-10 21:33:14 -08:00
William Woodruff
9cf2516251
doc(array,vec): add notes about side effects when empty-initializing 2020-12-10 17:47:28 -05:00
Clément Renault
7952ea5a04
Fix the fmt issues 2020-12-10 19:44:37 +01:00
bors
d32c320d7e Auto merge of #79814 - lcnr:deque-f, r=Mark-Simulacrum
fix soundness issue in `make_contiguous`

fixes #79808
2020-12-10 17:49:42 +00:00
Clément Renault
9940c47885
Update the slice GroupBy/Mut test 2020-12-10 13:42:31 +01:00
Clément Renault
1b406afe23
Use none as the issue instead of 0 2020-12-10 11:37:40 +01:00
Clément Renault
1c55a73b75
Implement it with only safe code 2020-12-10 11:20:15 +01:00
Clément Renault
a891f6edfe
Introduce the GroupBy and GroupByMut Iterators 2020-12-10 10:16:29 +01:00
Tyler Mandry
26e4cf0fc7
Rollup merge of #79795 - matklad:unicode-private, r=cramertj
Privatize some of libcore unicode_internals

My understanding is that these API are perma unstable, so it doesn't
make sense to pollute docs & IDE completion[1] with them.

[1]: https://github.com/rust-analyzer/rust-analyzer/issues/6738
2020-12-09 13:38:22 -08:00
Corey Farwell
33ae62c3d7
Clarify that String::split_at takes a byte index. 2020-12-09 13:17:54 -05:00
Mara Bos
5cab04ea92 Remove deprecated linked_list_extras methods. 2020-12-08 20:52:57 +01:00
Bastian Kauschke
4fb9f1d784 fix unsoundness in make_contiguous 2020-12-08 10:34:31 +01:00
Mike Hommey
76bd145489 Do not inline finish_grow
We also change the specialization of `SpecFromIterNested::from_iter` for
`TrustedLen` to use `Vec::with_capacity` when the iterator has a proper size
hint, instead of `Vec::new`, avoiding calls to `grow_*` and thus
`finish_grow` in some fully inlinable cases, which would regress with
this change.

Fixes #78471.
2020-12-08 13:05:34 +09:00
Chai T. Rex
f115be93ab
Removed spurious linebreak from new documentation 2020-12-07 21:59:52 -05:00
Chai T. Rex
f1b930d57c Improved documentation for HashMap/BTreeMap Entry's .or_insert_with_key method 2020-12-07 21:36:01 -05:00
Aleksey Kladov
88da5682c3 Privatize some of libcore unicode_internals
My understanding is that these API are perma unstable, so it doesn't
make sense to pollute docs & IDE completion[1] with them.

[1]: https://github.com/rust-analyzer/rust-analyzer/issues/6738
2020-12-07 16:16:42 +03:00
bors
9122b769c8 Auto merge of #78373 - matthewjasper:drop-on-into, r=pnkfelix
Don't leak return value after panic in drop

Closes #47949
2020-12-05 13:41:08 +00:00
Matthew Jasper
4fef39113a Avoid leaking block expression values 2020-12-04 23:07:46 +00:00
Tim Diekmann
9274b37d99 Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
Ralf Jung
7e74b72d13 break formatting so rustfmt is happy 2020-12-02 14:09:36 +01:00
Ralf Jung
67a67d827a disable a ptr equality test on Miri 2020-12-02 13:49:33 +01:00
Chai T. Rex
866ef87d3f Update rustc version that or_insert_with_key landed 2020-12-01 01:06:40 -05:00
Christiaan Dirkx
be554c4101 Make ui test that are run-pass and do not test the compiler itself library tests 2020-11-30 02:47:32 +01:00
Dylan DPC
bfa854dbe5
Rollup merge of #79363 - ssomers:btree_cleanup_comments, r=Mark-Simulacrum
BTreeMap: try to enhance various comments

All in internal documentation, propagating the "key-value pair" notation from public documentation.

r? ``@Mark-Simulacrum``
2020-11-29 03:14:15 +01:00
Dylan DPC
a2b4d97984
Rollup merge of #79327 - TimDiekmann:static-alloc-pin-in-box, r=Mark-Simulacrum
Require allocator to be static for boxed `Pin`-API

Allocators has to retain their validity until the instance and all of its clones are dropped. When pinning a value, it must live forever, thus, the allocator requires a `'static` lifetime for pinning a value. [Example from reddit](https://www.reddit.com/r/rust/comments/jymzdw/the_story_continues_vec_now_supports_custom/gd7qak2?utm_source=share&utm_medium=web2x&context=3):

```rust
let alloc = MyAlloc(/* ... */);
let pinned = Box::pin_in(42, alloc);
mem::forget(pinned); // Now `value` must live forever
// Otherwise `Pin`'s invariants are violated, storage invalidated
// before Drop was called.
// borrow of `memory` can end here, there is no value keeping it.
drop(alloc); // Oh, value doesn't live forever.
```
2020-11-29 03:14:07 +01:00
Tim Diekmann
7387f48e50 Require allocator to be static for boxed Pin-API 2020-11-28 15:24:44 +01:00
Stein Somers
d1a2c0f99c BTreeMap: try to enhance various comments & local identifiers 2020-11-28 10:35:02 +01:00
Aaron Hill
6f91c32da6
Fix new 'unnecessary trailing semicolon' warnings 2020-11-26 17:08:36 -05:00
bors
ec039bd075 Auto merge of #79336 - camelid:rename-feature-oibit-to-auto, r=oli-obk
Rename `optin_builtin_traits` to `auto_traits`

They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.

r? `@oli-obk` (feel free to re-assign if you're not the right reviewer for this)
2020-11-25 07:25:19 +00:00
Jonas Schievink
ce197961ac
Rollup merge of #79358 - ssomers:btree_public_comments, r=Mark-Simulacrum
BTreeMap/BTreeSet: make public doc more consistent

Tweaks #72876 and #73667 and propagate them to `BTreeSet`.
2020-11-24 13:17:47 +01:00
Jonas Schievink
012d5fd8d7
Rollup merge of #79354 - ssomers:btree_bereave_BoxedNode, r=Mark-Simulacrum
BTreeMap: cut out the ceremony around BoxedNode

The opposite direction of #79093.

r? ``@Mark-Simulacrum``
2020-11-24 13:17:45 +01:00
Camelid
810324d1f3 Rename optin_builtin_traits to auto_traits
They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-23 14:14:06 -08:00
Stein Somers
9c8db454af BTreeMap/BTreeSet: make public doc more consistent 2020-11-23 19:10:02 +01:00
bors
40624dde6c Auto merge of #79345 - jonas-schievink:rollup-1yhhzx9, r=jonas-schievink
Rollup of 10 pull requests

Successful merges:

 - #76829 (stabilize const_int_pow)
 - #79080 (MIR visitor: Don't treat debuginfo field access as a use of the struct)
 - #79236 (const_generics: assert resolve hack causes an error)
 - #79287 (Allow using generic trait methods in `const fn`)
 - #79324 (Use Option::and_then instead of open-coding it)
 - #79325 (Reduce boilerplate with the `?` operator)
 - #79330 (Fix typo in comment)
 - #79333 (doc typo)
 - #79337 (Use Option::map instead of open coding it)
 - #79343 (Add my (`@flip1995)` work mail to the mailmap)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-23 16:33:03 +00:00
Stein Somers
8526c313c1 BTreeMap: cut out the ceremony around BoxedNode 2020-11-23 17:02:08 +01:00
Jonas Schievink
a0cf162329
Rollup merge of #79333 - o752d:patch-3, r=Mark-Simulacrum
doc typo

plus a small edit for clarity
2020-11-23 15:25:51 +01:00
bors
40cf72108e Auto merge of #79186 - JulianKnodt:str_from, r=Mark-Simulacrum
Change slice::to_vec to not use extend_from_slice

I saw this [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/String.3A.3Afrom%28.26str%29.20wonky.20codegen/near/216164455), and didn't see any update from it, so I thought I'd try to fix it. This converts `to_vec` to no longer use `extend_from_slice`, but relies on knowing that the allocated capacity is the same size as the input.

[Godbolt new v1](https://rust.godbolt.org/z/1bcWKG)
[Godbolt new v2 w/ drop guard](https://rust.godbolt.org/z/5jn76K)
[Godbolt old version](https://rust.godbolt.org/z/e4ePav)

After some amount of iteration, there are now two specializations for `to_vec`, one for `Copy` types that use memcpy, and one for clone types which is the original from this PR.

This is then used inside of `impl<T: Clone> FromIterator<Iter::Slice<T>> for Vec<T>` which is essentially equivalent to `&[T] -> Vec<T>`, instead of previous specialization of the `extend` function. This is because extend has to reason more about existing capacity by calling `reserve` on an existing vec, and thus produces worse asm.

Downsides: This allocates the exact capacity, so I think if many items are added to this `Vec` after, it might need to allocate whereas extending may not. I also noticed the number of faults went up in the benchmarks, but not sure where from exactly.
2020-11-23 14:20:22 +00:00
oliver
a804e38dde
doc typo
plus a small edit for clarity
2020-11-23 02:47:45 +00:00
bors
f32459c7ba Auto merge of #79172 - a1phyr:cold_abort, r=Mark-Simulacrum
Add #[cold] attribute to `std::process::abort` and `alloc::alloc::handle_alloc_error`
2020-11-23 02:25:13 +00:00
bors
32da90b431 Auto merge of #79319 - m-ou-se:rollup-d9n5viq, r=m-ou-se
Rollup of 10 pull requests

Successful merges:

 - #76941 (Add f{32,64}::is_subnormal)
 - #77697 (Split each iterator adapter and source into individual modules)
 - #78305 (Stabilize alloc::Layout const functions)
 - #78608 (Stabilize refcell_take)
 - #78793 (Clean up `StructuralEq` docs)
 - #79267 (BTreeMap: address namespace conflicts)
 - #79293 (Add test for eval order for a+=b)
 - #79295 (BTreeMap: fix minor testing mistakes in #78903)
 - #79297 (BTreeMap: swap the names of NodeRef::new and Root::new_leaf)
 - #79299 (Stabilise `then`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-22 23:59:48 +00:00
kadmin
a9915581d7 Change slice::to_vec to not use extend_from_slice
This also required adding a loop guard in case clone panics

Add specialization for copy

There is a better version for copy, so I've added specialization for that function
and hopefully that should speed it up even more.

Switch FromIter<slice::Iter> to use `to_vec`

Test different unrolling version for to_vec

Revert to impl

From benchmarking, it appears this version is faster
2020-11-22 22:22:03 +00:00
Mara Bos
d39e095331
Rollup merge of #79297 - ssomers:btree_post_redux, r=Mark-Simulacrum
BTreeMap: swap the names of NodeRef::new and Root::new_leaf

#78104 preserved the name of Root::new_leaf to minimize changes, but the resulting names are confusing.

r? `@Mark-Simulacrum`
2020-11-22 23:01:07 +01:00
Mara Bos
b54838f960
Rollup merge of #79295 - ssomers:btree_fix_78903, r=Mark-Simulacrum
BTreeMap: fix minor testing mistakes in #78903

Mostly a duplicate test case
r? `@Mark-Simulacrum`
2020-11-22 23:01:05 +01:00
Mara Bos
5793fa9cda
Rollup merge of #79267 - ssomers:btree_namespaces, r=Mark-Simulacrum
BTreeMap: address namespace conflicts

Fix an annoyance popping up whenever synchronizing the test cases with a version capable of miri-track-raw-pointers.

r? `@Mark-Simulacrum`
2020-11-22 23:01:02 +01:00
bors
a0d664bae6 Auto merge of #79219 - shepmaster:beta-bump, r=Mark-Simulacrum
Bump bootstrap compiler version

r? `@Mark-Simulacrum`

/cc `@pietroalbini`
2020-11-22 21:38:03 +00:00
Stein Somers
b04abc433e BTreeMap: swap the names of NodeRef::new and Root::new_leaf 2020-11-22 13:40:03 +01:00
Stein Somers
9186c073fc BTreeMap: fix minor testing mistakes in #78903 2020-11-22 13:37:39 +01:00
bors
20328b5323 Auto merge of #79275 - integer32llc:doc-style, r=jonas-schievink
More consistently use spaces after commas in lists in docs

This PR changes instances of lists that didn't use spaces after commas, like `vec![1,2,3]`, to `vec![1, 2, 3]` to be more consistent with idiomatic Rust style (the way these were looks strange to me, especially because there are often lists that *do* use spaces after the commas later in the same code block 😬).

I noticed one of these in an example in the stdlib docs and went looking for more, but as far as I can see, I'm only changing those spots in user-facing documentation or rustc output, and the changes make no semantic difference.
2020-11-22 08:30:23 +00:00
bors
a1a13b2bc4 Auto merge of #78461 - TimDiekmann:vec-alloc, r=Amanieu
Add support for custom allocators in `Vec`

This follows the [roadmap](https://github.com/rust-lang/wg-allocators/issues/7) of the allocator WG to add custom allocators to collections.

r? `@Amanieu`

This pull request requires a crater run.

### Prior work:
- #71873: Crater-test to solve rust-lang/wg-allocators#1
- [`alloc-wg`](https://github.com/TimDiekmann/alloc-wg)-crate
2020-11-21 22:46:50 +00:00
Carol (Nichols || Goulding)
ae17d7d455
More consistently use spaces after commas in lists in docs 2020-11-21 14:43:34 -05:00
Dylan DPC
6cd02a85f1
Rollup merge of #77844 - RalfJung:zst-box, r=nikomatsakis
clarify rules for ZST Boxes

LLVM's rules around `getelementptr inbounds` with offset 0 are a bit annoying, and as a consequence we have no choice but say that a `Box<()>` pointing to previously allocated memory that has since been freed is UB. Clarify the docs to reflect this.

This is based on conversations on the LLVM mailing list.
* Here's my initial mail: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130452.html
* The first email of the March part of that thread: https://lists.llvm.org/pipermail/llvm-dev/2019-March/130831.html
* First email of the April part: https://lists.llvm.org/pipermail/llvm-dev/2019-April/131693.html

The conclusion for me at least was that `getelementptr inbounds` with offset 0 is *not* the identity function, but can sometimes return `poison` even when the input is a regular pointer -- specifically, it returns `poison` when this pointer points into something that LLVM "knows has been deallocated", i.e., a former LLVM-managed allocation. It is however the identity function on pointers obtained by casting integers.

Note that there [are formal proposals](https://people.mpi-sws.org/~jung/twinsem/twinsem.pdf) for LLVM semantics where `getelementptr inbounds` with offset 0 isn't quite the identity function but never returns `poison` (it affects the provenance of the pointer but in a way that doesn't matter if this pointer is never used for memory accesses), and indeed this is likely necessary to consistently describe LLVM semantics. But with the informal LLVM LangRef that we have right now, and with LLVM devs insisting otherwise, it seems unwise to rely on this.
2020-11-21 19:44:07 +01:00
Stein Somers
0f005c2241 BTreeMap: address namespace conflicts 2020-11-21 16:07:24 +01:00
Ralf Jung
a7677f7714 reference NonNull::dangling 2020-11-20 11:09:49 +01:00
Jake Goulding
dcef5ff372 Bump bootstrap compiler version 2020-11-19 19:23:36 -05:00
Tim Diekmann
8725e4c337 Add support for custom allocators in Vec 2020-11-18 19:34:19 +01:00
Benoît du Garreau
b4c91f9a52 Add #[cold] to abort and handle_alloc_error 2020-11-18 18:15:03 +01:00
Stein Somers
9fca57ceb9 BTreeMap: reuse NodeRef as Root, keep BoxedNode for edges only, ban Unique 2020-11-18 10:07:42 +01:00
Mara Bos
70a4e433b1
Rollup merge of #79077 - RalfJung:llvm-magic, r=Mark-Simulacrum
document that __rust_alloc is also magic to our LLVM fork

Based on [comments](https://github.com/rust-lang/rust/pull/79045#discussion_r523442198) by ````@tmiasko```` and ````@bjorn3.````
2020-11-17 10:06:23 +01:00
Andreas Jonson
88d1f31a90 mark raw_vec::ptr with inline 2020-11-16 22:47:35 +01:00
Mara Bos
bac213bee4
Rollup merge of #78903 - ssomers:btree_order_chaos_testing, r=Mark-Simulacrum
BTreeMap: test chaotic ordering & other bits & bobs

r? `@Mark-Simulacrum`
2020-11-16 17:26:33 +01:00
Mara Bos
5bbf75da78
Rollup merge of #77691 - exrook:rename-layouterr, r=KodrAus
Rename/Deprecate LayoutErr in favor of LayoutError

Implements rust-lang/wg-allocators#73.

This patch renames LayoutErr to LayoutError, and uses a type alias to support users using the old name.

The new name will be instantly stable in release 1.49 (current nightly), the type alias will become deprecated in release 1.51 (so that when the current nightly is 1.51, 1.49 will be stable).

This is the only error type in `std` that ends in `Err` rather than `Error`, if this PR lands all stdlib error types will end in `Error` 🥰
2020-11-16 17:26:17 +01:00
bors
f5230fbf76 Auto merge of #78631 - ssomers:btree-alias_for_underfull, r=Mark-Simulacrum
BTreeMap: fix pointer provenance rules in underfullness

Continuing on #78480, and for readability, and possibly for performance: avoid aliasing when handling underfull nodes, and consolidate the code doing that. In particular:
- Avoid the rather explicit aliasing for internal nodes in `remove_kv_tracking`.
- Climb down to the root to handle underfull nodes using a reborrowed handle, rather than one copied with `ptr::read`, before resuming on the leaf level.
- Integrate the code tracking leaf edge position into the functions performing changes, rather than bolting it on.

r? `@Mark-Simulacrum`
2020-11-16 03:22:10 +00:00
Ralf Jung
af869c2f8d document that __rust_alloc is also magic to our LLVM fork 2020-11-15 18:40:49 +01:00
bors
5fab31e5dd Auto merge of #79070 - jonas-schievink:rollup-wacn2b8, r=jonas-schievink
Rollup of 13 pull requests

Successful merges:

 - #77802 (Allow making `RUSTC_BOOTSTRAP` conditional on the crate name)
 - #79004 (Add `--color` support to bootstrap)
 - #79005 (cleanup: Remove `ParseSess::injected_crate_name`)
 - #79016 (Make `_` an expression, to discard values in destructuring assignments)
 - #79019 (astconv: extract closures into a separate trait)
 - #79026 (Implement BTreeMap::retain and BTreeSet::retain)
 - #79031 (Validate that locals have a corresponding `LocalDecl`)
 - #79034 (rustc_resolve: Make `macro_rules` scope chain compression lazy)
 - #79036 (Move Steal to rustc_data_structures.)
 - #79041 (Rename clean::{ItemEnum -> ItemKind}, clean::Item::{inner -> kind})
 - #79058 (Move likely/unlikely argument outside of invisible unsafe block)
 - #79059 (Print 'checking cranelift artifacts' to easily separate it from other artifacts)
 - #79063 (Update rustfmt to v1.4.26)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-15 13:19:05 +00:00
Jonas Schievink
aa685e2024
Rollup merge of #79026 - mbrubeck:btree_retain, r=m-ou-se
Implement BTreeMap::retain and BTreeSet::retain

Adds new methods `BTreeMap::retain` and `BTreeSet::retain`.  These are implemented on top of `drain_filter` (#70530).

The API of these methods is identical to `HashMap::retain` and `HashSet::retain`, which were implemented in #39560 and stabilized in #36648.  The docs and tests are also copied from HashMap/HashSet.

The new methods are unstable, behind the `btree_retain` feature gate, with tracking issue #79025.  See also rust-lang/rfcs#1338.
2020-11-15 13:39:54 +01:00
Spyros Roum
161300d41e stabilize deque_range 2020-11-15 13:30:35 +02:00
bors
0468845924 Auto merge of #78472 - hermitcore:builtins, r=Mark-Simulacrum
add options to use optimized and mangled compiler builtins

In principle the compiler builtin features are also offered to alloc and std.
2020-11-15 10:37:11 +00:00
Stefan Lankes
6de51252e0
add options to use optimized and mangled compiler builtins 2020-11-15 08:23:31 +01:00
Matt Brubeck
bf6902ca61 Add BTreeMap::retain and BTreeSet::retain 2020-11-13 10:23:50 -08:00
C
75dfc711da refactor: vec_deque ignore-tidy-filelength
commit c547d5fabcd756515afa7263ee5304965bb4c497
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 11:22:23 2020 +0000

    test: updating ui/hygiene/panic-location.rs expected

commit 2af03769c4ffdbbbad75197a1ad0df8c599186be
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 10:43:30 2020 +0000

    fix: documentation unresolved link

commit c4b0df361ce27d7392d8016229f2e0265af32086
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:58:31 2020 +0000

    style: compiling with Rust's style guidelines

commit bdd2de5f3c09b49a18e3293f2457fcab25557c96
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:56:31 2020 +0000

    refactor: removing ignore-tidy-filelength

commit fcc4b3bc41f57244c65ebb8e4efe4cbc9460b5a9
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:51:35 2020 +0000

    refactor: moving trait RingSlices to ring_slices.rs

commit 2f0cc539c06d8841baf7f675168f68ca7c21e68e
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:46:09 2020 +0000

    refactor: moving struct PairSlices to pair_slices.rs

commit a55d3ef1dab4c3d85962b3a601ff8d1f7497faf2
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:31:45 2020 +0000

    refactor: moving struct Iter to iter.rs

commit 76ab33a12442a03726f36f606b4e0fe70f8f246b
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:24:32 2020 +0000

    refactor: moving struct IntoIter into into_iter.rs

commit abe0d9eea2933881858c3b1bc09df67cedc5ada5
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:19:07 2020 +0000

    refactor: moving struct IterMut into iter_mut.rs

commit 70ebd6420335e1895e2afa2763a0148897963e24
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 01:49:15 2020 +0000

    refactor: moved macros into macros.rs

commit b08dd2add994b04ae851aa065800bd8bd6326134
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 01:05:36 2020 +0000

    refactor: moving vec_deque.rs to vec_deque/mod.rs
2020-11-13 17:56:39 +00:00
Mara Bos
40889819ee
Rollup merge of #78857 - SkiFire13:bheap-opt, r=KodrAus
Improve BinaryHeap performance

By changing the condition in the loops from `child < end` to `child < end - 1` we're guaranteed that `right = child + 1 < end` and since finding the index of the biggest sibling can be done with an arithmetic operation we can remove a branch from the loop body. The case where there's no right child, i.e. `child == end - 1` is instead handled outside the loop, after it ends; note that if the loops ends early we can use `return` instead of `break` since the check `child == end - 1` will surely fail.

I've also removed a call to `<[T]>::swap` that was hiding a bound check that [wasn't being optimized by LLVM](https://godbolt.org/z/zrhdGM).

A quick benchmarks on my pc shows that the gains are pretty significant:

|name                 |before ns/iter  |after ns/iter  |diff ns/iter  |diff %    |speedup |
|---------------------|----------------|---------------|--------------|----------|--------|
|find_smallest_1000   | 352,565        | 260,098       |     -92,467  | -26.23%  | x 1.36 |
|from_vec             | 676,795        | 473,934       |    -202,861  | -29.97%  | x 1.43 |
|into_sorted_vec      | 469,511        | 304,275       |    -165,236  | -35.19%  | x 1.54 |
|pop                  | 483,198        | 373,778       |    -109,420  | -22.64%  | x 1.29 |

The other 2 benchmarks for `BinaryHeap` (`peek_mut_deref_mut` and `push`) weren't impacted and as such didn't show any significant change.
2020-11-12 19:46:11 +01:00
Stein Somers
8972bcb0dd BTreeMap: test chaotic ordering & other bits & bobs 2020-11-12 16:18:30 +01:00
Stein Somers
4cfa5bddf1 BTreeMap: avoid aliasing while handling underfull nodes 2020-11-12 10:09:59 +01:00
Jonas Schievink
56e0806a1a
Rollup merge of #78417 - ssomers:btree_chop_up_2, r=Mark-Simulacrum
BTreeMap: split off most code of append

To complete #78056, move the last single-purpose pieces of code out of map.rs into a separate module. Also, tweaked documentation and safeness - I doubt think this code would be safe if the iterators passed in wouldn't be as sorted as the method says they should be - and bounds on MergeIterInner.

r? ```@Mark-Simulacrum```
2020-11-11 20:59:00 +01:00
Jonas Schievink
e15fee9fe4
Rollup merge of #78854 - the8472:workaround-normalization-regression-master, r=Mark-Simulacrum
Workaround for "could not fully normalize" ICE

Workaround for "could not fully normalize" ICE (#78139) by removing the `needs_drop::<T>()` calls triggering it.
Corresponding beta PR: #78845

Fixes #78139 -- the underlying bug is likely not fixed but we don't have another test case isolated for now, so closing.
2020-11-10 14:45:19 +01:00
Giacomo Stevanato
387568cd56 Added SAFETY comment as request 2020-11-09 22:34:31 +01:00
Stein Somers
7ca6e8f767 BTreeMap: fix pointer provenance rules, make borrowing explicit 2020-11-09 09:13:50 +01:00
Dylan DPC
5639d9793f
Rollup merge of #78476 - RalfJung:btree-alias, r=Mark-Simulacrum
fix some incorrect aliasing in the BTree

This line is wrong:
```
ptr::copy(slice.as_ptr().add(idx), slice.as_mut_ptr().add(idx + 1), slice.len() - idx);
```
When `slice.as_mut_ptr()` is called, that creates a mutable reference to the entire slice, which invalidates the raw pointer previously returned by `slice.as_ptr()`. (Miri currently misses this because raw pointers are not tracked properly.)

Cc ````````@ssomers````````
2020-11-09 01:13:40 +01:00
Dylan DPC
4e5b7add7f
Rollup merge of #78437 - ssomers:btree_no_ord_at_node_level, r=Mark-Simulacrum
BTreeMap: stop mistaking node for an orderly place

A second mistake in #77612 was to ignore the node module's rightful comment "this module doesn't care whether the entries are sorted". And there's a much simpler way to visit the keys in order, if you check this separately from a single pass checking everything.

r? ````````@Mark-Simulacrum````````
2020-11-09 01:13:38 +01:00
Stein Somers
685fd53ada BTreeMap: split off most code of append, slightly improve interfaces 2020-11-08 18:58:46 +01:00
Mara Bos
96975e515a
Rollup merge of #78852 - camelid:intra-doc-bonanza, r=jyn514
Convert a bunch of intra-doc links

An intra-doc link bonanza!

This was accomplished using a bunch of trial-and-error with sed.
2020-11-08 13:36:28 +01:00
Mara Bos
1f034f77bc
Rollup merge of #76097 - pickfire:stabilize-spin-loop, r=KodrAus
Stabilize hint::spin_loop

Partially fix #55002, deprecate in another release

r? ``````@KodrAus``````
2020-11-08 13:35:54 +01:00
Giacomo Stevanato
8d1575365d Remove useless bound checks from into_sorted_vec 2020-11-07 22:20:26 +01:00
Giacomo Stevanato
25b3f61c38 Remove useless branches from sift_down_range loop 2020-11-07 22:20:26 +01:00
Giacomo Stevanato
6dfcf9afde Remove branches from sift_down_to_bottom loop 2020-11-07 22:20:26 +01:00
Camelid
8258cf285f Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
The8472
8c7046e675 remove needs_drop 2020-11-07 21:40:55 +01:00
Yuki Okushi
162f400328
Rollup merge of #78538 - ssomers:btree_testing_rng, r=Mark-Simulacrum
BTreeMap: document a curious assumption in test cases

r? ```@Mark-Simulacrum```
2020-11-07 01:02:09 +09:00
Ivan Tham
e8b5be5dff Stabilize hint::spin_loop
Partially fix #55002, deprecate in another release

Co-authored-by: Ashley Mannix <kodraus@hey.com>

Update stable version for stabilize_spin_loop

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Use better example for spinlock

As suggested by KodrAus

Remove renamed_spin_loop already available in master

Fix spin loop example
2020-11-06 23:41:55 +08:00
Mara Bos
55f4b802fb
Rollup merge of #76718 - poliorcetics:vec-ui-to-unit-test, r=jyn514
Move Vec UI tests to unit tests when possible

Helps with #76268.

I'm moving the tests using `Vec` or `VecDeque`.

````@rustbot```` modify labels: A-testsuite C-cleanup T-libs
2020-11-05 10:29:35 +01:00
Mara Bos
8ed31d2782
Rollup merge of #78602 - RalfJung:raw-ptr-aliasing-issues, r=m-ou-se
fix various aliasing issues in the standard library

This fixes various cases where the standard library either used raw pointers after they were already invalidated by using the original reference again, or created raw pointers for one element of a slice and used it to access neighboring elements.
2020-11-01 11:53:36 +01:00
Mara Bos
25eac92987
Rollup merge of #78596 - pavlukivan:master, r=m-ou-se
Fix doc links to std::fmt

`std::format` and `core::write` macros' docs linked to `core::fmt` for format string reference, even though only `std::fmt` has format string documentation (and the link titles were `std::fmt`)
2020-11-01 11:53:33 +01:00
Ralf Jung
607076e209 fix aliasing issue in binary_heap 2020-10-31 16:26:06 +01:00
Ivan Pavluk
3baf6a4a74 Fix doc links to std::fmt
std::format and core::write macros' docs linked to core::fmt for format string reference, even though only std::fmt has format string documentation and the link titles were std::fmt.
2020-10-31 18:02:55 +07:00
Benoît du Garreau
307cc11beb Constantify more BTreeMap and BTreeSet functions
- BTreeMap::len
- BTreeMap::is_empty
- BTreeSet::len
- BTreeSet::is_empty
2020-10-30 19:24:08 +01:00
Yuki Okushi
0723b274d2
Rollup merge of #77334 - pickfire:patch-4, r=jyn514
Reorder benches const variable

Move LEN so it is is read in order.
2020-10-30 18:00:41 +09:00
Stein Somers
be01d54f07 BTreeMap: document a curious assumption in test cases 2020-10-29 20:51:39 +01:00
Jonas Schievink
48c4afbf9c
Rollup merge of #78499 - SkiFire13:fix-string-retain, r=m-ou-se
Prevent String::retain from creating non-utf8 strings when abusing panic

Fixes #78498

The idea is the same as `Vec::drain`, set the len to 0 so that nobody can observe the broken invariant if it escapes the function (in this case if `f` panics)
2020-10-29 17:05:28 +01:00
Jonas Schievink
a384a5866b
Rollup merge of #76138 - camelid:rc-fully-qualified-syntax, r=steveklabnik
Explain fully qualified syntax for `Rc` and `Arc`

Also cleaned up some other small things.

@rustbot modify labels: T-doc
2020-10-29 17:05:08 +01:00
bors
a53fb30e3b Auto merge of #78446 - RalfJung:box, r=Amanieu
fix Box::into_unique

https://github.com/rust-lang/rust/pull/77187/ broke Stacked Borrows pointer tagging around `Box::into_unique` (this is caused by `Box` being a special case in the type system, which box-internal code needs to account for). This PR fixes that.

r? `@Amanieu` Cc `@TimDiekmann`

Fixes https://github.com/rust-lang/rust/issues/78419.
2020-10-29 12:08:16 +00:00
Giacomo Stevanato
1f6f917f73 Added test for issue #78498 2020-10-29 12:25:02 +01:00
Giacomo Stevanato
e83666f45e Prevent String::retain from creating non-utf8 strings when abusing panic 2020-10-29 11:58:12 +01:00
Camelid
4e30e10f25 Don't say you "should" use fully qualified syntax
That recommendation was removed last year; there isn't a particular
style that is officially recommended anymore.
2020-10-28 16:49:30 -07:00
Camelid
e0eed3c558 Fix broken intra-doc link 2020-10-28 16:31:45 -07:00
Camelid
bd7cbaecd3 Explain fully qualified syntax for Rc and Arc 2020-10-28 16:31:44 -07:00
Ralf Jung
b0df3f76dc fix some incorrect aliasing in the BTree 2020-10-28 11:08:21 +01:00
Santiago Pastorino
708fc3b1a2
Add unsized_fn_params feature 2020-10-27 14:45:02 -03:00
Ralf Jung
ab374dc37c fix Box::into_unique 2020-10-27 17:02:42 +01:00
Stein Somers
e099138eb6 BTreeMap: stop mistaking node for an orderly place 2020-10-27 11:19:02 +01:00
bors
c9b606ed67 Auto merge of #78359 - ssomers:btree_cleanup_mem, r=Mark-Simulacrum
BTreeMap: move generic support functions out of navigate.rs

A preparatory step chipped off #78104, useful in general (if at all).

r? `@Mark-Simulacrum`
2020-10-27 04:01:52 +00:00
Yuki Okushi
727e93dc74
Rollup merge of #78347 - Rustin-Liu:rustin-patch-doc, r=kennytm
Add lexicographical comparison doc

close https://github.com/rust-lang/rust/issues/72255
2020-10-27 08:45:01 +09:00
bors
fd542592f0 Auto merge of #77187 - TimDiekmann:box-alloc, r=Amanieu
Support custom allocators in `Box`

r? `@Amanieu`

This pull request requires a crater run.

### Prior work:
- #71873
- #58457
- [`alloc-wg`](https://github.com/TimDiekmann/alloc-wg)-crate

Currently blocked on:
- ~#77118~
- ~https://github.com/rust-lang/chalk/issues/615 (#77515)~
2020-10-26 21:16:33 +00:00
Rustin-Liu
42844ed2cf Add lexicographical comparison doc
Add links

Fix typo

Use `sequence`

Fix typo

Fix broken link

Fix broken link

Fix broken link

Fix broken links

Fix broken links
2020-10-26 22:39:43 +08:00
Stein Somers
0da7941e1c BTreeMap: move generic functions out of navigate.rs 2020-10-26 09:31:36 +01:00
bors
b6ac411f45 Auto merge of #78015 - ssomers:btree_merge_mergers, r=Mark-Simulacrum
btree: merge the implementations of MergeIter

Also remove the gratuitous Copy bounds. Same benchmark performance.

r? `@Mark-Simulacrum`
2020-10-25 22:29:02 +00:00
Tim Diekmann
06e4497a04 Merge remote-tracking branch 'upstream/master' into box-alloc 2020-10-25 16:32:28 +01:00
Yuki Okushi
9085656512
Rollup merge of #78322 - ssomers:btree_no_min_len_at_node_level, r=Mark-Simulacrum
BTreeMap: stop mistaking node::MIN_LEN for a node level constraint

Correcting #77612 that fell into the trap of assuming that node::MIN_LEN is an imposed minimum everywhere, and trying to make it much more clear it is an offered minimum at the node level.

r? @Mark-Simulacrum
2020-10-25 18:43:47 +09:00
Yuki Okushi
72e02b015e
Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obk
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s

`#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks.
While it was originally only meant to be used only on macros, its use was expanded to `const fn`s.

This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s.

This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540).

Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'.

Closes rust-lang/rust#69399

r? @oli-obk
2020-10-25 18:43:40 +09:00
Jonas Schievink
e34263d86a
Rollup merge of #77610 - hermitcore:dtors, r=m-ou-se
revise Hermit's mutex interface to support the behaviour of StaticMutex

rust-lang/rust#77147 simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. To support the new behavior of StaticMutex, we move part of the mutex implementation into libstd.

The interface to the OS changed. Consequently, I removed a few functions, which aren't longer needed.
2020-10-24 22:39:44 +02:00
Stein Somers
3b6c4fe465 BTreeMap: stop mistaking node::MIN_LEN as a node level constraint 2020-10-24 15:24:37 +02:00
Jonas Schievink
d9acd7d148
Rollup merge of #78109 - cuviper:exhausted-rangeinc, r=dtolnay
Check for exhaustion in RangeInclusive::contains and slicing

When a range has finished iteration, `is_empty` returns true, so it
should also be the case that `contains` returns false.

Fixes #77941.
2020-10-24 14:12:01 +02:00
Tim Diekmann
693a2bf18b Rename Box::alloc to Box::alloc_ref 2020-10-23 22:45:15 +02:00
Nicolas Nattis
929f80ece9 Add a spin loop hint for Arc::downgrade 2020-10-23 16:10:56 -03:00
Yuki Okushi
dfb0d09bae
Rollup merge of #78163 - camelid:fixup-lib-docs, r=m-ou-se
Clean up lib docs

Cherry-picked out of #78094.
2020-10-23 18:26:33 +09:00
Yuki Okushi
39f8289e38
Rollup merge of #77969 - ryan-scott-dev:bigo-notation-consistency, r=m-ou-se
Doc formating consistency between slice sort and sort_unstable, and big O notation consistency

Updated documentation for slice sorting methods to be consistent between stable and unstable versions, which just ended up being minor formatting differences.

I also went through and updated any doc comments with big O notation to be consistent with #74010 by italicizing them rather than having them in a code block.
2020-10-23 18:26:26 +09:00
Camelid
13bc087a73 Clean up lib docs 2020-10-22 10:36:35 -07:00
Stein Somers
2c5f64f683 BTreeMap/Set: merge the implementations of MergeIter 2020-10-22 09:39:24 +02:00
Florian Warzecha
05f4a9a42a
switch allow_internal_unstable const fns to rustc_allow_const_fn_unstable 2020-10-21 20:54:20 +02:00
Yuki Okushi
f8bae8b102
Rollup merge of #78056 - ssomers:btree_chop_up_1, r=dtolnay
BTreeMap: split off most code of remove and split_off

Putting map.rs on a diet, in addition to #77851.
r? @dtolnay
2020-10-21 13:59:37 +09:00
Josh Stone
9202fbdbdb Check for exhaustion in SliceIndex for RangeInclusive 2020-10-20 17:18:08 -07:00
Stein Somers
76c466a18f BTreeMap: less sharing, more similarity between leaf and internal nodes 2020-10-20 15:13:57 +02:00
Stein Somers
7829e18899 BTreeMap: reuse BoxedNode instances directly instead of their contents 2020-10-20 13:58:11 +02:00
Yuki Okushi
c5b0a88669
Rollup merge of #77612 - ssomers:btree_cleanup_2, r=Mark-Simulacrum
BTreeMap: test invariants more thoroughly and more readably

r? @Mark-Simulacrum
2020-10-20 12:10:52 +09:00
Stein Somers
488b999fc2 BTreeMap: test invariants more thoroughly and more readably 2020-10-19 11:36:39 +02:00
Chai T. Rex
c2de8fe294 Stabilize or_insert_with_key 2020-10-18 15:45:09 -04:00
bors
187b8771dc Auto merge of #76885 - dylni:move-slice-check-range-to-range-bounds, r=KodrAus
Move `slice::check_range` to `RangeBounds`

Since this method doesn't take a slice anymore (#76662), it makes more sense to define it on `RangeBounds`.

Questions:
- Should the new method be `assert_len` or `assert_length`?
2020-10-18 18:50:43 +00:00
Stein Somers
003516f91a BTreeMap: split off most code of remove and split_off 2020-10-18 13:13:23 +02:00
Yuki Okushi
a0242e73bb
Rollup merge of #77851 - exrook:split-btreemap, r=dtolnay
BTreeMap: refactor Entry out of map.rs into its own file

btree/map.rs is approaching the 3000 line mark, splitting out the entry
code buys about 500 lines of headroom.

I've created this PR because the changes I've made in #77438 will push `map.rs` over the 3000 line limit and cause tidy to complain.

I picked `Entry` to factor out because it feels less tightly coupled to the rest of `BTreeMap` than the various iterator implementations.

Related: #60302
2020-10-18 04:11:07 +09:00
Alexis Bourget
1bdee96c5e Move subslice pattern tests to alloc/tests/slice.rs 2020-10-17 18:48:20 +02:00
Alexis Bourget
42271a537a Move vec swap test 2020-10-17 18:48:20 +02:00
Alexis Bourget
4fd06b9bb5 Move vec-macro-repeat test 2020-10-17 18:48:20 +02:00
Alexis Bourget
85afbd8a15 Rebase conflicts 2020-10-17 18:47:58 +02:00
Alexis Bourget
4af560ecef Move zero-sized-vec-push test 2020-10-17 18:42:14 +02:00
Dylan DPC
16b878fd0f
Rollup merge of #77932 - ssomers:btree_cleanup_gdb, r=Mark-Simulacrum
BTreeMap: improve gdb introspection of BTreeMap with ZST keys or values

I accidentally pushed an earlier revision in #77788: it changes the index of tuples for BTreeSet from ""[{}]".format(i) to "key{}".format(i). Which doesn't seem to make the slightest difference on my linux box nor on CI. In fact, gdb doesn't make any distinction between "key{}" and "val{}" for a BTreeMap either, leading to confusing output if you test more. But easy to improve.

r? @Mark-Simulacrum
2020-10-17 03:27:18 +02:00
Dylan DPC
f40ecff964
Rollup merge of #77751 - vojtechkral:vecdeque-binary-search, r=scottmcm,dtolnay
liballoc: VecDeque: Add binary search functions

I am submitting rust-lang/rfcs#2997 as a PR as suggested by @scottmcm

I haven't yet created a tracking issue - if there's a favorable feedback I'll create one and update the issue links in the unstable attribs.
2020-10-17 03:27:15 +02:00
bors
f1b97ee7f8 Auto merge of #77997 - fusion-engineering-forks:to-string-no-shrink, r=joshtriplett
Remove shrink_to_fit from default ToString::to_string implementation.

As suggested by `@scottmcm` on Zulip. shrink_to_fit() seems like the wrong thing to do here in most use cases of to_string(). Would be intereseting to see if it makes any difference in a timer run.

r? `@joshtriplett`
2020-10-16 22:53:50 +00:00
Vojtech Kral
c7a787a327 liballoc: VecDeque: Simplify binary_search_by() 2020-10-16 20:49:19 +02:00
Vojtech Kral
e0506d1e9a liballoc: VecDeque: Add tracking issue for binary search fns 2020-10-16 18:17:55 +02:00
bors
8850893d96 Auto merge of #77850 - kornelski:resizedefault, r=dtolnay
Remove deprecated unstable Vec::resize_default

It's [been deprecated](https://github.com/rust-lang/rust/pull/57656) for 15 releases.
2020-10-16 12:11:32 +00:00
Mara Bos
0b062887db Remove shrink_to_fit from default ToString::to_string implementation.
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
2020-10-16 11:15:12 +02:00
Tim Diekmann
955b37b305
Merge branch 'master' into box-alloc 2020-10-16 08:54:38 +02:00
Dylan DPC
b64b5fac40
Rollup merge of #77935 - ssomers:btree_cleanup_1, r=Mark-Simulacrum
BTreeMap: make PartialCmp/PartialEq explicit and tested

Follow-up on a topic raised in #77612

r? @Mark-Simulacrum
2020-10-16 02:10:24 +02:00
strct
8d8554d234
Fix typo in documentation 2020-10-15 16:57:19 +02:00
Ryan Scott
8446d949f1 Following #74010 by converting some newer cases of backticked O notations to be italicized 2020-10-15 23:21:26 +11:00
Ryan Scott
000ec5e2f8 Made slice sort documentation consistent between stable and unstable versions 2020-10-15 23:21:14 +11:00
Stein Somers
a22cd05965 BTreeMap: making PartialCmp/PartialEq explicit and tested 2020-10-14 14:57:24 +02:00
Stein Somers
28af355b9f BTreeMap: improve gdb introspection of BTreeMap with ZST keys or values 2020-10-14 13:03:23 +02:00
Dylan DPC
ed34f82cbc
Rollup merge of #77870 - camelid:intra-doc-super, r=jyn514
Use intra-doc links for links to module-level docs

r? @jyn514
2020-10-14 02:30:46 +02:00
Yuki Okushi
6a596210a6
Rollup merge of #77569 - ssomers:btree_cleanup_1, r=Mark-Simulacrum
BTreeMap: type-specific variants of node_as_mut and cast_unchecked

Improves debug checking and shortens some expressions. Extracted from #77408
2020-10-14 06:02:17 +09:00
Stefan Lankes
77d98316f4
minor changes to pass the format check 2020-10-13 12:22:18 +02:00
Stefan Lankes
bc6b2ac449
move __rg_oom to the libos to avoid duplicated symbols 2020-10-13 12:06:48 +02:00
Ralf Jung
0f572a9810 explicitly talk about integer literals 2020-10-13 09:30:09 +02:00
Camelid
95221b4eb5 Use intra-doc links for links to module-level docs 2020-10-12 19:22:47 -07:00
Jacob Hughes
4b96049da2 BTreeMap: refactor Entry out of map.rs into its own file
btree/map.rs is approaching the 3000 line mark, splitting out the entry
code buys about 500 lines of headroom
2020-10-12 08:44:53 -04:00
Kornel
07637db883 Remove deprecated unstable Vec::resize_default 2020-10-12 13:36:19 +01:00
Ralf Jung
c555aabc5b clarify rules for ZST Boxes 2020-10-12 10:32:11 +02:00
Yuki Okushi
b6b6bc0a61
Rollup merge of #77738 - RalfJung:alloc-error-handler-comment, r=Amanieu
fix __rust_alloc_error_handler comment

`__rust_alloc_error_handler` was added in the same `extern` block as the allocator functions, but the comment there was not actually correct for `__rust_alloc_error_handler`. So move it down to the rest of the default allocator handling with a fixed comment. At least the comment reflects my understanding of what happens, please check carefully. :)

r? @Amanieu Cc @haraldh
2020-10-11 03:19:10 +09:00
Yuki Okushi
45e35745d3
Rollup merge of #77709 - pickfire:patch-1, r=jyn514
Link Vec leak doc to Box
2020-10-11 03:19:09 +09:00
Ivan Tham
8688fa8250
Improve vec leak wording
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-10-10 22:17:48 +08:00
Ivan Tham
66369a6c70
Alloc vec doc mention cannot undo leak 2020-10-10 22:12:28 +08:00
Vojtech Kral
36d9b72354 liballoc: VecDeque: Add binary search functions 2020-10-09 19:59:35 +02:00
Ralf Jung
b6bedc80c9 rename __default_lib_allocator -> __default_alloc_error_handler 2020-10-09 11:39:28 +02:00
Ralf Jung
1911d21866 also extend global allocator comment 2020-10-09 11:36:20 +02:00
Ralf Jung
6cd9b88a25 fix __rust_alloc_error_handler comment 2020-10-09 11:36:13 +02:00
Jonas Schievink
738a41b363
Rollup merge of #77449 - ssomers:btree_drain_filter_size_hint, r=Mark-Simulacrum
BTreeMap: comment why drain_filter's size_hint is somewhat pessimistic

The `size_hint` of the `DrainFilter` iterator doesn't adjust as you iterate. This hardly seems important to me, but there has been a comparable PR #64383 in the past. I guess a scenario is that you first iterate half the map manually and keep most of the key/value pairs in the map, and then tell the predicate to drain most of the key/value pairs and `.collect` the iterator over the remaining half of the map.

I am totally ambivalent whether this is better or not.

r? @Mark-Simulacrum
2020-10-08 23:23:08 +02:00
Ivan Tham
176b96516f
Link Vec leak doc to Box 2020-10-08 23:39:31 +08:00
Jacob Hughes
bf0adc3c36 Rename LayoutErr to LayoutError outside of core 2020-10-08 00:40:10 -04:00
bors
5779815f89 Auto merge of #74194 - mbrubeck:slice-eq, r=sfackler
Add PartialEq impls for Vec <-> slice

This is a follow-up to #71660 and rust-lang/rfcs#2917 to add two more missing vec/slice PartialEq impls:

```
impl<A, B> PartialEq<[B]> for Vec<A> where A: PartialEq<B> { .. }
impl<A, B> PartialEq<Vec<B>> for [A] where A: PartialEq<B> { .. }
```

Since this is insta-stable, it should go through the `@rust-lang/libs` FCP process.  Note that I used version 1.47.0 for the `stable` attribute because I assume this will not merge before the 1.46.0 branch is cut next week.
2020-10-07 01:20:11 +00:00
Tim Diekmann
f288cd2e17 Support custom allocators in Box
Remove `Box::leak_with_alloc`


Add leak-test for box with allocator


Rename `AllocErr` to `AllocError` in leak-test


Add `Box::alloc` and adjust examples to use the new API
2020-10-07 03:07:02 +02:00
Ralf Jung
fa6a4f7d37 avoid unnecessary intermediate reference and improve safety comments 2020-10-06 10:54:43 +02:00
Stein Somers
97beb074af BTreeMap: derive type-specific variants of node_as_mut and cast_unchecked 2020-10-05 13:23:38 +02:00
Ralf Jung
69669cbdb2 make IterMut Send/Sync again 2020-10-05 09:12:56 +02:00
Ralf Jung
e4c1a3867f VecDeque: avoid more aliasing issues by working with raw pointers instead of references 2020-10-05 09:12:56 +02:00
Ralf Jung
f251dc446f VecDeque: fix incorrect &mut aliasing in IterMut::next/next_back 2020-10-05 09:12:54 +02:00
Dylan DPC
9dbc9ed870
Rollup merge of #77514 - scottmcm:less-once-chain-once, r=estebank
Replace some once(x).chain(once(y)) with [x, y] IntoIter

Now that we have by-value array iterators that are [already used](25c8c53dd9/compiler/rustc_hir/src/def.rs (L305-L307))...

For example,
```diff
-        once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it)
+        IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
```
2020-10-05 02:29:42 +02:00
Dylan DPC
23b1e3d772
Rollup merge of #77471 - ssomers:btree_cleanup_3, r=Mark-Simulacrum
BTreeMap: refactoring around edges, missed spots

Tweaks from #77244 (and more) that are really inconsistencies in #77005.

r? @Mark-Simulacrum
2020-10-05 02:29:38 +02:00
Dylan DPC
fe087ece94
Rollup merge of #77395 - ssomers:btree_love_the_leaf_edge_comments, r=Mark-Simulacrum
BTreeMap: admit the existence of leaf edges in comments

The btree code is ambiguous about leaf edges (i.e., edges within leaf nodes). Iteration relies on them heavily, but some of the comments suggest there are no leaf edges (extracted from #77025)

r? @Mark-Simulacrum
2020-10-05 02:29:31 +02:00
Jonas Schievink
80953177ed
Rollup merge of #77445 - ssomers:btree_cleanup_7, r=Mark-Simulacrum
BTreeMap: complete the compile-time test_variance test case

Some of the items added to the new `test_sync` belonged in the old `test_variance` as well. And fixed inconsistent paths to nearby modules.
r? @Mark-Simulacrum
2020-10-04 15:45:41 +02:00
bors
0d37dca25a Auto merge of #76448 - haraldh:default_alloc_error_handler_reduced, r=Amanieu
Implement Make `handle_alloc_error` default to panic (for no_std + liballoc)

Related: https://github.com/rust-lang/rust/issues/66741

Guarded with `#![feature(default_alloc_error_handler)]` a default
`alloc_error_handler` is called, if a custom allocator is used and no
other custom `#[alloc_error_handler]` is defined.
2020-10-04 08:56:05 +00:00
Yuki Okushi
25d0650d0f
Rollup merge of #77447 - ssomers:btree_cleanup_8, r=Mark-Simulacrum
BTreeMap: document DrainFilterInner better

r? @Mark-Simulacrum
2020-10-04 11:45:04 +09:00
Scott McMurray
d74b8e0505 Replace some once(x).chain(once(y)) with [x, y] IntoIter
Now that we have by-value array iterators...
2020-10-03 16:51:43 -07:00
Stein Somers
a58089e097 BTreeMap/Set: complete the compile-time test cases 2020-10-04 01:04:29 +02:00
Stein Somers
3b051d0171 BTreeMap: comment why drain_filter's size_hint is somewhat pessimistictid 2020-10-03 21:18:18 +02:00
bors
738d4a7a36 Auto merge of #74160 - CAD97:weak-as-unsized-ptr, r=RalfJung
Allow Weak::as_ptr and friends for unsized T

Relaxes `impl<T> Weak<T>` to `impl<T: ?Sized> Weak<T>` for the methods `rc::Weak::as_ptr`, `into_raw`, and `from_raw`.

Follow-up to #73845, which did most of the impl work to make these functions work for `T: ?Sized`.

We still have to adjust the implementation of `Weak::from_raw` here, however, because I missed a use of `ptr.is_null()` previously. This check was necessary when `into`/`from_raw` were first implemented, as `into_raw` returned `ptr::null()` for dangling weak. However, we now just (wrapping) offset dangling weaks' pointers the same as nondangling weak, so the null check is no longer necessary (or even hit). (I can submit just 17a928f as a separate PR if desired.)

As a nice side effect, moves the `fn is_dangling` definition closer to `Weak::new`, which creates the dangling weak.

This technically stabilizes that "something like `align_of_val_raw`" is possible to do. However, I believe the part of the functionality required by these methods here -- specifically, getting the alignment of a pointee from a pointer where it may be dangling iff the pointee is `Sized` -- is uncontroversial enough to stabilize these methods without a way to implement them on stable Rust.

r? `@RalfJung,` who reviewed #73845.

ATTN: This changes (relaxes) the (input) generic bounds on stable fn!
2020-10-03 14:18:26 +00:00
Ralf Jung
e27ef130c1
grammar nit 2020-10-03 12:15:26 +02:00
Stein Somers
d71d13e82d BTreeMap: refactoring around edges, missed spots 2020-10-03 01:06:55 +02:00
Jonas Schievink
1118ab9930
Rollup merge of #75377 - canova:map_debug_impl, r=dtolnay
Fix Debug implementations of some of the HashMap and BTreeMap iterator types

HashMap's `ValuesMut`, BTreeMaps `ValuesMut`, IntoValues and `IntoKeys` structs were printing both keys and values on their Debug implementations. But they are iterators over either keys or values. Irrelevant values should not be visible. With this PR, they only show relevant fields.
This fixes #75297.

[Here's an example code.](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0c79356ed860e347a0c1a205616f93b7) This prints this on nightly:
```
ValuesMut { inner: IterMut { range: [(1, "hello"), (2, "goodbye")], length: 2 } }
IntoKeys { inner: [(1, "hello"), (2, "goodbye")] }
IntoValues { inner: [(1, "hello"), (2, "goodbye")] }
[(2, "goodbye"), (1, "hello")]
```

After the patch this example prints these instead:
```
["hello", "goodbye"]
["hello", "goodbye"]
[1, 2]
["hello", "goodbye"]
```

I didn't add test cases for them, since I couldn't see any tests for Debug implementations anywhere. But please let me know if I should add it to a specific place.

r? @dtolnay
2020-10-03 00:31:04 +02:00
Stein Somers
90c8b43bc3 BTreeMap: document DrainFilterInner better 2020-10-02 13:13:28 +02:00
Harald Hoyer
cadd12b5f0 Implement Make handle_alloc_error default to panic (for no_std + liballoc)
Related: https://github.com/rust-lang/rust/issues/66741

Guarded with `#![feature(default_alloc_error_handler)]` a default
`alloc_error_handler` is called, if a custom allocator is used and no
other custom `#[alloc_error_handler]` is defined.

The panic message does not contain the size anymore, because it would
pull in the fmt machinery, which would blow up the code size
significantly.
2020-10-02 09:00:29 +02:00
Stein Somers
424347527d BTreeMap: use Unique::from to avoid a cast where type information exists 2020-10-01 15:03:51 +02:00
Stein Somers
df76cf89ad BTreeMap: admit the existence of leaf edges in comments 2020-10-01 13:20:39 +02:00
bors
00730fd0f1 Auto merge of #77383 - pickfire:patch-6, r=Mark-Simulacrum
Fix typo in vec doc "tries to reserves"

Superseeds #77192
2020-10-01 05:35:48 +00:00
Ivan Tham
86e30b605c
Fix typo in vec doc "tries to reserves" 2020-10-01 10:08:51 +08:00
Dylan DPC
70740b1b82
Rollup merge of #77315 - exrook:rename-allocerror, r=joshtriplett
Rename AllocErr to AllocError

Implements rust-lang/wg-allocators#57
2020-10-01 02:13:39 +02:00
Jonas Schievink
fea2ad8a0a
Rollup merge of #77340 - pickfire:patch-9, r=kennytm
Alloc vec use imported path

mem::ManuallyDrop::new -> ManuallyDrop::new

cc @the8472
2020-09-30 20:56:21 +02:00
Jonas Schievink
054ba3db2d
Rollup merge of #77338 - pickfire:patch-7, r=jyn514
Fix typo in alloc vec comment

cc @the8472
2020-09-30 20:56:19 +02:00
Jonas Schievink
7ad03dd91d
Rollup merge of #77233 - ssomers:btree_size_matters, r=Mark-Simulacrum
BTreeMap: keep an eye out on the size of the main components

r? @Mark-Simulacrum
2020-09-30 20:56:07 +02:00
Ivan Tham
f9b625f8e0
Alloc vec use imported path
mem::ManuallyDrop::new -> ManuallyDrop::new
2020-09-29 23:00:02 +08:00
Ivan Tham
b141e49d87
Fix typo in alloc vec comment 2020-09-29 22:33:57 +08:00
Ivan Tham
55ba9e4755
Reorder benches const variable
Move LEN so it is is read in order.
2020-09-29 21:39:24 +08:00
bors
9e34b72964 Auto merge of #77253 - jyn514:crate-link, r=Manishearth
Resolve `crate` in intra-doc links properly across crates

Closes https://github.com/rust-lang/rust/issues/77193; see https://github.com/rust-lang/rust/issues/77193#issuecomment-699065946 for an explanation of what's going on here.
~~This also fixes the BTreeMap docs that have been broken for a while; see the description on the second commit for why and how.~~ Nope, see the second commit for why the link had to be changed.

r? `@Manishearth`
cc `@dylni`

`@dylni` note that this doesn't solve your original problem - now _both_ `with_code` and `crate::with_code` will be broken links. However this will fix a lot of other broken links (in particular I think https://docs.rs/sqlx/0.4.0-beta.1/sqlx/query/struct.Query.html is because of this bug). I'll open another issue for resolving additional docs in the new scope.
2020-09-29 12:11:17 +00:00
Jacob Hughes
5829560a68 Rename AllocErr to AllocError 2020-09-28 14:51:03 -04:00
Ralf Jung
734c57d45c
Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matklad
UI to unit test for those using Cell/RefCell/UnsafeCell

Helps with #76268.

I'm working on all files using `Cell` and moving them to unit tests when possible.

r? @matklad
2020-09-28 18:39:39 +02:00
Joshua Nelson
406584621a Use relative links instead of intra-doc links
Previously, `BTreeMap` tried to link to `crate::collections`, intending
for the link to go to `std/collections/index.html`. But `BTreeMap` is
defined in `alloc`, so after the fix in the previous commit, the links
instead went to `alloc/collections/index.html`, which has almost no
information.

This changes it to link to `index.html`, which only works when viewing
from `std::collections::BTreeMap`, the most common place to visit the
docs. Fixing it to work from anywhere would require the docs for
`std::collections` to be duplicated in `alloc::collections`, which in
turn would require HashMap to be `alloc` for intra-doc links to work
(https://github.com/rust-lang/rust/issues/74481).
2020-09-27 11:28:13 -04:00
Jonas Schievink
bb416f3a59
Rollup merge of #77184 - pickfire:patch-4, r=kennytm
Rust vec bench import specific rand::RngCore

Using `RngCore` import for side effects is clearer than `*` which may bring it unnecessary more stuff than needed, it is also more explicit doing so.

@pickfire change `LEN = 16384` (and pos) and `once` instead of `[0].iter()` after this.

@rustbot modify labels: +C-cleanup +A-testsuite
2020-09-27 01:53:22 +02:00
Stein Somers
3e485d7cf5 BTreeMap: keep an eye out on the size of the main components 2020-09-26 20:07:48 +02:00
bors
043f6d747c Auto merge of #77201 - matthewjasper:rename-get-unchecked, r=spastorino
Rename Iterator::get_unchecked

Closes #76479

r? `@pnkfelix`
2020-09-25 21:44:26 +00:00
Alexis Bourget
a61b9638bb review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
Matthew Jasper
04a0b1d087 Rename Iterator::get_unchecked
It's possible for method resolution to pick this method over a lower
priority stable method,  causing compilation errors. Since this method
is permanently unstable, give it a name that is very unlikely to be used
in user code.
2020-09-25 19:52:01 +01:00
Matthew Jasper
323a27967a Improve <vec::IntoIter>::get_unchecked` safety comment 2020-09-25 19:46:06 +01:00
Jonas Schievink
d72b7cc329
Rollup merge of #77189 - pickfire:patch-5, r=Mark-Simulacrum
Remove extra space from vec drawing
2020-09-25 19:42:54 +02:00
Jonas Schievink
e8dc07c242
Rollup merge of #77005 - ssomers:btree_cleanup_3, r=Mark-Simulacrum
BtreeMap: refactoring around edges

Parts chipped off a more daring effort, that the btree benchmarks judge to be performance-neutral.

r? @Mark-Simulacrum
2020-09-25 19:42:31 +02:00
Ivan Tham
606ed2a076
Remove extra space from vec drawing 2020-09-25 23:20:22 +08:00
Ivan Tham
939fd37643
Rust vec bench import specific rand::RngCore 2020-09-25 22:19:28 +08:00
Stein Somers
55fa8afe94 BTreeMap: various tweaks 2020-09-25 11:29:39 +02:00
Stein Somers
3965524570 BTreeMap: introduce edge methods similar to those of keys and values 2020-09-25 11:29:38 +02:00
Stein Somers
1e64d98761 BTreeMap: refactor correct_childrens_parent_links 2020-09-25 11:29:38 +02:00
Jonas Schievink
dc4f39c43f
Rollup merge of #77079 - poliorcetics:more-self-in-docs, r=jyn514
Use `Self` in docs when possible

Fixes #76542.

I used `rg '\s*//[!/]\s+fn [\w_]+\(&?self, ' .` in `library/` to find instances, I found some with that and some by manually checking.

@rustbot modify labels: C-enhancement T-doc
2020-09-25 02:29:42 +02:00
Jonas Schievink
862faea4be
Rollup merge of #77050 - follower:patch-1, r=oli-obk
Typo fix: "satsify" -> "satisfy"
2020-09-25 02:29:37 +02:00
Jonas Schievink
67bcf04bdb
Rollup merge of #77044 - pickfire:patch-4, r=jyn514
Liballoc bench vec use mem take not replace
2020-09-25 02:29:35 +02:00
Dylan DPC
b76343643d
Rollup merge of #77017 - GuillaumeGomez:vec-missing-examples-iter, r=Dylan-DPC
Add missing examples on Vec iter types

r? @Dylan-DPC
2020-09-23 14:54:10 +02:00