Commit graph

7088 commits

Author SHA1 Message Date
Axel Viala 37c1eb0a47 Doc: Fix use of quote instead of backstick in Adapter::map. 2022-03-03 11:25:01 +01:00
Matthias Krüger 6f1730c9e3
Rollup merge of #94534 - bstrie:cffistd, r=Mark-Simulacrum
Re-export (unstable) core::ffi types from std::ffi
2022-03-03 11:02:53 +01:00
Matthias Krüger afd6f5c478
Rollup merge of #93562 - sunfishcode:sunfishcode/io-docs, r=joshtriplett
Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`.

This change weakens the descriptions of the
`{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that
they *do* express ownership relations to say that they are *typically used*
in ways that express ownership relations. This is needed since, for
example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of
the ownership relationships.

This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`,
adds the requirement that raw handles be not opened with the
`FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle`
comment into the main `FromRawHandle::from_raw_handle` comment.

And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement
`FromRawHandle`, since they are intended for limited use in FFI situations,
and not for generic use, and they have constraints that are stronger than
the those of `FromRawHandle`.

[`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html
2022-03-03 11:02:49 +01:00
Dan Gohman 8253cfef7a Remove the comment about FILE_FLAG_OVERLAPPED.
There may eventually be something to say about `FILE_FLAG_OVERLAPPED` here,
however this appears to be independent of the other changes in this PR,
so remove them from this PR so that it can be discussed separately.
2022-03-02 16:25:31 -08:00
Dylan DPC 878a4ff90e
Rollup merge of #94529 - GuillaumeGomez:unused-doc-comments-blocks, r=estebank
Unused doc comments blocks

Fixes #77030.
2022-03-03 01:09:15 +01:00
Dylan DPC c9dc44be24
Rollup merge of #93663 - sunfishcode:sunfishcode/as-raw-name, r=joshtriplett
Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`.

Also, rename `BorrowedHandle::borrow_raw_handle` and
`BorrowedSocket::borrow_raw_socket` to `BorrowedHandle::borrow_raw` and
`BorrowedSocket::borrow_raw`.

This is just a minor rename to reduce redundancy in the user code calling
these functions, and to eliminate an inessential difference between
`BorrowedFd` code and `BorrowedHandle`/`BorrowedSocket` code.

While here, add a simple test exercising `BorrowedFd::borrow_raw_fd`.

r? ``````@joshtriplett``````
2022-03-03 01:09:10 +01:00
Dylan DPC bc1a8905d6
Rollup merge of #93354 - sunfishcode:sunfishcode/document-borrowedfd-toowned, r=joshtriplett
Add documentation about `BorrowedFd::to_owned`.

Following up on #88564, this adds documentation explaining why
`BorrowedFd::to_owned` returns another `BorrowedFd` rather than an
`OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`.

r? `````@joshtriplett`````
2022-03-03 01:09:09 +01:00
The 8472 e18abbf2ac update available_parallelism docs since cgroups and sched_getaffinity are now taken into account 2022-03-03 00:43:46 +01:00
The 8472 af6d2ed245 hardcode /sys/fs/cgroup instead of doing a lookup via mountinfo
this avoids parsing mountinfo which can be huge on some systems and
something might be emulating cgroup fs for sandboxing reasons which means
it wouldn't show up as mountpoint

additionally the new implementation operates on a single pathbuffer, reducing allocations
2022-03-03 00:43:46 +01:00
The 8472 bac5523ea0 Use cgroup quotas for calculating available_parallelism
Manually tested via


```
// spawn a new cgroup scope for the current user
$ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS


// quota.rs
#![feature(available_parallelism)]
fn main() {
    println!("{:?}", std:🧵:available_parallelism()); // prints Ok(3)
}
```


Caveats

* cgroup v1 is ignored
* funky mountpoints (containing spaces, newlines or control chars) for cgroupfs will not be handled correctly since that would require unescaping /proc/self/mountinfo
  The escaping behavior of procfs seems to be undocumented. systemd and docker default to `/sys/fs/cgroup` so it should be fine for most systems.
* quota will be ignored when `sched_getaffinity` doesn't work
* assumes procfs is mounted under `/proc` and cgroupfs mounted and readable somewhere in the directory tree
2022-03-03 00:43:45 +01:00
Dan Gohman af642bb466 Fix a broken doc link on Windows. 2022-03-02 12:39:36 -08:00
Guillaume Gomez 6f0eb2a4e1 Update stdarch submodule 2022-03-02 20:06:46 +01:00
Guillaume Gomez 628fbdf9b7 Fix unused_doc_comments lint errors 2022-03-02 20:06:35 +01:00
bstrie 9aed829fe6 Re-export core::ffi types from std::ffi 2022-03-02 13:52:31 -05:00
Sébastien Marie fa8e1bedd3 merge the char signess list of archs with freebsd as it is the same 2022-03-02 12:12:28 +00:00
Sébastien Marie 3768f0b813 update char signess for openbsd
adds more archs for openbsd: arm, mips64, powerpc, powerpc64, and riscv64.
2022-03-02 10:33:50 +00:00
Ralf Jung 6739299d18 Miri/CTFE: properly treat overflow in (signed) division/rem as UB 2022-03-01 20:39:51 -05:00
Josh Triplett 75c3e9c23f Temporarily make CStr not a link in the c_char docs
When CStr moves to core with an alias in std, this can link to
`crate::ffi::CStr`. However, linking in the reverse direction (from core
to std) requires a relative path, and that path can't work from both
core::ffi and std::os::raw (different number of `../` traversals
required).
2022-03-01 17:36:40 -08:00
Josh Triplett 335c9609c6 Provide C FFI types via core::ffi, not just in std
The ability to interoperate with C code via FFI is not limited to crates
using std; this allows using these types without std.

The existing types in `std::os::raw` become type aliases for the ones in
`core::ffi`. This uses type aliases rather than re-exports, to allow the
std types to remain stable while the core types are unstable.

This also moves the currently unstable `NonZero_` variants and
`c_size_t`/`c_ssize_t`/`c_ptrdiff_t` types to `core::ffi`, while leaving
them unstable.
2022-03-01 17:16:05 -08:00
Josh Triplett 0f505c6377 Add a copy of cfg_if to core's internal_macros.rs
core can't depend on external crates the way std can. Rather than revert
usage of cfg_if, add a copy of it to core. This does not export our
copy, even unstably; such a change could occur in a later commit.
2022-03-01 16:24:10 -08:00
Dylan DPC 4001d98019
Rollup merge of #94452 - workingjubilee:sync-simd-bitmasks, r=workingjubilee
Sync portable-simd for bitmasks &c.

In the ideal case, where everything works easily and nothing has to be rearranged, it is as simple as:
- `git subtree pull -P library/portable-simd https://github.com/rust-lang/portable-simd - ${branch}`
- write the commit message
- `python x.py test --stage 1` to make sure it runs
- `git push` to your PR-to-rustc branch

If anything borks up this flow, you can fix it with sufficient git wizardry but you are usually better off going back to the source, fixing it, and starting over, before you open the PR.

r? `@calebzulawski`
2022-03-01 03:41:53 +01:00
Dylan DPC 5bd119da84
Rollup merge of #94384 - cuviper:atomic-slice, r=dtolnay
Add Atomic*::from_mut_slice

Tracking issue #76314 for `from_mut` has a question about the possibility of `from_mut_slice`, and I found a real case for it. A user in the forum had a parallelism problem that could be solved by open-indexing updates to a vector of atomics, but they didn't want to affect the other code using that vector. Using `from_mut_slice`, they could borrow that data as atomics just long enough for their parallel loop.

ref: https://users.rust-lang.org/t/sharing-vector-with-rayon-par-iter-correctly/72022
2022-03-01 03:41:51 +01:00
Dylan DPC 06d47a414b
Rollup merge of #94094 - chrisnc:tcp-nodelay-windows-bool, r=dtolnay
use BOOL for TCP_NODELAY setsockopt value on Windows

This issue was found by the Wine project and mitigated there [^1].

Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY
[^2]. Windows itself is forgiving and will accept any positive optlen and
interpret the first byte of *optval as the value, so this bug does not
affect Windows itself, but does affect systems implementing Windows'
interface more strictly, such as Wine. Wine was previously passing this
through to the host's setsockopt, where, e.g., Linux requires that
optlen be correct for the chosen option, and TCP_NODELAY expects an int.

[^1]: d6ea38f32d
[^2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
2022-03-01 03:41:50 +01:00
Matthias Krüger 9d23c320e4
Rollup merge of #92399 - Veeupup:fix_vec_typo, r=Dylan-DPC
fix typo in btree/vec doc: Self -> self

this pr fixes #92345
the documentation refers to the object the method is called for, not the type, so it should be using the lower case self.
2022-02-28 20:05:13 +01:00
Jubilee Young 4de99e187c Sync rust-lang/portable-simd@5f49d4c843 2022-02-28 10:17:40 -08:00
Matthias Krüger 770ee32b34
Rollup merge of #89793 - ibraheemdev:from_ptr_range, r=m-ou-se
Add `slice::{from_ptr_range, from_mut_ptr_range} `

Adds `slice::{from_ptr_range, from_mut_ptr_range}` as counterparts to `slice::{as_ptr_range, as_mut_ptr_range}`.
2022-02-28 12:57:44 +01:00
Ibraheem Ahmed aac0281d30 add slice::{from_ptr_range, from_mut_ptr_range} 2022-02-27 16:53:26 -05:00
bors 6a70556616 Auto merge of #94412 - scottmcm:cfg-out-miri-from-swap, r=oli-obk
For MIRI, cfg out the swap vectorization logic from 94212

Because of #69488 the swap logic from #94212 doesn't currently work in MIRI.

Copying in smaller pieces is probably much worse for its performance anyway, so it'd probably rather just use the simple path regardless.

Part of #94371, though another PR will be needed for the CTFE aspect.

r? `@oli-obk`
cc `@RalfJung`
2022-02-27 17:42:48 +00:00
Thomas de Zeeuw a84e77bebf Stabilize unix_socket_creation 2022-02-27 15:34:48 +01:00
Scott McMurray b582bd388f For MIRI, cfg out the swap logic from 94212 2022-02-26 18:57:15 -08:00
bors 035a717ee8 Auto merge of #94373 - erikdesjardins:getitinl, r=Mark-Simulacrum
Make TLS __getit #[inline(always)] on non-Windows

This may improve perf, and/or stop `externs` perf benchmarks from being flaky.

r? `@ghost`
2022-02-27 01:23:48 +00:00
bors 12b71ed4c5 Auto merge of #94385 - matthiaskrgr:rollup-4pwegqk, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #93603 (Populate liveness facts when calling `get_body_with_borrowck_facts` without `-Z polonius`)
 - #93870 (Fix switch on discriminant detection in a presence of coverage counters)
 - #94355 (Add one more case to avoid ICE)
 - #94363 (Remove needless borrows from core::fmt)
 - #94377 (`check_used` should only look at actual `used` attributes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-26 02:09:29 +00:00
Matthias Krüger 0c9d5e3c77
Rollup merge of #94363 - aDotInTheVoid:fmt-needless-borrows, r=scottmcm
Remove needless borrows from core::fmt
2022-02-26 00:49:23 +01:00
bors d973b358c6 Auto merge of #94342 - ibraheemdev:swap-regression, r=Dylan-DPC
Revert implementation of `slice::swap`

Due to the perf regressions noticed here, possible due to inlining? https://github.com/rust-lang/rust/pull/88540#issuecomment-944344343

r? `@kennytm`
2022-02-25 23:47:00 +00:00
Josh Stone d3d2a279fe Add Atomic*::from_mut_slice 2022-02-25 15:30:29 -08:00
Erik Desjardins 2d6d30f4a8 Make TLS __getit #[inline(always)] on non-Windows
This may improve perf.
2022-02-25 15:21:27 -05:00
bors d981633ed6 Auto merge of #94290 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini
Bump bootstrap to 1.60

This bumps the bootstrap compiler to 1.60 and cleans up cfgs and Span's rustc_pass_by_value (enabled by the bootstrap bump).
2022-02-25 18:34:02 +00:00
Nixon Enraght-Moony 6b68882e45 Remove needless borrows from core::fmt 2022-02-25 16:06:23 +00:00
Mark Rousskov 3c62f2f635 Re-add track_caller to panic_no_unwind in bootstrap
This function was updated in a recent PR (92911) to be called without the caller
information passed in, but the function signature itself was not altered with
cfg_attr at the time.
2022-02-25 08:00:53 -05:00
Mark Rousskov 22c3a71de1 Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
Thomas de Zeeuw 7f44b3a118 Rename unix::net::SocketAddr::from_path to from_pathname
Matching SocketAddr::as_pathname.
2022-02-25 13:05:49 +01:00
Jethro Beekman 355d503ace Fix SGX docs build 2022-02-25 12:12:37 +01:00
Matthias Krüger e5bd222c6b
Rollup merge of #94184 - ssomers:btree_tests, r=Dylan-DPC
BTree: simplify test code

Mostly, use `from` & `from_iter`.
2022-02-25 07:30:49 +01:00
Matthias Krüger 6ec5b056b0
Rollup merge of #92714 - yanganto:ignore-message, r=Mark-Simulacrum
Provide ignore message in the result of test

Provide ignore the message in the result of the test.

This PR does not need RFC, because it is about the presentation of the report of `cargo test`.

However, the following document listed here helps you to know about PR.

- [RFC](https://github.com/rust-lang/rfcs/pull/3217)
- [Rendered](https://github.com/yanganto/rfcs/blob/ignore-test-message/text/0000-ignore-test-message.md)
- [Previous discussion on IRLO](https://internals.rust-lang.org/t/pre-rfc-provide-ignore-message-when-the-test-ignored/15904)

If there is something improper, please let me know.
Thanks.
2022-02-25 07:30:47 +01:00
Ibraheem Ahmed 072d35dc2d revert implementation of slice::swap 2022-02-24 19:32:54 -05:00
Antonio Yang bb3b5574cd Include ignore message in libtest output
As an example:

    #[test]
    #[ignore = "not yet implemented"]
    fn test_ignored() {
        ...
    }

Will now render as:

    running 2 tests
    test tests::test_ignored ... ignored, not yet implemented

    test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s
2022-02-24 17:36:36 -05:00
Dylan DPC 7fb55b4c3a
Rollup merge of #94212 - scottmcm:swapper, r=dtolnay
Stop manually SIMDing in `swap_nonoverlapping`

Like I previously did for `reverse` (#90821), this leaves it to LLVM to pick how to vectorize it, since it can know better the chunk size to use, compared to the "32 bytes always" approach we currently have.

A variety of codegen tests are included to confirm that the various cases are still being vectorized.

It does still need logic to type-erase in some cases, though, as while LLVM is now smart enough to vectorize over slices of things like `[u8; 4]`, it fails to do so over slices of `[u8; 3]`.

As a bonus, this change also means one no longer gets the spurious `memcpy`(s?) at the end up swapping a slice of `__m256`s: <https://rust.godbolt.org/z/joofr4v8Y>

<details>

<summary>ASM for this example</summary>

## Before (from godbolt)

note the `push`/`pop`s and `memcpy`

```x86
swap_m256_slice:
        push    r15
        push    r14
        push    r13
        push    r12
        push    rbx
        sub     rsp, 32
        cmp     rsi, rcx
        jne     .LBB0_6
        mov     r14, rsi
        shl     r14, 5
        je      .LBB0_6
        mov     r15, rdx
        mov     rbx, rdi
        xor     eax, eax
.LBB0_3:
        mov     rcx, rax
        vmovaps ymm0, ymmword ptr [rbx + rax]
        vmovaps ymm1, ymmword ptr [r15 + rax]
        vmovaps ymmword ptr [rbx + rax], ymm1
        vmovaps ymmword ptr [r15 + rax], ymm0
        add     rax, 32
        add     rcx, 64
        cmp     rcx, r14
        jbe     .LBB0_3
        sub     r14, rax
        jbe     .LBB0_6
        add     rbx, rax
        add     r15, rax
        mov     r12, rsp
        mov     r13, qword ptr [rip + memcpy@GOTPCREL]
        mov     rdi, r12
        mov     rsi, rbx
        mov     rdx, r14
        vzeroupper
        call    r13
        mov     rdi, rbx
        mov     rsi, r15
        mov     rdx, r14
        call    r13
        mov     rdi, r15
        mov     rsi, r12
        mov     rdx, r14
        call    r13
.LBB0_6:
        add     rsp, 32
        pop     rbx
        pop     r12
        pop     r13
        pop     r14
        pop     r15
        vzeroupper
        ret
```

## After (from my machine)

Note no `rsp` manipulation, sorry for different ASM syntax

```x86
swap_m256_slice:
	cmpq	%r9, %rdx
	jne	.LBB1_6
	testq	%rdx, %rdx
	je	.LBB1_6
	cmpq	$1, %rdx
	jne	.LBB1_7
	xorl	%r10d, %r10d
	jmp	.LBB1_4
.LBB1_7:
	movq	%rdx, %r9
	andq	$-2, %r9
	movl	$32, %eax
	xorl	%r10d, %r10d
	.p2align	4, 0x90
.LBB1_8:
	vmovaps	-32(%rcx,%rax), %ymm0
	vmovaps	-32(%r8,%rax), %ymm1
	vmovaps	%ymm1, -32(%rcx,%rax)
	vmovaps	%ymm0, -32(%r8,%rax)
	vmovaps	(%rcx,%rax), %ymm0
	vmovaps	(%r8,%rax), %ymm1
	vmovaps	%ymm1, (%rcx,%rax)
	vmovaps	%ymm0, (%r8,%rax)
	addq	$2, %r10
	addq	$64, %rax
	cmpq	%r10, %r9
	jne	.LBB1_8
.LBB1_4:
	testb	$1, %dl
	je	.LBB1_6
	shlq	$5, %r10
	vmovaps	(%rcx,%r10), %ymm0
	vmovaps	(%r8,%r10), %ymm1
	vmovaps	%ymm1, (%rcx,%r10)
	vmovaps	%ymm0, (%r8,%r10)
.LBB1_6:
	vzeroupper
	retq
```

</details>

This does all its copying operations as either the original type or as `MaybeUninit`s, so as far as I know there should be no potential abstract machine issues with reading padding bytes as integers.

<details>

<summary>Perf is essentially unchanged</summary>

Though perhaps with more target features this would help more, if it could pick bigger chunks

## Before

```
running 10 tests
test slice::swap_with_slice_4x_usize_30                            ... bench:         894 ns/iter (+/- 11)
test slice::swap_with_slice_4x_usize_3000                          ... bench:      99,476 ns/iter (+/- 2,784)
test slice::swap_with_slice_5x_usize_30                            ... bench:       1,257 ns/iter (+/- 7)
test slice::swap_with_slice_5x_usize_3000                          ... bench:     139,922 ns/iter (+/- 959)
test slice::swap_with_slice_rgb_30                                 ... bench:         328 ns/iter (+/- 27)
test slice::swap_with_slice_rgb_3000                               ... bench:      16,215 ns/iter (+/- 176)
test slice::swap_with_slice_u8_30                                  ... bench:         312 ns/iter (+/- 9)
test slice::swap_with_slice_u8_3000                                ... bench:       5,401 ns/iter (+/- 123)
test slice::swap_with_slice_usize_30                               ... bench:         368 ns/iter (+/- 3)
test slice::swap_with_slice_usize_3000                             ... bench:      28,472 ns/iter (+/- 3,913)
```

## After

```
running 10 tests
test slice::swap_with_slice_4x_usize_30                            ... bench:         868 ns/iter (+/- 36)
test slice::swap_with_slice_4x_usize_3000                          ... bench:      99,642 ns/iter (+/- 1,507)
test slice::swap_with_slice_5x_usize_30                            ... bench:       1,194 ns/iter (+/- 11)
test slice::swap_with_slice_5x_usize_3000                          ... bench:     139,761 ns/iter (+/- 5,018)
test slice::swap_with_slice_rgb_30                                 ... bench:         324 ns/iter (+/- 6)
test slice::swap_with_slice_rgb_3000                               ... bench:      15,962 ns/iter (+/- 287)
test slice::swap_with_slice_u8_30                                  ... bench:         281 ns/iter (+/- 5)
test slice::swap_with_slice_u8_3000                                ... bench:       5,324 ns/iter (+/- 40)
test slice::swap_with_slice_usize_30                               ... bench:         275 ns/iter (+/- 5)
test slice::swap_with_slice_usize_3000                             ... bench:      28,277 ns/iter (+/- 277)
```

</detail>
2022-02-24 21:42:14 +01:00
Matthias Krüger bdcdd1b122
Rollup merge of #94300 - WaffleLapkin:patch-4, r=scottmcm
Fix a typo in documentation of `array::IntoIter::new_unchecked`

🌸
2022-02-24 07:48:12 +01:00
Matthias Krüger f3433d1b59
Rollup merge of #94283 - hellow554:stable_flow_control, r=Dylan-DPC
remove feature gate in control_flow examples

Stabilization was done in https://github.com/rust-lang/rust/pull/91091, but the two examples weren't updated accordingly.

Probably too late to put it into stable, but it should be in the next release :)
2022-02-24 07:48:08 +01:00
Matthias Krüger aa0b7ac0bf
Rollup merge of #94273 - Dylan-DPC:doc/errorkind, r=joshtriplett
add matching doc to errorkind

Rework of #90706
2022-02-24 07:48:07 +01:00
Dylan DPC 3f4b039e33 word wrpa 2022-02-24 00:37:06 +01:00
Dylan DPC eb795c24fb word wrpa 2022-02-24 00:30:07 +01:00
Dylan DPC c46d9f6c89
Update library/std/src/io/error.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-02-23 23:18:42 +01:00
Waffle Maybe 715262f151
Fix a typo in documentation of array::IntoIter::new_unchecked 2022-02-23 21:10:04 +03:00
Tavian Barnes 478cf8b3a4 fs: Don't dereference a pointer to a too-small allocation
ptr::addr_of!((*ptr).field) still requires ptr to point to an
appropriate allocation for its type.  Since the pointer returned by
readdir() can be smaller than sizeof(struct dirent), we need to entirely
avoid dereferencing it as that type.

Link: https://github.com/rust-lang/miri/pull/1981#issuecomment-1048278492
Link: https://github.com/rust-lang/rust/pull/93459#discussion_r795089971
2022-02-23 09:51:02 -05:00
Matthias Krüger efe6a979b5
Rollup merge of #94264 - NyantasticUwU:patch-1, r=yaahc
Fix typo.

Yeah just a typo (probably some breaking changes in here be careful) :)
2022-02-23 12:26:45 +01:00
Matthias Krüger 40afbdd148
Rollup merge of #94240 - compiler-errors:pathbuf-display, r=lcnr
Suggest calling .display() on `PathBuf` too

Fixes #94210
2022-02-23 12:26:42 +01:00
Matthias Krüger 0c676a8a84
Rollup merge of #94128 - mqy:master, r=Dylan-DPC
rustdoc: several minor fixes

``@rustbot`` label A-docs
2022-02-23 12:26:40 +01:00
Marcel Hellwig c403424203 remove feature gate in control_flow examples 2022-02-23 10:42:46 +01:00
Dylan DPC 057dc09eae add some more summary from pr discussion 2022-02-23 03:29:02 +01:00
Dylan DPC 37cbc7d120 add some more summary from pr discussion 2022-02-23 03:28:27 +01:00
Dylan DPC 4905814249 add matching to errorkind 2022-02-23 03:22:23 +01:00
bors 5bd1ec3283 Auto merge of #83706 - a1phyr:fix_vec_layout_calculation, r=JohnTitor
Fix a layout possible miscalculation in `alloc::RawVec`

A layout miscalculation could happen in `RawVec` when used with a type whose size isn't a multiple of its alignment. I don't know if such type can exist in Rust, but the Layout API provides ways to manipulate such types. Anyway, it is better to calculate memory size in a consistent way.
2022-02-22 20:50:38 +00:00
NyantasticUwU c61d5923f2
Fix typo.
Yeah just a typo (probably some breaking changes in here be careful) :)
2022-02-22 11:44:45 -06:00
Matthias Krüger 21fb81405e
Rollup merge of #94179 - devnexen:getexecname_directcall, r=kennytm
solarish current_exe using libc call directly
2022-02-22 12:16:30 +01:00
Deadbeef 5941fef292
Constify slice indexing 2022-02-22 12:39:36 +11:00
Michael Goulet a08809ff7b Suggest calling .display() on PathBuf too 2022-02-21 16:58:12 -08:00
Matthias Krüger ed3530925e
Rollup merge of #94220 - GuillaumeGomez:miniz-oxide-decl, r=Amanieu
Correctly handle miniz_oxide extern crate declaration

Fixes https://github.com/rust-lang/rust/issues/94219.

Follow-up of https://github.com/rust-lang/rust/pull/94122.

The `miniz_oxide` dependency is optional and therefore should allow be "imported" when it makes sense.

r? `@ivmarkov`
2022-02-21 19:36:55 +01:00
Matthias Krüger 74cb6b77a0
Rollup merge of #94186 - ehuss:pin-stable-1.61, r=m-ou-se
Update pin_static_ref stabilization version.

#93580 slipped into 1.61

cc `@m-ou-se`
2022-02-21 19:36:49 +01:00
Matthias Krüger 12705b4700
Rollup merge of #91192 - r00ster91:futuredocs, r=GuillaumeGomez
Some improvements to the async docs

The goal here is to make the docs overall a little bit more comprehensive and add more links between the things.

One thing that's not working yet is the links to the keywords. Somehow I couldn't get them to work.

r? ````@GuillaumeGomez```` do you know how I could get the keyword links to work?
2022-02-21 19:36:46 +01:00
Guillaume Gomez 910d46fd60 Correctly handle miniz_oxide extern crate declaration 2022-02-21 17:27:55 +01:00
Scott McMurray 8ca47d7ae4 Stop manually SIMDing in swap_nonoverlapping
Like I previously did for `reverse`, this leaves it to LLVM to pick how to vectorize it, since it can know better the chunk size to use, compared to the "32 bytes always" approach we currently have.

It does still need logic to type-erase where appropriate, though, as while LLVM is now smart enough to vectorize over slices of things like `[u8; 4]`, it fails to do so over slices of `[u8; 3]`.

As a bonus, this also means one no longer gets the spurious `memcpy`(s?) at the end up swapping a slice of `__m256`s: <https://rust.godbolt.org/z/joofr4v8Y>
2022-02-21 00:54:02 -08:00
Chris Copeland b02698c7e6
use BOOL for TCP_NODELAY setsockopt value on Windows
This issue was found by the Wine project and mitigated there [1].

Windows' documented interface for `setsockopt` expects a `BOOL` (a
`typedef` for `int`) for `TCP_NODELAY` [2]. Windows is forgiving and
will accept any positive length and interpret the first byte of
`*option_value` as the value, so this bug does not affect Windows
itself, but does affect systems implementing Windows' interface more
strictly, such as Wine. Wine was previously passing this through to the
host's `setsockopt`, where, e.g., Linux requires that `option_len` be
correct for the chosen option, and `TCP_NODELAY` expects an `int`.

[1]: d6ea38f32d
[2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
2022-02-20 21:27:36 -08:00
Chris Copeland f2ebd0a11f
Remove assertion on output length for getsockopt.
POSIX allows `getsockopt` to set `*option_len` to a smaller value if
necessary. Windows will set `*option_len` to 1 for boolean options even
when the caller passes a `BOOL` (`int`) with `*option_len` as 4.
2022-02-20 21:27:36 -08:00
Chris Copeland 3eb983ed99
Fix setsockopt and getsockopt parameter names.
Previously `level` was named `opt` and `option_name` was named `val`,
then extra names of `payload` or `slot` were used for the option value.
This change aligns the wrapper parameters with their names in POSIX.
Winsock uses similar but more abbreviated names: `level`, `optname`,
`optval`, `optlen`.
2022-02-20 21:27:22 -08:00
Eric Huss 72a7e731e1 Update pin_static_ref stabilization version. 2022-02-20 06:42:20 -08:00
Stein Somers 7950ebcd8e BTree: simplify test code 2022-02-20 14:43:59 +01:00
David Carlier f810314bc6 solarish current_exe using libc call directly 2022-02-20 08:53:18 +00:00
bors 25ad89e47b Auto merge of #94174 - matthiaskrgr:rollup-snyrlhy, r=matthiaskrgr
Rollup of 14 pull requests

Successful merges:

 - #93580 (Stabilize pin_static_ref.)
 - #93639 (Release notes for 1.59)
 - #93686 (core: Implement ASCII trim functions on byte slices)
 - #94002 (rustdoc: Avoid duplicating macros in sidebar)
 - #94019 (removing architecture requirements for RustyHermit)
 - #94023 (adapt static-nobundle test to use llvm-nm)
 - #94091 (Fix rustdoc const computed value)
 - #94093 (Fix pretty printing of enums without variants)
 - #94097 (Add module-level docs for `rustc_middle::query`)
 - #94112 (Optimize char_try_from_u32)
 - #94113 (document rustc_middle::mir::Field)
 - #94122 (Fix miniz_oxide types showing up in std docs)
 - #94142 (rustc_typeck: adopt let else in more places)
 - #94146 (Adopt let else in more places)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-20 02:19:41 +00:00
fren_gor 04b3162764
Add collect_into 2022-02-20 01:57:32 +01:00
Matthias Krüger a69aaf4aee
Rollup merge of #94122 - GuillaumeGomez:miniz-oxide-std, r=notriddle
Fix miniz_oxide types showing up in std docs

Fixes #90526.

Thanks to ```````@camelid,``````` I rediscovered `doc(masked)`, allowing us to prevent `miniz_oxide` type to show up in std docs.

r? ```````@notriddle```````
2022-02-20 00:37:32 +01:00
Matthias Krüger 7cd857dc34
Rollup merge of #94112 - digama0:patch-3, r=scottmcm
Optimize char_try_from_u32

The optimization was proposed by ```````@falk-hueffner``````` in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Micro-optimizing.20char.3A.3Afrom_u32/near/272146171,  and I simplified it a bit and added an explanation of why the optimization is correct. The generated code is 2 instructions shorter and uses 2 registers instead of 4 on x86.
2022-02-20 00:37:30 +01:00
Matthias Krüger 6b69121d0d
Rollup merge of #94019 - hermitcore:target, r=Mark-Simulacrum
removing architecture requirements for RustyHermit

RustHermit and HermitCore is able to run on aarch64 and x86_64. In the future these operating systems will also support RISC-V. Consequently, the dependency to a specific target should be removed.

The build process of `hermit-abi` fails if the architecture isn't supported.
2022-02-20 00:37:25 +01:00
Matthias Krüger 575f6c5cc1
Rollup merge of #93686 - dbrgn:trim-on-byte-slices, r=joshtriplett
core: Implement ASCII trim functions on byte slices

Hi ````````@rust-lang/libs!```````` This is a feature that I wished for when implementing serial protocols with microcontrollers. Often these protocols may contain leading or trailing whitespace, which needs to be removed. Because oftentimes drivers will operate on the byte level, decoding to unicode and checking for unicode whitespace is unnecessary overhead.

This PR adds three new methods to byte slices:

- `trim_ascii_start`
- `trim_ascii_end`
- `trim_ascii`

I did not find any pre-existing discussions about this, which surprises me a bit. Maybe I'm missing something, and this functionality is already possible through other means? There's https://github.com/rust-lang/rfcs/issues/2547 ("Trim methods on slices"), but that has a different purpose.

As per the [std dev guide](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), this is a proposed implementation without any issue / RFC. If this is the wrong process, please let me know. However, I thought discussing code is easier than discussing a mere idea, and hacking on the stdlib was fun.

Tracking issue: https://github.com/rust-lang/rust/issues/94035
2022-02-20 00:37:23 +01:00
Matthias Krüger 7977af5975
Rollup merge of #93580 - m-ou-se:stabilize-pin-static-ref, r=scottmcm
Stabilize pin_static_ref.

FCP finished here: https://github.com/rust-lang/rust/issues/78186#issuecomment-1024987221

Closes #78186
2022-02-20 00:37:21 +01:00
bors 2690468727 Auto merge of #92911 - nbdd0121:unwind, r=Amanieu
Guard against unwinding in cleanup code

Currently the only safe guard we have against double unwind is the panic count (which is local to Rust). When double unwinds indeed happen (e.g. C++ exception + Rust panic, or two C++ exceptions), then the second unwind actually goes through and the first unwind is leaked. This can cause UB. cc rust-lang/project-ffi-unwind#6

E.g. given the following C++ code:
```c++
extern "C" void foo() {
    throw "A";
}

extern "C" void execute(void (*fn)()) {
    try {
        fn();
    } catch(...) {
    }
}
```

This program is well-defined to terminate:
```c++
struct dtor {
    ~dtor() noexcept(false) {
        foo();
    }
};

void a() {
    dtor a;
    dtor b;
}

int main() {
    execute(a);
    return 0;
}
```

But this Rust code doesn't catch the double unwind:
```rust
extern "C-unwind" {
    fn foo();
    fn execute(f: unsafe extern "C-unwind" fn());
}

struct Dtor;

impl Drop for Dtor {
    fn drop(&mut self) {
        unsafe { foo(); }
    }
}

extern "C-unwind" fn a() {
    let _a = Dtor;
    let _b = Dtor;
}

fn main() {
    unsafe { execute(a) };
}
```

To address this issue, this PR adds an unwind edge to an abort block, so that the Rust example aborts. This is similar to how clang guards against double unwind (except clang calls terminate per C++ spec and we abort).

The cost should be very small; it's an additional trap instruction (well, two for now, since we use TrapUnreachable, but that's a different issue) for each function with landing pads; if LLVM gains support to encode "abort/terminate" info directly in LSDA like GCC does, then it'll be free. It's an additional basic block though so compile time may be worse, so I'd like a perf run.

r? `@ghost`
`@rustbot` label: F-c_unwind
2022-02-19 23:25:06 +00:00
r00ster91 297364eb07 Some improvements to the async docs 2022-02-19 17:17:40 +01:00
bors e08d569360 Auto merge of #94148 - matthiaskrgr:rollup-jgea68f, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #92902 (Improve the documentation of drain members)
 - #93658 (Stabilize `#[cfg(panic = "...")]`)
 - #93954 (rustdoc-json: buffer output)
 - #93979 (Add debug assertions to validate NUL terminator in c strings)
 - #93990 (pre #89862 cleanup)
 - #94006 (Use a `Field` in `ConstraintCategory::ClosureUpvar`)
 - #94086 (Fix ScalarInt to char conversion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-19 12:15:10 +00:00
Matthias Krüger 26dd6ac830
Rollup merge of #93979 - SUPERCILEX:debug_check, r=dtolnay
Add debug assertions to validate NUL terminator in c strings

The `unchecked` variants from the stdlib usually perform the check anyway if debug assertions are on (for example, `unwrap_unchecked`). This PR does the same thing for `CStr` and `CString`, validating the correctness for the NUL byte in debug mode.
2022-02-19 06:45:30 +01:00
Matthias Krüger f19adc7acc
Rollup merge of #93658 - cchiw:issue-77443-fix, r=joshtriplett
Stabilize `#[cfg(panic = "...")]`

[Stabilization PR](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr) for #77443
2022-02-19 06:45:29 +01:00
Matthias Krüger 4fa71ed0f0
Rollup merge of #92902 - ssomers:docter_drain, r=yaahc
Improve the documentation of drain members

hopefully fixes #92765
2022-02-19 06:45:28 +01:00
bors cb4ee81ef5 Auto merge of #94105 - 5225225:destabilise-entry-insert, r=Mark-Simulacrum
Destabilise entry_insert

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

I didn't revert the rename that was done in that PR, I left it as `entry_insert`.

Additionally, before that PR, `VacantEntry::insert_entry` seemingly had no stability attribute on it? I kept the attribute, just made it an unstable one, same as the one on `Entry`.

There didn't seem to be any mention of this in the RELEASES.md, so I don't think there's anything for me to do other than this?
2022-02-19 05:08:13 +00:00
Stein Somers a677e60840 Collections: improve the documentation of drain members 2022-02-19 00:55:31 +01:00
Matthias Krüger 724cca6d7f
Rollup merge of #93847 - solid-rs:fix-kmc-solid-fs-ts, r=yaahc
kmc-solid: Use the filesystem thread-safety wrapper

Fixes the thread unsafety of the `std::fs` implementation used by the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

Neither the SOLID filesystem API nor built-in filesystem drivers guarantee thread safety by default. Although this may suffice in general embedded-system use cases, and in fact the API can be used from multiple threads without any problems in many cases, this has been a source of unsoundness in `std::sys::solid::fs`.

This commit updates the implementation to leverage the filesystem thread-safety wrapper (which uses a pluggable synchronization mechanism) to enforce thread safety. This is done by prefixing all paths passed to the filesystem API with `\TS`. (Note that relative paths aren't supported in this platform.)
2022-02-18 23:23:07 +01:00
mqy 997492538b rustdoc: several minor fixes 2022-02-19 03:47:41 +08:00
Guillaume Gomez b78123cdcf Fix miniz_oxide types showing up in std 2022-02-18 17:31:38 +01:00
Matthias Krüger f1c918f1f3
Rollup merge of #93613 - crlf0710:rename_to_async_iter, r=yaahc
Move `{core,std}::stream::Stream` to `{core,std}::async_iter::AsyncIterator`

Following amendments in https://github.com/rust-lang/rfcs/pull/3208/.

cc #79024
cc ``@yoshuawuyts`` ``@joshtriplett``
2022-02-18 16:23:32 +01:00
Mario Carneiro 7c3ebec0ca
fix 2022-02-17 22:14:54 -08:00
Mario Carneiro 0f14bea448
Optimize char_try_from_u32
The optimization was proposed by @falk-hueffner in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Micro-optimizing.20char.3A.3Afrom_u32/near/272146171,  and I simplified it a bit and added an explanation of why the optimization is correct.
2022-02-17 20:27:53 -08:00
bors f838a425e3 Auto merge of #94095 - Amanieu:update_stdarch, r=dtolnay
Fix documentation for is_X_feature_detected!

These are now properly documented for all architectures and the
stability attributes in the docs are now correctly displayed.

This addresses this comment by `@ehuss:` https://github.com/rust-lang/rust/pull/90271#issuecomment-1038400916

cc `@adamgemmell`
2022-02-18 04:16:03 +00:00
5225225 319dd150fc Destabilise entry_insert 2022-02-17 22:23:31 +00:00
Matthias Krüger a4be35e321
Rollup merge of #94041 - a-lafrance:try-collect, r=scottmcm
Add a `try_collect()` helper method to `Iterator`

Implement `Iterator::try_collect()` as a helper around `Iterator::collect()` as discussed [here](https://internals.rust-lang.org/t/idea-fallible-iterator-mapping-with-try-map/15715/5?u=a.lafrance).

First time contributor so definitely open to any feedback about my implementation! Specifically wondering if I should open a tracking issue for the unstable feature I introduced.

As the main participant in the internals discussion: r? `@scottmcm`
2022-02-17 23:01:00 +01:00
Matthias Krüger 09350d2cf0
Rollup merge of #93976 - SUPERCILEX:separator_str, r=yaahc
Add MAIN_SEPARATOR_STR

Currently, if someone needs access to the path separator as a str, they need to go through this mess:

```rust
unsafe {
    std::str::from_utf8_unchecked(slice::from_ref(&(MAIN_SEPARATOR as u8)))
}
```

This PR just re-exports an existing path separator str API.
2022-02-17 23:00:58 +01:00
Danilo Bargen f7448a77e4 core: Implement trim functions on byte slices
Co-authored-by: Jubilee Young <workingjubilee@gmail.com>
2022-02-17 21:19:42 +01:00
Amanieu d'Antras 2b3fa06994 Fix documentation for is_X_feature_detected!
These are now properly documented for all architectures and the
stability attributes in the docs are now correctly displayed.
2022-02-17 18:17:15 +00:00
Matthias Krüger d855121a44
Rollup merge of #93479 - smoelius:master, r=yaahc
Use `optflag` for `--report-time`

Essentially, what is described here:
https://github.com/rust-lang/rust/issues/64888#issuecomment-1008047228

There is one difference. The comment proposes to add a
`--report-time-color` option. This change instead uses libtest's
existing `--color` option for that purpose.
2022-02-17 06:29:59 +01:00
Matthias Krüger 1cc0ae4cbb
Rollup merge of #89869 - kpreid:from-doc, r=yaahc
Add documentation to more `From::from` implementations.

For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy.

Notes on specific cases:
* The new documentation for `From<T> for T` explains that it is not a conversion at all.
* Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion.
* The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set.
* I did not add documentation to conversions of a specific error type to a more general error type.
* I did not add documentation to unstable code.

This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
2022-02-17 06:29:57 +01:00
Alex Saveau 80fde23a75
Add MAIN_SEPARATOR_STR
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-02-16 19:38:12 -08:00
Alex Saveau 897c8d0ab9
Add debug asserts to validate NUL terminator in c strings
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-02-16 18:34:17 -08:00
bors 930fc4f59d Auto merge of #94040 - Mark-Simulacrum:destabilize-load-store, r=Amanieu
Destabilize cfg(target_has_atomic_load_store = ...)

This was not intended to be stabilized yet.

This keeps the cfg_target_has_atomic feature gate name since compiler-builtins otherwise depends on it and I'd rather not try to manage a bump across a crates.io published repository given the time-sensitivity here (we need to land this quickly to avoid a beta backport).

Closes https://github.com/rust-lang/rust/issues/32976

r? `@Amanieu`
2022-02-17 01:56:40 +00:00
Arthur Lafrance 47d5196a00 Add a try_collect() helper method to Iterator
Tweaked `try_collect()` to accept more `Try` types

Updated feature attribute for tracking issue
2022-02-16 14:26:39 -08:00
bors 2ff7ea4de2 Auto merge of #91182 - ChrisDenton:command-broken-symlink, r=m-ou-se
Maintain broken symlink behaviour for the Windows exe resolver

When the resolver was updated to remove the current directory from the search path (see #87704), care was take to avoid unintentional changes that hadn't been discussed. However, I missed the broken symlink behaviour. This PR fixes that.

**Edit** This turned out to be more important than I first realised. There are some types of application stubs that will redirect to the actual process when run using `CreateProcessW`, but due to the way they're implemented they cannot be opened normally using a `File::open` that follows reparse points. So this doesn't work with our current `exists` and `try_exists` methods.

Fixes #91177
2022-02-16 22:11:22 +00:00
Matthias Krüger 9a42121135
Rollup merge of #93962 - joboet:branchless_slice_ord, r=Mark-Simulacrum
Make [u8]::cmp implementation branchless

The current implementation generates rather ugly assembly code, branching when the common parts are equal. By performing the comparison of the lengths upfront using a subtraction, the assembly gets much prettier: https://godbolt.org/z/4e5fnEKGd.

This will probably not impact speed too much, as the expensive part is in most cases the `memcmp`, but it sure looks better (I'm porting a sorting algorithm currently, and that branch just bothered me).
2022-02-16 18:59:29 +01:00
Mark Rousskov fc01d2b854 Destabilize cfg(target_has_atomic_load_store = ...)
This was not intended to be stabilized yet.
2022-02-16 10:28:12 -05:00
Matthias Krüger e1baa3d5b9
Rollup merge of #93949 - glaubitz:m68k-unwind, r=Mark-Simulacrum
Add basic platform support to library/{panic_}unwind for m68k

This PR adds basic platform support for m68k for library/{panic_}unwind for m68k.

Register information for UNWIND_DATA_REG has been extracted from LLVM.
2022-02-15 16:02:35 +01:00
Matthias Krüger cdfdcfcf18
Rollup merge of #93899 - ssomers:vecdeque_naming, r=m-ou-se
Describe VecDeque with more consistent names

The public documentation of VecDeque starts describing itself as a "queue". In method descriptions, it's ~~never~~ sometimes named queue again, or `VecDeque` (IMO a sometimes useful and often noisy notation) or "deque" or "vector". In examples, `deque`, `v` (hidden in `range_mut`) or `vector`. Here is a subjective attempt at more consistency.
2022-02-15 16:02:34 +01:00
Stefan Lankes 227d106aec remove compiler warnings 2022-02-15 14:03:26 +01:00
Stefan Lankes 1ab5b0bc05 removing architecture requirements for RustyHermit
RustHermit and HermitCore is able to run on aarch64 and x86_64.
In the future these operating systems will also support RISC-V.
Consequently, the dependency to a specific target should be removed.
Building hermit-abi fails if the architecture isn't supported.
2022-02-15 13:57:07 +01:00
joboet 3960ce6ec5
Make [u8]::cmp implementation branchless 2022-02-14 23:16:35 +01:00
Daniel Henry-Mantilla 002f627d38 Add a comment to justify why the pointer field is pub.
Addresses https://github.com/rust-lang/rust/pull/93176/files#r795258110.
2022-02-14 17:35:27 +01:00
Daniel Henry-Mantilla 6df63cc148 Replace def_site-&-privacy implementation with a stability-based one.
Since `decl_macro`s and/or `Span::def_site()` is deemed quite unstable,
no public-facing macro that relies on it can hope to be, itself, stabilized.

We circumvent the issue by no longer relying on field privacy for safety and,
instead, relying on an unstable feature-gate to act as the gate keeper for
non users of the macro (thanks to `allow_internal_unstable`).

This is technically not correct (since a `nightly` user could technically enable
the feature and cause unsoundness with it); or, in other words, this makes the
feature-gate used to gate the access to the field be (technically unsound, and
in practice) `unsafe`. Hence it having `unsafe` in its name.

Back to the macro, we go back to `macro_rules!` / `mixed_site()`-span rules thanks
to declaring the `decl_macro` as `semitransparent`, which is a hack to basically have
`pub macro_rules!`

Co-Authored-By: Mara Bos <m-ou.se@m-ou.se>
2022-02-14 17:27:37 +01:00
Daniel Henry-Mantilla 54e443dceb Improve documentation.
Co-Authored-By: Mara Bos <m-ou.se@m-ou.se>
2022-02-14 17:27:32 +01:00
Daniel Henry-Mantilla 42d69e2793 Write {ui,} tests for pin_macro and pin! 2022-02-14 16:56:37 +01:00
Daniel Henry-Mantilla ee9cd7bb6a Add a stack-pin!-ning macro to the pin module.
Add a type annotation to improve error messages with type mismatches

Add a link to the temporary-lifetime-extension section of the reference
2022-02-14 16:56:37 +01:00
Chris Denton 9a7a8b9255
Maintain broken symlink behaviour for the Windows exe resolver 2022-02-14 12:50:18 +00:00
Stein Somers 5d5359759d Describe VecDeque with more consistent names 2022-02-14 11:17:27 +01:00
Mark Rousskov 398cccd42e Make default stdio lock() return 'static handles
This also deletes the unstable API surface area previously added to expose this
functionality on new methods rather than built into the current set.
2022-02-13 10:23:16 -05:00
bors 1f4681ad7a Auto merge of #91673 - ChrisDenton:path-absolute, r=Mark-Simulacrum
`std::path::absolute`

Implements #59117 by adding a `std::path::absolute` function that creates an absolute path without reading the filesystem. This is intended to be a drop-in replacement for [`std::fs::canonicalize`](https://doc.rust-lang.org/std/fs/fn.canonicalize.html) in cases where it isn't necessary to resolve symlinks. It can be used on paths that don't exist or where resolving symlinks is unwanted. It can also be used to avoid circumstances where `canonicalize` might otherwise fail.

On Windows this is a wrapper around [`GetFullPathNameW`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew). On Unix it partially implements the POSIX [pathname resolution](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13) specification, stopping just short of actually resolving symlinks.
2022-02-13 12:03:52 +00:00
Matthias Krüger 2b7f3ee89d
Rollup merge of #93930 - name1e5s:chore/docs, r=Mark-Simulacrum
add link to format_args! when mention it in docs

close #93904
2022-02-13 06:44:18 +01:00
Matthias Krüger 5699f683a4
Rollup merge of #93886 - clarfonthey:stable_ascii_escape, r=Mark-Simulacrum
Stabilise inherent_ascii_escape (FCP in #77174)

Implements #77174, which completed its FCP.

This does *not* deprecate any existing methods or structs, as that is tracked in #93887. That stated, people should prefer using `u8::escape_ascii` to `std::ascii::escape_default`.
2022-02-13 06:44:17 +01:00
Matthias Krüger 783b56ba68
Rollup merge of #93851 - cyqsimon:option-examples, r=scottmcm
More practical examples for `Option::and_then` & `Result::and_then`

To be blatantly honest, I think the current example given for `Option::and_then` is objectively terrible. (No offence to whoever wrote them initially.)

```rust
fn sq(x: u32) -> Option<u32> { Some(x * x) }
fn nope(_: u32) -> Option<u32> { None }

assert_eq!(Some(2).and_then(sq).and_then(sq), Some(16));
assert_eq!(Some(2).and_then(sq).and_then(nope), None);
assert_eq!(Some(2).and_then(nope).and_then(sq), None);
assert_eq!(None.and_then(sq).and_then(sq), None);
```

Current example:
 - does not demonstrate that `and_then` converts `Option<T>` to `Option<U>`
 - is far removed from any realistic code
 - generally just causes more confusion than it helps

So I replaced them with two blocks:
 - the first one shows basic usage (including the type conversion)
 - the second one shows an example of typical usage

Same thing with `Result::and_then`.

Hopefully this helps with clarity.
2022-02-13 06:44:15 +01:00
Matthias Krüger 953c4dcc30
Rollup merge of #90532 - fee1-dead:improve-const-fn-err-msg, r=oli-obk
More informative error message for E0015

Helps with #92380
2022-02-13 06:44:13 +01:00
Matthias Krüger 92613a25fc
Rollup merge of #89926 - the8472:saturate-instant, r=Mark-Simulacrum
make `Instant::{duration_since, elapsed, sub}` saturating and remove workarounds

This removes all mutex/atomic-based workarounds for non-monotonic clocks and makes the previously panicking methods saturating instead. Additionally `saturating_duration_since` becomes deprecated since `duration_since` now fills that role.

Effectively this moves the fixup from `Instant` construction to the comparisons.

This has some observable effects, especially on platforms without monotonic clocks:

* Incorrectly ordered Instant comparisons no longer panic in release mode. This could hide some programming errors, but since debug mode still panics tests can still catch them.
* `checked_duration_since` will now return `None` in more cases. Previously it only happened when one compared instants obtained in the wrong order or manually created ones. Now it also does on backslides.
* non-monotonic intervals will not be transitive, i.e. `b.duration_since(a) + c.duration_since(b) != c.duration_since(a)`

The upsides are reduced complexity and lower overhead of `Instant::now`.

## Motivation

Currently we must choose between two poisons. One is high worst-case latency and jitter of `Instant::now()` due to explicit synchronization; see #83093 for benchmarks, the worst-case overhead is > 100x. The other is sporadic panics on specific, rare combinations of CPU/hypervisor/operating system due to platform bugs.

Use-cases where low-overhead, fine-grained timestamps are needed - such as syscall tracing, performance profiles or sensor data acquisition (drone flight controllers were mentioned in a libs meeting) in multi-threaded programs - are negatively impacted by the synchronization.

The panics are user-visible (program crashes), hard to reproduce and can be triggered by any dependency that might be using Instants for any reason.

A solution that is fast _and_ doesn't panic is desirable.

----

closes #84448
closes #86470
2022-02-13 06:44:12 +01:00
Gary Guo f74e8c7afc Guard against unwinding in cleanup code 2022-02-13 03:10:09 +00:00
bors 01c4c41301 Auto merge of #93696 - Amanieu:compiler-builtins-0.1.68, r=Mark-Simulacrum
Bump compiler-builtins to 0.1.69

This includes https://github.com/rust-lang/compiler-builtins/pull/452 which should fix some issues with duplicate symbol defintions of some intrinsics.
2022-02-13 02:40:56 +00:00
Josh Triplett 37a1fc542f Capitalize "Rust"
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2022-02-13 01:06:36 +01:00
The 8472 376d955a32 Add panic docs describing old, current and possible future behavior 2022-02-13 01:06:34 +01:00
The 8472 bda2693e9b Add caveat about the monotonicity guarantee by linking to the later section 2022-02-13 01:05:00 +01:00
The8472 9d8ef11607 make Instant::{duration_since, elapsed, sub} saturating and remove workarounds
This removes all mutex/atomics based workarounds for non-monotonic clocks and makes the previously panicking methods saturating instead.

Effectively this moves the monotonization from `Instant` construction to the comparisons.

This has some observable effects, especially on platforms without monotonic clocks:

* Incorrectly ordered Instant comparisons no longer panic. This may hide some programming errors until someone actually looks at the resulting `Duration`
* `checked_duration_since` will now return `None` in more cases. Previously it only happened when one compared instants obtained in the wrong order or
  manually created ones. Now it also does on backslides.

The upside is reduced complexity and lower overhead of `Instant::now`.
2022-02-13 01:04:55 +01:00
John Paul Adrian Glaubitz c26d5b3f9c library/unwind: Define unwinder_private_data_size for m68k 2022-02-12 20:21:10 +00:00
John Paul Adrian Glaubitz 990326fa74 library/panic_unwind: Define UNWIND_DATA_REG for m68k 2022-02-12 20:19:06 +00:00
ltdk de6e973176 Stabilise inherent_ascii_escape (FCP in #77174) 2022-02-12 13:21:59 -05:00
ltdk 9efe61df7f Fix signature of u8::escape_ascii 2022-02-12 13:15:10 -05:00
bors 9c3a3e3d5b Auto merge of #93697 - the8472:fix-windows-path-hash, r=Mark-Simulacrum
Fix hashing for windows paths containing a CurDir component

* the logic only checked for / but not for \
* verbatim paths shouldn't skip items at all since they don't get normalized
* the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false
* tests lacked windows coverage for these cases

That lead to equal paths not having equal hashes and to unnecessary collisions.
2022-02-12 14:01:13 +00:00
Alphyr fe7d7c2004 Fix typo
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-02-12 12:31:33 +01:00
Benoît du Garreau d3e2ffcbc6 Fix shrink and capacity_from_bytes 2022-02-12 11:51:15 +01:00
Benoît du Garreau 6027182328 Fix a layout miscalculation in alloc::RawVec 2022-02-12 11:40:59 +01:00
Deadbeef f7f0f843b7
Improve error messages even more 2022-02-12 19:24:08 +11:00
cyqsimon f6f93fd7ba
Add note on Windows path behaviour 2022-02-12 12:52:42 +08:00
yuhaixin.hx daa3c795dc add link to format_args! when being mentioned in doc 2022-02-12 12:35:30 +08:00
cyqsimon 160faf1b30
Option::and_then basic example: show failure 2022-02-12 12:23:38 +08:00
cyqsimon adfac00f45
Result::and_then: show type conversion 2022-02-12 12:19:03 +08:00
cyqsimon 7eaecc6508
Result::and_then: improve basic example 2022-02-12 12:12:11 +08:00
bors f19851069e Auto merge of #93921 - matthiaskrgr:rollup-wn3jlxj, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #90955 (Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`)
 - #91607 (Make `span_extend_to_prev_str()` more robust)
 - #92895 (Remove some unused functionality)
 - #93635 (Add missing platform-specific information on current_dir and set_current_dir)
 - #93660 (rustdoc-json: Add some tests for typealias item)
 - #93782 (Split `pauth` target feature)
 - #93868 (Fix incorrect register conflict detection in asm!)
 - #93888 (Implement `AsFd` for `&T` and `&mut T`.)
 - #93909 (Fix typo: explicitely -> explicitly)
 - #93910 (fix mention of moved function in `rustc_hir` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-11 23:01:50 +00:00
Matthias Krüger 34997f0114
Rollup merge of #93888 - sunfishcode:sunfishcode/impl-asfd-for-ref, r=joshtriplett
Implement `AsFd` for `&T` and `&mut T`.

Add implementations of `AsFd` for `&T` and `&mut T`, so that users can
write code like this:

```rust
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
```

with `fd: F` rather than `fd: &F`.

And similar for `AsHandle` and `AsSocket` on Windows.

Also, adjust the `fchown` example to pass the file by reference. The
code can work either way now, but passing by reference is more likely
to be what users will want to do.

This is an alternative to #93869, and is a simpler way to achieve the
same goals: users don't need to pass borrowed-`BorrowedFd` arguments,
and it prevents a pitfall in the case where users write `fd: F` instead
of `fd: &F`.

r? ```@joshtriplett```
2022-02-11 21:48:50 +01:00
Matthias Krüger 15d71cff2d
Rollup merge of #93635 - GuillaumeGomez:missing-platform-spec-info, r=Amanieu
Add missing platform-specific information on current_dir and set_current_dir

Fixes #93598.
2022-02-11 21:48:46 +01:00
Matthias Krüger ce4df92c8c
Rollup merge of #90955 - JohnTitor:os-error-123-as-invalid-input, r=m-ou-se
Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`

Address https://github.com/rust-lang/rust/issues/90940#issuecomment-970157931
`ERROR_INVALID_NAME` (i.e. "The filename, directory name, or volume label syntax is incorrect") happens if we pass an invalid filename, directory name, or label syntax, so mapping as `InvalidInput` is reasonable to me.
2022-02-11 21:48:42 +01:00
bors e789f3a3a3 Auto merge of #90271 - adamgemmell:dev/feat-detect-stabilise, r=Amanieu
Stabilise `is_aarch64_feature_detected!` under `simd_aarch64` feature

Initial implementation, looking for feedback on the approach here. https://github.com/rust-lang/rust/issues/86941

One point I noticed was that I haven't seen different "since" versions for the same feature - does this mean that other features can't be added to to the `simd_aarch64` feature once this is in stable? If so it might need a more specific name.

r? `@Amanieu`
2022-02-11 20:41:51 +00:00
Guillaume Gomez 22a24c98d3 Add missing platform-specific information on current_dir and set_current_dir 2022-02-11 16:33:02 +01:00
Dan Gohman 1f98ef7793 Implement AsFd for &T and &mut T.
Add implementations of `AsFd` for `&T` and `&mut T`, so that users can
write code like this:

```rust
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
```

with `fd: F` rather than `fd: &F`.

And similar for `AsHandle` and `AsSocket` on Windows.

Also, adjust the `fchown` example to pass the file by reference. The
code can work either way now, but passing by reference is more likely
to be what users will want to do.

This is an alternative to #93869, and is a simpler way to achieve the
same goals: users don't need to pass borrowed-`BorrowedFd` arguments,
and it prevents a pitfall in the case where users write `fd: F` instead
of `fd: &F`.
2022-02-10 18:26:12 -08:00
cyqsimon 942eaa7ffc
Add negative example for Result::and_then 2022-02-11 09:57:19 +08:00
Charisee dbeab9c532 added space 2022-02-10 22:30:51 +00:00
Charisee a889079b29 add cfg_panic bootstrap 2022-02-10 22:10:08 +00:00
Charisee d018a8b624 remove mention of cfg_panic from library tests 2022-02-10 22:09:11 +00:00
Charisee 5e6be7df94 replace feature expression (cfg_panic) in lib and remove expression from tests
Rebase commit
2022-02-10 22:06:47 +00:00
Adam Gemmell 93b5bfbc48 Update stdarch submodule 2022-02-10 15:24:13 +00:00
Adam Gemmell 102a0ffd37 Move is_aarch64_feature_detected! to simd_aarch64 feature and stabilise 2022-02-10 15:24:13 +00:00
Yuki Okushi a898b31662
Rename to InvalidFilename 2022-02-10 23:49:27 +09:00
Josh Triplett 861f3c70a2
Fix description of FilenameInvalid
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-02-10 23:42:27 +09:00
Yuki Okushi cc9407924d
Map ERROR_INVALID_NAME to FilenameInvalid 2022-02-10 23:42:27 +09:00
Yuki Okushi 755e475c8b
Rename FilenameTooLong to FilenameInvalid 2022-02-10 23:42:26 +09:00
Yuki Okushi 1115f15e1c
windows: Map ERROR_INVALID_NAME as InvalidInput 2022-02-10 23:42:23 +09:00
Matthias Krüger 8c60f44877
Rollup merge of #93843 - solid-rs:fix-kmc-solid-condvar, r=m-ou-se
kmc-solid: Fix wait queue manipulation errors in the `Condvar` implementation

This PR fixes a number of bugs in the `Condvar` wait queue implementation used by the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. These bugs can occur when there are multiple threads waiting on the same `Condvar` and sometimes manifest as an `unwrap` failure.
2022-02-10 12:10:02 +01:00
Matthias Krüger aa2095936a
Rollup merge of #93824 - Amanieu:stable_cfg_target_has_atomic, r=davidtwco
Stabilize cfg_target_has_atomic

`target_has_atomic_equal_alignment` is now tracked separately in #93822.

Closes #32976
2022-02-10 12:10:00 +01:00
cyqsimon bd421e2880
More practical examples for Result::and_then 2022-02-10 17:59:46 +08:00
cyqsimon 73a5f01263
Use 0-based idx for array content 2022-02-10 16:32:53 +08:00
cyqsimon a8e9708aeb
More practical examples for Option::and_then 2022-02-10 16:09:49 +08:00
Tomoaki Kawada 64406c5996 kmc-solid: Use the filesystem thread-safety wrapper
Neither the SOLID filesystem API nor built-in filesystems guarantee
thread safety by default. Although this may suffice in general embedded-
system use cases, and in fact the API can be used from multiple threads
without any problems in many cases, this has been a source of
unsoundness in `std::sys::solid::fs`.

This commit updates the `std` code to leverage the filesystem thread-
safety wrapper to enforce thread safety. This is done by prefixing all
paths passed to the filesystem API with `\TS`. (Note that relative paths
aren't supported in this platform.)
2022-02-10 13:33:35 +09:00
Tomoaki Kawada 1d180caf1a kmc-solid: Wait queue should be sorted in the descending order of task priorities
In ITRON, lower priority values mean higher priorities.
2022-02-10 11:35:37 +09:00
Tomoaki Kawada bdc9508bb6 kmc-solid: Fix wait queue manipulation errors in the Condvar implementation 2022-02-10 10:21:39 +09:00
Matthias Krüger 6db0f9ca0d
Rollup merge of #93799 - wooorm:patch-1, r=dtolnay
Fix typo in `std::fmt` docs

Hey!

Reading the docs (https://doc.rust-lang.org/std/fmt/#named-parameters), this seems like a typo?

The docs here also seem to mix “named argument” and “named parameter”? Intentional? Mistake?
2022-02-09 23:29:58 +01:00
Amanieu d'Antras 7b8f6ac5ab Bump compiler-builtins to 0.1.69 2022-02-09 21:03:13 +00:00
Amanieu d'Antras 49d4823112 Stabilize cfg_target_has_atomic
Closes #32976
2022-02-09 18:45:44 +00:00
Michael Goulet fea0015f93 Suggest collecting into Vec<_> when collecting into [_] 2022-02-09 09:35:46 -08:00
Titus 3d3318b406
Fix typo in std::fmt docs 2022-02-09 11:26:10 +01:00
Yuki Okushi 56094651b8
Rollup merge of #93735 - m-ou-se:stabilize-int-abs-diff, r=joshtriplett
Stabilize int_abs_diff in 1.60.0.

FCP finished here: https://github.com/rust-lang/rust/issues/89492#issuecomment-1030694522
2022-02-09 14:12:21 +09:00
Yuki Okushi ec2fd8a35f
Rollup merge of #93445 - yaahc:exitcode-constructor, r=dtolnay
Add From<u8> for ExitCode

This should cover a mostly cross-platform subset of supported exit codes.

We decided to stick with `u8` initially since its the common subset between all platforms that we support (excluding wasm which I think only works with `true` or `false`). Posix is supposed to take i32s, but in practice many unix platforms mask out all but the low 8 bits or in some cases the 8-15th bits. Windows takes a u32 instead of an i32. Bourne-compatible shells also report signals as exitcode 128 + `signal_no`, so there's some ambiguity there when returning exit codes > 127, but it is possible to disambiguate them on the other side so we decided against restricting the possible codes further than to `u8`.

## Related

- Detailed analysis of exit code support on various platforms: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426
- https://github.com/rust-lang/rust/issues/48711
- https://github.com/rust-lang/rust/issues/43301
- https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization
2022-02-09 14:12:17 +09:00
bors 9a5a961be9 Auto merge of #93778 - matthiaskrgr:rollup-yfngdao, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #91950 (Point at type when a `static` `#[global_allocator]` doesn't `impl` `GlobalAlloc`)
 - #92715 (Do not suggest char literal for zero-length strings)
 - #92917 (Don't constrain projection predicates with inference vars in GAT substs)
 - #93206 (Use `NtCreateFile` instead of `NtOpenFile` to open a file)
 - #93732 (add fut/back compat tests for implied trait bounds)
 - #93764 (⬆️ rust-analyzer)
 - #93767 (deduplicate `lcnr` in mailmap)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-09 01:18:06 +00:00
Matthias Krüger 9cb39a6083
Rollup merge of #93206 - ChrisDenton:ntopenfile, r=nagisa
Use `NtCreateFile` instead of `NtOpenFile` to open a file

Generally the internal `Nt*` functions should be avoided but when we do need to use one we should stick to the most commonly used for the job. To that end, this PR replaces `NtOpenFile` with `NtCreateFile`.

NOTE: The initial version of this comment hypothesised that this may help with some recent false positives from malware scanners. This hypothesis proved wrong. Sorry for the distraction.
2022-02-08 16:40:49 +01:00
Chris Denton 81cc3afe20
Fix absolute issues 2022-02-08 14:57:35 +00:00
Chris Denton d59d32c4f1
std::path::absolute 2022-02-08 14:57:34 +00:00
bors 0c292c9667 Auto merge of #93572 - scottmcm:generic-iter-process, r=yaahc
Change `ResultShunt` to be generic over `Try`

Just a refactor (and rename) for now, so it's not `Result`-specific.

This could be used for a future `Iterator::try_collect`, or similar, but anything like that is left for a future PR.
2022-02-08 13:41:40 +00:00
Matthias Krüger 1f841fc5fe
Rollup merge of #86497 - clarfonthey:nearest_char_boundary, r=scottmcm
Add {floor,ceil}_char_boundary methods to str

This is technically already used internally by the standard library in the form of `truncate_to_char_boundary`.

Essentially these are two building blocks to allow for approximate string truncation, where you want to cut off the string at "approximately" a given length in bytes but don't know exactly where the character boundaries lie. It's also a good candidate for the standard library as it can easily be done naively, but would be difficult to properly optimise. Although the existing code that's done in error messages is done naively, this code will explicitly only check a window of 4 bytes since we know that a boundary must lie in that range, and because it will make it possible to vectorise.

Although this method doesn't take into account graphemes or other properties, this would still be a required building block for splitting that takes those into account. For example, if you wanted to split at a grapheme boundary, you could take your approximate splitting point and then determine the graphemes immediately following and preceeding the split. If you then notice that these two graphemes could be merged, you can decide to either include the whole grapheme or exclude it depending on whether you decide splitting should shrink or expand the string.

This takes the most conservative approach and just offers the raw indices to the user, and they can decide how to use them. That way, the methods are as useful as possible despite having as few methods as possible.

(Note: I'll add some tests and a tracking issue if it's decided that this is worth including.)
2022-02-08 06:47:31 +01:00
Scott McMurray 413945ecc5 Change ResultShunt to be generic over Try
Just a refactor (and rename) for now, so it's not `Result`-specific.

This could be used for a future `Iterator::try_collect`, or similar, but anything like that is left for a future PR.
2022-02-07 12:57:25 -08:00
Jane Lusby 4c5a36e2d1 fix exclusive range error 2022-02-07 12:45:36 -08:00
bors 734368a200 Auto merge of #87869 - thomcc:skinny-io-error, r=yaahc
Make io::Error use 64 bits on targets with 64 bit pointers.

I've wanted this for a long time, but didn't see a good way to do it without having extra allocation. When looking at it yesterday, it was more clear what to do for some reason.

This approach avoids any additional allocations, and reduces the size by half (8 bytes, down from 16). AFAICT it doesn't come additional runtime cost, and the compiler seems to do a better job with code using it.

Additionally, this `io::Error` has a niche (still), so `io::Result<()>` is *also* 64 bits (8 bytes, down from 16), and `io::Result<usize>` (used for lots of io trait functions) is 2x64 bits (16 bytes, down from 24 — this means on x86_64 it can use the nice rax/rdx 2-reg struct return). More generally, it shaves a whole 64 bit integer register off of the size of basically any `io::Result<()>`.

(For clarity: Improving `io::Result` (rather than io::Error) was most of the motivation for this)

On 32 bit (or other non-64bit) targets we still use something equivalent the old repr — I don't think think there's improving it, since one of the fields it stores is a `i32`, so we can't get below that, and it's already about as close as we can get to it.

---

### Isn't Pointer Tagging Dodgy?

The details of the layout, and why its implemented the way it is, are explained in the header comment of library/std/src/io/error/repr_bitpacked.rs. There's probably more details than there need to be, but I didn't trim it down that much, since there's a lot of stuff I did deliberately, that might have not seemed that way.

There's actually only one variant holding a pointer which gets tagged. This one is the (holder for the) user-provided error.

I believe the scheme used to tag it is not UB, and that it preserves pointer provenance (even though often pointer tagging does not) because the tagging operation is just `core::ptr::add`, and untagging is `core::ptr::sub`. The result of both operations lands inside the original allocation, so it would follow the safety contract of `core::ptr::{add,sub}`.

The other pointer this had to encode is not tagged — or rather, the tagged repr is equivalent to untagged (it's tagged with 0b00, and has >=4b alignment, so we can reuse the bottom bits). And the other variants we encode are just integers, which (which can be untagged using bitwise operations without worry — they're integers).

CC `@RalfJung` for the stuff in repr_bitpacked.rs, as my comments are informed by a lot of the UCG work, but it's possible I missed something or got it wrong (even if the implementation is okay, there are parts of the header comment that says things like "We can't do $x" which could be false).

---

### Why So Many Changes?

The repr change was mostly internal, but changed one widely used API: I had to switch how `io::Error::new_const` works.

This required switching `io::Error::new_const` to take the full message data (including the kind) as a `&'static`, rather than just the string. This would have been really tedious, but I made a macro that made it much simpler, but it was a wide change since `io::Error::new_const` is used everywhere.

This included changing files for a lot of targets I don't have easy access to (SGX? Haiku? Windows? Who has heard of these things), so I expect there to be spottiness in CI initially, unless luck is on my side.

Anyway this large only tangentially-related change is all in the first commit (although that commit also pulls the previous repr out into its own file), whereas the packing stuff is all in commit 2.

---

P.S. I haven't looked at all of this since writing it, and will do a pass over it again later, sorry for any obvious typos or w/e. I also definitely repeat myself in comments and such.

(It probably could use more tests too. I did some basic testing, and made it so we `debug_assert!` in cases the decode isn't what we encoded, but I don't know the degree which I can assume libstd's testing of IO would exercise this. That is: it wouldn't be surprising to me if libstds IO testing were minimal, especially around error cases, although I have no idea).
2022-02-07 20:32:56 +00:00
ltdk edd318c313 Add {floor,ceil}_char_boundary methods to str 2022-02-07 13:34:08 -05:00
bors f52c31840d Auto merge of #93738 - m-ou-se:rollup-zjyd2et, r=m-ou-se
Rollup of 13 pull requests

Successful merges:

 - #88313 (Make the pre-commit script pre-push instead)
 - #91530 (Suggest 1-tuple parentheses on exprs without existing parens)
 - #92724 (Cleanup c_str.rs)
 - #93208 (Impl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}Assign<$t> for Wrapping<$t> for rust 1.60.0)
 - #93394 (Don't allow {} to refer to implicit captures in format_args.)
 - #93416 (remove `allow_fail` test flag)
 - #93487 (Fix linking stage1 toolchain in `./x.py setup`)
 - #93673 (Linkify sidebar headings for sibling items)
 - #93680 (Drop json::from_reader)
 - #93682 (Update tracking issue for `const_fn_trait_bound`)
 - #93722 (Use shallow clones for submodules managed by rustbuild, not just bootstrap.py)
 - #93723 (Rerun bootstrap's build script when RUSTC changes)
 - #93737 (bootstrap: prefer using '--config' over 'RUST_BOOTSTRAP_CONFIG')

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-07 15:32:19 +00:00
Mara Bos 252ff5ead0
Rollup merge of #93416 - name1e5s:chore/remove_allow_fail, r=m-ou-se
remove `allow_fail` test flag

close #93345
2022-02-07 14:08:34 +00:00
Mara Bos e3c972e252
Rollup merge of #93208 - kellerkindt:wrapping_int_assign_impl, r=m-ou-se
Impl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}Assign<$t> for Wrapping<$t> for rust 1.60.0

Tracking issue #93204

This is about adding basic integer operations to the `Wrapping` type:

```rust
let mut value = Wrapping(2u8);
value += 3u8;
value -= 1u8;
value *= 2u8;
value /= 2u8;
value %= 2u8;
value ^= 255u8;
value |= 123u8;
value &= 2u8;
```

Because this adds stable impls on a stable type, it runs into the following issue if an `#[unstable(...)]` attribute is used:

```
an `#[unstable]` annotation here has no effect
note: see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information
```

This means - if I understood this correctly - the new impls have to be stabilized instantly.
Which in turn means, this PR has to kick of an FCP on the tracking issue as well?

This impl is analog to 1c0dc1810d #92356 for the `Saturating` type ``@dtolnay``  ``@Mark-Simulacrum``
2022-02-07 14:08:32 +00:00