Commit graph

5525 commits

Author SHA1 Message Date
Jacob Pratt
bce8621983
Stabilize const_panic 2021-10-04 02:33:33 -04:00
Manish Goregaokar
e021a10395
Rollup merge of #89472 - nagisa:nagisa/wsa-cleanup, r=dtolnay
Only register `WSACleanup` if `WSAStartup` is actually ever called

See https://github.com/rust-lang/rust/pull/85595

Fixes #85441
2021-10-03 23:13:24 -07:00
Manish Goregaokar
d236c04bbf
Rollup merge of #89401 - owengage:master, r=joshtriplett
Add truncate note to Vec::resize

A very minor addition to the `Vec::resize` documentation to point out the `truncate` method.
When I was searching for something matching `truncate` I managed to miss it, along with some colleagues. We later found it by chance. We did find `resize` however, so I was hoping to point it out in the documentation.
2021-10-03 23:13:22 -07:00
Manish Goregaokar
c167eeedf4
Rollup merge of #89138 - newpavlov:patch-2, r=dtolnay
Fix link in Ipv6Addr::to_ipv4 docs
2021-10-03 23:13:21 -07:00
Manish Goregaokar
5e66ba799b
Rollup merge of #88370 - Seppel3210:master, r=dtolnay
Add missing `# Panics` section to `Vec` method

namely `Vec::extend_from_within`
2021-10-03 23:13:20 -07:00
Manish Goregaokar
70d82e0a6e
Rollup merge of #88353 - jhpratt:stabilize-array-as-ref, r=joshtriplett
Partially stabilize `array_methods`

This stabilizes `<[T; N]>::as_slice` and `<[T; N]>::as_mut_slice`, which is forms part of the `array_methods` feature: #76118.

This also makes `<[T; N]>::as_slice` const due to its trivial nature.
2021-10-03 23:13:19 -07:00
Manish Goregaokar
e4d257e1d3
Rollup merge of #88305 - ijackson:exitstatus-debug, r=dtolnay
Manual Debug for Unix ExitCode ExitStatus ExitStatusError

These structs have misleading names.  An ExitStatus[Error] is actually a Unix wait status; an ExitCode is actually an exit status.  These misleading names appear in the `Debug` output.

The `Display` impls on Unix have been improved, but the `Debug` impls are still misleading, as reported in #74832.

Fix this by pretending that these internal structs are called `unix_exit_status` and `unix_wait_status` as applicable.  (We can't actually rename the structs because of the way that the cross-platform machinery works: the names are cross-platform.)

After this change, this program
```
#![feature(exit_status_error)]
fn main(){
    let x = std::process::Command::new("false").status().unwrap();
    dbg!(x.exit_ok());
    eprintln!("x={:?}",x);
}
```
produces this output
```
[src/main.rs:4] x.exit_ok() = Err(
    ExitStatusError(
        unix_wait_status(
            256,
        ),
    ),
)
x=ExitStatus(unix_wait_status(256))
```

Closes #74832
2021-10-03 23:13:18 -07:00
Manish Goregaokar
f2ec71fe74
Rollup merge of #88286 - LeSeulArtichaut:unnecessary-unsafe-block-std, r=dtolnay
Remove unnecessary unsafe block in `process_unix`

Because it's nested under this unsafe fn!

This block isn't detected as unnecessary because of a bug in the compiler: #88260.
2021-10-03 23:13:18 -07:00
Manish Goregaokar
e500f1c1e9
Rollup merge of #87910 - iago-lito:mark_unsafe_nonzero_arithmetics_as_const, r=joshtriplett
Mark unsafe methods NonZero*::unchecked_(add|mul) as const.

Now that https://github.com/rust-lang/rfcs/pull/3016 has landed, these two unstable `std` function can be marked `const`, according to this detail of #84186.
2021-10-03 23:13:17 -07:00
Manish Goregaokar
0f9e960241
Rollup merge of #87679 - ssomers:btree_comments, r=joshtriplett
BTree: refine some comments
2021-10-03 23:13:16 -07:00
Manish Goregaokar
287af0403a
Rollup merge of #86828 - lambinoo:67441-const-fn-copied-take-replace, r=joshtriplett
const fn for option copied, take & replace

Tracking issue: [#67441](https://github.com/rust-lang/rust/issues/67441)

Adding const fn for the copied, take and replace method of Option. Also adding necessary unit test.

It's my first contribution so I am pretty sure I don't know what I'm doing but there's a first for everything!
2021-10-03 23:13:16 -07:00
Manish Goregaokar
22714ed4e3
Rollup merge of #86434 - CDirkx:ipv6-benchmarking, r=joshtriplett
Add `Ipv6Addr::is_benchmarking`

This PR adds the unstable method `Ipv6Addr::is_benchmarking`. This method is added for parity with `Ipv4Addr::is_benchmarking`, and I intend to use it in a future rework of `Ipv6Addr::is_global` (edit: #86634) to more accurately follow the [IANA Special Address Registry](https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml) (like is done in `Ipv4Addr::is_global`).

With `Ipv6Addr::is_benchmarking` and `Ipv4Addr::is_benchmarking` now both existing, `IpAddr::is_benchmarking` is also added.
2021-10-03 23:13:15 -07:00
bors
d25de31a0e Auto merge of #89165 - jkugelman:read-to-end-overallocation, r=joshtriplett
Fix read_to_end to not grow an exact size buffer

If you know how much data to expect and use `Vec::with_capacity` to pre-allocate a buffer of that capacity, `Read::read_to_end` will still double its capacity. It needs some space to perform a read, even though that read ends up returning `0`.

It's a bummer to carefully pre-allocate 1GB to read a 1GB file into memory and end up using 2GB.

This fixes that behavior by special casing a full buffer and reading into a small "probe" buffer instead. If that read returns `0` then it's confirmed that the buffer was the perfect size. If it doesn't, the probe buffer is appended to the normal buffer and the read loop continues.

Fixing this allows several workarounds in the standard library to be removed:

- `Take` no longer needs to override `Read::read_to_end`.
- The `reservation_size` callback that allowed `Take` to inhibit the previous over-allocation behavior isn't needed.
- `fs::read` doesn't need to reserve an extra byte in `initial_buffer_size`.

Curiously, there was a unit test that specifically checked that `Read::read_to_end` *does* over-allocate. I removed that test, too.
2021-10-04 04:44:56 +00:00
Josh Triplett
199b33f0d7
Use a test value that doesn't depend on the handling of even/odd rounding 2021-10-03 20:15:12 -07:00
Fabian Wolff
e3996ffcb6 Fix Lower/UpperExp formatting for integers and precision zero 2021-10-03 23:05:03 +02:00
Benoît du Garreau
4846fd92c0 Revert suggested use of unwrap_or 2021-10-03 22:56:34 +02:00
Alphyr
70e55a8938
Apply suggestions
Co-authored-by: kennytm <kennytm@gmail.com>
2021-10-03 22:44:07 +02:00
bors
08759c691e Auto merge of #88086 - ssomers:btree_clone_testing, r=dtolnay
BTree: toughen panicky test of clone()

Test did not cover the second half of `clone_subtree` and why this clones key & value first.
2021-10-03 16:22:37 +00:00
Orson Peters
6dd6e7c002 Added tracking issue numbers for int_abs_diff. 2021-10-03 17:44:07 +02:00
Caio
91ad91efb6 Skip platforms without unwinding support 2021-10-03 12:25:23 -03:00
bors
5051904d66 Auto merge of #87870 - WaffleLapkin:pub_split_at_unchecked, r=dtolnay
Make `<[T]>::split_at_unchecked` and `<[T]>::split_at_mut_unchecked` public

The methods were originally added in https://github.com/rust-lang/rust/pull/75936 (30dc32b10e), but for some reason as private. Nevertheless, the methods have documentation and even a [tracking issue](https://github.com/rust-lang/rust/issues/76014).

It's very weird to have a tracking issue for private methods and these methods may be useful outside of the standard library. As such, this PR makes the methods public.
2021-10-03 13:41:52 +00:00
bors
4479cb82e5 Auto merge of #89459 - tspiteri:idiv-overflow-bitand, r=kennytm
Use bitand when checking for signed integer division overflow

For `self == Self::MIN && rhs == -1`, LLVM does not realize that this is the same check made by `self / rhs`, so the code generated may have some unnecessary duplication. For `(self == Self::MIN) & (rhs == -1)`, LLVM realizes it is the same check.
2021-10-03 10:34:57 +00:00
Hirochika Matsumoto
3818981ca1 Practice diagnostic message convention 2021-10-03 16:16:28 +09:00
bors
c24c9067ee Auto merge of #88060 - TennyZhuang:optimize-vec-retain, r=dtolnay
Optimize unnecessary check in Vec::retain

The function `vec::Vec::retain` only have two stages:

1. Nothing was deleted.
2. Some elements were deleted.

Here is an unnecessary check `if g.deleted_cnt > 0` in the loop, and it's difficult for compiler to optimize it. I split the loop into two stages manully and keep the code clean using const generics.

I write a special but common bench case for this optimization. I call retain on vec but keep all elements.

Before and after this optimization:

```
test vec::bench_retain_whole_100000                      ... bench:      84,803 ns/iter (+/- 17,314)
```

```
test vec::bench_retain_whole_100000                      ... bench:      42,638 ns/iter (+/- 16,910)
```

The result is expected, there are two `if`s before the optimization and one `if` after.
2021-10-03 06:24:06 +00:00
Cameron Steffen
eec856bfbc Make diangostic item names consistent 2021-10-02 19:38:19 -05:00
Simonas Kazlauskas
5b4873a759 Run the #85441 regression test on MSVC only
On MinGW toolchains the various features (such as function sections)
necessary to eliminate dead function references are disabled due to
various bugs. This means that the windows sockets library will most
likely remain linked to any mingw toolchain built program that also
utilizes libstd.

That said, I made an attempt to also enable `function-sections` and
`--gc-sections` during my experiments, but the symbol references
remained, sadly.
2021-10-02 22:16:23 +03:00
Christiaan Dirkx
9a6f2e655a Only register WSACleanup if WSAStartup is actually ever called 2021-10-02 22:08:35 +03:00
David Carlier
98dde56eb1 haiku thread affinity build fix 2021-10-02 13:24:30 +01:00
Trevor Spiteri
1139ee32aa Use bitand when checking for signed integer division overflow
For `self == Self::MIN && rhs == -1`, LLVM does not realize that this is the
same check made by `self / rhs`, so the code generated may have some unnecessary
duplication. For `(self == Self::MIN) & (rhs == -1)`, LLVM realizes it is the
same check.
2021-10-02 12:16:08 +02:00
bors
a8387aef8c Auto merge of #89450 - usbalbin:const_try_revert, r=oli-obk
Revert #86853

Should fix issue found in #89432
2021-10-02 07:41:25 +00:00
Albin Hedman
81bb5a54c3
Revert "Auto merge of #86853 - usbalbin:const_try, r=oli-obk"
This reverts commit c6007fdc70, reversing
changes made to 69c1c6a173.
2021-10-02 00:07:48 +02:00
Josh Stone
d6fde80cb4 Include the length in BTree hashes
This change makes it consistent with `Hash` for all other collections.
2021-10-01 12:29:09 -07:00
Fabian Wolff
65ef265c12 Call libc::sigaction() only on Android 2021-10-01 21:22:18 +02:00
Sean Young
fa4072f7d3 path.push() should work as expected on windows verbatim paths 2021-10-01 19:54:57 +01:00
pierwill
2a5dcd5890 fix: edit description of "prefix-free" 2021-10-01 13:18:06 -05:00
chrismit3s
1a796441f5 Clarify a sentence in the documentation of Vec (#84488) 2021-10-01 20:07:36 +02:00
pierwill
f531b8122e docs: std:#️⃣:Hash should ensure prefix-free data
Closes #89429
2021-10-01 12:41:22 -05:00
Benoît du Garreau
9faf621355 Add methods to add/sub uX to/from iX 2021-10-01 19:09:52 +02:00
Benoît du Garreau
b5dd5227ee Fix doc test 2021-10-01 19:08:14 +02:00
Alphyr
ab9f8a0b59 Apply suggestion for overflowing_add_signed
Co-authored-by: kennytm <kennytm@gmail.com>
2021-10-01 19:08:13 +02:00
Benoît du Garreau
fe11483afa Add functions to add unsigned and signed integers 2021-10-01 19:08:13 +02:00
bors
ed937594d3 Auto merge of #89403 - camsteffen:fmt-unsafe-private, r=Mark-Simulacrum
Add private arg to fmt::UnsafeArg

As discussed [here](https://github.com/rust-lang/rust/pull/89139#discussion_r719467357)

r? `@Mark-Simulacrum`
2021-10-01 12:08:35 +00:00
Manish Goregaokar
fccfc981d6
Rollup merge of #89306 - devnexen:haiku_ncpus, r=nagisa
thread: implements available_concurrency on haiku
2021-09-30 18:05:24 -07:00
Manish Goregaokar
7b40d4240e
Rollup merge of #89303 - guswynn:std_suspend, r=dtolnay
Add `#[must_not_suspend]` to some types in std

I am not sure what else should have it? `Ref`?
2021-09-30 18:05:23 -07:00
Matthew Jasper
051d5b0118 Fix standard library for min_specialization changes 2021-09-30 21:42:41 +01:00
The8472
ffd7ade203 fix issues pointed out in review 2021-09-30 21:23:30 +02:00
the8472
6654a0bbdc from review: code style
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2021-09-30 21:23:30 +02:00
The8472
2c6e67105e implement advance_(back_)_by on more iterators 2021-09-30 21:23:28 +02:00
Cameron Steffen
f5e4f78eb7 Add private arg to fmt::UnsafeArg 2021-09-30 12:32:05 -05:00
Samuel E. Moelius III
32b6ac5b44 Check allow_unstable before checking environment variables 2021-09-30 12:57:34 -04:00
Owen Gage
e8e7f6e05c Add truncate note to Vec::resize 2021-09-30 17:21:03 +01:00
Tyler Hart
35b0015b09
Improve wording of map_or_else docs
Changes doc text to refer to the "default" parameter as the "default"
function.
2021-09-30 11:12:09 -04:00
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
bors
c6007fdc70 Auto merge of #86853 - usbalbin:const_try, r=oli-obk
Constify ?-operator for Result and Option

Try to make `?`-operator usable in `const fn` with `Result` and `Option`, see #74935 . Note that the try-operator itself was constified in #87237.

TODO
* [x] Add tests for const T -> T conversions
* [x] cleanup commits
* [x] Remove `#![allow(incomplete_features)]`
* [?] Await decision in #86808 - I'm not sure
* [x] Await support for parsing `~const` in bootstrapping compiler
* [x] Tracking issue(s)? - #88674
2021-09-30 10:35:24 +00:00
Eric Huss
8f9f3aa04d
Rollup merge of #89335 - mbrubeck:range-is-sorted, r=cuviper
Optimize is_sorted for Range and RangeInclusive

The [`Step`] trait guarantees that `Range<impl Step>` yields items in sorted order.  We can override `Iterator::is_sorted` based on this guarantee, as we already do for `Iterator::min` and `max`.

Thank you to ``@fiveseven-lambda`` who pointed this out [on the Rust Users Forum](https://users.rust-lang.org/t/is-sorted-method-in-impl-iterator-for-range/64717).

[`Step`]: https://doc.rust-lang.org/stable/std/iter/trait.Step.html
2021-09-29 19:33:42 -07:00
Eric Huss
e392f5d90d
Rollup merge of #89315 - et342:cstr_from_vec_unchecked_doc, r=yaahc
Clarify that `CString::from_vec_unchecked` appends 0 byte.
2021-09-29 19:33:41 -07:00
Eric Huss
e24f52294a
Rollup merge of #88412 - mdsn:slice-sort-safety, r=dtolnay
Remove ignore-tidy-undocumented-unsafe from core::slice::sort

Write down the missing safety arguments to be able to remove `ignore-tidy-undocumented-unsafe` from `core::slice::sort`.

Helps with #66219

``@rustbot`` label C-cleanup T-libs
2021-09-29 19:33:35 -07:00
Samuel E. Moelius III
a6738c7231 Add tests 2021-09-29 21:51:59 -04:00
Samuel E. Moelius III
fa23d4fe93 Implement #85440 2021-09-29 21:51:46 -04:00
bors
11491938f8 Auto merge of #89011 - bjorn3:restructure_rt, r=dtolnay
Restructure std::rt

These changes should reduce binary size slightly while at the same slightly improving performance of startup, thread spawning and `std:🧵:current()`. I haven't verified if the compiler is able to optimize some of these cases already, but at least for some others the compiler is unable to do these optimizations as they slightly change behavior in cases where program startup would crash anyway by omitting a backtrace and panic location.

I can remove 6f6bb16 if preferred.
2021-09-29 17:58:08 +00:00
David Tolnay
e3e5ae91d0
Clean up unneeded explicit pointer cast
The reference automatically coerces to a pointer. Writing an explicit
cast here is slightly misleading because that's most commonly used when
a pointer needs to be converted from one pointer type to another, e.g.
`*const c_void` to `*const sigaction` or vice versa.
2021-09-28 21:22:37 -07:00
Gus Wynn
cb8e83caeb ref/refmut 2021-09-28 17:57:08 -07:00
Matt Brubeck
830ecbd96c Optimize is_sorted for Range and RangeInclusive
The `Step` trait guarantees that `Range<impl Step>` yields items in
sorted order.  We can override the `Iterator::is_sorted` method based on
this guarantee, as we already do for `Iterator::min` and `max`.
2021-09-28 12:50:38 -07:00
Guillaume Gomez
e601554dc0
Rollup merge of #89235 - yaahc:junit-formatting, r=kennytm
make junit output more consistent with default format

The default format of libtest includes new-lines between each section to ensure the label output from cargo is on it's own line

<pre><font color="#A1B56C"><b>❯</b></font> <font color="#A1B56C">cargo</font><font color="#D8D8D8"> </font><font color="#A1B56C">test</font>
<font color="#A1B56C"><b>   Compiling</b></font> test-test v0.1.0 (/home/jlusby/tmp/test-test)
<font color="#A1B56C"><b>    Finished</b></font> test [unoptimized + debuginfo] target(s) in 0.59s
<font color="#A1B56C"><b>     Running</b></font> unittests (target/debug/deps/test_test-639f369234319c09)

running 1 test
test tests::it_works ... <font color="#A1B56C">ok</font>

test result: <font color="#A1B56C">ok</font>. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

<font color="#A1B56C"><b>   Doc-tests</b></font> test-test

running 0 tests

test result: <font color="#A1B56C">ok</font>. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

</pre>

But when the junit outputter was added to libtest these newlines were omitted, resulting in some "fun" output when run via cargo.

Note the `Doc-tests` text at the end of the first line of xml.

<pre><font color="#A1B56C"><b>❯</b></font> <font color="#A1B56C">cargo</font><font color="#D8D8D8"> </font><font color="#A1B56C">test</font><font color="#D8D8D8"> </font><font color="#A1B56C">--</font><font color="#D8D8D8"> </font><font color="#A1B56C">-Zunstable-options</font><font color="#D8D8D8"> </font><font color="#A1B56C">--format</font><font color="#D8D8D8"> </font><font color="#A1B56C">junit</font>
<font color="#A1B56C"><b>    Finished</b></font> test [unoptimized + debuginfo] target(s) in 0.00s
<font color="#A1B56C"><b>     Running</b></font> unittests (target/debug/deps/test_test-639f369234319c09)
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;testsuites&gt;&lt;testsuite name=&quot;test&quot; package=&quot;test&quot; id=&quot;0&quot; errors=&quot;0&quot; failures=&quot;0&quot; tests=&quot;1&quot; skipped=&quot;0&quot; &gt;&lt;testcase classname=&quot;tests&quot; name=&quot;it_works&quot; time=&quot;0&quot;/&gt;&lt;system-out/&gt;&lt;system-err/&gt;&lt;/testsuite&gt;&lt;/testsuites&gt;<font color="#A1B56C"><b>   Doc-tests</b></font> test-test
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;testsuites&gt;&lt;testsuite name=&quot;test&quot; package=&quot;test&quot; id=&quot;0&quot; errors=&quot;0&quot; failures=&quot;0&quot; tests=&quot;0&quot; skipped=&quot;0&quot; &gt;&lt;system-out/&gt;&lt;system-err/&gt;&lt;/testsuite&gt;&lt;/testsuites&gt;

</pre>

After this PR the junit output includes the same style of newlines as the pretty format

<pre><font color="#A1B56C"><b>❯</b></font> <font color="#A1B56C">cargo</font><font color="#D8D8D8"> </font><font color="#A1B56C">test</font><font color="#D8D8D8"> </font><font color="#A1B56C">--</font><font color="#D8D8D8"> </font><font color="#A1B56C">-Zunstable-options</font><font color="#D8D8D8"> </font><font color="#A1B56C">--format</font><font color="#D8D8D8"> </font><font color="#A1B56C">junit</font>
<font color="#A1B56C"><b>   Compiling</b></font> test-test v0.1.0 (/home/jlusby/tmp/test-test)
<font color="#A1B56C"><b>    Finished</b></font> test [unoptimized + debuginfo] target(s) in 0.39s
<font color="#A1B56C"><b>     Running</b></font> unittests (target/debug/deps/test_test-42c2320bb9450c69)

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;testsuites&gt;&lt;testsuite name=&quot;test&quot; package=&quot;test&quot; id=&quot;0&quot; errors=&quot;0&quot; failures=&quot;0&quot; tests=&quot;1&quot; skipped=&quot;0&quot; &gt;&lt;testcase classname=&quot;tests&quot; name=&quot;it_works&quot; time=&quot;0&quot;/&gt;&lt;system-out/&gt;&lt;system-err/&gt;&lt;/testsuite&gt;&lt;/testsuites&gt;

<font color="#A1B56C"><b>   Doc-tests</b></font> test-test

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;testsuites&gt;&lt;testsuite name=&quot;test&quot; package=&quot;test&quot; id=&quot;0&quot; errors=&quot;0&quot; failures=&quot;0&quot; tests=&quot;0&quot; skipped=&quot;0&quot; &gt;&lt;system-out/&gt;&lt;system-err/&gt;&lt;/testsuite&gt;&lt;/testsuites&gt;

</pre>
2021-09-28 20:00:15 +02:00
Yoshua Wuyts
6cc91cb3d8 Rename std:🧵:available_onccurrency to std:🧵:available_parallelism 2021-09-28 14:59:33 +02:00
bors
1d71ba8623 Auto merge of #86191 - kawadakk:release-add-solid-support, r=nagisa,estebank,m-ou-se,
Add SOLID targets

This PR introduces new tier 3 targets for [SOLID](https://www.kmckk.co.jp/eng/SOLID/) embedded development platform by Kyoto Microcomputer Co., Ltd.

|          Target name           | `target_arch` | `target_vendor` | `target_os`  |
|--------------------------------|---------------|-----------------|--------------|
| `aarch64-kmc-solid_asp3`       | `aarch64`     | `kmc`           | `solid_asp3` |
| `armv7a-kmc-solid_asp3-eabi`   | `arm`         | `kmc`           | `solid_asp3` |
| `armv7a-kmc-solid_asp3-eabihf` | `arm`         | `kmc`           | `solid_asp3` |

## Related PRs

- [ ] `libc`: https://github.com/rust-lang/libc/pull/2227
- [ ] `cc`: https://github.com/alexcrichton/cc-rs/pull/609

## Non-blocking Issues

- [ ] The target kernel can support `Thread::unpark` directly, but this property is not utilized because the underlying kernel feature is used to implement `Condvar` and it's unclear whether `std` should guarantee that parking tokens are not clobbered by other synchronization primitives.
- [ ] The rustc book: The page title "\*-kmc-solid-\*" shows up as "-kmc-solid-" in TOC

## Tier 3 Target Policy

As tier 3 targets, the new targets are required to adhere to [the tier 3 target policy](https://doc.rust-lang.org/nightly/rustc/target-tier-policy.html#tier-3-target-policy) requirements. This section quotes each requirement in entirety and describes how they are met.

> - A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

See [`src/doc/rustc/src/platform-support/kmc-solid.md`](https://github.com/kawadakk/rust/blob/release-add-solid-support/src/doc/rustc/src/platform-support/kmc-solid.md).

> - Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.
>     - Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.

The new target names follow this format: `$ARCH-$VENDOR-$OS-$ABI`, which is already adopted by most existing targets. `$ARCH` and `$ABI` follow the convention: `aarch64-*` for AArch64, `armv7a-*-eabi` for Armv7-A with EABI. `$OS` is used to distinguish multiple variations of the platform in a somewhat similar way to the Apple targets, though we are only adding one variation in this PR. `$VENDOR` denotes the platform vendor name similarly to the Apple, Solaris, SGX, and VxWorks targets.

`$OS` corresponds to the value of `target_os` and takes the format `solid-$KERNEL`. The inclusion of a hyphen prevents unique decomposition of target names, though the mapping between target names and target attributes isn't trivial in the first place, e.g., because of the Android targets.

More targets may be added later, as we support other base kernels (there are at least three at the point of writing) and are interested in supporting other processor architectures in the future.

> - Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
>     - The target must not introduce license incompatibilities.
>     - Anything added to the Rust repository must be under the standard Rust license (`MIT OR Apache-2.0`).
>     - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the `tidy` tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.
>     - If the target supports building host tools (such as `rustc` or `cargo`), those host tools must not depend on proprietary (non-FOSS) libraries, other than ordinary runtime libraries supplied by the platform and commonly used by other binaries built for the target. For instance, `rustc` built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.
>     - Targets should not require proprietary (non-FOSS) components to link a functional binary or library.
>     - "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are *not* limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.

We intend to make the contribution fully available under the standard Rust license with no additional legal restrictions whatsoever. This PR does not introduce any new dependency less permissive than the Rust license policy, and we are willing to ensure this doesn't happen for future contributions regarding the new targets.

The new targets don't support building host tools.

Although the new targets use a platform-provided C compiler toolchain, it can be substituted by [GNU Arm Embedded Toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm) for testing purposes.

> - Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (`core` for most targets, `alloc` for targets that can support dynamic memory allocation, `std` for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

Most features are implemented. The following features are not implemented due to the lack of native support:

- `fs::File::{file_attr, truncate, duplicate, set_permissions}`
- `fs::{symlink, link, canonicalize}`
- Process creation
- Command-line arguments

~~Networking is not implemented yet, and we intend to add it as soon as it's ready.~~
Edit (2021-07-07): Networking is now implemented.

Backtrace generation is not really a good fit for embedded targets, so it's intentionally left unimplemented. Unwinding is functional, however.

> - The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running tests (even if they do not pass), the documentation must explain how to run tests for the target, using emulation if possible or dedicated hardware if necessary.

See [`src/doc/rustc/src/platform-support/kmc-solid.md`](https://github.com/kawadakk/rust/blob/release-add-solid-support/src/doc/rustc/src/platform-support/kmc-solid.md). Running tests is not supported.

> - Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.
>     - This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.
> - Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via ``@`)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.
>     - Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.
> - Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.
>     - In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.

We acknowledge these requirements and intend to ensure they are met.

There are no closely related targets at the moment.
2021-09-28 11:50:33 +00:00
Tomoaki Kawada
da9ca41c31 Add SOLID targets
SOLID[1] is an embedded development platform provided by Kyoto
Microcomputer Co., Ltd. This commit introduces a basic Tier 3 support
for SOLID.

# New Targets

The following targets are added:

 - `aarch64-kmc-solid_asp3`
 - `armv7a-kmc-solid_asp3-eabi`
 - `armv7a-kmc-solid_asp3-eabihf`

SOLID's target software system can be divided into two parts: an
RTOS kernel, which is responsible for threading and synchronization,
and Core Services, which provides filesystems, networking, and other
things. The RTOS kernel is a μITRON4.0[2][3]-derived kernel based on
the open-source TOPPERS RTOS kernels[4]. For uniprocessor systems
(more precisely, systems where only one processor core is allocated for
SOLID), this will be the TOPPERS/ASP3 kernel. As μITRON is
traditionally only specified at the source-code level, the ABI is
unique to each implementation, which is why `asp3` is included in the
target names.

More targets could be added later, as we support other base kernels
(there are at least three at the point of writing) and are interested
in supporting other processor architectures in the future.

# C Compiler

Although SOLID provides its own supported C/C++ build toolchain, GNU Arm
Embedded Toolchain seems to work for the purpose of building Rust.

# Unresolved Questions

A μITRON4 kernel can support `Thread::unpark` natively, but it's not
used by this commit's implementation because the underlying kernel
feature is also used to implement `Condvar`, and it's unclear whether
`std` should guarantee that parking tokens are not clobbered by other
synchronization primitives.

# Unsupported or Unimplemented Features

Most features are implemented. The following features are not
implemented due to the lack of native support:

- `fs::File::{file_attr, truncate, duplicate, set_permissions}`
- `fs::{symlink, link, canonicalize}`
- Process creation
- Command-line arguments

Backtrace generation is not really a good fit for embedded targets, so
it's intentionally left unimplemented. Unwinding is functional, however.

## Dynamic Linking

Dynamic linking is not supported. The target platform supports dynamic
linking, but enabling this in Rust causes several problems.

 - The linker invocation used to build the shared object of `std` is
   too long for the platform-provided linker to handle.

 - A linker script with specific requirements is required for the
   compiled shared object to be actually loadable.

As such, we decided to disable dynamic linking for now. Regardless, the
users can try to create shared objects by manually invoking the linker.

## Executable

Building an executable is not supported as the notion of "executable
files" isn't well-defined for these targets.

[1] https://solid.kmckk.com/SOLID/
[2] http://ertl.jp/ITRON/SPEC/mitron4-e.html
[3] https://en.wikipedia.org/wiki/ITRON_project
[4] https://toppers.jp/
2021-09-28 11:31:47 +09:00
et342
dd0b5f4815
Clarify that CString::from_vec_unchecked appends 0 byte. 2021-09-28 05:51:52 +05:00
Jane Lusby
0911069feb
Apply suggestions from code review
Co-authored-by: kennytm <kennytm@gmail.com>
2021-09-27 14:50:35 -07:00
David Carlier
5d4048b66f thread: implements available_concurrency on haiku 2021-09-27 18:51:52 +01:00
Gus Wynn
0f9c349834 lock types 2021-09-27 08:43:30 -07:00
bors
c81c3ea321 Auto merge of #89145 - rusticstuff:bump_stdarch, r=kennytm
Update stdarch submodule

This is mainly to fix the critical issue of aarch64 store intrinsics overwriting additional memory, see https://github.com/rust-lang/stdarch/issues/1220

Changes:
* aarch64/armv7: additional vld1/vst1 intrinsics + perf fixes for existing ones
  * https://github.com/rust-lang/stdarch/pull/1205
  * https://github.com/rust-lang/stdarch/pull/1207
  * https://github.com/rust-lang/stdarch/pull/1216
* armv7: Make FMA work with vfpv4 and optimize
  * https://github.com/rust-lang/stdarch/pull/1219
* Non-visible changes to the testing framework
  * https://github.com/rust-lang/stdarch/pull/1208
  * https://github.com/rust-lang/stdarch/pull/1211
  * https://github.com/rust-lang/stdarch/pull/1213
  * https://github.com/rust-lang/stdarch/pull/1215
  * https://github.com/rust-lang/stdarch/pull/1218
2021-09-27 02:11:52 +00:00
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
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
DeveloperC
f83853e342 refactor: VecDeques PairSlices fields to private 2021-09-25 13:09:17 +01: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
Jane Lusby
7779eb74c8 make junit output more consistent with default format 2021-09-24 14:45:09 -07: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
Aman Arora
994793faab PR fixup 2021-09-22 05:17:30 -04:00
John Kugelman
9b9c24ec7f Fix read_to_end to not grow an exact size buffer
If you know how much data to expect and use `Vec::with_capacity` to
pre-allocate a buffer of that capacity, `Read::read_to_end` will still
double its capacity. It needs some space to perform a read, even though
that read ends up returning `0`.

It's a bummer to carefully pre-allocate 1GB to read a 1GB file into
memory and end up using 2GB.

This fixes that behavior by special casing a full buffer and reading
into a small "probe" buffer instead. If that read returns `0` then it's
confirmed that the buffer was the perfect size. If it doesn't, the probe
buffer is appended to the normal buffer and the read loop continues.

Fixing this allows several workarounds in the standard library to be
removed:

- `Take` no longer needs to override `Read::read_to_end`.
- The `reservation_size` callback that allowed `Take` to inhibit the
  previous over-allocation behavior isn't needed.
- `fs::read` doesn't need to reserve an extra byte in
  `initial_buffer_size`.

Curiously, there was a unit test that specifically checked that
`Read::read_to_end` *does* over-allocate. I removed that test, too.
2021-09-22 00:54:27 -04: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
Hans Kratz
1afb5374d0 Update stdarch submodule
This mainly fixes the critical issue of aarch64 store intrinsics
overwriting additional memory, see
https://github.com/rust-lang/stdarch/issues/1220

Other changes:
* aarch64/armv7: additional vld1/vst1 intrinsics + perf fixes for existing ones
* armv7: Make FMA work with vfpv4
* Non-visible changes to the testing framework
2021-09-21 11:24:08 +02:00
Aman Arora
099a34cd95 2229: Annotate stdlib with insignficant dtors 2021-09-21 04:06:00 -04: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
Artyom Pavlov
a993d7d963
Fix link in Ipv6Addr::to_ipv4 docs 2021-09-21 05:36:03 +00:00
Iago-lito
74c4c0172a Mark unsafe NonZero*::unchecked_(add|mul) as const 2021-09-20 12:01:05 +02: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
Guillaume Gomez
723d27934b
Rollup merge of #88953 - joshtriplett:chown, r=dtolnay
Add chown functions to std::os::unix::fs to change the owner and group of files

This is a straightforward wrapper that uses the existing helpers for C
string handling and errno handling.

Having this available is convenient for UNIX utility programs written in
Rust, and avoids having to call unsafe functions like `libc::chown`
directly and handle errors manually, in a program that may otherwise be
entirely safe code.

In addition, these functions provide a more Rustic interface by
accepting appropriate traits and using `None` rather than `-1`.
2021-09-17 17:41:18 +02:00
John Paul Adrian Glaubitz
2cef5d8091 library/std/env: Add 'm68k' to comment on ARCH constant 2021-09-17 15:07:14 +00:00
John Paul Adrian Glaubitz
5e56778dc8 libstd: Add m68k for raw type definitions on Linux 2021-09-17 15:07:14 +00:00
Yuki Okushi
5d14396ed0
Rollup merge of #88887 - fee1-dead:const-deref, r=oli-obk
Const Deref

Implements `const Deref`/`const DerefMut` for `&mut T`, `&T`, `Cow<'_, B>` and `ManuallyDrop<T>`
2021-09-17 14:09:48 +09:00
Yuki Okushi
0f06e36603
Rollup merge of #88339 - piegamesde:master, r=joshtriplett
Add TcpListener::into_incoming and IntoIncoming

The `incoming` method is really useful, however for some use cases the borrow
this introduces is needlessly restricting. Thus, an owned variant is added.

r? ``@joshtriplett``
2021-09-17 14:09:45 +09:00
Gary Guo
be5a5b70b4 Fix missing no_global_oom_handling cfg-gating 2021-09-17 03:53:18 +01:00
The8472
ca2d2fa283 Don't inline OnceCell initialization closures 2021-09-17 00:24:36 +02:00
TennyZhuang
3839ca9953 Optimize unnecessary check in Vec::retain
Co-authored-by: oxalica <oxalicc@pm.me>
2021-09-17 02:55:12 +08:00
TennyZhuang
20e14e4030 Add benchmark for Vec::retain 2021-09-17 02:55:12 +08:00
Manish Goregaokar
d9fa3561b6
Rollup merge of #89009 - tatami4:master, r=Mark-Simulacrum
Fix typo in `break` docs
2021-09-16 10:57:25 -07:00
Manish Goregaokar
84d384c8c1
Rollup merge of #88986 - hargoniX:master, r=Mark-Simulacrum
Update the backtrace crate

https://github.com/rust-lang/backtrace-rs/pull/437 fixed backtraces in
OpenBSD -> update it here as well so OpenBSD Rust code can produce
proper backtraces.
2021-09-16 10:57:24 -07:00
Manish Goregaokar
06dbc284a8
Rollup merge of #88976 - notriddle:notriddle/cow-from-cstr-docs, r=Mark-Simulacrum
Clean up and add doc comments for CStr

CC #51430
2021-09-16 10:57:21 -07:00
Manish Goregaokar
5b6285e370
Rollup merge of #88928 - lefth:master, r=Mark-Simulacrum
Document the closure arguments for `reduce`.

See issue #88927.
2021-09-16 10:57:20 -07:00
The8472
2b512cc329 fix potential race in AtomicU64 time monotonizer 2021-09-16 18:32:28 +02:00
bjorn3
37608c7c50 Rustfmt 2021-09-16 15:54:12 +02:00
bjorn3
5e7f641a32 Merge two THREAD_INFO.with and following RefCell borrow
This is a bit faster
2021-09-16 15:24:53 +02:00
bjorn3
cb14269145 Replace a couple of asserts with rtassert! in rt code
This replaces a couple of panic locations with hard aborts. The panics
can't be catched by the user anyway in these locations.
2021-09-16 15:20:44 +02:00
bjorn3
1ad44b23d1 Remove unused function 2021-09-16 14:58:36 +02:00
bjorn3
a8bb3bcd38 Use const {} for the THREAD_INFO thread local
This makes accesses to it cheaper
2021-09-16 14:55:15 +02:00
bjorn3
f78cd44602 Optimize ThreadInfo::with
The RefCell is now borrowed exactly once. In addition a code sequence
that contains an unwrap that is guaranteed to never panic at runtime is
replaced with get_or_insert_with, which makes the intended behavior
clearer and will not emit code to panic even without optimizations.
2021-09-16 14:48:33 +02:00