Commit graph

1222 commits

Author SHA1 Message Date
bors
05044c2e6c Auto merge of #89144 - sexxi-goose:insig_stdlib, r=nikomatsakis
2229: Mark insignificant dtor in stdlib

I looked at all public [stdlib Drop implementations](https://doc.rust-lang.org/stable/std/ops/trait.Drop.html#implementors) and categorized them into Insigificant/Maybe/Significant Drop.

Reasons are noted here: https://docs.google.com/spreadsheets/d/19edb9r5lo2UqMrCOVjV0fwcSdS-R7qvKNL76q7tO8VA/edit#gid=1838773501

One thing missing from this PR is tagging HashMap as insigificant destructor as that needs some discussion.

r? `@Mark-Simulacrum`

cc `@nikomatsakis`
2021-09-26 19:36:00 +00:00
Manish Goregaokar
653dcaac2b
Rollup merge of #89216 - r00ster91:bigo, r=dtolnay
Consistent big O notation

This makes the big O time complexity notation in places with markdown support more consistent.
Inspired by #89210
2021-09-25 18:22:20 -07:00
Manish Goregaokar
b8c3a6cfb9
Rollup merge of #89010 - est31:intra_doc_links, r=m-ou-se
Add some intra doc links
2021-09-25 18:22:19 -07:00
bors
addb4da686 Auto merge of #88343 - steffahn:fix_code_spacing, r=jyn514
Fix spacing of links in inline code.

Similar to #80733, but the focus is different. This PR eliminates all occurrences of pieced-together inline code blocks like [`Box`]`<`[`Option`]`<T>>` and replaces them with good-looking ones (using HTML-syntax), like <code>[Box]<[Option]\<T>></code>. As far as I can tell, I should’ve found all of these in the standard library (regex search with `` r"`\]`|`\[`" ``) \[except for in `core::convert` where I’ve noticed other things in the docs that I want to fix in a separate PR]. In particular, unlike #80733, I’ve added almost no new instance of inline code that’s broken up into multiple links (or some link and some link-free part). I also added tooltips (the stuff in quotes for the markdown link listings) in places that caught my eye, but that’s by no means systematic, just opportunistic.

[Box]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box"
[`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box"
[Option]: https://doc.rust-lang.org/std/option/enum.Option.html "Option"
[`Option`]: https://doc.rust-lang.org/std/option/enum.Option.html "Option"

Context: I got annoyed by repeatedly running into new misformatted inline code while reading the standard library docs. I know that once issue #83997 (and/or related ones) are resolved, these changes become somewhat obsolete, but I fail to notice much progress on that end right now.

r? `@jyn514`
2021-09-25 20:08:11 +00:00
Frank Steffahn
67065fe933 Apply 16 commits (squashed)
----------

Fix spacing for links inside code blocks, and improve link tooltips in alloc::fmt

----------

Fix spacing for links inside code blocks, and improve link tooltips in alloc::{rc, sync}

----------

Fix spacing for links inside code blocks, and improve link tooltips in alloc::string

----------

Fix spacing for links inside code blocks in alloc::vec

----------

Fix spacing for links inside code blocks in core::option

----------

Fix spacing for links inside code blocks, and improve a few link tooltips in core::result

----------

Fix spacing for links inside code blocks in core::{iter::{self, iterator}, stream::stream, poll}

----------

Fix spacing for links inside code blocks, and improve a few link tooltips in std::{fs, path}

----------

Fix spacing for links inside code blocks in std::{collections, time}

----------

Fix spacing for links inside code blocks in and make formatting of `&str`-like types consistent in std::ffi::{c_str, os_str}

----------

Fix spacing for links inside code blocks, and improve link tooltips in std::ffi

----------

Fix spacing for links inside code blocks, and improve a few link tooltips
in std::{io::{self, buffered::{bufreader, bufwriter}, cursor, util}, net::{self, addr}}

----------

Fix typo in link to `into` for `OsString` docs

----------

Remove tooltips that will probably become redundant in the future

----------

Apply suggestions from code review

Replacing `…std/primitive.reference.html` paths with just `reference`

Co-authored-by: Joshua Nelson <github@jyn.dev>

----------

Also replace `…std/primitive.reference.html` paths with just `reference` in `core::pin`
2021-09-25 20:04:35 +02:00
bors
e9f29a8519 Auto merge of #89030 - nbdd0121:box2, r=jonas-schievink
Introduce `Rvalue::ShallowInitBox`

Polished version of #88700.

Implements MCP rust-lang/compiler-team#460, and should allow #43596 to go forward.

In short, creating an empty box is split from a nullary-op `NullOp::Box` into two steps, first a call to `exchange_malloc`, then a `Rvalue::ShallowInitBox` which transmutes `*mut u8` to a shallow-initialized `Box<T>`. This allows the `exchange_malloc` call to unwind. Details can be found in the MCP.

`NullOp::Box` is not yet removed, purely to make reverting easier in case anything goes wrong as the result of this PR. If revert is needed a reversion of "Use Rvalue::ShallowInitBox for box expression" commit followed by a test bless should be sufficient.

Experiments in #88700 showed a very slight compile-time perf regression due to (supposedly) slightly more time spent in LLVM. We could omit unwind edge generation (in non-`oom=panic` case) in box expression MIR construction to restore perf; but I don't think it's necessary since runtime perf isn't affected and perf difference is rather small.
2021-09-25 11:01:13 +00:00
Gary Guo
511333fcc4 Use Rvalue::ShallowInitBox for box expression 2021-09-25 01:08:41 +01:00
Takashi Idobe
cebba31d4a
unitalicize O(1) complexities 2021-09-24 08:33:49 -05:00
r00ster91
956f87fb04 consistent big O notation 2021-09-24 12:44:28 +02:00
Takashi Idobe
b146525140
remove trailing whitespace 2021-09-23 18:20:46 -05:00
Takashi Idobe
d63e0f0e47
Add time complexities to linked_list.rs 2021-09-23 17:58:02 -05:00
the8472
00635511db
Rollup merge of #89036 - nbdd0121:alloc, r=yaahc
Fix missing `no_global_oom_handling` cfg-gating

Cfg-gate these trait impls that are neglected.

These functions compile now because they use `box` syntax which depends on `exchange_malloc` during codegen only; as a result they compiles with cfg `no_global_oom_handling` but shouldn't.

Discovered in #89030 because that PR makes `box` syntax depend on `exchange_malloc` lang item during MIR construction.
2021-09-22 19:03:20 +02:00
Aman Arora
994793faab PR fixup 2021-09-22 05:17:30 -04:00
the8472
d7de8d2b53
Rollup merge of #89086 - WaffleLapkin:stabilize_iter_map_while, r=kennytm
Stabilize `Iterator::map_while`

Per the FCP: https://github.com/rust-lang/rust/issues/68537#issuecomment-922385035

This PR stabilizes `Iterator::map_while` and `iter::MapWhile` in Rust 1.57.
2021-09-21 22:54:01 +02:00
Aman Arora
099a34cd95 2229: Annotate stdlib with insignficant dtors 2021-09-21 04:06:00 -04:00
DeveloperC286
05b01cd787 refactor: VecDeques IntoIter fields to private 2021-09-17 21:46:32 +01:00
Maybe Waffle
71e2eacc7b Stabilize Iterator::map_while 2021-09-17 19:42:46 +03:00
Gary Guo
be5a5b70b4 Fix missing no_global_oom_handling cfg-gating 2021-09-17 03:53:18 +01:00
est31
372711906b Add IntoIterator intra doc link to various collections 2021-09-16 13:55:27 +02:00
est31
a8a829deb4 Add intra-doc-links to BinaryHeap rustdoc 2021-09-16 13:35:54 +02:00
est31
52ab3e8e76 Add intra-doc-links to LinkedList rustdoc 2021-09-16 13:20:36 +02:00
Deadbeef
349ac4f6c8
Const Deref 2021-09-15 03:06:53 +00:00
Mark Rousskov
b4e7649d6d Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
bors
ffaf857045 Auto merge of #88448 - xu-cheng:btree-blk-build, r=Mark-Simulacrum
BTreeMap/BTreeSet::from_iter: use bulk building to improve the performance

Bulk building is a common technique to increase the performance of building a fresh btree map. Instead of inserting items one-by-one, we sort all the items beforehand then create the BtreeMap in bulk.

Benchmark
```
./x.py bench library/alloc --test-args btree::map::from_iter
```

* Before
```
test btree::map::from_iter_rand_100                      ... bench:       3,694 ns/iter (+/- 840)
test btree::map::from_iter_rand_10_000                   ... bench:   1,033,446 ns/iter (+/- 192,950)
test btree::map::from_iter_seq_100                       ... bench:       5,689 ns/iter (+/- 1,259)
test btree::map::from_iter_seq_10_000                    ... bench:     861,033 ns/iter (+/- 118,815)
```

* After
```
test btree::map::from_iter_rand_100                      ... bench:       3,033 ns/iter (+/- 707)
test btree::map::from_iter_rand_10_000                   ... bench:     775,958 ns/iter (+/- 105,152)
test btree::map::from_iter_seq_100                       ... bench:       2,969 ns/iter (+/- 336)
test btree::map::from_iter_seq_10_000                    ... bench:     258,292 ns/iter (+/- 29,364)
```
2021-09-07 02:24:11 +00:00
Yechan Bae
3a105cfcea Fix typo: needede -> needed 2021-09-05 16:04:19 -04:00
Mara Bos
22dd6a4e30
Rollup merge of #88432 - terrarier2111:patch-1, r=joshtriplett
Fix a typo in raw_vec
2021-09-05 10:32:21 +02:00
Mara Bos
8fd1bf3323
Rollup merge of #88505 - ibraheemdev:use-unwrap-unchecked, r=kennytm
Use `unwrap_unchecked` where possible
2021-09-02 19:10:14 +02:00
Mara Bos
5878780e64
Rollup merge of #88040 - nbdd0121:btreemap, r=m-ou-se
BTree: remove Ord bound from new

`K: Ord` bound is unnecessary on `BTree{Map,Set}::new` and their `Default` impl. No elements exist so there are nothing to compare anyway, so I don't think "future proof" would be a blocker here. This is analogous to `HashMap::new` not having a `K: Eq + Hash` bound.

#79245 originally does this and for some reason drops the change to `new` and `Default`. I can see why changes to other methods like `entry` or `symmetric_difference` need to be careful but I couldn't find out any reason not to do it on `new`.

Removing the bound also makes the stabilisation of `const fn new` not depending on const trait bounds.

cc `@steffahn` who suggests me to make this PR.

r? `@dtolnay`
2021-09-01 09:23:23 +02:00
Ibraheem Ahmed
ffc43b8468
add safety annotation to LinkedList::detach_all_nodes
Co-authored-by: kennytm <kennytm@gmail.com>
2021-08-31 11:18:30 -04:00
ibraheemdev
b99038f478 use unwrap_unchecked where possible 2021-08-30 16:13:56 -04:00
Cheng XU
a03287bbf7
BTreeSet::from_iter: use bulk building to improve the performance
Apply the same optimization as BTreeMap::from_iter.
2021-08-28 17:19:07 -07:00
Cheng XU
cf814d60f8
BTreeMap::from_iter: use bulk building to improve the performance
Bulk building is a common technique to increase the performance of
building a fresh btree map. Instead of inserting items one-by-one,
we sort all the items beforehand then create the BtreeMap in bulk.
2021-08-28 17:18:50 -07:00
Cheng XU
6a6885c6bd
add benchmark for BTreeMap::from_iter 2021-08-28 17:18:43 -07:00
terrarier2111
3e477c1772
Fix a typo in raw_vec 2021-08-28 20:20:22 +02:00
Manish Goregaokar
cf5e362fd5
Rollup merge of #88216 - kornelski:from_layout_err, r=kennytm
Don't stabilize creation of TryReserveError instances

#48043 + https://github.com/rust-lang/rust/pull/87993#issuecomment-903189016
2021-08-26 12:38:08 -07:00
Léo Lanteri Thauvin
0aabf4bb4b
Rollup merge of #88293 - est31:fix_grammar, r=Mark-Simulacrum
Fix grammar in alloc test
2021-08-25 15:48:59 +02:00
Léo Lanteri Thauvin
cc2a1271d4
Rollup merge of #88226 - steffahn:an_rc, r=michaelwoerister
Fix typo “a Rc” → “an Rc” (and a few more)

After stumbling about it in the dev-guide, I’ve devided to eliminate all mentions of “a Rc”, replacing it with “an Rc”. E.g.
```plain
$ rg "(^|[^'])\ba\b[^\w=:]*\bRc"
compiler/rustc_data_structures/src/owning_ref/mod.rs
1149:/// Typedef of a owning reference that uses a `Rc` as the owner.

library/std/src/ffi/os_str.rs
919:    /// Converts a [`OsString`] into a [`Rc`]`<OsStr>` without copying or allocating.

library/std/src/ffi/c_str.rs
961:    /// Converts a [`CString`] into a [`Rc`]`<CStr>` without copying or allocating.

src/doc/rustc-dev-guide/src/query.md
61:are cheaply cloneable; insert a `Rc` if necessary).

src/doc/book/src/ch15-06-reference-cycles.md
72:decreases the reference count of the `a` `Rc<List>` instance from 2 to 1 as

library/alloc/src/rc.rs
1746:    /// Converts a generic type `T` into a `Rc<T>`
```
_(the match in the book is a false positive)_
Since the dev-guide is a submodule, it’s getting a separate PR: rust-lang/rustc-dev-guide#1191

I’ve also gone ahead and done the same search for `RwLock` and hit a few cases in the `OwningRef` adaption. Then, I couldn’t keep the countless cases of “a owning …” or “a owner” unaddressed, which concludes this PR.

`@rustbot` label C-cleanup
2021-08-25 15:48:53 +02:00
Léo Lanteri Thauvin
214d8e3cd4
Rollup merge of #88156 - steffahn:arc_make_mut_and_weak, r=Mark-Simulacrum
Adjust / fix documentation of `Arc::make_mut`

Related discussion in the users forum:
[Whatʼs this alleged difference between Arc::make_mut and Rc::make_mut? – The Rust Programming Language Forum](https://users.rust-lang.org/t/what-s-this-alleged-difference-between-arc-make-mut-and-rc-make-mut/63747?u=steffahn)

Also includes a small formatting improvement in the documentation of `Rc::make_mut`.

This PR makes the two documentations in question complete analogs. The previously claimed point in which one “differs from the behavior of” the other turns out to be incorrect, AFAIK.

One remaining inaccuracy: `Weak` pointers aren’t disassociated from the allocation but only from the contained value, i.e. in case of outstanding `Weak` pointers there still is a new allocation created, just the call to `.clone()` is avoided, instead the value is moved from one allocation to the other.

`@rustbot` label T-libs-api, A-docs
2021-08-25 15:48:48 +02:00
Frank Steffahn
90354c719a Make explanations of cross-references between make_mut and get_mut more accurate 2021-08-24 21:34:12 +02:00
Frank Steffahn
335bf7ca6b Clarifiy weak pointers being diassociated…
…noting the fact that `clone` is not called.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2021-08-24 21:17:20 +02:00
est31
8f7007991e Fix grammar 2021-08-24 17:56:39 +02:00
Frank Steffahn
04fa1d81dd Fix typo “a Rc” → “an Rc” 2021-08-24 02:23:16 +02:00
Frank Steffahn
2f9ddf3bc7 Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
Frank Steffahn
bf88b113ea Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
bors
9faa714154 Auto merge of #88075 - Xuanwo:vec_deque_retain, r=dtolnay
Optimize unnecessary check in VecDeque::retain

This pr is highly inspired by https://github.com/rust-lang/rust/pull/88060 which shared the same idea: we can split the `for` loop into stages so that we can remove unnecessary checks like `del > 0`.

## Benchmarks

Before

```rust
test collections::vec_deque::tests::bench_retain_half_10000  ... bench:     290,125 ns/iter (+/- 8,717)
test collections::vec_deque::tests::bench_retain_odd_10000   ... bench:     291,588 ns/iter (+/- 9,621)
test collections::vec_deque::tests::bench_retain_whole_10000 ... bench:     287,426 ns/iter (+/- 9,009)
```

After

```rust
test collections::vec_deque::tests::bench_retain_half_10000  ... bench:     243,940 ns/iter (+/- 8,563)
test collections::vec_deque::tests::bench_retain_odd_10000   ... bench:     242,768 ns/iter (+/- 3,903)
test collections::vec_deque::tests::bench_retain_whole_10000 ... bench:     202,926 ns/iter (+/- 6,332)
```

Based on the current benchmark, this PR will improve the perf of `VecDeque::retain` by around 16%. For special cases, the improvement will be up to 30%.

Signed-off-by: Xuanwo <github@xuanwo.io>
2021-08-21 23:35:54 +00:00
Kornel
f1e860757e Don't stabilize creation of TryReserveError instances 2021-08-21 23:40:02 +01:00
Frank Steffahn
51d598ec28 Adjust documentation of Arc::make_mut
Related discussion in the users forum:
https://users.rust-lang.org/t/what-s-this-alleged-difference-between-arc-make-mut-and-rc-make-mut/63747?u=steffahn

Also includes small formatting improvement in the documentation of `Rc::make_mut`.

This commit makes the two documentations in question complete analogs. The previously claimed point in which
one "differs from the behavior of" the other turns out to be incorrect, AFAIK.

One remaining inaccuracy: `Weak` pointers aren't disassociated from the allocation but only from the contained
value, i.e. in case of outstanding `Weak` pointers there still is a new allocation created, just the
call to `.clone()` is avoided, instead the value is moved from one allocation to the other.
2021-08-19 15:07:53 +02:00
Gary Guo
f33f266a8a BTree: remove Ord bound from new 2021-08-18 03:55:36 +01:00
Deadbeef
b5afa6807b
Constified Default implementations
The libs-api team agrees to allow const_trait_impl to appear in the
standard library as long as stable code cannot be broken (they are
properly gated) this means if the compiler teams thinks it's okay, then
it's okay.

My priority on constifying would be:

	1. Non-generic impls (e.g. Default) or generic impls with no
	   bounds
	2. Generic functions with bounds (that use const impls)
	3. Generic impls with bounds
	4. Impls for traits with associated types

For people opening constification PRs: please cc me and/or oli-obk.
2021-08-17 07:15:54 +00:00
Mara Bos
fa4edcc851
Rollup merge of #88030 - fee1-dead:fixme, r=oli-obk
Assign FIXMEs to me and remove obsolete ones

Also fixed capitalization of documentation

We also don't need to transform predicates to be non-const since we basically ignore const predicates in non-const contexts.

r? `````@oli-obk`````
2021-08-16 23:37:30 +02:00