Commit graph

10022 commits

Author SHA1 Message Date
joboet da0a54277a
std: cleanup timeouts in pthread condvar 2022-12-02 14:38:20 +01:00
Tomoaki Kawada ae7633f434 kmc-solid: Don't do Box::from_raw(&*(x: Box<T>) as *const T as *mut T)
This pattern seems to be considered illegal by Miri.
2022-12-02 16:58:41 +09:00
Matthias Krüger c7edfddc2f
Rollup merge of #105137 - yjhn:patch-1, r=Dylan-DPC
Add tracking issue number for `file_create_new` feature

It was missing a tracking issue, so I opened one (#105135).
2022-12-02 08:28:11 +01:00
Matthias Krüger 4c4dec4408
Rollup merge of #105126 - Sp00ph:const_new_in, r=dtolnay
Make `VecDeque::new_in` unstably const

(See #105072)
2022-12-02 08:28:09 +01:00
Matthias Krüger 4fdc3eb176
Rollup merge of #104614 - Nilstrieb:type-ascribe!, r=TaKO8Ki
Add `type_ascribe!` macro as placeholder syntax for type ascription

This makes it still possible to test the internal semantics of type ascription even once the `:`-syntax is removed from the parser. The macro now gets used in a bunch of UI tests that test the semantics and not syntax of type ascription.

I might have forgotten a few tests but this should hopefully be most of them. The remaining ones will certainly be found once type ascription is removed from the parser altogether.

Part of #101728
2022-12-02 08:28:08 +01:00
Oli Scherer e59025867d Create a hacky fail-fast mode that stops tests at the first failure 2022-12-01 20:29:18 +00:00
Andrius Pukšta 0af5b7265d
Add tracking issue for file_create_new 2022-12-01 17:42:31 +02:00
Markus Everling c959fbe771 Fix typo in comment 2022-12-01 12:44:29 +01:00
Markus Everling 929003aacf Make VecDeque::new_in unstably const 2022-12-01 12:15:29 +01:00
bors 9c0bc3028a Auto merge of #104975 - JakobDegen:custom_mir_let, r=oli-obk
`#![custom_mir]`: Various improvements

This PR makes a bunch of improvements to `#![custom_mir]`. Ideally this would be 4 PRs, one for each commit, but those would take forever to get merged and be a pain to juggle. Should still be reviewed one commit at a time though.

### Commit 1: Support arbitrary `let`

Before this change, all locals used in the body need to be declared at the top of the `mir!` invocation, which is rather annoying. We attempt to change that.

Unfortunately, we still have the requirement that the output of the `mir!` macro must resolve, typecheck, etc. Because of that, we can't just accept this in the THIR -> MIR parser because something like
```rust
{
    let x = 0;
    Goto(other)
}
other = {
    RET = x;
    Return()
}
```
will fail to resolve. Instead, the implementation does macro shenanigans to find the let declarations and extract them as part of the `mir!` macro. That *works*, but it is fairly complicated and degrades debuginfo by quite a bit. Specifically, the spans for any statements and declarations that are affected by this are completely wrong. My guess is that this is a net improvement though.

One way to recover some of the debuginfo would be to not support type annotations in the `let` statements, which would allow us to parse like `let $stmt:stmt`. That seems quite surprising though.

### Commit 2: Parse consts

Reuses most of the const parsing from regular Mir building for building custom mir

### Commit 3: Parse statics

Statics are slightly weird because the Mir primitive associated with them is a reference/pointer to them, so this is factored out separately.

### Commit 4: Fix some spans

A bunch of the spans were non-ideal, so we adjust them to be much more helpful.

r? `@oli-obk`
2022-12-01 10:40:10 +00:00
nils efea79ca80
Gate macros behind #[cfg(not(bootstrap))]
Co-authored-by: Takayuki Maeda <takoyaki0316@gmail.com>
2022-12-01 11:16:18 +01:00
Tomoaki Kawada f482e55adf kmc-solid: Address compiler warnings
Addresses the warn-by-default lints `unused_imports` and
`unused_unsafe`.
2022-12-01 13:18:05 +09:00
Tomoaki Kawada 47f2f6d615 kmc-solid: Add a stub implementation of is_terminal
Copied from `unsupported/io.rs`. Fixes build failure.
2022-12-01 13:18:05 +09:00
Tomoaki Kawada 427a079d31 kmc-solid: Use expose_addr and from_exposed_addr for pointer-integer casts
Pointer-integer casts are required for conversion between `EXINF` (ITRON
task entry point parameter) and `*const ThreadInner`. Addresses the
deny-level lint `fuzzy_provenance_casts`.
2022-12-01 13:18:05 +09:00
bors 1dcf6add3d Auto merge of #104160 - Ayush1325:windows-args, r=m-ou-se
Extract WStrUnits to sys_common::wstr

This commit extracts WStrUnits from sys::windows::args to sys_common::wstr. This allows using the same structure for other targets which use wtf8 (example UEFI).

This was originally a part of https://github.com/rust-lang/rust/pull/100316

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-12-01 01:22:32 +00:00
Arthur Carcano 6259028862 Add test for regression for FileType equality
Cf: https://github.com/rust-lang/rust/issues/104900
2022-11-30 23:45:01 +01:00
Jacob Pratt d777c84603
Add missing intra-doc link 2022-11-30 20:42:31 +00:00
Matthias Krüger c752eaa7de
Rollup merge of #104811 - haraldh:feat/wasm32_wasi_shutdown, r=joshtriplett
feat: implement TcpStream shutdown for wasm32-wasi

Signed-off-by: Harald Hoyer <harald@profian.com>
2022-11-30 07:00:31 +01:00
Jakob Degen 52ce1f7697 Support statics in custom mir 2022-11-29 19:27:26 -08:00
Jakob Degen 7578100317 Support most constant kinds in custom mir 2022-11-29 19:26:04 -08:00
Jakob Degen a98254179b Support arbitrary let statements in custom mir 2022-11-29 19:19:33 -08:00
Matthias Krüger aa674eefda
Rollup merge of #105049 - mkroening:hermit-fixes, r=jyn514
Hermit: Minor build fixes

These changes are necessary to build for the hermit targets.

CC: ``@stlankes``
2022-11-29 22:43:20 +01:00
Matthias Krüger 804fa66a02
Rollup merge of #105002 - zertosh:acp-140, r=dtolnay
Add `PathBuf::as_mut_os_string` and `Path::as_mut_os_str`

Implements rust-lang/libs-team#140 (tracking issue #105021).
2022-11-29 22:43:18 +01:00
Matthias Krüger e4d1fe7b15
Rollup merge of #104436 - ismailmaj:add-slice-to-stack-allocated-string-comment, r=Mark-Simulacrum
Add slice to the stack allocated string comment

Precise that the "stack allocated string" is not a string but a string slice.

``@rustbot`` label +A-docs
2022-11-29 22:43:16 +01:00
Ben Kimock 906c3601fa Adjust inlining attributes around panic_immediate_abort 2022-11-29 09:24:01 -05:00
Martin Kröning 0a4e5efe6f hermit: Remove unused exports 2022-11-29 12:25:35 +01:00
Martin Kröning c8f3203c46 hermit: Fix fuzzy_provenance_casts 2022-11-29 12:25:35 +01:00
Scott McMurray a964a37211 Send VecDeque::from_iter via Vec::from_iter
Since it's O(1) to convert between them now, might as well reuse the logic.

Mostly for the various specializations it does, but might also save some monomorphization work if, say, people collect slice iterators into both `Vec`s and `VecDeque`s.
2022-11-29 00:24:15 -08:00
Fabian Hintringer f9490c8121 improve doc 2022-11-28 22:42:05 +01:00
Andres Suarez 9d66ab0f9d Add as_mut_os_string to &mut PathBuf and as_mut_os_str to &mut Path
Implements rust-lang/libs-team#140
2022-11-28 12:06:59 -05:00
Ayush Singh 348a058505
Extract WStrUnits to sys_common::wstr
This commit extracts WStrUnits from sys::windows::args to sys_common::wstr. This
allows using the same structure for other targets which use wtf8 (example UEFI).

This was originally a part of https://github.com/rust-lang/rust/pull/100316

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-28 21:17:08 +05:30
bors 69df0f2c2f Auto merge of #102991 - Sp00ph:master, r=scottmcm
Update VecDeque implementation to use head+len instead of head+tail

(See #99805)

This changes `alloc::collections::VecDeque`'s internal representation from using head and tail indices to using a head index and a length field. It has a few advantages over the current design:
* It allows the buffer to be of length 0, which means the `VecDeque::new` new longer has to allocate and could be changed to a `const fn`
* It allows the `VecDeque` to fill the buffer completely, unlike the old implementation, which always had to leave a free space
* It removes the restriction for the size to be a power of two, allowing it to properly `shrink_to_fit`, unlike the old `VecDeque`
* The above points also combine to allow the `Vec<T> -> VecDeque<T>` conversion to be very cheap and guaranteed O(1). I mention this in the `From<Vec<T>>` impl, but it's not a strong guarantee just yet, as that would likely need some form of API change proposal.

All the tests seem to pass for the new `VecDeque`, with some slight adjustments.

r? `@scottmcm`
2022-11-28 10:39:47 +00:00
Matthias Krüger 8d90647641
Rollup merge of #104934 - ChrisDenton:all-anybody-wants, r=thomcc
Remove redundant `all` in cfg

This appears to have been accidentally left in after removing the other branches 45bf1ed1a1

(hat tip to kangalioo for the git archaeology)
2022-11-27 16:03:08 +01:00
Matthias Krüger 9ba78ac08b
Rollup merge of #104892 - lukas-code:discriminant, r=scottmcm
Explain how to get the discriminant out of a `#[repr(T)] enum` with payload

example stolen from https://github.com/rust-lang/reference/pull/1055

````@rustbot```` label A-docs
2022-11-27 16:03:07 +01:00
bors faf1891deb Auto merge of #104818 - scottmcm:refactor-extend-func, r=the8472
Stop peeling the last iteration of the loop in `Vec::resize_with`

`resize_with` uses the `ExtendWith` code that peels the last iteration:
341d8b8a2c/library/alloc/src/vec/mod.rs (L2525-L2529)

But that's kinda weird for `ExtendFunc` because it does the same thing on the last iteration anyway:
341d8b8a2c/library/alloc/src/vec/mod.rs (L2494-L2502)

So this just has it use the normal `extend`-from-`TrustedLen` code instead.

r? `@ghost`
2022-11-27 00:58:50 +00:00
Markus Everling acf95adfe2 Add second test case in make_contiguous_head_to_end 2022-11-26 23:08:57 +01:00
Markus Everling 451259811a Improve slow path in make_contiguous 2022-11-26 22:55:39 +01:00
Lukas Markeffsky 946d51e8ba fix broken link fragment 2022-11-26 16:56:29 +01:00
Lukas Markeffsky e06b61c8f9 explain how to get the discriminant out of a #[repr(T)] enum 2022-11-26 16:14:03 +01:00
bors 579c993b35 Auto merge of #104935 - matthiaskrgr:rollup-nuca86l, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #104121 (Refine `instruction_set` MIR inline rules)
 - #104675 (Unsupported query error now specifies if its unsupported for local or external crate)
 - #104839 (improve array_from_fn documenation)
 - #104880 ([llvm-wrapper] adapt for LLVM API change)
 - #104899 (rustdoc: remove no-op CSS `#help dt { display: block }`)
 - #104906 (Remove AscribeUserTypeCx)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-26 12:11:32 +00:00
Matthias Krüger 1fc83aee1e
Rollup merge of #104839 - HintringerFabian:docs_array_from_fn, r=scottmcm
improve array_from_fn documenation

Improves array::from_fn documentation
Fixes #102609

There were also unresolved comments from [this PR #100462](https://github.com/rust-lang/rust/pull/100462), which have been added to my PR
2022-11-26 10:39:11 +01:00
Chris Denton c256bd2908
Remove redundant all in cfg 2022-11-26 09:31:40 +00:00
bors 8841bee954 Auto merge of #103556 - clubby789:specialize-option-partial-eq, r=scottmcm
Manually implement PartialEq for Option<T> and specialize non-nullable types

This PR manually implements `PartialEq` and `StructuralPartialEq` for `Option`, which seems to produce slightly better codegen than the automatically derived implementation.

It also allows specializing on the `core::num::NonZero*` and `core::ptr::NonNull` types, taking advantage of the niche optimization by transmuting the `Option<T>` to `T` to be compared directly, which can be done in just two instructions.

A comparison of the original, new and specialized code generation is available [here](https://godbolt.org/z/dE4jxdYsa).
2022-11-26 08:56:20 +00:00
Markus Everling f6f25983c6 Don't use Take in SpecExtend impl 2022-11-26 00:44:24 +01:00
Ralf Jung 34de2573f5 PERs are homogeneous 2022-11-25 20:48:53 +01:00
Arthur Carcano 77005950f0 Implement masking in FileType comparison on Unix
Fixes: https://github.com/rust-lang/rust/issues/104900
2022-11-25 18:15:59 +01:00
Matthias Krüger f360686ed6
Rollup merge of #104873 - RalfJung:therefore, r=Dylan-DPC
RefCell::get_mut: fix typo

and fix the same typo in a bunch of other places
2022-11-25 10:44:40 +01:00
Matthias Krüger 808157bd7d
Rollup merge of #104654 - thomcc:alloc-tests-unsafe_op_in_unsafe_fn, r=Mark-Simulacrum
Add `#![deny(unsafe_op_in_unsafe_fn)]` in liballoc tests

In https://github.com/rust-lang/rust/pull/104647#discussion_r1027332930 it was mentioned that liballoc tests should probably have this enabled (we have it pretty much everywhere else in the stdlib), so I added it.

This will probably conflict with https://github.com/rust-lang/rust/pull/104647 so I'll rebase after that lands.
2022-11-25 10:44:38 +01:00
Fabian Hintringer 69d562d684 change example of array_from_fn to match suggestion 2022-11-25 10:05:07 +01:00
Ralf Jung 6ed4f15940 RefCell::get_mut: fix typo
and fix the same typo in a bunch of other places
2022-11-25 08:52:06 +01:00
bors af63e3b39f Auto merge of #104855 - thomcc:revert-noinline-wintls, r=ChrisDenton
Revert "Forbid inlining `thread_local!`'s `__getit` function on Windows"

Revert of #101368, fixes #104852.

I'd rather not do this since that's a soundness fix and this is hitting some compiler bug, but I don't really know an alternative.

r? `@ChrisDenton`
2022-11-25 03:17:25 +00:00
Scott McMurray 9d68a1a74c Tune RepeatWith::try_fold and Take::for_each and Vec::extend_trusted 2022-11-24 19:14:19 -08:00
Markus Everling ecca8c5328 Changes according to code review 2022-11-25 03:39:59 +01:00
Thom Chiovoloni 24712f9982
Revert "Forbid inlining thread_local!'s __getit function on Windows"
This reverts commit 3099dfdd9f.
2022-11-24 18:12:12 -08:00
Matthias Krüger d4e5418b0c
Rollup merge of #104774 - vojtechkral:doc-str-empty-split-whitespace, r=thomcc
Document split{_ascii,}_whitespace() for empty strings

doc change only
2022-11-24 21:34:54 +01:00
Fabian Hintringer 480f850868 improve array_from_fn documenation 2022-11-24 19:30:46 +01:00
Vojtech Kral 07ccf67f59 Document split{_ascii,}_whitespace() for empty strings 2022-11-24 15:22:24 +01:00
Scott McMurray a8954f1f6a Stop peeling the last iteration of the loop in Vec::repeat_with 2022-11-24 03:12:54 -08:00
Scott McMurray 1c966e7f15 Extract the logic for TrustedLen to a named method that can be called directly 2022-11-24 03:12:05 -08:00
Harald Hoyer e598af6f27 feat: implement TcpStream shutdown for wasm32-wasi
Signed-off-by: Harald Hoyer <harald@profian.com>
2022-11-24 10:08:36 +01:00
Arpad Borsos 9f36f988ad
Avoid GenFuture shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
2022-11-24 10:04:27 +01:00
Thom Chiovoloni 54a6d4edbc
Add #![deny(unsafe_op_in_unsafe_fn)] in liballoc tests 2022-11-23 08:10:17 -08:00
Manish Goregaokar 316bda89e4
Rollup merge of #104647 - RalfJung:alloc-strict-provenance, r=thomcc
enable fuzzy_provenance_casts lint in liballoc and libstd

r? ````@thomcc````
2022-11-22 22:54:41 -05:00
bors 604d52108e Auto merge of #104743 - JohnTitor:rollup-9z9u7yd, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #101368 (Forbid inlining `thread_local!`'s `__getit` function on Windows)
 - #102293 (Add powerpc64-ibm-aix as Tier-3 target)
 - #104717 (Add failing test for projections used as const generic)
 - #104720 (rustdoc: remove no-op CSS `.popover::before / a.test-arrow { display: inline-block }`)
 - #104722 (Speed up mpsc_stress test)
 - #104724 (Fix `ClosureKind::to_def_id`)
 - #104728 (Use `tcx.require_lang_item` instead of unwrapping lang items)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-22 23:43:13 +00:00
Yuki Okushi 2f506e6dd4
Rollup merge of #101368 - thomcc:wintls-noinline, r=ChrisDenton
Forbid inlining `thread_local!`'s `__getit` function on Windows

Sadly, this will make things slower to avoid UB in an edge case, but it seems hard to avoid... and really whenever I look at this code I can't help but think we're asking for trouble.

It's pretty dodgy for us to leave this as a normal function rather than `#[inline(never)]`, given that if it *does* get inlined into a dynamically linked component, it's extremely unsafe (you get some other thread local, or if you're lucky, crash). Given that it's pretty rare for people to use dylibs on Windows, the fact that we haven't gotten bug reports about it isn't really that convincing. Ideally we'd come up with some kind of compiler solution (that avoids paying for this cost when static linking, or *at least* for use within the same crate...), but it's not clear what that looks like.

Oh, and because all this is only needed when we're implementing `thread_local!` with `#[thread_local]`, this patch adjusts the `cfg_attr` to be `all(windows, target_thread_local)` as well.

r? ``@ChrisDenton``

See also #84933, which is about improving the situation.
2022-11-23 06:40:21 +09:00
The 8472 3ed8fccff5 fix OOB access in SIMD impl of str.contains() 2022-11-22 20:59:19 +01:00
The 8472 d576a9b241 add test for issue 104726 2022-11-22 20:58:43 +01:00
Dylan DPC a40659ded3
Rollup merge of #104710 - RalfJung:doc-strict-provenance, r=thomcc
disable strict-provenance-violating doctests in Miri

Most of these are on deprecated unstable functions anyway. This lets us run the remaining doctests with `-Zmiri-strict-provenance`, which I think is a win.

r? `@thomcc`
2022-11-22 16:36:39 +05:30
Dylan DPC 20d6a44334
Rollup merge of #104464 - mati865:reduce-eh-overallocation-amd64, r=thomcc
Reduce exceptions overallocation on non Windows x86_64

Addressing https://github.com/rust-lang/rust/pull/103894#discussion_r1020950196
2022-11-22 16:36:37 +05:30
Ralf Jung 3a95e12c9b disable strict-provenance-violating doctests in Miri 2022-11-22 11:49:02 +01:00
Thom Chiovoloni 3099dfdd9f
Forbid inlining thread_local!'s __getit function on Windows 2022-11-22 02:09:47 -08:00
Manish Goregaokar 3683c43a05
Rollup merge of #103193 - krasimirgg:sysonce, r=Amanieu
mark sys_common::once::generic::Once::new const-stable

Attempt to address https://github.com/rust-lang/rust/issues/103191 by marking the impl const-stable.
Picked the declaration from the callsite:
21b246587c/library/std/src/sync/once.rs (L67)

This is similar to https://github.com/rust-lang/rust/pull/98457.

With this in, `python3 x.py build library/std --target x86_64-unknown-none` succeeds.
2022-11-22 01:26:07 -05:00
Manish Goregaokar 1625435fa4
Rollup merge of #102207 - CraftSpider:const-layout, r=scottmcm
Constify remaining `Layout` methods

Makes the methods on `Layout` that aren't yet unstably const, under the same feature and issue, #67521. Most of them required no changes, only non-trivial change is probably constifying `ValidAlignment` which may affect #102072
2022-11-22 01:26:07 -05:00
Manish Goregaokar 2f8dbe3797
Rollup merge of #101655 - dns2utf8:box_docs, r=dtolnay
Make the Box one-liner more descriptive

I would like to avoid a definition that relies on itself.

r? `@GuillaumeGomez`
2022-11-22 01:26:06 -05:00
Manish Goregaokar 81ea6105e2
Rollup merge of #95583 - scottmcm:deprecate-ptr-to-from-bits, r=dtolnay
Deprecate the unstable `ptr_to_from_bits` feature

I propose that we deprecate the (unstable!) `to_bits` and `from_bits` methods on raw pointers.  (With the intent to ~~remove them once `addr` has been around long enough to make the transition easy on people -- maybe another 6 weeks~~ remove them fairly soon after, as the strict and expose versions have been around for a while already.)

The APIs that came from the strict provenance explorations (#95228) are a more holistic version of these, and things like `.expose_addr()` work for the "that cast looks sketchy" case even if the full strict provenance stuff never happens.  (As a bonus, `addr` is even shorter than `to_bits`, though it is only applicable if people can use full strict provenance! `addr` is *not* a direct replacement for `to_bits`.)  So I think it's fine to move away from the `{to|from}_bits` methods, and encourage the others instead.

That also resolves the worry that was brought up (I forget where) that `q.to_bits()` and `(*q).to_bits()` both work if `q` is a pointer-to-floating-point, as they also have a `to_bits` method.

Tracking issue #91126
Code search: https://github.com/search?l=Rust&p=1&q=ptr_to_from_bits&type=Code

For potential pushback, some users in case they want to chime in
- `@RSSchermer` 365bb68541/arwa/src/html/custom_element.rs (L105)
- `@strax` 99616d1dbf/openexr/src/core/alloc.rs (L36)
- `@MiSawa` 577c622358/crates/kernel/src/timer.rs (L50)
2022-11-22 01:26:05 -05:00
Manish Goregaokar 1dd515f273
Rollup merge of #83608 - Kimundi:index_many, r=Mark-Simulacrum
Add slice methods for indexing via an array of indices.

Disclaimer: It's been a while since I contributed to the main Rust repo, apologies in advance if this is large enough already that it should've been an RFC.

---

# Update:

- Based on feedback, removed the `&[T]` variant of this API, and removed the requirements for the indices to be sorted.

# Description

This adds the following slice methods to `core`:

```rust
impl<T> [T] {
    pub unsafe fn get_many_unchecked_mut<const N: usize>(&mut self, indices: [usize; N]) -> [&mut T; N];
    pub fn get_many_mut<const N: usize>(&mut self, indices: [usize; N]) -> Option<[&mut T; N]>;
}
```

This allows creating multiple mutable references to disjunct positions in a slice, which previously required writing some awkward code with `split_at_mut()` or `iter_mut()`. For the bound-checked variant, the indices are checked against each other and against the bounds of the slice, which requires `N * (N + 1) / 2` comparison operations.

This has a proof-of-concept standalone implementation here: https://crates.io/crates/index_many

Care has been taken that the implementation passes miri borrow checks, and generates straight-forward assembly (though this was only checked on x86_64).

# Example

```rust
let v = &mut [1, 2, 3, 4];
let [a, b] = v.get_many_mut([0, 2]).unwrap();
std::mem::swap(a, b);
*v += 100;
assert_eq!(v, &[3, 2, 101, 4]);
```

# Codegen Examples

<details>
  <summary>Click to expand!</summary>

Disclaimer: Taken from local tests with the standalone implementation.

## Unchecked Indexing:

```rust
pub unsafe fn example_unchecked(slice: &mut [usize], indices: [usize; 3]) -> [&mut usize; 3] {
    slice.get_many_unchecked_mut(indices)
}
```

```nasm
example_unchecked:
 mov     rcx, qword, ptr, [r9]
 mov     r8, qword, ptr, [r9, +, 8]
 mov     r9, qword, ptr, [r9, +, 16]
 lea     rcx, [rdx, +, 8*rcx]
 lea     r8, [rdx, +, 8*r8]
 lea     rdx, [rdx, +, 8*r9]
 mov     qword, ptr, [rax], rcx
 mov     qword, ptr, [rax, +, 8], r8
 mov     qword, ptr, [rax, +, 16], rdx
 ret
```

## Checked Indexing (Option):

```rust
pub unsafe fn example_option(slice: &mut [usize], indices: [usize; 3]) -> Option<[&mut usize; 3]> {
    slice.get_many_mut(indices)
}
```

```nasm
 mov     r10, qword, ptr, [r9, +, 8]
 mov     rcx, qword, ptr, [r9, +, 16]
 cmp     rcx, r10
 je      .LBB0_7
 mov     r9, qword, ptr, [r9]
 cmp     rcx, r9
 je      .LBB0_7
 cmp     rcx, r8
 jae     .LBB0_7
 cmp     r10, r9
 je      .LBB0_7
 cmp     r9, r8
 jae     .LBB0_7
 cmp     r10, r8
 jae     .LBB0_7
 lea     r8, [rdx, +, 8*r9]
 lea     r9, [rdx, +, 8*r10]
 lea     rcx, [rdx, +, 8*rcx]
 mov     qword, ptr, [rax], r8
 mov     qword, ptr, [rax, +, 8], r9
 mov     qword, ptr, [rax, +, 16], rcx
 ret
.LBB0_7:
 mov     qword, ptr, [rax], 0
 ret
```

## Checked Indexing (Panic):

```rust
pub fn example_panic(slice: &mut [usize], indices: [usize; 3]) -> [&mut usize; 3] {
    let len = slice.len();
    match slice.get_many_mut(indices) {
        Some(s) => s,
        None => {
            let tmp = indices;
            index_many::sorted_bound_check_failed(&tmp, len)
        }
    }
}
```

```nasm
example_panic:
 sub     rsp, 56
 mov     rax, qword, ptr, [r9]
 mov     r10, qword, ptr, [r9, +, 8]
 mov     r9, qword, ptr, [r9, +, 16]
 cmp     r9, r10
 je      .LBB0_6
 cmp     r9, rax
 je      .LBB0_6
 cmp     r9, r8
 jae     .LBB0_6
 cmp     r10, rax
 je      .LBB0_6
 cmp     rax, r8
 jae     .LBB0_6
 cmp     r10, r8
 jae     .LBB0_6
 lea     rax, [rdx, +, 8*rax]
 lea     r8, [rdx, +, 8*r10]
 lea     rdx, [rdx, +, 8*r9]
 mov     qword, ptr, [rcx], rax
 mov     qword, ptr, [rcx, +, 8], r8
 mov     qword, ptr, [rcx, +, 16], rdx
 mov     rax, rcx
 add     rsp, 56
 ret
.LBB0_6:
 mov     qword, ptr, [rsp, +, 32], rax
 mov     qword, ptr, [rsp, +, 40], r10
 mov     qword, ptr, [rsp, +, 48], r9
 lea     rcx, [rsp, +, 32]
 mov     edx, 3
 call    index_many::bound_check_failed
 ud2
```
</details>

# Extensions

There are multiple optional extensions to this.

## Indexing With Ranges

This could easily be expanded to allow indexing with `[I; N]` where `I: SliceIndex<Self>`.  I wanted to keep the initial implementation simple, so I didn't include it yet.

## Panicking Variant

We could also add this method:

```rust
impl<T> [T] {
    fn index_many_mut<const N: usize>(&mut self, indices: [usize; N]) -> [&mut T; N];
}
```

This would work similar to the regular index operator and panic with out-of-bound indices. The advantage would be that we could more easily ensure good codegen with a useful panic message, which is non-trivial with the `Option` variant.

This is implemented in the standalone implementation, and used as basis for the codegen examples here and there.
2022-11-22 01:26:05 -05:00
David Tolnay 70cee5af4b
Touch up Box<T> one-liner 2022-11-21 15:28:41 -08:00
David Tolnay 6d943af735
Rustc_deprecated attribute superseded by deprecated 2022-11-21 15:18:36 -08:00
David Tolnay a9e92be1f9
Bump ptr_to_from_bits deprecation to Rust 1.67 2022-11-21 15:10:59 -08:00
Matthias Krüger 04e8ebe3f2
Rollup merge of #104692 - chbaker0:libtest-cfg-if, r=thomcc
Update test's cfg-if dependency to 1.0

This change was mistakenly left out of #103367

Finishes #103365
2022-11-22 00:01:12 +01:00
Matthias Krüger 3278dea67a
Rollup merge of #103396 - RalfJung:pinning-closure-captures, r=dtolnay
Pin::new_unchecked: discuss pinning closure captures

Regardless of how the discussion in https://github.com/rust-lang/rust/pull/102737 turns out, pinning closure captures is super subtle business and probably worth discussing separately.
2022-11-22 00:01:06 +01:00
Collin Baker 426296ecc3 Update test's cfg-if dependency to 1.0
This change was mistakenly left out of #103367
2022-11-21 16:43:34 -05:00
Ralf Jung 1a6966602a dont attempt strict provenance in SGX 2022-11-21 16:10:56 +01:00
Matthias Krüger 369e44943f
Rollup merge of #104420 - TethysSvensson:master, r=JohnTitor
Fix doc example for `wrapping_abs`

The `max` variable is unused. This change introduces the `min_plus` variable, to make the example similar to the one from `saturating_abs`. An alternative would be to remove the unused variable.
2022-11-21 14:11:09 +01:00
ismailmaj 005c6dfde6 type annotate &str when stack allocating a string 2022-11-21 10:38:04 +01:00
Matthias Krüger 846574828a
Rollup merge of #104643 - pnkfelix:examples-for-chunks-remainder, r=scottmcm
add examples to chunks remainder methods.

add examples to chunks remainder methods.

my motivation for adding the examples was to make it very clear that the state of the iterator (in terms of where its cursor lies) has no effect on what remainder returns.

Also fixed some links to rchunk remainder methods.
2022-11-20 23:50:30 +01:00
Matthias Krüger 9a9569698b
Rollup merge of #104641 - tshepang:grammar, r=Mark-Simulacrum
replace unusual grammar
2022-11-20 23:50:29 +01:00
Matthias Krüger b3d491696b
Rollup merge of #104634 - RalfJung:core-arch, r=Mark-Simulacrum
move core::arch into separate file

This works around https://github.com/rust-lang/rust/issues/104633 which otherwise leads to warnings in miri-test-libstd.
2022-11-20 23:50:29 +01:00
Matthias Krüger ff72187b06
Rollup merge of #104632 - RalfJung:core-test-strict-provenance, r=thomcc
avoid non-strict-provenance casts in libcore tests

r? `@thomcc`
2022-11-20 23:50:28 +01:00
Matthias Krüger 6a722aa170
Rollup merge of #104461 - mati865:gnullvm-aarch64-fixup, r=Mark-Simulacrum
Fix building of `aarch64-pc-windows-gnullvm`

That change had been lost during rebase of my last PR (https://github.com/rust-lang/rust/pull/103894).
2022-11-20 23:50:26 +01:00
Matthias Krüger b4513ce6f8
Rollup merge of #101310 - zachs18:rc_get_unchecked_mut_docs_soundness, r=Mark-Simulacrum
Clarify and restrict when `{Arc,Rc}::get_unchecked_mut` is allowed.

(Tracking issue for `{Arc,Rc}::get_unchecked_mut`: #63292)

(I'm using `Rc` in this comment, but it applies for `Arc` all the same).

As currently documented, `Rc::get_unchecked_mut` can lead to unsoundness when multiple `Rc`/`Weak` pointers to the same allocation exist. The current documentation only requires that other `Rc`/`Weak` pointers to the same allocation "must not be dereferenced for the duration of the returned borrow". This can lead to unsoundness in (at least) two ways: variance, and `Rc<str>`/`Rc<[u8]>` aliasing. ([playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d7e2d091c389f463d121630ab0a37320)).

This PR changes the documentation of `Rc::get_unchecked_mut` to restrict usage to when all `Rc<T>`/`Weak<T>` have the exact same `T` (including lifetimes). I believe this is sufficient to prevent unsoundness, while still allowing `get_unchecked_mut` to be called on an aliased `Rc` as long as the safety contract is upheld by the caller.

## Alternatives

* A less strict, but still sound alternative would be to say that the caller must only write values which are valid for all aliased `Rc`/`Weak` inner types. (This was [mentioned](https://github.com/rust-lang/rust/issues/63292#issuecomment-568284090) in the tracking issue). This may be too complicated to clearly express in the documentation.
* A more strict alternative would be to say that there must not be any aliased `Rc`/`Weak` pointers, i.e. it is required that get_mut would return `Some(_)`. (This was also mentioned in the tracking issue). There is at least one codebase that this would cause to become unsound ([here](be5a164d77/src/memtable.rs (L166)), where additional locking is used to ensure unique access to an aliased `Rc<T>`;  I saw this because it was linked on the tracking issue).
2022-11-20 23:50:26 +01:00
Rune Tynan 8998711d9b Only one feature gate needed 2022-11-20 17:10:47 -05:00
Rune Tynan 07911879d2 Use ? instead of match 2022-11-20 15:01:22 -05:00
Rune Tynan a5fecc6905 Fix issue number 2022-11-20 15:01:21 -05:00
Rune Tynan 7972b8aa37 Add derive_const feature 2022-11-20 15:01:21 -05:00
Rune Tynan 6f2dcac78b Update with derive_const 2022-11-20 15:01:21 -05:00
Rune Tynan 414e84a2f7 Add stability for alignment 2022-11-20 15:01:21 -05:00
Rune Tynan 9f4b4e46a3 constify remaining layout methods
Remove bad impl for Eq

Update Cargo.lock and fix last ValidAlign
2022-11-20 15:01:21 -05:00
Ralf Jung 7f5adddb25 enable fuzzy_provenance_casts lint in libstd 2022-11-20 19:23:28 +01:00
Ralf Jung 644a5a34dd enable fuzzy_provenance_casts lint in liballoc 2022-11-20 19:12:18 +01:00