Commit graph

837 commits

Author SHA1 Message Date
bors
cd64446196 Auto merge of #82076 - jyn514:update-bootstrap, r=Mark-Simulacrum
Update the bootstrap compiler

This updates the bootstrap compiler, notably leaving out a change to enable semicolon in macro expressions lint, because stdarch still depends on the old behavior.
2021-02-23 07:19:41 +00:00
bors
a4e595db8f Auto merge of #82430 - Dylan-DPC:rollup-nu4kfyc, r=Dylan-DPC
Rollup of 12 pull requests

Successful merges:

 - #79423 (Enable smart punctuation)
 - #81154 (Improve design of `assert_len`)
 - #81235 (Improve suggestion for tuple struct pattern matching errors.)
 - #81769 (Suggest `return`ing tail expressions that match return type)
 - #81837 (Slight perf improvement on char::to_ascii_lowercase)
 - #81969 (Avoid `cfg_if` in `std::os`)
 - #81984 (Make WASI's `hard_link` behavior match other platforms.)
 - #82091 (use PlaceRef abstractions more consistently)
 - #82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice)
 - #82166 (add s390x-unknown-linux-musl target)
 - #82234 (Remove query parameters when skipping search results)
 - #82255 (Make `treat_err_as_bug` Option<NonZeroUsize>)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-23 04:31:32 +00:00
Dylan DPC
b8d4354099
Rollup merge of #82128 - anall:feature/add_diagnostic_items, r=davidtwco
add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice

This is adding diagnostic items to be used by rust-lang/rust-clippy#6730, but my understanding is the clippy-side change does need to be done over there since I am adding a new clippy feature.

Add diagnostic items to the following types:
  OsString (os_string_type)
  PathBuf (path_buf_type)
  Owned (to_owned_trait)

As well as the to_vec method on slice/[T]
2021-02-23 02:51:51 +01:00
Dylan DPC
72e6d51583
Rollup merge of #81154 - dylni:improve-design-of-assert-len, r=KodrAus
Improve design of `assert_len`

It was discussed in the [tracking issue](https://github.com/rust-lang/rust/issues/76393#issuecomment-761765448) that `assert_len`'s name and usage are confusing. This PR improves them based on a suggestion by ``@scottmcm`` in that issue.

I also improved the documentation to make it clearer when you might want to use this method.

Old example:

```rust
let range = range.assert_len(slice.len());
```

New example:

```rust
let range = range.ensure_subset_of(..slice.len());
```

Fixes #81157
2021-02-23 02:51:43 +01:00
bors
b02a6193b3 Auto merge of #81937 - ssomers:btree_drainy_refactor_9b, r=Mark-Simulacrum
BTree: move more shared iterator code into navigate.rs

The functions in navigate.rs only exist to support iterators, and these look easier on my eyes if there is a shared `struct` with the recurring pair of handles.

r? `@Mark-Simulacrum`
2021-02-23 00:30:37 +00:00
bors
a15f484b91 Auto merge of #81362 - ssomers:btree_drainy_refactor_8, r=Mark-Simulacrum
BTreeMap: gather and decompose reusable tree fixing functions

This is kind of pushing it as a standalone refactor, probably only useful for #81075 (or similar).
r? `@Mark-Simulacrum`
2021-02-22 17:56:43 +00:00
Yuki Okushi
56ae3fb2f0
Rollup merge of #81706 - SkiFire13:document-binaryheap-unsafe, r=Mark-Simulacrum
Document BinaryHeap unsafe functions

`BinaryHeap` contains some private safe functions but that are actually unsafe to call. This PR marks them `unsafe` and documents all the `unsafe` function calls inside them.

While doing this I might also have found a bug: some "SAFETY" comments in `sift_down_range` and `sift_down_to_bottom` are valid only if you assume that `child` doesn't overflow. However it may overflow if `end > isize::MAX` which can be true for ZSTs (but I think only for them). I guess the easiest fix would be to skip any sifting if `mem::size_of::<T> == 0`.

Probably conflicts with #81127 but solving the eventual merge conflict should be pretty easy.
2021-02-21 15:26:40 +09:00
Yuki Okushi
3219a100fa
Rollup merge of #81300 - ssomers:btree_cleanup_leak_tests, r=Mark-Simulacrum
BTree: share panicky test code & test panic during clear, clone

Bases almost all tests of panic on the same, richer definition, and extends it to cloning to test panic during clone.

r? ```@Mark-Simulacrum```
2021-02-21 15:26:36 +09:00
Joshua Nelson
3733275854 Update the bootstrap compiler
Note this does not change `core::derive` since it was merged after the
beta bump.
2021-02-20 17:19:30 -05:00
Giacomo Stevanato
3ec1a28418 Add FIXME for safety comments that are invalid when T is a ZST 2021-02-20 15:44:17 -05:00
Giacomo Stevanato
9b4e61255c Document BinaryHeap unsafe functions 2021-02-20 15:44:17 -05:00
Andrea Nall
67fcaaaa7a a few more diagnostic items 2021-02-16 02:32:21 +00:00
Andrea Nall
c6bb62810a requested/proposed changes 2021-02-15 22:59:47 +00:00
Jonas Schievink
c7ebc590da
Rollup merge of #82060 - taiki-e:typo, r=m-ou-se
Fix typos in BTreeSet::{first, last} docs

map -> set
2021-02-15 16:06:56 +01:00
Stein Somers
342aa694f9 BTree: move more shared iterator code into navigate.rs 2021-02-15 10:56:22 +01:00
Andrea Nall
5ef202520f add diagnostic items
Add diagnostic items to the following types:
  OsString (os_string_type)
  PathBuf (path_buf_type)
  Owned (to_owned_trait)

As well as the to_vec method on slice/[T]
2021-02-15 02:27:28 +00:00
Dylan DPC
4e888bf403
Rollup merge of #81919 - ssomers:btree_cleanup_comments, r=Mark-Simulacrum
BTreeMap: fix internal comments

Salvaged from #81372

r? `@Mark-Simulacrum`
2021-02-14 16:54:49 +01:00
bors
b86674e7cc Auto merge of #81956 - ssomers:btree_post_75200, r=Mark-Simulacrum
BTree: remove outdated traces of coercions

The introduction of `marker::ValMut` (#75200) meant iterators no longer see mutable keys but their code still pretends it does. And settle on the majority style `Some(unsafe {…})` over `unsafe { Some(…) }`.

r? `@Mark-Simulacrum`
2021-02-14 04:53:24 +00:00
bors
3c10a880ec Auto merge of #81494 - cuviper:btree-node-init, r=Mark-Simulacrum
Initialize BTree nodes directly in the heap

We can avoid any stack-local nodes entirely by using `Box::new_uninit`, and since the nodes are mostly `MaybeUninit` fields, we only need a couple of actual writes before `assume_init`. This should help with the stack overflows in #81444, and may also improve performance in general.

r? `@Mark-Simulacrum`
cc `@ssomers`
2021-02-13 17:29:22 +00:00
Taiki Endo
dd9db236cd Fix typos in BTreeSet::{first, last} docs 2021-02-13 22:49:46 +09:00
Yuki Okushi
0ca5fd7ebc
Rollup merge of #82050 - hbina:fix/added-test-to-drain-empty-vec, r=dtolnay
Added tests to drain an empty vec

Discovered this kind of issue in an unrelated library.
The author copied the tests from here and AFAIK, there are no tests for this particular case.

https://github.com/LeonineKing1199/minivec/pull/19

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-02-13 16:36:52 +09:00
Yuki Okushi
2673026995
Rollup merge of #82041 - notriddle:shared-from-slice-docs, r=m-ou-se
Add docs for shared_from_slice From impls

The advantage of making these docs is mostly in pointing out that these
functions all make new allocations and copy/clone/move the source into them.

These docs are on the function, and not the `impl` block, to avoid showing
the "[+] show undocumented items" button.

CC #51430
2021-02-13 16:36:51 +09:00
Yuki Okushi
4cb381037e
Rollup merge of #81811 - schteve:fix_vec_retain_doc_test, r=m-ou-se
Fix doc test for Vec::retain(), now passes clippy::eval_order_dependence

Doc test for Vec::retain() works correctly but is flagged by clippy::eval_order_dependence. Fix avoids the issue by using an iterator instead of an index.
2021-02-13 16:36:40 +09:00
Hanif Bin Ariffin
fa9af6a9be Added tests to drain an empty vec
Discovered this kind of issue in an unrelated library.
The author copied the tests from here and AFAIK, there are no tests for this particular case.

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-02-13 11:18:36 +08:00
dylni
fe4fe19ddc Update new usage of assert_len 2021-02-12 22:03:39 -05:00
dylni
5d519eaa6e Rename Range::ensure_subset_of to slice::range 2021-02-12 22:01:04 -05:00
dylni
cb647f3e8e Fix possible soundness issue in ensure_subset_of 2021-02-12 22:01:04 -05:00
dylni
9d29793614 Improve design of assert_len 2021-02-12 22:01:04 -05:00
Dylan DPC
54013fe59e
Rollup merge of #82023 - MikailBag:boxed-docs-unallow, r=jyn514
Remove unnecessary lint allow attrs on example

It seems they are not needed anymore.
2021-02-12 22:53:37 +01:00
Michael Howell
7fafa4d0ca Add docs for shared_from_slice From impls
The advantage of making these docs is mostly in pointing out that these
functions all make new allocations and copy/clone/move the source into them.

These docs are on the function, and not the `impl` block, to avoid showing
the "[+] show undocumented items" button.

CC #51430
2021-02-12 14:02:23 -07:00
Stein Somers
5a58cf4943 Use raw ref macros as in #80886 2021-02-12 12:14:17 -08:00
Josh Stone
48e5866d11 Initialize BTree nodes directly in the heap 2021-02-12 12:14:17 -08:00
Mikail Bagishov
f546633cf8
Remove unnecessary lint allow attrs on example 2021-02-12 12:46:02 +03:00
bors
a118ee2c13 Auto merge of #81486 - ssomers:btree_separate_drop, r=Mark-Simulacrum
BTreeMap: disentangle Drop implementation from IntoIter

No longer require every `BTreeMap` to dig up its last leaf edge before dying. This speeds up the `clone_` benchmarks by 25% for normal keys and values (far less for huge values).

r? `@Mark-Simulacrum`
2021-02-12 06:34:21 +00:00
bors
1efd804983 Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-se
Optimize Vec::retain

Use `copy_non_overlapping` instead of `swap` to reduce memory writes, like what we've done in #44355 and `String::retain`.
#48065 already tried to do this optimization but it is reverted in #67300 due to bad codegen of `DrainFilter::drop`.

This PR re-implement the drop-then-move approach. I did a [benchmark](https://gist.github.com/oxalica/3360eec9376f22533fcecff02798b698) on small-no-drop, small-need-drop, large-no-drop elements with different predicate functions. It turns out that the new implementation is >20% faster in average for almost all cases. Only 2/24 cases are slower by 3% and 5%. See the link above for more detail.

I think regression in may-panic cases is due to drop-guard preventing some optimization. If it's permitted to leak elements when predicate function of element's `drop` panic, the new implementation should be almost always faster than current one.
I'm not sure if we should leak on panic, since there is indeed an issue (#52267) complains about it before.
2021-02-11 04:40:57 +00:00
Stein Somers
f81358d578 BTree: remove outdated traces of coercions 2021-02-10 07:48:13 +01:00
Yuki Okushi
e2765f8cbd
Rollup merge of #81687 - WaffleLapkin:split_at_spare, r=KodrAus
Make Vec::split_at_spare_mut public

This PR introduces a new method to the public API, under
`vec_split_at_spare` feature gate:

```rust
impl<T, A: Allocator> impl Vec<T, A> {
    pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit<T>]);
}
```

The method returns 2 slices, one slice references the content of the vector,
and the other references the remaining spare capacity.

The method was previously implemented while adding `Vec::extend_from_within` in #79015,
and used to implement `Vec::spare_capacity_mut` (as the later is just a
subset of former one).

See also previous [discussion in `Vec::spare_capacity_mut` tracking issue](https://github.com/rust-lang/rust/issues/75017#issuecomment-770381335).

## Unresolved questions

- [ ] Should we consider changing the name? `split_at_spare_mut` doesn't seem like an intuitive name
- [ ] Should we deprecate `Vec::spare_capacity_mut`? Any usecase of `Vec::spare_capacity_mut` can be replaced with `Vec::split_at_spare_mut` (but not vise-versa)

r? `@KodrAus`
2021-02-10 12:24:22 +09:00
Yuki Okushi
a28f2afbeb
Rollup merge of #80438 - crlf0710:box_into_inner, r=m-ou-se
Add `Box::into_inner`.

This adds a `Box::into_inner` method to the `Box` type. <del>I actually suggest deprecating the compiler magic of `*b` if this gets stablized in the future.</del>

r? `@m-ou-se`
2021-02-10 12:24:19 +09:00
Ashley Mannix
8ff7b75c01
update tracking issue for vec_split_at_spare 2021-02-10 09:50:59 +10:00
Stein Somers
3045b75c6d BTreeMap: disentangle Drop implementation from IntoIter 2021-02-09 13:53:12 +01:00
Stein Somers
cbbdb4439a BTreeMap: gather and decompose reusable tree fixing functions 2021-02-09 13:41:51 +01:00
Stein Somers
f7edf5ce05 BTreeMap: fix internal comments 2021-02-09 13:19:37 +01:00
Stein Somers
3e1d602a6b BTreeMap: share panicky test code & test panic during clear, clone 2021-02-09 12:33:18 +01:00
Stein Somers
6d2247eac2 BTreeMap/BTreeSet: separate off code supporting tests 2021-02-09 11:21:42 +01:00
bors
f4008fe949 Auto merge of #81905 - Dylan-DPC:rollup-mxpz1j7, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #72209 (Add checking for no_mangle to unsafe_code lint)
 - #80732 (Allow Trait inheritance with cycles on associated types take 2)
 - #81697 (Add "every" as a doc alias for "all".)
 - #81826 (Prefer match over combinators to make some Box methods inlineable)
 - #81834 (Resolve typedef in HashMap lldb pretty-printer only if possible)
 - #81841 ([rustbuild] Output rustdoc-json-types docs )
 - #81849 (Expand the docs for ops::ControlFlow a bit)
 - #81876 (parser: Fix panic in 'const impl' recovery)
 - #81882 (⬆️ rust-analyzer)
 - #81888 (Fix pretty printer macro_rules with semicolon.)
 - #81896 (Remove outdated comment in windows' mutex.rs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-09 05:57:18 +00:00
Charles Lew
ce7de07866 Add Box::into_inner. 2021-02-09 10:28:50 +08:00
Dylan DPC
d19f37541c
Rollup merge of #81826 - tesuji:inline-box-zeros, r=Amanieu
Prefer match over combinators to make some Box methods inlineable

Hopefully this patch would make two snippets generated identical code: <https://rust.godbolt.org/z/fjrj4E>.
2021-02-09 02:39:53 +01:00
bors
a2704448c1 Auto merge of #81361 - ssomers:btree_drainy_refactor_7, r=Mark-Simulacrum
BTreeMap: lightly refactor the split_off implementation

r? `@Mark-Simulacrum`
2021-02-08 23:37:06 +00:00
bors
0b96f60c07 Auto merge of #79245 - ssomers:btree_curb_ord_bound, r=dtolnay
BTree: remove Ord bound where it is absent elsewhere

Some btree methods don't really need an Ord bound and don't have one, while some methods that more obviously don't need it, do have one.

An example of the former is `iter`, even though it explicitly exposes the work of the Ord implementation (["sorted by key"](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.iter) - but I'm not suggesting it should have the Ord bound). An example of the latter is `new`, which doesn't involve any keys whatsoever.
2021-02-08 07:56:04 +00:00
Guillaume Gomez
6e1f7139c9
Rollup merge of #81526 - ojeda:btree-use-unwrap_unchecked, r=scottmcm
btree: use Option's unwrap_unchecked()

Now that https://github.com/rust-lang/rust/issues/81383 is available, start using it.
2021-02-07 14:45:46 +01:00