Commit graph

1625 commits

Author SHA1 Message Date
Christiaan Dirkx
5b0908587e Introduce sys_common::rt::rterr! 2021-05-19 15:01:47 +02:00
bors
9f8012e3aa Auto merge of #85458 - jackh726:rollup-zvvybmt, r=jackh726
Rollup of 8 pull requests

Successful merges:

 - #83366 (Stabilize extended_key_value_attributes)
 - #83767 (Fix v0 symbol mangling bug)
 - #84883 (compiletest: "fix" FileCheck with --allow-unused-prefixes)
 - #85274 (Only pass --[no-]gc-sections if linker is GNU ld.)
 - #85297 (bootstrap: build cargo only if requested in tools)
 - #85396 (rustdoc: restore header sizes)
 - #85425 (Fix must_use on `Option::is_none`)
 - #85438 (Fix escape handling)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-19 04:44:09 +00:00
Jack Huey
3c99dcd82d
Rollup merge of #83366 - jyn514:stabilize-key-value-attrs, r=petrochenkov
Stabilize extended_key_value_attributes

Closes https://github.com/rust-lang/rust/issues/44732. Closes https://github.com/rust-lang/rust/issues/78835. Closes https://github.com/rust-lang/rust/issues/82768 (by making it irrelevant).

 # Stabilization report

 ## Summary

This stabilizes using macro expansion in key-value attributes, like so:

 ```rust
 #[doc = include_str!("my_doc.md")]
 struct S;

 #[path = concat!(env!("OUT_DIR"), "/generated.rs")]
 mod m;
 ```

See Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455)
for alternatives that were considered and rejected ("why accept no more and no less?")

This has been available on nightly since 1.50 with no major issues.

## Notes

### Accepted syntax

The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`).  Note that decorators and the like may be able to observe other expression forms.

### Expansion ordering

Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input.

There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work).

## Test cases

 - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs
 - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs

The feature has also been dogfooded extensively in the compiler and
standard library:

- https://github.com/rust-lang/rust/pull/83329
- https://github.com/rust-lang/rust/pull/83230
- https://github.com/rust-lang/rust/pull/82641
- https://github.com/rust-lang/rust/pull/80534

## Implementation history

- Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412
- Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121
- Preliminary work to restrict expansion that would conflict with this
feature: https://github.com/rust-lang/rust/pull/77271
- Initial implementation: https://github.com/rust-lang/rust/pull/78837
- Fix for an ICE: https://github.com/rust-lang/rust/pull/80563

## Unresolved Questions

~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~

 ## Additional Information

 There are two workarounds that have a similar effect for `#[doc]`
attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons:

```rust
macro_rules! forward_inner_docs {
    ($e:expr => $i:item) => {
        #[doc = $e]
        $i
    };
}

forward_inner_docs!(include_str!("lib.rs") => struct S {});
```

This also works for other attributes (like `#[path = concat!(...)]`).
The other is to use `doc(include)`:

```rust
 #![feature(external_doc)]
 #[doc(include = "lib.rs")]
 struct S {}
```

The first works, but is non-trivial for people to discover, and
difficult to read and maintain. The second is a strange special-case for
a particular use of the macro. This generalizes it to work for any use
case, not just including files.

I plan to remove `doc(include)` when this is stabilized
(https://github.com/rust-lang/rust/pull/82539). The `forward_inner_docs`
workaround will still compile without warnings, but I expect it to be
used less once it's no longer necessary.
2021-05-18 22:35:54 -04:00
bors
3d31363338 Auto merge of #85176 - a1phyr:impl_clone_from, r=yaahc
Override `clone_from` for some types

Override `clone_from` method of the `Clone` trait for:
- `cell::RefCell`
- `cmp::Reverse`
- `io::Cursor`
- `mem::ManuallyDrop`

This can bring performance improvements.
2021-05-19 02:17:41 +00:00
Alex Crichton
641d3b09f4 std: Attempt again to inline thread-local-init across crates
Issue #25088 has been part of `thread_local!` for quite some time now.
Historical attempts have been made to add `#[inline]` to `__getit`
in #43931, #50252, and #59720, but these attempts ended up not landing
at the time due to segfaults on Windows.

In the interim though with `const`-initialized thread locals AFAIK this
is the only remaining bug which is why you might want to use
`#[thread_local]` over `thread_local!`. As a result I figured it was
time to resubmit this and see how it fares on CI and if I can help
debugging any issues that crop up.

Closes #25088
2021-05-18 11:22:04 -07:00
Jorge Ferreira
d13745d99b
fix typo 2021-05-18 17:05:40 +01:00
Mateusz Gacek
d730cc6646 Add diagnostic item to CStr 2021-05-18 15:45:30 +02:00
bors
25a277f03d Auto merge of #82973 - ijackson:exitstatuserror, r=yaahc
Provide ExitStatusError

Closes #73125

In MR #81452 "Add #[must_use] to [...] process::ExitStatus" we concluded that the existing arrangements in are too awkward so adding that `#[must_use]` is blocked on improving the ergonomics.

I wrote a mini-RFC-style discusion of the approach in https://github.com/rust-lang/rust/issues/73125#issuecomment-771092741
2021-05-18 08:01:32 +00:00
Joshua Nelson
e48b6b4599 Stabilize extended_key_value_attributes
# Stabilization report

 ## Summary

This stabilizes using macro expansion in key-value attributes, like so:

 ```rust
 #[doc = include_str!("my_doc.md")]
 struct S;

 #[path = concat!(env!("OUT_DIR"), "/generated.rs")]
 mod m;
 ```

See the changes to the reference for details on what macros are allowed;
see Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455)
for alternatives that were considered and rejected ("why accept no more
and no less?")

This has been available on nightly since 1.50 with no major issues.

 ## Notes

 ### Accepted syntax

The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`).  Note that decorators and the like may be able to observe other expression forms.

 ### Expansion ordering

Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input.

There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work).

 ## Test cases

 - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs
 - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs

The feature has also been dogfooded extensively in the compiler and
standard library:

- https://github.com/rust-lang/rust/pull/83329
- https://github.com/rust-lang/rust/pull/83230
- https://github.com/rust-lang/rust/pull/82641
- https://github.com/rust-lang/rust/pull/80534

 ## Implementation history

- Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412
- Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121
- Preliminary work to restrict expansion that would conflict with this
feature: https://github.com/rust-lang/rust/pull/77271
- Initial implementation: https://github.com/rust-lang/rust/pull/78837
- Fix for an ICE: https://github.com/rust-lang/rust/pull/80563

 ## Unresolved Questions

~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~

 ## Additional Information

 There are two workarounds that have a similar effect for `#[doc]`
attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons:

```rust
macro_rules! forward_inner_docs {
    ($e:expr => $i:item) => {
        #[doc = $e]
        $i
    };
}

forward_inner_docs!(include_str!("lib.rs") => struct S {});
```

This also works for other attributes (like `#[path = concat!(...)]`).
The other is to use `doc(include)`:

```rust
 #![feature(external_doc)]
 #[doc(include = "lib.rs")]
 struct S {}
```

The first works, but is non-trivial for people to discover, and
difficult to read and maintain. The second is a strange special-case for
a particular use of the macro. This generalizes it to work for any use
case, not just including files.

I plan to remove `doc(include)` when this is stabilized. The
`forward_inner_docs` workaround will still compile without warnings, but
I expect it to be used less once it's no longer necessary.
2021-05-18 01:01:36 -04:00
Ralf Jung
360db9c384
Rollup merge of #85409 - CDirkx:cfg_redox, r=nagisa
Simplify `cfg(any(unix, target_os="redox"))` in example to just `cfg(unix)`

Update example for `OsString` that handled `redox` seperately from `unix`: Redox has been completely integrated under `target_family="unix"`, so `cfg(unix)` implies `target_os="redox"`

35dbef2350/compiler/rustc_target/src/spec/redox_base.rs (L26)
2021-05-17 18:52:13 +02:00
Ralf Jung
8a1403af1e
Rollup merge of #85302 - r00ster91:patch-7, r=joshtriplett
Expand WASI abbreviation in docs

I was pretty sure this was related to something for WebAssembly but wasn't 100% sure so I checked but even on these top-level docs I couldn't find the abbreviation expanded. I'm normally used to Rust docs being detailed and explanatory and writing abbreviations like this out in full at least once so I thought it was worth the change. Feel free to close this if it's too much.
2021-05-17 18:52:04 +02:00
Christiaan Dirkx
383642714a Simplify cfg(any(unix, target_os="redox")) to just cfg(unix) 2021-05-17 13:49:14 +02:00
bors
d565c74887 Auto merge of #81858 - ijackson:fork-no-unwind, r=m-ou-se
Do not allocate or unwind after fork

### Objective scenarios

 * Make (simple) panics safe in `Command::pre_exec_hook`, including most `panic!` calls, `Option::unwrap`, and array bounds check failures.
 * Make it possible to `libc::fork` and then safely panic in the child (needed for the above, but this requirement means exposing the new raw hook API which the `Command` implementation needs).
 * In singlethreaded programs, where panic in `pre_exec_hook` is already memory-safe, prevent the double-unwinding malfunction #79740.

I think we want to make panic after fork safe even though the post-fork child environment is only experienced by users of `unsafe`, beause the subset of Rust in which any panic is UB is really far too hazardous and unnatural.

#### Approach

 * Provide a way for a program to, at runtime, switch to having panics abort.  This makes it possible to panic without making *any* heap allocations, which is needed because on some platforms malloc is UB in a child forked from a multithreaded program (see https://github.com/rust-lang/rust/pull/80263#issuecomment-774272370, and maybe also the SuS [spec](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html)).
 * Make that change in the child spawned by `Command`.
 * Document the rules comprehensively enough that a programmer has a fighting chance of writing correct code.
 * Test that this all works as expected (and in particular, that there aren't any heap allocations we missed)

Fixes #79740

#### Rejected (or previously attempted) approaches

 * Change the panic machinery to be able to unwind without allocating, at least when the payload and message are both `'static`.  This seems like it would be even more subtle.  Also that is a potentially-hot path which I don't want to mess with.
 * Change the existing panic hook mechanism to not convert the message to a `String` before calling the hook.  This would be a surprising change for existing code and would not be detected by the type system.
 * Provide a `raw_panic_hook` function to intercept panics in a way that doesn't allocate.  (That was an earlier version of this MR.)

### History

This MR could be considered a v2 of #80263.  Thanks to everyone who commented there.  In particular, thanks to `@m-ou-se,` `@Mark-Simulacrum` and `@hyd-dev.`  (Tagging you since I think you might be interested in this new MR.)  Compared to #80263, this MR has very substantial changes and additions.

Additionally, I have recently (2021-04-20) completely revised this series following very helpful comments from `@m-ou-se.`

r? `@m-ou-se`
2021-05-15 22:27:09 +00:00
r00ster
10c43c3980
Add doc aliases to unit 2021-05-15 17:31:32 +02:00
Guillaume Gomez
5a8619b435
Rollup merge of #85221 - ijackson:dbg-doc-re-tests, r=joshtriplett
dbg macro: Discuss use in tests, and slightly clarify

As discussed in a tangent in #82778.

I chose to use [semantic newlines](https://rhodesmill.org/brandon/2012/one-sentence-per-line/) in the source text but I don't mind reformatting it.
2021-05-15 13:29:50 +02:00
Guillaume Gomez
c4f81c12ea
Rollup merge of #85207 - andrewhalle:typo-rootseparator, r=kennytm
Fix typo in comment

missing space in "rootseparator"
2021-05-15 13:29:48 +02:00
r00ster
4f66337df2
Expand WASI abbreviation in docs 2021-05-14 22:03:00 +02:00
Geoffroy Couprie
95ccdb11da add an example to explain std::io::Read::read returning 0 in some cases
the example focuses on Linux, but that should be enough to explain how
the behaviour can change
2021-05-14 18:06:31 +02:00
Christiaan Dirkx
5353c5c3fb Move std::memchr to sys_common 2021-05-14 03:54:46 +02:00
Amanieu d'Antras
d9cf2ce28f Update compiler_builtins to 0.1.43 2021-05-13 22:32:44 +01:00
Amanieu d'Antras
5918ee4317 Add support for const operands and options to global_asm!
On x86, the default syntax is also switched to Intel to match asm!
2021-05-13 22:31:57 +01:00
Thomas Otto
95920d15b9 Fix indentation in move keyword documentation 2021-05-13 23:01:38 +02:00
Ian Jackson
6369637a19 Tolerate SIGTRAP for panic abort after panic::always_abort
Some platforma (eg ARM64) apparently generate SIGTRAP for panic abort!

See eg
  https://github.com/rust-lang/rust/pull/81858#issuecomment-840702765

This is probably a bug, but we don't want to entangle this MR with it.
When it's fixed, this commit should be reverted.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-13 18:42:52 +01:00
Ian Jackson
b36a3162fe
Change "etc." to "and similar"
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-05-13 15:02:02 +01:00
bors
28e2b29b89 Auto merge of #84730 - sexxi-goose:rox-auto-trait, r=nikomatsakis
Add auto traits and clone trait migrations for RFC2229

This PR
- renames the existent RFC2229 migration `disjoint_capture_drop_reorder` to `disjoint_capture_migration`
- add additional migrations for auto traits and clone trait

Closes rust-lang/project-rfc-2229#29
Closes rust-lang/project-rfc-2229#28

r? `@nikomatsakis`
2021-05-12 13:33:32 +00:00
Ian Jackson
a173518ceb dbg macro: Discuss use in tests, and slightly clarify
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-12 12:09:53 +01:00
Ian Jackson
26c782b8e7 ExitStatusError: Remove mentions in stable docs
We should revert this commit when this is stabilised.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-12 11:12:20 +01:00
Ian Jackson
46871539e4 impl crate::error::Error for ExitStatusError
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-12 11:12:20 +01:00
Ian Jackson
bb4ef68639 ExitStatusError: Be more verbose in Display impl
Co-authored-by: Jane Lusby <jlusby@yaah.dev>
2021-05-12 11:12:19 +01:00
Ian Jackson
8832b0a81c Fix typo in doc
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-05-12 11:12:19 +01:00
Ian Jackson
60a4d9612d unix: impl ExitStatusExt for ExitStatusError
It is unergnomic to have to say things like
   bad.into_status().signal()

Implementing `ExitStatusExt` for `ExitStatusError` fixes this.
Unfortunately it does mean making a previously-infallible method
capable of panicing, although of course the existing impl remains
infallible.

The alternative would be a whole new `ExitStatusErrorExt` trait.

`<ExitStatus as ExitStatusExt>::into_raw()` is not particularly
ergonomic to call because of the often-required type annotation.
See for example the code in the test case in
  library/std/src/sys/unix/process/process_unix/tests.rs

Perhaps we should provide equivalent free functions for `ExitStatus`
and `ExitStatusExt` in std::os::unix::process and maybe deprecate this
trait method.  But I think that is for the future.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-12 11:12:19 +01:00
Ian Jackson
e893089ea0 Provide ExitStatusError
Closes #73125

This is in pursuance of
  Issue #73127 Consider adding #[must_use] to std::process::ExitStatus

In
  MR #81452 Add #[must_use] to [...] process::ExitStatus
we concluded that the existing arrangements in are too awkward
so adding that #[must_use] is blocked on improving the ergonomics.

I wrote a mini-RFC-style discusion of the approach in
  https://github.com/rust-lang/rust/issues/73125#issuecomment-771092741

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-12 11:12:19 +01:00
Andrew Halle
3c06f00985 Fix typo in comment
missing space in "rootseparator"
2021-05-11 18:13:01 -07:00
Yuki Okushi
6ec4f91610
Rollup merge of #85136 - shirshak55:master, r=dtolnay
Change param name (k to key and v to value) in std::env module

1. When I was reading code the ide displayed `k` and `v`, so I
thought it would be better to show key and value?

2. I noticed var method already uses `key` instead of `k` so it
is more consistent to use `key` instead of `k`?

Thanks
2021-05-12 07:18:02 +09:00
Roxane
564b4de626 use the correct attributes and add helper function 2021-05-11 14:01:33 -04:00
Benoît du Garreau
9332ac3bfc Override clone_from for some types 2021-05-11 13:00:34 +02:00
bors
506e75cbf8 Auto merge of #85109 - RalfJung:remove-const_fn, r=oli-obk
remove const_fn feature gate

Fixes https://github.com/rust-lang/rust/issues/84510
r? `@oli-obk`
2021-05-11 10:25:14 +00:00
bors
fe62c6e295 Auto merge of #80300 - LeSeulArtichaut:80275-doc-inline, r=Manishearth
Emit errors/warns on some wrong uses of rustdoc attributes

This PR adds a few diagnostics:
- error if conflicting `#[doc(inline)]`/`#[doc(no_inline)]` are found
- introduce the `invalid_doc_attributes` lint (warn-by-default) which triggers:
  - if a crate-level attribute is used on a non-`crate` item
  - if `#[doc(inline)]`/`#[doc(no_inline)]` is used on a non-`use` item

The code could probably be improved but I wanted to get feedback first. Also, some of those changes could be considered breaking changes, so I don't know what the procedure would be? ~~And finally, for the warnings, they are currently hard warnings, maybe it would be better to introduce a lint?~~ (EDIT: introduced the `invalid_doc_attributes` lint)

Closes #80275.
r? `@jyn514`
2021-05-11 05:03:18 +00:00
LeSeulArtichaut
804ab9f78e Remove an invalid #[doc(inline)] 2021-05-11 00:03:44 +02:00
Ian Jackson
7ae852e349 io::Seek: Set tracking issue
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-10 13:55:31 +01:00
Ian Jackson
3113b6bd69
Fix typo in doc
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-05-10 13:50:56 +01:00
Ian Jackson
c3ca148ac0 io::Seek: Provide rewind()
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-10 13:03:49 +01:00
Ian Jackson
74e0e45f3c io::Seek: Mention that seeking can fail due to buffer flush fail
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-10 12:57:19 +01:00
shirshak55
0778e8dcb8 change k to key and v to v in std::env mod 2021-05-10 19:31:09 +08:00
Ian Jackson
b50c1bbb0e windows: provide NonZeroDWORD
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-10 11:18:08 +01:00
Ralf Jung
bafc51e01a remove const_fn feature gate 2021-05-09 14:29:31 +02:00
Ian Jackson
8220f2f212 panic/fork test: Do not run on emscripten
fork fails there.  The failure message is confusing: so c.status()
returns an Err, the closure panics, and the test thinks the panic was
propagated from inside the child.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-05-07 16:51:13 +01:00
Dylan DPC
62b68f9688
Rollup merge of #85030 - jethrogb:jb/sgx-rearrange-files, r=nagisa
Rearrange SGX split module files

In #75979 several inlined modules were split out into multiple files.
This PR keeps the multiple files but moves a few things around to
organize things in a coherent way.
2021-05-07 16:19:24 +02:00
Dylan DPC
73d3544fb9
Rollup merge of #85029 - jethrogb:jb/sgx-movable-mutex, r=m-ou-se
SGX mutex is movable

r? ``@m-ou-se``
2021-05-07 16:19:23 +02:00
Dylan DPC
8f0b1863d0
Rollup merge of #84655 - CDirkx:wasm, r=m-ou-se
Cleanup of `wasm`

Some more cleanup of `sys`, this time `wasm`

- Reuse `unsupported::args` (functionally equivalent implementation, just an empty iterator).
- Split out `atomics` implementation of `wasm::thread`, the non-`atomics` implementation is reused from `unsupported`.
- Move all of the `atomics` code to a separate directory `wasm/atomics`.

````@rustbot```` label: +T-libs-impl
r? ````@m-ou-se````
2021-05-07 16:19:20 +02:00
Jethro Beekman
bfa84842e5 Rearrange SGX split module files
In #75979 several inlined modules were split out into multiple files.
This PR keeps the multiple files but moves a few things around to
organize things in a coherent way.
2021-05-07 13:55:03 +02:00
Jethro Beekman
30b82e0f96 SGX mutex is movable 2021-05-07 13:21:38 +02:00
Ian Jackson
a17eab7bed panic ui test: Provide comprehensive test for panic after fork
This tests that we can indeed safely panic after fork, both
a raw libc::fork and in a Command pre_exec hook.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-05-07 11:17:44 +01:00
Ian Jackson
f8015061c8 panic tests: Command: Test that we do not unwind past fork
This is safe (does not involve heap allocation) but we don't yet have
a test to ensure that stays true.  That will come in a moment.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-05-07 11:17:44 +01:00
Ian Jackson
9283cdca36 unix process: pre_exec: Discuss panic safety
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-05-07 11:17:44 +01:00
Ian Jackson
820123a949 panic/fork: Command: Do not unwind after fork() in child
Unwinding after fork() in the child is UB on some platforms, because
on those (including musl) malloc can be UB in the child of a
multithreaded program, and unwinding must box for the payload.

Even if it's safe, unwinding past fork() in the child causes whatever
traps the unwind to return twice.  This is very strange and clearly
not desirable.  With the default behaviour of the thread library, this
can even result in a panic in the child being transformed into zero
exit status (ie, success) as seen in the parent!

Fixes #79740.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-07 11:17:44 +01:00
Ian Jackson
3cba120ba4 std panicking: ALWAYS_ABORT: use Relaxed memory ordering
As per
  https://github.com/rust-lang/rust/pull/81858#discussion_r626507810

Suggested-by: Mara Bos <m-ou.se@m-ou.se>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-07 11:17:44 +01:00
Ian Jackson
1b1bf24636 std panicking: Provide panic::always_abort
We must change the atomic read on panic entry to `Acquire`, to pick up
a possible an `always_panic` on another thread.

We add `count` to the names of panic_count::get and ::is_zaero,
because now there is another reason why panic ought to maybe abort.
Renaming these ensures that we have checked every call site to ensure
that they don't need further adjustment.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-05-07 11:17:44 +01:00
Ian Jackson
a9f43a2a8f std panicking: Make decrease() return ()
Nothing uses the return value.  This will make the next changes
easier.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-07 11:17:44 +01:00
Dylan DPC
b30e428689
Rollup merge of #84409 - mzohreva:mz/tls-dtors-before-join, r=jethrogb
Ensure TLS destructors run before thread joins in SGX

The excellent test is from ```@jethrogb```

For context see: https://github.com/rust-lang/rust/pull/83416#discussion_r617282907
2021-05-07 00:38:33 +02:00
bors
676ee14729 Auto merge of #79930 - tgnottingham:bufwriter_performance, r=m-ou-se
Optimize BufWriter
2021-05-06 20:04:32 +00:00
Roxane
9afea614bf Add additional migrations to handle auto-traits and clone traits
Combine all 2229 migrations under one flag name
2021-05-06 14:17:59 -04:00
Mohsen Zohrevandi
2acd62d7c3 join_orders_after_tls_destructors: ensure thread 2 is launched before thread 1 enters TLS destructors 2021-05-06 09:36:26 -07:00
Dylan DPC
2ed0134cfa
Rollup merge of #84712 - joshtriplett:simplify-chdir, r=yaahc
Simplify chdir implementation and minimize unsafe block
2021-05-06 13:30:55 +02:00
Dylan DPC
6a6c644016
Rollup merge of #84328 - Folyd:stablize_map_into_keys_values, r=m-ou-se
Stablize {HashMap,BTreeMap}::into_{keys,values}

I would propose to stabilize `{HashMap,BTreeMap}::into_{keys,values}`( aka. `map_into_keys_values`).

Closes #75294.
2021-05-06 13:30:54 +02:00
Chris Denton
fc40aa059b
Use the proper import library names 2021-05-06 04:04:19 +01:00
Chris Denton
25712afd94
Add #[link] attributes to dll imports
This avoids using jmp stubs when calling functions exported from a dll.
2021-05-06 02:41:51 +01:00
bors
bacf770f29 Auto merge of #84956 - RalfJung:rollup-m70mx2n, r=RalfJung
Rollup of 11 pull requests

Successful merges:

 - #83553 (Update `ptr` docs with regards to `ptr::addr_of!`)
 - #84183 (Update RELEASES.md for 1.52.0)
 - #84709 (Add doc alias for `chdir` to `std::env::set_current_dir`)
 - #84803 (Reduce duplication in `impl_dep_tracking_hash` macros)
 - #84808 (Account for unsatisfied bounds in E0599)
 - #84843 (use else if in std library )
 - #84865 (rustbuild: Pass a `threads` flag that works to windows-gnu lld)
 - #84878 (Clarify documentation for `[T]::contains`)
 - #84882 (platform-support: Center the contents of the `std` and `host` columns)
 - #84903 (Remove `rustc_middle::mir::interpret::CheckInAllocMsg::NullPointerTest`)
 - #84913 (Do not ICE on invalid const param)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-05 17:45:41 +00:00
Ralf Jung
4c4b3e81df
Rollup merge of #84709 - joshtriplett:doc-alias-chdir, r=dtolnay
Add doc alias for `chdir` to `std::env::set_current_dir`

Searching for `chdir` in the Rust documentation produces no useful
results.

I wrote some code recently that called `libc::chdir` and manually
handled errors, because I didn't realize that the safe
`std::env::set_current_dir` existed. I searched for `chdir` and
`change_dir` and `change_directory` (the latter two based on the
precedent of unabbreviating set by `create_dir`), and I also read
through `std::fs` expecting to potentially find it there. Given that
none of those led to `std::env::set_current_dir`, I think that provides
sufficient justification to add this specific alias.
2021-05-05 17:52:20 +02:00
Ralf Jung
722bebf163
Rollup merge of #83553 - jfrimmel:addr-of, r=m-ou-se
Update `ptr` docs with regards to `ptr::addr_of!`

This updates the documentation since `ptr::addr_of!` and `ptr::addr_of_mut!` are now stable. One might remove the distinction between the sections `# On packed structs` and `# Examples`, as the old section on packed structs was primarily to prevent users of doing undefined behavior, which is not necessary anymore.

Technically there is now wrong/outdated documentation on stable, but I don't think this is worth a point release 😉

Fixes #83509.

``````````@rustbot`````````` modify labels: T-doc
2021-05-05 17:52:18 +02:00
Mara Bos
b6f3dbb65d Bump map_into_keys_values stable version to 1.54.0. 2021-05-05 16:40:06 +02:00
bors
342db70ae4 Auto merge of #84200 - CDirkx:os, r=m-ou-se
Move all `sys::ext` modules to `os`

This PR moves all `sys::ext` modules to `os`, centralizing the location of all `os` code and simplifying the dependencies between `os` and `sys`.

Because this also removes all uses `cfg_if!` on publicly exported items, where after #81969 there were still a few left, this should properly work around https://github.com/rust-analyzer/rust-analyzer/issues/6038.

`@rustbot` label: +T-libs-impl
2021-05-05 14:15:19 +00:00
Julian Frimmel
389333a21c Update ptr docs with regards to ptr::addr_of!
This updates the documentation since `ptr::addr_of!` and
`ptr::addr_of_mut!` are now stable. One might remove the distinction
between the sections `# On packed structs` and `# Examples`, as the old
section on packed structs was primarily to prevent users of doing unde-
fined behavior, which is not necessary anymore.
There is also a new section in "how to obtain a pointer", which referen-
ces the `ptr::addr_of!` macros.

This commit contains squashed commits from code review.

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
Co-authored-by: Soveu <marx.tomasz@gmail.com>
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-05-03 23:14:17 +02:00
Christiaan Dirkx
0caa20ee5d Allow documenting on hermit 2021-05-03 16:56:22 +02:00
Christiaan Dirkx
a0ca3f94f0 Rework os to avoid using cfg_if! with public items 2021-05-03 16:56:22 +02:00
Christiaan Dirkx
e098d2730a Move std::sys::sgx::ext to std::os::fortanix_sgx 2021-05-03 16:56:21 +02:00
Christiaan Dirkx
3edba7a806 Move std::sys::wasi::ext to std::os::wasi 2021-05-03 16:56:21 +02:00
Christiaan Dirkx
a808fd44a3 Move std::sys::unix::ext to std::os::unix 2021-05-03 16:56:21 +02:00
Christiaan Dirkx
ffc20e48de Move std::sys::windows::ext to std::os::windows 2021-05-03 16:56:20 +02:00
Christiaan Dirkx
7024bfffbd Move std::sys::hermit::ext to std::os::hermit 2021-05-03 16:56:20 +02:00
Christiaan Dirkx
0e2cd33db8 Cleanup std::os 2021-05-03 16:56:20 +02:00
Guillaume Gomez
2604440d8a
Rollup merge of #84856 - kornelski:enomem, r=JohnTitor
Correct stability of ErrorKind::OutOfMemory

Fix for #84744
2021-05-03 15:08:10 +02:00
Guillaume Gomez
dd5fc8edb8
Rollup merge of #84835 - wcampbell0x2a:add-issue-34202-link, r=m-ou-se
Add link to Issue #34202 in udp docs
2021-05-03 15:08:02 +02:00
Kornel
2247d46b11 Correct stability of ErrorKind::OutOfMemory 2021-05-03 10:28:19 +01:00
bors
2428cc4816 Auto merge of #84842 - blkerby:null_lowercase, r=joshtriplett
Replace 'NULL' with 'null'

This replaces occurrences of "NULL" with "null" in docs, comments, and compiler error/lint messages. This is for the sake of consistency, as the lowercase "null" is already the dominant form in Rust. The all-caps NULL looks like the C macro (or SQL keyword), which seems out of place in a Rust context, given that NULL does not exist in the Rust language or standard library (instead having [`ptr::null()`](https://doc.rust-lang.org/stable/std/ptr/fn.null.html)).
2021-05-03 05:41:23 +00:00
Brent Kerby
6679f5ceb1 Change 'NULL' to 'null' 2021-05-02 17:46:00 -06:00
wcampbell
e4250a014e
Add link to Issue #34202 in udp docs
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2021-05-02 19:13:41 -04:00
Kornel
19568f9a83 Use ErrorKind::OutOfMemory in unix, windows, and wasi 2021-05-02 11:40:32 +01:00
Kornel
541c8d898e Add ErrorKind::OutOfMemory 2021-05-02 11:40:31 +01:00
bors
603a42ec54 Auto merge of #84658 - Amanieu:reserved_regs, r=petrochenkov
Be stricter about rejecting LLVM reserved registers in asm!

LLVM will silently produce incorrect code if these registers are used as operands.

cc `@rust-lang/wg-inline-asm`
2021-05-01 13:01:24 +00:00
Amanieu d'Antras
ea310d9253 Reserve x18 on AArch64 and un-reserve x16 2021-05-01 13:25:56 +01:00
Amanieu d'Antras
09cfb248e7 Avoid using rbx in SGX inline assembly since it is reserved 2021-04-30 18:27:12 +01:00
bors
7506228e2e Auto merge of #84716 - joshtriplett:chroot, r=dtolnay
Add std::os::unix::fs::chroot to change the root directory of the current process

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 the unsafe `libc::chroot` directly and
handle errors manually, in a program that may otherwise be entirely safe
code.
2021-04-30 12:19:37 +00:00
bors
49920bc581 Auto merge of #84522 - CDirkx:cmath, r=yaahc
Reuse `sys::unix::cmath` on other platforms

Reuse `sys::unix::cmath` on all non-`windows` platforms.

`unix` is chosen as the canonical location instead of `unsupported` or `common` because `unsupported` doesn't make sense semantically and `common` is reserved for code that is supported on all platforms. Also `unix` is already the home of some non-`windows` code that is technically not exclusive to `unix` like `unix::path`.
2021-04-30 09:52:32 +00:00
Josh Triplett
ffb874ac90 Add std::os::unix::fs::chroot to change the root directory of the current process
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 the unsafe `libc::chroot` directly and
handle errors manually, in a program that may otherwise be entirely safe
code.
2021-04-30 00:11:03 -07:00
Jack Huey
6e50ac8a34
Rollup merge of #84692 - r00ster91:var-var_os-vars, r=joshtriplett
Link between std::env::{var, var_os} and std::env::{vars, vars_os}

In #84551 I linked between `std::env::{args, args_os}` and this PR does the same but for `std::env::{var, var_os}` and `std::env::{vars, vars_os}`. Now all of `std::env::{var, var_os, vars, vars_os, args, args_os}` should each mention their `_os` or non-`_os` equivalent in the docs so that you can easily navigate between them.
2021-04-29 19:27:25 -04:00
Jack Huey
e720df672d
Rollup merge of #84590 - est31:array_into_iter, r=nikomatsakis
Point out that behavior might be switched on 2015 and 2018 too one day

Reword documentation to make it clear that behaviour can be switched on older editions too, one day in the future. It doesn't *have* to be switched, but I think it's good to have it as an option and re-evaluate it a few months/years down the line when e.g. the crates that showed up in crater were broken by different changes in the language already.

cc #25725, #65819, #66145, #84147 , and https://github.com/rust-lang/rust/issues/84133#issuecomment-818005314
2021-04-29 19:27:21 -04:00
Josh Triplett
8a2e67e0d0 Simplify chdir implementation and minimize unsafe block 2021-04-29 13:11:20 -07:00
Josh Triplett
c185f08e46 Add doc alias for chdir to std::env::set_current_dir
Searching for `chdir` in the Rust documentation produces no useful
results.
2021-04-29 12:41:23 -07:00
Mohsen Zohrevandi
8a0a4b1493 Use atomics in join_orders_after_tls_destructors test
std::sync::mpsc uses thread locals and depending on the order TLS dtors
are run `rx.recv()` can panic when used in a TLS dtor.
2021-04-29 08:51:18 -07:00