Commit graph

5300 commits

Author SHA1 Message Date
Frank Steffahn
355c7e9415 Remove an unnecessary use of unwrap_unchecked
also add a new SAFETY comment and simplify/remove a closure
2021-09-30 10:09:03 -03:00
Frank Steffahn
325025e74b Improve previous commit 2021-09-30 13:53:24 +02:00
Caio
fdccc7dad9 Use reference instead of raw pointer 2021-09-30 08:40:05 -03:00
Caio
4be574e6c9 Add 'core::array::from_fn' and 'core::array::try_from_fn' 2021-09-30 07:49:32 -03: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
Manish Goregaokar
f9d4eb0ae3
Rollup merge of #88973 - lu-zero:std_detect-env_override, r=Amanieu
Expose the std_detect env_override feature
2021-09-25 18:22:18 -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
Luca Barbato
160b93903c Expose the std_detect env_override feature 2021-09-25 20:30:25 +02: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
Jubilee
0fa43494bd
Rollup merge of #89210 - Takashiidobe:master, r=kennytm
Add missing time complexities to linked_list.rs

Most functions in LinkedList have time complexities in their description:
Like push front:

```
Adds an element first in the list.

This operation should compute in O(1) time.
```

Time complexities were missing for the following, so I've added them in this PR:

contains: O(n)
front: O(1)
front_mut: O(1)
back: O(1)
back_mut: O(1)
2021-09-24 11:40:15 -07:00
bors
f06f9bbd3a Auto merge of #88999 - Migi:master, r=oli-obk
Make `Duration` respect `width` when formatting using `Debug`

When printing or writing a `std::time::Duration` using `Debug` formatting, it previously completely ignored any specified `width`. This is unlike types like integers and floats, which do pad to `width`, for both `Display` and `Debug`, though not all types consider `width` in their `Debug` output (see e.g. #30164). Curiously, `Duration`'s `Debug` formatting *did* consider `precision`.

This PR makes `Duration` pad to `width` just like integers and floats, so that
```rust
format!("|{:8?}|", Duration::from_millis(1234))
```
returns
```
|1.234s  |
```

Before you ask "who formats `Debug` output?", note that `Duration` doesn't actually implement `Display`, so `Debug` is currently the only way to format `Duration`s. I think that's wrong, and `Duration` should get a `Display` implementation, but in the meantime there's no harm in making the `Debug` formatting respect `width` rather than ignore it.

I chose the default alignment to be left-aligned. The general rule Rust uses is: numeric types are right-aligned by default, non-numeric types left-aligned. It wasn't clear to me whether `Duration` is a numeric type or not. The fact that a formatted `Duration` can end with suffixes of variable length (`"s"`, `"ms"`, `"µs"`, etc.) made me lean towards left-alignment, but it would be trivial to change it.

Fixes issue #88059.
2021-09-24 15:22:26 +00:00
Takashi Idobe
cebba31d4a
unitalicize O(1) complexities 2021-09-24 08:33:49 -05:00
Takashi Idobe
cb1c06fdd8
Merge branch 'rust-lang:master' into master 2021-09-24 08:31:03 -05:00
r00ster91
956f87fb04 consistent big O notation 2021-09-24 12:44:28 +02:00
Jubilee
384dd53641
Rollup merge of #89184 - joshtriplett:master, r=estebank
Temporarily rename int_roundings functions to avoid conflicts

These functions are unstable, but because they're inherent they still
introduce conflicts with stable trait functions in crates. Temporarily
rename them to fix these conflicts, until we can resolve those conflicts
in a better way.
2021-09-23 17:31:46 -07:00
Jubilee
586d028d0e
Rollup merge of #88612 - lovasoa:patch-1, r=m-ou-se
Add a better error message for #39364

There is a known bug in the implementation of mpsc channels in rust.
This adds a clearer error message when the bug occurs, so that developers don't lose too much time looking for the origin of the bug.
See https://github.com/rust-lang/rust/issues/39364
2021-09-23 17:31:41 -07: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
bors
15d9ba0133 Auto merge of #88587 - bdbai:fix/uwpio, r=joshtriplett
Fix WinUWP std compilation errors due to I/O safety

I/O safety for Windows has landed in #87329. However, it does not cover UWP specific parts and prevents all UWP targets from building. See https://github.com/YtFlow/Maple/issues/18. This PR fixes these compile errors when building std for UWP targets.
2021-09-23 06:18:07 +00:00
bors
67365d64bc Auto merge of #89139 - camsteffen:write-perf, r=Mark-Simulacrum
Use ZST for fmt unsafety

as suggested here - https://github.com/rust-lang/rust/pull/83302#issuecomment-923529151.
2021-09-23 02:10:26 +00:00
bdbai
4e01157969 Reason safety for unsafe blocks for uwp stdin 2021-09-23 07:29:52 +08:00
Josh Triplett
3ece63b64e Temporarily rename int_roundings functions to avoid conflicts
These functions are unstable, but because they're inherent they still
introduce conflicts with stable trait functions in crates. Temporarily
rename them to fix these conflicts, until we can resolve those conflicts
in a better way.
2021-09-22 13:56:01 -07:00
Mara Bos
598e5b27be
Update library/std/src/sync/mpsc/shared.rs 2021-09-22 20:20:33 +02: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
the8472
17c9a22d48
Rollup merge of #89141 - mbartlett21:patch-2, r=kennytm
Impl `Error` for `FromSecsError` without foreign type

Using it through the crate-local path in `std` means that it shouldn't make an "Implementations on Foreign Types" section in the `std::error::Error` docs.
2021-09-21 22:54:07 +02:00
the8472
8a6e9cf074
Rollup merge of #89114 - dequbed:c-char, r=yaahc
Fixes a technicality regarding the size of C's `char` type

Specifically, ISO/IEC 9899:2018 — better known as "C18" — (and at least
C11, C99 and C89) do not specify the size of `byte` in bits.
Section 3.6 defines "byte" as "addressable unit of data storage" while
section 6.2.5 ("Types") only defines "char" as "large enough to store
any member of the basic execution set" giving it a lower bound of 7 bit
(since there are 96 characters in the basic execution set).
With section 6.5.3.4 paragraph 4 "When sizeof is applied to an operant
that has type char […] the result is 1" you could read this as the size
of `char` in bits being defined as exactly the same as the number of
bits in a byte but it's also valid to read that as an exception.

In general implementations take `char` as the smallest unit of
addressable memory, which for modern byte-addressed architectures is
overwhelmingly 8 bits to the point of this convention being completely
cemented into just about all of our software.

So is any of this actually relevant at all? I hope not. I sincerely hope
that this never, ever comes up.
But if for some reason a poor rustacean is having to interface with C
code running on a Cray X1 that in 2003 is still doing word-addressed
memory with 64-bit chars and they trust the docs here blindly it will
blow up in her face. And I'll be truly sorry for her to have to deal
with … all of that.
2021-09-21 22:54:04 +02: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
the8472
051168b876
Rollup merge of #89015 - klensy:escape-def, r=Mark-Simulacrum
core::ascii::escape_default: reduce struct size
2021-09-21 22:53:59 +02:00
Cameron Steffen
09b37d7433 Use ZST for fmt unsafety
This allows the format_args! macro to keep the pre-expansion code out of
the unsafe block without doing gymnastics with nested `match`
expressions. This reduces codegen.
2021-09-21 10:04:44 -05:00
mbartlett21
e4faf17437
Re-export FromSecsError from std 2021-09-21 21:18:57 +10:00
mbartlett21
33766ae372
Impl Error for FromSecsError without foreign type
Using it through the crate-local path in `std` means that it shouldn't make an "Implementations on Foreign Types" section in the `std::error::Error` docs.
2021-09-21 18:02:18 +10:00
bors
db1fb85cff Auto merge of #88321 - glaubitz:m68k-linux, r=wesleywiser
Add initial support for m68k

This patch series adds initial support for m68k making use of the new M68k
backend introduced with LLVM-13. Additional changes will be needed to be
able to actually use the backend for this target.
2021-09-20 07:21:05 +00:00
Nadja Reitzenstein
23c608f3a1 Fix a technicality regarding the size of C's char type
Specifically, ISO/IEC 9899:2018 — better known as "C18" — (and at least
C11, C99 and C89) do not specify the size of `byte` in bits.
Section 3.6 defines "byte" as "addressable unit of data storage" while
section 6.2.5 ("Types") only defines "char" as "large enough to store
any member of the basic execution set" giving it a lower bound of 7 bit
(since there are 96 characters in the basic execution set).
With section 6.5.3.4 paragraph 4 "When sizeof is applied to an operant
that has type char […] the result is 1" you could read this as the size
of `char` in bits being defined as exactly the same as the number of
bits in a byte but it's also valid to read that as an exception.

In general implementations take `char` as the smallest unit of
addressable memory, which for modern byte-addressed architectures is
overwhelmingly 8 bits to the point of this convention being completely
cemented into just about all of our software.

So is any of this actually relevant at all? I hope not. I sincerely hope
that this never, ever comes up.
But if for some reason a poor rustacean is having to interface with C
code running on a Cray X1 that in 2003 is still doing word-addressed
memory with 64-bit words and they trust the docs here blindly it will
blow up in her face. And I'll be truly sorry for her to have to deal
with … all of that.
2021-09-20 08:19:13 +02:00
bors
08a0307b32 Auto merge of #89089 - JohnTitor:rollup-6s6mccx, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #87960 (Suggest replacing an inexisting field for an unmentioned field)
 - #88855 (Allow simd_shuffle to accept vectors of any length)
 - #88966 (Check for shadowing issues involving block labels)
 - #88996 (Fix linting when trailing macro expands to a trailing semi)
 - #89017 (fix potential race in AtomicU64 time monotonizer)
 - #89021 (Add a separate error for `dyn Trait` in `const fn`)
 - #89051 (Add intra-doc links and small changes to `std::os` to be more consistent)
 - #89053 (refactor: VecDeques IntoIter fields to private)
 - #89055 (Suggest better place to add call parentheses for method expressions wrapped in parentheses)
 - #89081 (Fix a typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-19 11:03:09 +00:00
Yuki Okushi
4877ad3d12
Rollup merge of #89081 - ondra05:patch-1, r=dtolnay
Fix a typo

Removed extra spaces in front of commas
2021-09-19 17:31:35 +09:00
Yuki Okushi
e4dbe27235
Rollup merge of #89053 - DeveloperC286:into_iter_fields_to_private, r=Mark-Simulacrum
refactor: VecDeques IntoIter fields to private

Made the fields of VecDeque's IntoIter private by creating a IntoIter::from(...) function to create a new instance of IntoIter and migrating usage to use IntoIter::from(...).
2021-09-19 17:31:34 +09:00
Yuki Okushi
4366059124
Rollup merge of #89051 - schctl:master, r=jyn514
Add intra-doc links and small changes to `std::os` to be more consistent

I believe that a few items in `std::os` should be linked. I've also added a basic example in `std::os::windows`.
2021-09-19 17:31:33 +09:00
Yuki Okushi
91c5e7cbb6
Rollup merge of #89017 - the8472:fix-u64-time-monotonizer, r=kennytm
fix potential race in AtomicU64 time monotonizer

The AtomicU64-based monotonizer introduced in #83093 is incorrect because several threads could try to update the value concurrently and a thread which doesn't have the newest value among all the updates could win.

That bug probably has little real world impact since it doesn't make observed time worse than hardware clocks. The worst case would probably be a thread which has a clock that is behind by several cycles observing several inconsistent fixups, which should be similar to observing the unfiltered backslide in the first place.

New benchmarks, they don't look as good as the original PR but still an improvement compared to the mutex.
I don't know why the contended mutex case is faster now than in the previous benchmarks.

```
actually_monotonic() == true:
test time::tests::instant_contention_01_threads                   ... bench:          44 ns/iter (+/- 0)
test time::tests::instant_contention_02_threads                   ... bench:          45 ns/iter (+/- 0)
test time::tests::instant_contention_04_threads                   ... bench:          45 ns/iter (+/- 0)
test time::tests::instant_contention_08_threads                   ... bench:          45 ns/iter (+/- 0)
test time::tests::instant_contention_16_threads                   ... bench:          46 ns/iter (+/- 0)

atomic u64:
test time::tests::instant_contention_01_threads                   ... bench:          66 ns/iter (+/- 0)
test time::tests::instant_contention_02_threads                   ... bench:         287 ns/iter (+/- 14)
test time::tests::instant_contention_04_threads                   ... bench:         296 ns/iter (+/- 43)
test time::tests::instant_contention_08_threads                   ... bench:         604 ns/iter (+/- 163)
test time::tests::instant_contention_16_threads                   ... bench:       1,147 ns/iter (+/- 29)

mutex:
test time::tests::instant_contention_01_threads                   ... bench:          78 ns/iter (+/- 0)
test time::tests::instant_contention_02_threads                   ... bench:         652 ns/iter (+/- 275)
test time::tests::instant_contention_04_threads                   ... bench:         900 ns/iter (+/- 32)
test time::tests::instant_contention_08_threads                   ... bench:       1,927 ns/iter (+/- 62)
test time::tests::instant_contention_16_threads                   ... bench:       3,748 ns/iter (+/- 146)
```
2021-09-19 17:31:32 +09:00
bors
7a3d1a5f3d Auto merge of #89031 - the8472:outline-once-cell-init-closure, r=Mark-Simulacrum
Don't inline OnceCell initialization closures

The more general variant of #89026, originally suggested in https://github.com/rust-lang/rust/pull/86898#issuecomment-920138051
2021-09-19 08:05:45 +00:00
ondra05
3f75ab3950
Fix typo
Removed extra spaces in front of commas
2021-09-18 23:39:56 +02:00
klensy
cccd6e0e83 EscapeDefault: change range field to Range<u8>, reducing struct size 24 -> 6 bytes 2021-09-18 14:20:00 +03:00
bors
6cdd42f9f8 Auto merge of #88988 - Mark-Simulacrum:avoid-into-ok, r=nagisa
Avoid codegen for Result::into_ok in lang_start

This extra codegen seems to be the cause for the regressions in max-rss on #86034. While LLVM will certainly optimize the dead code away, avoiding it's generation in the first place seems good, particularly when it is so simple.

#86034 produced this [diff](https://gist.github.com/Mark-Simulacrum/95c7599883093af3b960c35ffadf4dab#file-86034-diff) for a simple `fn main() {}`. With this PR, that diff [becomes limited to just a few extra IR instructions](https://gist.github.com/Mark-Simulacrum/95c7599883093af3b960c35ffadf4dab#file-88988-from-pre-diff) -- no extra functions.

Note that these are pre-optimization; LLVM surely will eliminate this during optimization. However, that optimization can end up generating more work and bump memory usage, and this eliminates that.
2021-09-18 09:15:40 +00:00
DeveloperC286
05b01cd787 refactor: VecDeques IntoIter fields to private 2021-09-17 21:46:32 +01:00
Sachin Cherian
ec34aa61d6 modify std::os docs to be more consistent
> add intra doc links
> add a usage example for the os::windows module
2021-09-17 23:23:21 +05:30
The8472
57465d9c1b use AtomicU64::fetch_update instead of handrolled RMW-loop 2021-09-17 18:54:24 +02:00
Maybe Waffle
71e2eacc7b Stabilize Iterator::map_while 2021-09-17 19:42:46 +03:00
Guillaume Gomez
eb62779f2d
Rollup merge of #88954 - nbdd0121:panic3, r=oli-obk
Allow `panic!("{}", computed_str)` in const fn.

Special-case `panic!("{}", arg)` and translate it to `panic_display(&arg)`. `panic_display` will behave like `panic_any` in cosnt eval and behave like `panic!(format_args!("{}", arg))` in runtime.

This should bring Rust 2015 and 2021 to feature parity in terms of `const_panic`; and hopefully would unblock the stabilisation of #51999.

`@rustbot` modify labels: +T-compiler +T-libs +A-const-eval +A-const-fn

r? `@oli-obk`
2021-09-17 17:41:19 +02:00