Commit Graph

9650 Commits

Author SHA1 Message Date
Matthias Krüger
6d43dfb7bb
Rollup merge of #103110 - RalfJung:manual-send, r=thomcc
remove redundant Send impl for references

Also explain why the other instance is not redundant, move it next to the trait they are implementing, and out of the redundant module. This seems to go back all the way to 35ca50bd56, not sure why the module was added.

The instance for `&mut` is the default instance we get anyway, and we don't have anything similar for `Sync`, so IMO we should be consistent and not have the redundant instance here, either.
2022-10-27 15:03:55 +02:00
Matthias Krüger
8a29784400
Rollup merge of #103564 - RalfJung:miri-unused, r=thomcc
library: allow some unused things in Miri

Should help for https://github.com/rust-lang/rust/pull/102950.
2022-10-27 09:25:10 +02:00
Matthias Krüger
0cd87148d9
Rollup merge of #103106 - saethlin:from_exposed_docs, r=thomcc
Try to say that memory outside the AM is always exposed

cc ``@Gankra`` ``@thomcc``

I want to confidently tell people that they can use `from_exposed_addr` to get a pointer for doing MMIO and/or other hardware interactions done with volatile reads/writes at particular addresses outside the Rust AM. Currently, the docs indicate that would be UB.

With this change, now the docs indicate that this is intended to be a valid use of `from_exposed_addr`.

r? ``@RalfJung``
2022-10-27 09:25:09 +02:00
Matthias Krüger
2937621aa7
Rollup merge of #103035 - saethlin:assert_unsafe_precondition3, r=thomcc
Even nicer errors from assert_unsafe_precondition

For example, now running `cargo test` with this patch I get things like:
```
$ cargo +stage1 test
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running unittests src/lib.rs (target/debug/deps/malloc_buf-9d105ddf86862995)

running 5 tests
thread 'tests::test_null_buf' panicked at 'unsafe precondition violated: is_aligned_and_not_null(data) &&
    crate::mem::size_of::<T>().saturating_mul(len) <= isize::MAX as usize', /home/ben/rust/library/core/src/slice/raw.rs:93:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread panicked while panicking. aborting.
error: test failed, to rerun pass `--lib`

Caused by:
  process didn't exit successfully: `/tmp/malloc_buf-1.0.0/target/debug/deps/malloc_buf-9d105ddf86862995` (signal: 6, SIGABRT: process abort signal)
```

This is still not perfect, but these are better for another PR:
* `stringify!` is trying to do clever pretty-printing on the `expr` inside `assert_unsafe_precondition` and can even add a newline.
* It would be nice to print a bit more information about where the problem is. Perhaps this is `cfg_attr(debug_assertions, track_caller)`, or perhaps it the function name added to `Location`.

cc ``@RalfJung`` this is what I was thinking of for https://github.com/rust-lang/rust/pull/102732#discussion_r989068907
2022-10-27 09:25:08 +02:00
Pointerbender
166d8b8c2b add "Memory layout" subsection to documentation of UnsafeCell for additional clarity 2022-10-27 06:32:36 +02:00
Ben Kimock
458aaa5a23 Print the precondition we violated, and visible through output capture
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-10-26 22:09:17 -04:00
Yuki Okushi
b4b3ff4e6b
Rollup merge of #103596 - RalfJung:thread-setname, r=cuviper
thread::set_name: debug-assert that things went well

r? `@cuviper`
2022-10-27 08:30:59 +09:00
Yuki Okushi
77145c042d
Rollup merge of #103580 - lukas-code:guaranteed_ne, r=GuillaumeGomez
Fix typo in docs for `guaranteed_ne`

`==` -> `!=`
2022-10-27 08:30:58 +09:00
Yuki Okushi
26ad51ff87
Rollup merge of #103567 - RalfJung:ptr-eq-dyn-trait, r=dtolnay
ptr::eq: clarify that comparing dyn Trait is fragile

Also remove the dyn trait example from `ptr::eq` since those tests are not actually guaranteed to pass due to how unstable vtable comparison is.

Cc ``@rust-lang/libs-api``
Cc discussion following https://github.com/rust-lang/rust/pull/80505
2022-10-27 08:30:57 +09:00
Yuki Okushi
cafb63d869
Rollup merge of #103526 - Rageking8:more-dupe-typos-again, r=Mark-Simulacrum
More dupe typos again

There are some others in submodules, which I will file separate PRs for in their respective repos. Thanks.
2022-10-27 08:30:55 +09:00
Ralf Jung
d1132fb805 thread::set_name: debug-assert that things went well 2022-10-26 22:11:12 +02:00
Lukas Markeffsky
cce46e9ae2 Fix typo in docs for guaranteed_ne 2022-10-26 16:50:08 +02:00
Ben Kimock
bd947632b5
Update library/core/src/ptr/mod.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-10-26 07:14:20 -07:00
Ralf Jung
1946a1842e explicitly mention that both components of wide prts are compared 2022-10-26 14:20:31 +02:00
Ralf Jung
99a74afa5f ptr::eq: clarify that comparing dyn Trait is fragile 2022-10-26 11:15:14 +02:00
Ralf Jung
20ab57e582 library: allow some unused things in Miri 2022-10-26 09:48:47 +02:00
Dylan DPC
8ed3a80b9a
Rollup merge of #103287 - saethlin:faster-len-check, r=thomcc
Use a faster allocation size check in slice::from_raw_parts

I've been perusing through the codegen changes that result from turning on the standard library debug assertions. The previous check in here uses saturating arithmetic, which in my experience sometimes makes LLVM just fail to optimize things around the saturating operation.

Here is a demo of the codegen difference: https://godbolt.org/z/WMEqrjajW
Before:
```asm
example::len_check_old:
        mov     rax, rdi
        mov     ecx, 3
        mul     rcx
        setno   cl
        test    rax, rax
        setns   al
        and     al, cl
        ret

example::len_check_old:
        mov     rax, rdi
        mov     ecx, 8
        mul     rcx
        setno   cl
        test    rax, rax
        setns   al
        and     al, cl
        ret
```
After:
```asm
example::len_check_new:
        movabs  rax, 3074457345618258603
        cmp     rdi, rax
        setb    al
        ret

example::len_check_new:
        shr     rdi, 60
        sete    al
        ret
```

Running rustc-perf locally, this looks like up to a 4.5% improvement when `debug-assertions-std = true`.

Thanks ```@LegionMammal978``` (I think that's you?) for turning my idea into a much cleaner implementation.

r? ```@thomcc```
2022-10-26 11:29:53 +05:30
Ben Kimock
0c3ae7d97c Try to say that memory outside the AM is always exposed
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-10-25 17:58:29 -04:00
Rageking8
c246a3ddd4 more dupe typos again 2022-10-25 22:51:47 +08:00
Dylan DPC
35b46de61b
Rollup merge of #103482 - aDotInTheVoid:vec-cap-docs, r=thomcc
Clairify Vec::capacity docs

Update both the text and example to be clear that the method gives *total*, (not *spare*) capacity

Fixes #103326
2022-10-25 14:43:15 +05:30
Dylan DPC
75023d61a1
Rollup merge of #103379 - cuviper:truncate-thread-name, r=thomcc
Truncate thread names on Linux and Apple targets

These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.

r? ``````@thomcc``````
2022-10-25 14:43:15 +05:30
Dylan DPC
d2d44f619f
Rollup merge of #98204 - Kixiron:stable-unzip, r=thomcc
Stabilize `Option::unzip()`

Stabilizes `Option::unzip()`, closes #87800

```@rustbot``` modify labels: +T-libs-api
2022-10-25 14:43:13 +05:30
Nixon Enraght-Moony
674cd6125d Clairify Vec::capacity docs
Fixes #103326
2022-10-24 15:01:58 +01:00
Yuki Okushi
a710f56e7d
Rollup merge of #103466 - jruderman:patch-2, r=Dylan-DPC
Fix grammar in docs for std::io::Read

Two independent clauses were incorrectly joined by a bare comma. The simplest fix would be to switch to a semicolon, but I think it's slightly better to keep the comma and use the coordinating conjunction "so".
2022-10-24 19:32:29 +09:00
Yuki Okushi
413380fc20
Rollup merge of #103277 - thomcc:bump-libc-135, r=Mark-Simulacrum
Update libstd's libc to 0.2.135 (to make `libstd` no longer pull in `libiconv.dylib` on Darwin)

This is to pull in https://github.com/rust-lang/libc/pull/2944.

It's related to https://github.com/rust-lang/rust/pull/102766, in that they both remove unused dylibs from libstd on Darwin platforms. As a result, I'm marking this as relnotes since everybody agreed it was good to add it to the other as well. (The note should be about no longer linking against libiconv -- the libc update is irrelevant).

Might as well have the same reviewer too.

r? `@Mark-Simulacrum`
2022-10-24 19:32:27 +09:00
Yuki Okushi
413a82051d
Rollup merge of #102766 - thomcc:remove-resolv, r=Mark-Simulacrum
Don't link to `libresolv` in libstd on Darwin

Currently we link `libresolv` into every Rust program on apple targets despite never using it (as of https://github.com/rust-lang/rust/pull/44965). I had thought we needed this for `getaddrinfo` or something, but we do not / cannot safely use it.

I'd like to fix this for `libiconv` too (the other library we pull in. that's harder since it's coming in through `libc`, which is https://github.com/rust-lang/libc/pull/2944)).

---

This may warrant release notes. I'm not sure but I've added the flag regardless -- It's a change to the list of dylibs every Rust program pulls in, so it's worth mentioning.

It's pretty unlikely anybody was relying on this being pulled in, and `std` does not guarantee that it will link (and thus transitively provide access to) any particular system library -- anybody relying on that behavior would already be broken when dynamically linking std. That is, there's an outside chance something will fail to link on macOS and iOS because it was accidentally relying on our unnecessary dependency.

(If that *does* happen, that project could be easily fixed by linking libresolv explicitly on those platforms, probably via `#[link(name = "resolv")] extern {}`,` -Crustc-link-lib=resolv`, `println!("cargo:rustc-link-lib=resolv")`, or one of several places in `.config/cargo.toml`)

---

I'm also going to preemptively add the nomination for discussing this in the libs meeting. Basically: Do we care about programs that assume we will bring libraries in that we do not use. `libresolv` and `libiconv` on macOS/iOS are in this camp (`libresolv` because we used to use it, and `libiconv` because the `libc` crate was unintentionally(?) pulling it in to every Rust program).

I'd like to remove them both, but this may cause link issues programs that are relying on `std` to depend on them transitively. (Relying on std for this does not work in all build configurations, so this seems very fragile, and like a use case we should not support).

More generally, IMO we should not guarantee the specific set of system-provided libraries we use (beyond what is implied by an OS version requirement), which means we'd be free to remove this cruft.
2022-10-24 19:32:27 +09:00
Yuki Okushi
c1f9d985d7
Rollup merge of #102271 - lopopolo:lopopolo/stabilize-duration-try-from-secs-float, r=dtolnay
Stabilize `duration_checked_float`

## Stabilization Report

This stabilization report is for a stabilization of `duration_checked_float`, tracking issue: https://github.com/rust-lang/rust/issues/83400.

### Implementation History

- https://github.com/rust-lang/rust/pull/82179
- https://github.com/rust-lang/rust/pull/90247
- https://github.com/rust-lang/rust/pull/96051
- Changed error type to `FromFloatSecsError` in https://github.com/rust-lang/rust/pull/90247
- https://github.com/rust-lang/rust/pull/96051 changes the rounding mode to round-to-nearest instead of truncate.

## API Summary

This stabilization report proposes the following API to be stabilized in `core`, along with their re-exports in `std`:

```rust
// core::time

impl Duration {
    pub const fn try_from_secs_f32(secs: f32) -> Result<Duration, TryFromFloatSecsError>;
    pub const fn try_from_secs_f64(secs: f64) -> Result<Duration, TryFromFloatSecsError>;
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TryFromFloatSecsError { ... }

impl core::fmt::Display for TryFromFloatSecsError { ... }
impl core::error::Error for TryFromFloatSecsError { ... }
```

These functions are made const unstable under `duration_consts_float`, tracking issue #72440.

There is an open question in the tracking issue around what the error type should be called which I was hoping to resolve in the context of an FCP.

In this stabilization PR, I have altered the name of the error type to `TryFromFloatSecsError`. In my opinion, the error type shares the name of the method (adjusted to accommodate both types of floats), which is consistent with other error types in `core`, `alloc` and `std` like `TryReserveError` and `TryFromIntError`.

## Experience Report

Code such as this is ready to be converted to a checked API to ensure it is panic free:

```rust
impl Time {
    pub fn checked_add_f64(&self, seconds: f64) -> Result<Self, TimeError> {
        // Fail safely during `f64` conversion to duration
        if seconds.is_nan() || seconds.is_infinite() {
            return Err(TzOutOfRangeError::new().into());
        }

        if seconds.is_sign_positive() {
            self.checked_add(Duration::from_secs_f64(seconds))
        } else {
            self.checked_sub(Duration::from_secs_f64(-seconds))
        }
    }
}
```

See: https://github.com/artichoke/artichoke/issues/2194.

`@rustbot` label +T-libs-api -T-libs

cc `@mbartlett21`
2022-10-24 19:32:26 +09:00
Yuki Okushi
779418deb4
Rollup merge of #99939 - saethlin:pre-sort-tests, r=thomcc,jackh726
Sort tests at compile time, not at startup

Recently, another Miri user was trying to run `cargo miri test` on the crate `iced-x86` with `--features=code_asm,mvex`. This configuration has a startup time of ~18 minutes. That's ~18 minutes before any tests even start to run. The fact that this crate has over 26,000 tests and Miri is slow makes a lot of code which is otherwise a bit sloppy but fine into a huge runtime issue.

Sorting the tests when the test harness is created instead of at startup time knocks just under 4 minutes out of those ~18 minutes. I have ways to remove most of the rest of the startup time, but this change requires coordinating changes of both the compiler and libtest, so I'm sending it separately.

(except for doctests, because there is no compile-time harness)
2022-10-24 19:32:25 +09:00
Yuki Okushi
fbb3650c89
Rollup merge of #99578 - steffahn:remove_redundant_bound, r=thomcc
Remove redundant lifetime bound from `impl Borrow for Cow`

The lifetime bound `B::Owned: 'a` is redundant and doesn't make a difference,
because `Cow<'a, B>` comes with an implicit `B: 'a`, and associated types
will outlive lifetimes outlived by the `Self` type (and all the trait's
generic parameters, of which there are none in this case), so the implicit `B: 'a`
implies `B::Owned: 'a` anyway.

The explicit lifetime bound here does however [end up in documentation](https://doc.rust-lang.org/std/borrow/enum.Cow.html#impl-Borrow%3CB%3E),
and that's confusing in my opinion, so let's remove it ^^

_(Documentation right now, compare to `AsRef`, too:)_
![Screenshot_20220722_014055](https://user-images.githubusercontent.com/3986214/180332665-424d0c05-afb3-40d8-a330-a57a2c9a494b.png)
2022-10-24 19:32:24 +09:00
Jesse Ruderman
f53b32288c
Fix grammar in docs for std::io::Read 2022-10-24 01:06:34 -07:00
bors
56f132565e Auto merge of #100848 - xfix:use-metadata-for-slice-len, r=thomcc
Use ptr::metadata in <[T]>::len implementation

This avoids duplication of ptr::metadata code.

I believe this is acceptable as the previous approach essentially duplicated `ptr::metadata` because back then `rustc_allow_const_fn_unstable` annotation did not exist.

I would like somebody to ping `@rust-lang/wg-const-eval` as the documentation says:

> Always ping `@rust-lang/wg-const-eval` if you are adding more rustc_allow_const_fn_unstable attributes to any const fn.
2022-10-24 04:14:46 +00:00
Pointerbender
5673536153
fix typos
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-10-24 04:27:37 +02:00
Michael Howell
ae2b1f096f
Rollup merge of #103447 - ajtribick:maybe_uninit_doc_update, r=scottmcm
`MaybeUninit`: use `assume_init_drop()` in the partially initialized array example

The `assume_init_drop()` method does the same thing as the pointer conversion, and makes the example more straightforward.
2022-10-23 14:48:19 -07:00
Michael Howell
23d1b05726
Rollup merge of #103005 - solid-rs:patch/kmc-solid/readdir-terminator, r=m-ou-se
kmc-solid: Handle errors returned by `SOLID_FS_ReadDir`

Fixes the issue where the `std::fs::ReadDir` implementaton of the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets silently suppressed errors returned by the underlying `SOLID_FS_ReadDir` system function. The new implementation correctly handles all cases:

- `SOLID_ERR_NOTFOUND` indicates the end of directory stream.
- `SOLID_ERR_OK` + non-empty `d_name` indicates success.
- Some old filesystem drivers may return `SOLID_ERR_OK` + empty `d_name` to indicate the end of directory stream.
- Any other negative values (per ITRON convention) represent an error.
2022-10-23 14:48:15 -07:00
Michael Howell
214fa9fb9c
Rollup merge of #101644 - Timmmm:file_permissions_docs, r=thomcc
Document surprising and dangerous fs::Permissions behaviour on Unix

This documents the very surprising behaviour that `set_readonly(false)` will make a file *world writable* on Unix. I would go so far as to say that this function should be deprecated on Unix, or maybe even entirely. But documenting the bad behaviour is a good first step.

Fixes #74895
2022-10-23 14:48:14 -07:00
Michael Howell
acc269d65b
Rollup merge of #100462 - zohnannor:master, r=thomcc
Clarify `array::from_fn` documentation

I've seen quite a few of people on social media confused of where the length of array is coming from in the newly stabilized `array::from_fn` example.

This PR tries to clarify the documentation on this.
2022-10-23 14:48:13 -07:00
Gary Guo
4e6d60c837 Fix alloc size 2022-10-23 20:30:16 +01:00
Gary Guo
979d1a2c78 Apply suggestion
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2022-10-23 20:30:16 +01:00
Gary Guo
86c65d2c1c Implement Rust foreign exception protection for EMCC and SEH 2022-10-23 20:30:16 +01:00
Gary Guo
e521a8d46b Prevent foreign Rust exceptions from being caught 2022-10-23 20:30:16 +01:00
bors
7fcf850d79 Auto merge of #103137 - dtolnay:readdir, r=Mark-Simulacrum
Eliminate 280-byte memset from ReadDir iterator

This guy:

1536ab1b38/library/std/src/sys/unix/fs.rs (L589)

It turns out `libc::dirent64` is quite big&mdash;https://docs.rs/libc/0.2.135/libc/struct.dirent64.html. In #103135 this memset accounted for 0.9% of the runtime of iterating a big directory.

Almost none of the big zeroed value is ever used. We memcpy a tiny prefix (19 bytes) into it, and then read just 9 bytes (`d_ino` and `d_type`) back out. We can read exactly those 9 bytes we need directly from the original entry_ptr instead.

## History

This code got added in #93459 and tweaked in #94272 and #94750.

Prior to #93459, there was no memset but a full 280 bytes were being copied from the entry_ptr.

<table><tr><td>copy 280 bytes</td></tr></table>

This was not legal because not all of those bytes might be initialized, or even allocated, depending on the length of the directory entry's name, leading to a segfault. That PR fixed the segfault by creating a new zeroed dirent64 and copying just the guaranteed initialized prefix into it.

<table><tr><td>memset 280 bytes</td><td>copy 19 bytes</td></tr></table>

However this was still buggy because it used `addr_of!((*entry_ptr).d_name)`, which is considered UB by Miri in the case that the full extent of entry_ptr is not in bounds of the same allocation. (Arguably this shouldn't be a requirement, but here we are.)

The UB got fixed by #94272 by replacing `addr_of` with some pointer manipulation based on `offset_from`, but still fundamentally the same operation.

<table><tr><td>memset 280 bytes</td><td>copy 19 bytes</td></tr></table>

Then #94750 noticed that only 9 of those 19 bytes were even being used, so we could pick out only those 9 to put in the ReadDir value.

<table><tr><td>memset 280 bytes</td><td>copy 19 bytes</td><td>copy 9 bytes</td></tr></table>

After my PR we just grab the 9 needed bytes directly from entry_ptr.

<table><tr><td>copy 9 bytes</td></tr></table>

The resulting code is more complex but I believe still worthwhile to land for the following reason. This is an extremely straightforward thing to accomplish in C and clearly libc assumes that; literally just `entry_ptr->d_name`. The extra work in comparison to accomplish it in Rust is not an example of any actual safety being provided by Rust. I believe it's useful to have uncovered that and think about what could be done in the standard library or language to support this obvious operation better.

## References

- https://man7.org/linux/man-pages/man3/readdir.3.html
2022-10-23 18:55:40 +00:00
Josh Stone
15cfeb33b0 Only test pthread_getname_np on linux-gnu 2022-10-23 11:53:39 -07:00
Andrew Tribick
560433ac86 MaybeUninit: use assume_init_drop() in the partially initialized array example 2022-10-23 19:09:18 +02:00
Finn Bear
9f0503e4a6 Fix typo in docs of String::leak. 2022-10-22 12:26:47 -07:00
Dylan DPC
b4536943e3
Rollup merge of #103360 - ChrisDenton:isterm-filetype, r=thomcc
Reduce false positives in msys2 detection

Currently msys2 will be detected by getting the file path and looking to see if it contains the substrings "msys-" and "-ptr" (or "cygwin-" and "-pty"). This risks false positives, especially with filesystem files and if `GetFileInformationByHandleEx` returns a [full path](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntqueryinformationfile#remarks).

This PR adds a check to see if the handle is a pipe before doing the substring search. Additionally, for "msys2-" or "cygwin-" it only checks if the file name starts with the substring rather than looking at the whole path.
2022-10-22 16:28:09 +05:30
Dylan DPC
b22559f547
Rollup merge of #103346 - HeroicKatora:metadata_of_const_pointer_argument, r=dtolnay
Adjust argument type for mutable with_metadata_of (#75091)

The method takes two pointer arguments: one `self` supplying the pointer value, and a second pointer supplying the metadata.

The new parameter type more clearly reflects the actual requirements. The provenance of the metadata parameter is disregarded completely. Using a mutable pointer in the call site can be coerced to a const pointer while the reverse is not true.

In some cases, the current parameter type can thus lead to a very slightly confusing additional cast. [Example](cad93775eb).

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = val as *const _ as *mut T;
let ptr = uninit.as_ptr().with_metadata_of(ptr);
```

This could then instead be simplified to:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = uninit.as_ptr().with_metadata_of(&**val);
```

Tracking issue: https://github.com/rust-lang/rust/issues/75091

``@dtolnay`` you're reviewed #95249, would you mind chiming in?
2022-10-22 16:28:09 +05:30
Dylan DPC
3f49f9506f
Rollup merge of #103329 - saethlin:nonnull-precondition, r=thomcc
Add a forgotten check for NonNull::new_unchecked's precondition

Looks like I forgot this function a while ago in https://github.com/rust-lang/rust/pull/92686

r? ```@thomcc```
2022-10-22 16:28:08 +05:30
Dylan DPC
141478b40f
Rollup merge of #103280 - finnbear:impl_string_leak_2, r=joshtriplett
(#102929) Implement `String::leak` (attempt 2)

Implementation of `String::leak` (#102929)

ACP: https://github.com/rust-lang/libs-team/issues/109

Supersedes #102941 (see previous reviews there)

```@rustbot``` label +T-libs-api -T-libs
2022-10-22 16:28:08 +05:30
Josh Stone
12e45846eb Move truncation next to other thread tests for tidy 2022-10-21 18:13:22 -07:00
Josh Stone
7280f3d28a Truncate thread names on Linux and Apple targets
These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.
2022-10-21 17:44:35 -07:00
bors
8f2c56aec7 Auto merge of #103375 - matthiaskrgr:rollup-4xrs7f2, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #102635 (make `order_dependent_trait_objects` show up in future-breakage reports)
 - #103335 (Replaced wrong test with the correct mcve)
 - #103339 (Fix some typos)
 - #103340 (WinConsole::new is not actually fallible)
 - #103341 (Add test for issue 97607)
 - #103351 (Require Drop impls to have the same constness on its bounds as the bounds on the struct have)
 - #103359 (Remove incorrect comment in `Vec::drain`)
 - #103364 (rustdoc: clean up rustdoc-toggle CSS)
 - #103370 (rustdoc: remove unused CSS `.out-of-band { font-weight: normal }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-21 23:42:01 +00:00
Matthias Krüger
1b2f594f48
Rollup merge of #103359 - WaffleLapkin:drain_no_mut_qqq, r=scottmcm
Remove incorrect comment in `Vec::drain`

r? ``@scottmcm``

Turns out this comment wasn't correct for 6 years, since #34951, which switched from using `slice::IterMut` into using `slice::Iter`.
2022-10-22 00:14:03 +02:00
Matthias Krüger
b21eb5e5ba
Rollup merge of #103340 - RalfJung:winconsole, r=thomcc
WinConsole::new is not actually fallible

I just noticed this while reading the code for other reasons.
r? ``@thomcc``
2022-10-22 00:14:01 +02:00
bors
5c8bff74bc Auto merge of #101263 - lopopolo:lopopolo/c-unwind-fn-ptr-impls, r=thomcc
Add default trait implementations for "c-unwind" ABI function pointers

Following up on #92964, only add default trait implementations for the `c-unwind` family of function pointers. The previous attempt in #92964 added trait implementations for many more ABIs and ran into concerns regarding the increase in size of the libcore rlib.

An attempt to abstract away function pointer types behind a unified trait to reduce the duplication of trait impls is being discussed in #99531 but this change looks to be blocked on a lang MCP.

Following `@RalfJung's` suggestion in https://github.com/rust-lang/rust/pull/99531#issuecomment-1233440142, this commit is another cut at #92964 but it _only_ adds the impls for `extern "C-unwind" fn` and `unsafe extern "C-unwind" fn`.

I am interested in landing this patch to unblock the stabilization of the `c_unwind` feature.

RFC: https://github.com/rust-lang/rfcs/pull/2945
Tracking Issue: https://github.com/rust-lang/rust/issues/74990
2022-10-21 20:59:03 +00:00
bors
57e2c06a8d Auto merge of #101077 - sunshowers:signal-mask-inherit, r=sunshowers
Change process spawning to inherit the parent's signal mask by default

Previously, the signal mask was always reset when a child process is
started. This breaks tools like `nohup` which expect `SIGHUP` to be
blocked for all transitive processes.

With this change, the default behavior changes to inherit the signal mask.

This also changes the signal disposition for `SIGPIPE` to only be changed if the `#[unix_sigpipe]` attribute isn't set.
2022-10-21 18:09:03 +00:00
Chris Denton
d7b0bcb20f
Reduce false positives in msys2 detection
This checks that:

* the handle is a pipe
* the pipe's file name starts with "msys-" or "cygwin-" rather than looking in the full path.
2022-10-21 18:06:12 +01:00
Maybe Waffle
e97d295d00 Remove incorrect comment in Vec::drain 2022-10-21 15:29:02 +00:00
Andreas Molzer
e3606b2b02 Reduce mutability in std-use of with_metadata_of 2022-10-21 14:49:29 +02:00
Andreas Molzer
71c39dea4d Argument type for mutable with_metadata_of (#75091)
The method takes two pointer arguments: one `self` supplying the pointer
value, and a second pointer supplying the metadata.

The new parameter type more clearly reflects the actual requirements.
The provenance of the metadata parameter is disregarded completely.
Using a mutable pointer in the call site can be coerced to a const
pointer while the reverse is not true.

An example of the current use:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = val as *const _ as *mut T;
let ptr = uninit.as_ptr().with_metadata_of(ptr);
```

This could then instead be simplified to:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = uninit.as_ptr().with_metadata_of(&**val);
```
2022-10-21 14:46:14 +02:00
Ralf Jung
3ff0a33a83 WinConsole::new is not actually fallible 2022-10-21 12:18:33 +02:00
bors
b1ab3b738a Auto merge of #103308 - sunfishcode:sunfishcode/wasi-io-safety, r=joshtriplett
Mark `std::os::wasi::io::AsFd` etc. as stable.

io_safety was stabilized in Rust 1.63, so mark the io_safety exports in `std::os::wasi::io` as stable.

Fixes #103306.
2022-10-21 04:05:02 +00:00
Ben Kimock
9b6791078a Add a missing precondition check 2022-10-20 20:40:35 -04:00
Rain
a52c79e859 Change process spawning to inherit the parent's signal mask by default
Previously, the signal mask is always reset when a child process is
started. This breaks tools like `nohup` which expect `SIGHUP` to be
blocked.

With this change, the default behavior changes to inherit the signal mask.

This also changes the signal disposition for `SIGPIPE` to only be
changed if the `#[unix_sigpipe]` attribute isn't set.
2022-10-20 14:53:38 -07:00
Dan Gohman
7ac645a565 Make the whole std::os::wasi::io module stable. 2022-10-20 14:31:11 -07:00
Matthias Krüger
c6a680ebc5
Rollup merge of #103288 - johnmatthiggins:master, r=thomcc
Fixed docs typo in `library/std/src/time.rs`

* Changed comment from `Previous rust versions panicked when self was earlier than the current time.` to `Previous rust versions panicked when the current time was earlier than self.`
* Resolves #103282.
2022-10-20 22:42:39 +02:00
Matthias Krüger
cfb424a044
Rollup merge of #103281 - thomcc:long-overdue, r=jyn514
Adjust `transmute{,_copy}` to be clearer about which of `T` and `U` is input vs output

This is essentially a documentation-only change (although it does touch code in an irrelevant way).
2022-10-20 22:42:39 +02:00
Dan Gohman
e56b84e844 Mark std::os::wasi::io::AsFd etc. as stable.
io_safety was stabilized in Rust 1.63, so mark the io_safety exports in
`std::os::wasi::io` as stable.

Fixes #103306.
2022-10-20 08:04:19 -07:00
Ryan Lopopolo
efe61dab21
Skip C-unwind fn pointer impls with the bootstrap compiler
These need to wait until #103239 makes it into the bootstrap compiler.
2022-10-20 07:37:17 -07:00
Pointerbender
16104474ad clarify documentation about the memory layout of UnsafeCell 2022-10-20 08:37:47 +02:00
Matthias Krüger
1f210238a0
Rollup merge of #103272 - clubby789:extra-spaces, r=thomcc
Remove extra spaces in docs

Removing some random extra spaces in the examples for `core::sync::atomic`.

r? `@thomcc`
2022-10-20 07:58:57 +02:00
Matthias Krüger
62bb0c6fdd
Rollup merge of #103197 - est31:stabilize_proc_macro_source_text, r=petrochenkov
Stabilize proc_macro::Span::source_text

Splits `proc_macro::Span::source_text` into a new feature gate and stabilizes it. The [FCP is complete](https://github.com/rust-lang/rust/issues/101991#issuecomment-1279393265).

```Rust
impl Span {
    pub fn source_text(&self) -> Option<String>;
}
```

Closes #101991
2022-10-20 07:58:55 +02:00
Thom Chiovoloni
afd08175de
Adjust transmute{,_copy} to be clearer about which of T and U is input vs output 2022-10-19 22:36:14 -07:00
John Higgins
a3ccb193be
Fixed docs typo in library/std/src/time.rs 2022-10-19 21:49:29 -07:00
Ben Kimock
cfcb0a2135 Use a faster allocation size check in slice::from_raw_parts 2022-10-20 00:30:00 -04:00
Ryan Lopopolo
531679684c
Update stability annotations on fnptr impls for C-unwind ABI 2022-10-19 19:17:32 -07:00
Ryan Lopopolo
16dd5737b0
Add default trait implementations for "c-unwind" ABI function pointers
Following up on #92964, only add default trait implementations for the
`c-unwind` family of function pointers. The previous attempt in #92964
added trait implementations for many more ABIs and ran into concerns
regarding the increase in size of the libcore rlib.

An attempt to abstract away function pointer types behind a unified
trait to reduce the duplication of trait impls is being discussed in #99531
but this change looks to be blocked on a lang MCP.

Following @RalfJung's suggestion in
https://github.com/rust-lang/rust/pull/99531#issuecomment-1233440142,
this commit is another cut at #92964 but it _only_ adds the impls for
`extern "C-unwind" fn` and `unsafe extern "C-unwind" fn`.

I am interested in landing this patch to unblock the stabilization of
the `c_unwind` feature.

RFC: https://github.com/rust-lang/rfcs/pull/2945
Tracking Issue: https://github.com/rust-lang/rust/issues/74990
2022-10-19 19:17:32 -07:00
Finn Bear
4f44d6253d Put fn in the right place. 2022-10-19 19:15:58 -07:00
Finn Bear
f81cd87eea Copy of #102941. 2022-10-19 19:07:45 -07:00
Thom Chiovoloni
4b66432268
Update libstd's libc to 0.2.135 2022-10-19 17:54:55 -07:00
clubby789
19bc8fb05a Remove extra spaces 2022-10-19 23:54:00 +01:00
inquisitivecrystal
4a92cf6156 Derive Eq and Hash for ControlFlow 2022-10-19 13:25:34 -07:00
Dylan DPC
d056ea8828
Rollup merge of #103153 - ChrisDenton:leak-oom, r=m-ou-se
Allow `Vec::leak` when using `no_global_oom_handling`

As [the documentation notes](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.leak), `Vec::leak` hasn't allocated since 1.57.

cc `@Ericson2314` in case I'm missing something.
2022-10-19 14:05:53 +05:30
Dylan DPC
f4afb9d9ec
Rollup merge of #103127 - SUPERCILEX:inline-const-uninit, r=scottmcm
Make transpose const and inline

r? `@scottmcm`

- These should have been const from the beginning since we're never going to do more than a transmute.
- Inline these always because that's what every other method in MaybeUninit which simply casts does. :) Ok, but a stronger justification is that because we're taking in arrays by `self`, not inlining would defeat the whole purpose of using `MaybeUninit` due to the copying.
2022-10-19 14:05:52 +05:30
bors
84365fff0a Auto merge of #103225 - matthiaskrgr:rollup-1zkv87y, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #103166 (Optimize `slice_iter.copied().next_chunk()`)
 - #103176 (Fix `TyKind::is_simple_path`)
 - #103178 (Partially fix `src/test/run-make/coverage-reports` when cross-compiling)
 - #103198 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-19 05:41:14 +00:00
Matthias Krüger
d6eb7bca09
Rollup merge of #103166 - the8472:copied-next-chunk, r=m-ou-se
Optimize `slice_iter.copied().next_chunk()`

```
OLD:
test iter::bench_copied_array_chunks                               ... bench:         371 ns/iter (+/- 7)
NEW:
test iter::bench_copied_array_chunks                               ... bench:          31 ns/iter (+/- 0)
```

The default `next_chunk` implementation suffers from having to assemble the array byte by byte via `next()`, checking the `Option<&T>` and then dereferencing `&T`. The specialization copies the chunk directly from the slice.
2022-10-19 07:15:30 +02:00
The 8472
873a18e221 specialize slice_iter.copied().next_chunk() 2022-10-19 00:02:00 +02:00
Matthias Krüger
18431b66ce
Rollup merge of #102507 - scottmcm:more-binary-search-docs, r=m-ou-se
More slice::partition_point examples

After seeing the discussion of `binary_search` vs `partition_point` in #101999, I thought some more example code could be helpful.
2022-10-18 21:18:46 +02:00
Matthias Krüger
d2644e538c
Rollup merge of #101889 - tspiteri:redoc-uint-adc-sbb, r=m-ou-se
doc: rewrite doc for uint::{carrying_add,borrowing_sub}

Reword the documentation for bigint helper methods `uint::{carrying_add,borrowing_sub}` (#85532).

The examples were also rewritten to demonstrate how the methods can be used in bignum arithmetic. No loops are used in the examples, but the variable names were chosen to include indices so that it is clear how this can be used in a loop if required.

Also, previously `carrying_add` had an example to say that if the input carry is false, the method is equivalent to `overflowing_add`. While the note was kept, the example was removed and an extra note was added to make sure this equivalence is not assumed for signed integers as well.
2022-10-18 21:18:46 +02:00
est31
d89fb1dee5 Stabilize proc_macro::Span::source_text
Splits proc_macro::Span::source_text into a new feature gate and stabilizes it.
2022-10-18 17:13:41 +02:00
bors
e94827e5b0 Auto merge of #103188 - JohnTitor:rollup-pwilam1, r=JohnTitor
Rollup of 6 pull requests

Successful merges:

 - #103023 (Adding `fuchsia-ignore` and `needs-unwind` to compiler test cases)
 - #103142 (Make diagnostic for unsatisfied `Termination` bounds more precise)
 - #103154 (Fix typo in `ReverseSearcher` docs)
 - #103159 (Remove the redundant `Some(try_opt!(..))` in `checked_pow`)
 - #103163 (Remove all uses of array_assume_init)
 - #103168 (Stabilize asm_sym)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-18 13:35:43 +00:00
Yuki Okushi
b411b8861c
Rollup merge of #103163 - SUPERCILEX:uninit-array-assume2, r=scottmcm
Remove all uses of array_assume_init

See https://github.com/rust-lang/rust/pull/103134#discussion_r997462733

r? `@scottmcm`
2022-10-18 21:21:32 +09:00
Yuki Okushi
e04bbcb9b1
Rollup merge of #103159 - cuviper:check_pow-final-try_opt, r=Mark-Simulacrum
Remove the redundant `Some(try_opt!(..))` in `checked_pow`

The final return value doesn't need to be tried at all -- we can just
return the checked option directly. The optimizer can probably figure
this out anyway, but there's no need to make it work here.
2022-10-18 21:21:31 +09:00
Yuki Okushi
ba643786b8
Rollup merge of #103154 - H4x5:reverse-searcher-typo, r=Mark-Simulacrum
Fix typo in `ReverseSearcher` docs
2022-10-18 21:21:31 +09:00
Yuki Okushi
472a8742a6
Rollup merge of #103142 - fmease:fix-103052, r=oli-obk
Make diagnostic for unsatisfied `Termination` bounds more precise

Don't blindly emit a diagnostic claiming that “*`main` has an invalid return type*” if we encounter a type that should but doesn't implement `std::process::Termination` and isn't actually the return type of the program entry `main`.

Fixes #103052.

``@rustbot`` label A-diagnostics T-compiler T-libs
r? diagnostics
2022-10-18 21:21:30 +09:00
bors
21b246587c Auto merge of #103075 - SUPERCILEX:miri-metadata, r=thomcc
Support DirEntry metadata calls in miri

This should work as it uses lstat64 which is supported here: ~d9ad25ee4b/src/shims/unix/macos/foreign_items.rs (L42~) just noticed that's macos, linux would be using statx: 86f0e63b21/src/shims/unix/linux/foreign_items.rs (L112)

The failing syscall is `dirfd`, so maybe that should actually be added to the shims?
2022-10-18 10:54:53 +00:00
The 8472
963d6f757c add a benchmark for slice_iter.copied().array_chunks() 2022-10-17 23:40:21 +02:00
Alex Saveau
55d71c61b8
Remove all uses of array_assume_init
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-17 13:03:54 -07:00
bors
06f049a355 Auto merge of #101837 - scottmcm:box-array-from-vec, r=m-ou-se
Add `Box<[T; N]>: TryFrom<Vec<T>>`

We have `[T; N]: TryFrom<Vec<T>>` (#76310) and `Box<[T; N]>: TryFrom<Box<[T]>>`, but not this combination.

`vec.into_boxed_slice().try_into()` isn't quite a replacement for this, as that'll reallocate unnecessarily in the error case.

**Insta-stable, so needs an FCP**

(I tried to make this work with `, A`, but that's disallowed because of `#[fundamental]` https://github.com/rust-lang/rust/issues/29635#issuecomment-1247598385)
2022-10-17 19:46:04 +00:00
Josh Stone
d7fd1d57ec Remove the redundant Some(try_opt!(..)) in checked_pow
The final return value doesn't need to be tried at all -- we can just
return the checked option directly. The optimizer can probably figure
this out anyway, but there's no need to make it work here.
2022-10-17 11:21:50 -07:00
Sky
9a7e527e28
Fix typo in ReverseSearcher docs 2022-10-17 13:14:15 -04:00