Commit Graph

10332 Commits

Author SHA1 Message Date
mochaaP
3e35b39d9d
std: only use LFS function on glibc
see #94173 and commit 27011b4185.
2022-12-22 16:01:27 +08:00
bors
75f4ee8b44 Auto merge of #106025 - matthiaskrgr:rollup-vz5rqah, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #105837 (Don't ICE in `check_must_not_suspend_ty` for mismatched tuple arity)
 - #105932 (Correct branch-protection ModFlagBehavior for Aarch64 on LLVM-15)
 - #105960 (Various cleanups)
 - #105985 (Method chain nitpicks)
 - #105996 (Test that async blocks are `UnwindSafe`)
 - #106012 (Clarify that raw retags are not permitted in Mir)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-22 05:30:00 +00:00
bors
8574880108 Auto merge of #106023 - JohnTitor:rollup-k8mettz, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #105584 (add assert messages if chunks/windows are length 0)
 - #105602 (interpret: add read_machine_[ui]size convenience methods)
 - #105824 (str.lines() docstring: clarify that line endings are not returned)
 - #105980 (Refer to "Waker" rather than "RawWaker" in `drop` comment)
 - #105986 (Fix typo in reading_half_a_pointer.rs)
 - #105995 (Add regression test for #96530)
 - #106008 (Sort lint_groups in no_lint_suggestion)
 - #106014 (Add comment explaining what the scrape-examples-toggle.goml GUI test is about)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-22 02:16:59 +00:00
Matthias Krüger
d0d0ccdca2
Rollup merge of #106012 - JakobDegen:retag-raw, r=RalfJung
Clarify that raw retags are not permitted in Mir

Not sure when this changed, but documentation and the validator needed to be updated. This also removes raw retags from custom mir.

cc rust-lang/miri#2735

r? `@RalfJung`
2022-12-22 01:01:15 +01:00
Matthias Krüger
ec7eb5b5ad
Rollup merge of #105960 - oli-obk:effect_cleanup, r=fee1-dead
Various cleanups

This PR pulls changes out of https://github.com/rust-lang/rust/pull/101900 that can land on master immediately

r? ``@fee1-dead``
2022-12-22 01:01:13 +01:00
Yuki Okushi
03a763c5c8
Rollup merge of #105980 - goffrie:waker-drop, r=thomcc
Refer to "Waker" rather than "RawWaker" in `drop` comment

In my view this is technically more correct as `Waker` actually implements `Drop` (which calls the `drop` method) whereas `RawWaker` does not.
2022-12-22 08:32:11 +09:00
Yuki Okushi
257edf2de5
Rollup merge of #105824 - zacchiro:patch-1, r=JohnTitor
str.lines() docstring: clarify that line endings are not returned

Previously, the str.lines() docstring stated that lines are split at line endings, but not whether those were returned or not.  This new version of the docstring states this explicitly, avoiding the need of getting to doctests to get an answer to this FAQ.
2022-12-22 08:32:10 +09:00
Yuki Okushi
342d1b7f01
Rollup merge of #105584 - raffimolero:patch-1, r=JohnTitor
add assert messages if chunks/windows are length 0
2022-12-22 08:32:09 +09:00
bors
bdbe392a13 Auto merge of #105613 - Nilstrieb:rename-assert_uninit_valid, r=RalfJung
Rename `assert_uninit_valid` intrinsic

It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.

This is actually not fully correct though, as it does still panic for all uninit with `-Zstrict-init-checks`. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if #100423 lands so removing it may be a bit over eager.

r? `@RalfJung`
2022-12-21 23:20:04 +00:00
Jakob Degen
cb2c7bb833 Clarify that raw retags are not permitted in Mir 2022-12-21 10:32:01 -08:00
bors
49143814e1 Auto merge of #100390 - jhpratt:float-from-bool, r=dtolnay
Implement `From<bool>` for f32, f64

As is required for trait implementations, these are insta-stable. Given there is a release tomorrow and this needs FCP, I set 1.65 as the stable version.

`@rustbot` label +A-floating-point +C-feature-request +needs-fcp +relnotes +S-waiting-on-review +T-libs-api -T-libs
2022-12-21 14:27:57 +00:00
Ralf Jung
6f21ba4a06
less specific wording 2022-12-21 11:06:20 +01:00
Geoffry Song
f5e776c3f7
Refer to "Waker" rather than "RawWaker" in drop comment 2022-12-20 14:51:24 -08:00
bors
1d12c3cea3 Auto merge of #105127 - Sp00ph:const_new, r=dtolnay
Make `VecDeque::new` const

(See #105072)
2022-12-20 20:25:42 +00:00
bors
d6da428f34 Auto merge of #105381 - uweigand:s390x-ffi-vaarg, r=nikic
Implement va_list and va_arg for s390x FFI

Following the s390x ELF ABI and based on the clang implementation, provide appropriate definitions of va_list in library/core/src/ffi/mod.rs and va_arg handling in compiler/rustc_codegen_llvm/src/va_arg.rs.

Fixes the following test cases on s390x:
src/test/run-make-fulldeps/c-link-to-rust-va-list-fn src/test/ui/abi/variadic-ffi.rs

Fixes https://github.com/rust-lang/rust/issues/84628.
2022-12-20 17:09:11 +00:00
Oli Scherer
c787de3bbd Fix some ~const usage in libcore 2022-12-20 15:01:37 +00:00
Anders Kaseorg
8c73ce6611 Update coerce_unsized tracking issue from #27732 to #18598
Issue #27732 was closed as a duplicate of #18598.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-12-19 23:09:47 -08:00
Ulrich Weigand
eb22d70aed Implement va_list and va_arg for s390x FFI
Following the s390x ELF ABI and based on the clang implementation,
provide appropriate definitions of va_list in library/core/src/ffi/mod.rs
and va_arg handling in compiler/rustc_codegen_llvm/src/va_arg.rs.

Fixes the following test cases on s390x:
src/test/run-make-fulldeps/c-link-to-rust-va-list-fn
src/test/ui/abi/variadic-ffi.rs

Fixes https://github.com/rust-lang/rust/issues/84628.
2022-12-19 21:07:57 +01:00
Matthias Krüger
575b2a2232
Rollup merge of #105915 - andrewpollack:revert-105250-async-rm-resumety, r=tmandry
Revert "Replace usage of `ResumeTy` in async lowering with `Context`"

Reverts rust-lang/rust#105250
Fixes: #105501

Following instructions from [forge](https://forge.rust-lang.org/compiler/reviews.html#reverts).

This change introduced a breaking change that is not actionable nor relevant, and is blocking updates to our toolchain. Along with other comments on the CL marking issues that are fixed by reverts, reverting is best until these issues can be resolved

cc. `@Swatinem`
2022-12-19 20:55:00 +01:00
Matthias Krüger
a81d0dc3cd
Rollup merge of #105902 - vincenzopalazzo:macros/pin_docs, r=eholk
docs: improve pin docs

Override https://github.com/rust-lang/rust/pull/104195 with a full cleanup of the git history, now it should be ready to be merged.

r? ``@eholk``

``@rustbot`` label +A-async-await
2022-12-19 20:54:59 +01:00
Matthias Krüger
3af45eeb98
Rollup merge of #105801 - zertosh:path_mut_os_str_doc_test, r=dtolnay
Realistic `Path::as_mut_os_str` doctest

With "Implement DerefMut for PathBuf" (#105018) now merged, it's
possible to exercise `Path::as_mut_os_str` (#105002) without going
through `into_boxed_path`.
2022-12-19 20:54:57 +01:00
Andrew Pollack
8441ca5d81
Revert "Replace usage of ResumeTy in async lowering with Context" 2022-12-19 11:24:59 -08:00
bors
7ab803891d Auto merge of #105698 - joboet:unsupported_threads_once, r=thomcc
Use a more efficient `Once` on platforms without threads

The current implementation uses an atomic queue and spins rather than panicking when calling `call_once` recursively. Since concurrency is not supported on platforms like WASM, `Once` can be implemented much more efficiently using just a single non-atomic state variable.
2022-12-19 16:46:57 +00:00
ch-iv
7fc6b0c9f3
docs: improve pin docs
Co-authored-by: <@ch-iv>
2022-12-19 15:46:44 +01:00
Dylan DPC
2a57493fa1
Rollup merge of #105889 - Nilstrieb:fmt-libtest, r=thomcc
Fix `uninlined_format_args` in libtest

Done using clippy with a quick manual review.
2022-12-19 14:41:37 +05:30
Dylan DPC
f74bcfbdb1
Rollup merge of #105682 - thomcc:expose-ptr-fmt, r=RalfJung
Use `expose_addr()` in `fmt::Pointer`

Discussion in https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Should.20.60fmt.3A.3APointer.60.20expose.20the.20argument.3F on whether or not we should do this (still undecided).

CC `@RalfJung`
2022-12-19 14:41:34 +05:30
nils
5fb2d63d07
Fix uninlined_format_args in libtest 2022-12-19 08:58:40 +01:00
Matthias Krüger
63fdc9a857
Rollup merge of #105858 - scottmcm:extra-as-chunks-example, r=the8472
Another `as_chunks` example

I really liked this structure that dtolney brought up in #105316, so wanted to put it in the docs to help others use it.
2022-12-18 18:57:04 +01:00
bors
48b3c46126 Auto merge of #105638 - tavianator:fix-50619-again, r=Mark-Simulacrum
fs: Fix #50619 (again) and add a regression test

Bug #50619 was fixed by adding an end_of_stream flag in #50630.
Unfortunately, that fix only applied to the readdir_r() path.  When I
switched Linux to use readdir() in #92778, I inadvertently reintroduced
the bug on that platform.  Other platforms that had always used
readdir() were presumably never fixed.

This patch enables end_of_stream for all platforms, and adds a
Linux-specific regression test that should hopefully prevent the bug
from being reintroduced again.
2022-12-18 05:04:04 +00:00
Scott McMurray
a37d42133c Another as_chunks example
I really liked this structure that dtolney brought up in #105316, so wanted to put it in the docs to help others use it.
2022-12-17 18:41:14 -08:00
Matthias Krüger
8fc1a72e56
Rollup merge of #105836 - evanj:fmt-doc-use-variables, r=Mark-Simulacrum
std::fmt: Use args directly in example code

The lint "clippy::uninlined_format_args" recommends inline variables in format strings. Fix two places in the docs that do not do this. I noticed this because I copy/pasted one example in to my project, then noticed this lint error. This fixes:

```
error: variables can be used directly in the `format!` string
  --> src/main.rs:30:22
   |
30 |         let string = format!("{:.*}", decimals, magnitude);
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: variables can be used directly in the `format!` string
  --> src/main.rs:39:2
   |
39 |  write!(&mut io::stdout(), "{}", args).unwrap();
```
2022-12-17 23:44:29 +01:00
Matthias Krüger
eaf2f26ecc
Rollup merge of #105814 - JakobDegen:custom-mir-terms, r=oli-obk
Support call and drop terminators in custom mir

The only caveat with this change is that cleanup blocks are not supported. I would like to add them, but it's not quite clear to me what the best way to do that is, so I'll have to think about it some more.

r? ``@oli-obk``
2022-12-17 23:44:28 +01:00
Matthias Krüger
6d1cdcaee5
Rollup merge of #105458 - Ayush1325:blocking_spawn, r=Mark-Simulacrum
Allow blocking `Command::output`

### Problem
Currently, `Command::output` is internally implemented using `Command::spawn`. This is problematic because some targets (like UEFI) do not actually support multitasking and thus block while the program is executing. This coupling does not make much sense as `Command::output` is supposed to block until the execution is complete anyway and thus does not need to rely on a non-blocking `Child` or any other intermediate.

### Solution
This PR moves the implementation of `Command::output` to `std::sys`. This means targets can choose to implement only `Command::output` without having to implement `Command::spawn`.

### Additional Information

This was originally conceived when working on https://github.com/rust-lang/rust/pull/100316. Currently, the only target I know about that will benefit from this change is UEFI.

This PR can also be used to implement more efficient `Command::output` since the intermediate `Process` is not actually needed anymore, but that is outside the scope of this PR.

Since this is not a public API change, I'm not sure if an RFC is needed or not.
2022-12-17 23:44:26 +01:00
Evan Jones
ab2151cbf8 std::fmt: Use args directly in example code
The lint "clippy::uninlined_format_args" recommends inline
variables in format strings. Fix two places in the docs that do
not do this. I noticed this because I copy/pasted one example in
to my project, then noticed this lint error. This fixes:

error: variables can be used directly in the `format!` string
  --> src/main.rs:30:22
   |
30 |         let string = format!("{:.*}", decimals, magnitude);
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: variables can be used directly in the `format!` string
  --> src/main.rs:39:2
   |
39 |  write!(&mut io::stdout(), "{}", args).unwrap();
2022-12-17 13:43:08 -05:00
Stefano Zacchiroli
7f9438910c
str.lines() docstring: clarify that line endings are not returned
Previously, the str.lines() docstring stated that lines are split at line
endings, but not whether those were returned or not.  This new version of the
docstring states this explicitly, avoiding the need of getting to doctests to
get an answer to this FAQ.
2022-12-17 12:20:56 +01:00
bors
fde3000299 Auto merge of #105794 - ChrisDenton:internal-doc, r=jyn514
Add CI test for documentation of hidden items in std

Fixes #87844

r? `@jyn514`
2022-12-17 06:27:30 +00:00
Jakob Degen
3d849ae44c Support call and drop terminators in custom mir 2022-12-16 22:26:33 -08:00
Andres Suarez
c68d2e4b87 Realistic Path::as_mut_os_str doctest 2022-12-16 16:52:36 -05:00
Chris Denton
8534fd3089
Fix intra-doc link 2022-12-16 20:21:44 +00:00
bors
9c07efe84f Auto merge of #105018 - zertosh:path_buf_deref_mut, r=dtolnay
Implement DerefMut for PathBuf

Without this, there's no way to get a `&mut Path` from `PathBuf` without
going through `into_boxed_path`. This is relevant now that #105002 adds
`PathBuf::as_mut_os_string` and `Path::as_mut_os_str`.
2022-12-16 18:06:10 +00:00
Maybe Waffle
b458a49f26 Replace Split*::as_str with remainder
This commit
- Renames `Split*::{as_str -> remainder}` as it seems less confusing
- Makes `remainder` return Option<&str> to distinguish between
  "iterator is exhausted" and "the tail is empty"
2022-12-16 13:04:22 +00:00
Matthias Krüger
1ad070a118
Rollup merge of #105748 - hakoerber:master, r=Dylan-DPC
doc: Fix a few small issues

Hey, while reading through the (awesome) stdlib docs, I found a few minor typos.

* A few typos around generic types (`;` vs `,`)
* Use inline code formatting for code fragments
* One instance of wrong wording
2022-12-16 14:02:19 +01:00
Maybe Waffle
ca4989eac2 SplitInternal: always set finished in get_end 2022-12-16 12:57:22 +00:00
bors
ec56537c43 Auto merge of #105356 - JakobDegen:more-custom-mir, r=oli-obk
Custom MIR: Many more improvements

Commits are each atomic changes, best reviewed one at a time, with the exception that the last commit includes all the documentation.

### First commit

Unsafetyck was not correctly disabled before for `dialect = "built"` custom MIR. This is fixed and a regression test is added.

### Second commit

Implements `Discriminant`, `SetDiscriminant`, and `SwitchInt`.

### Third commit

Implements indexing, field, and variant projections.

### Fourth commit

Documents the previous commits and everything else.

There is some amount of weirdness here due to having to beat Rust syntax into cooperating with MIR concepts, but it hopefully should not be too much. All of it is documented.

r? `@oli-obk`
2022-12-15 19:59:48 +00:00
Hannes Körber
9671dd239d doc: Fix a few small issues
* A few typos around generic types (`;` vs `,`)
* Use inline code formatting for code fragments
* One instance of wrong wording
2022-12-15 14:05:03 +01:00
Jacob Pratt
b134d1108f
Implement From<bool> for f32, f64 2022-12-15 03:55:21 +00:00
Matthias Krüger
6d3a93c823
Rollup merge of #105598 - RalfJung:more-comments, r=the8472
explain mem::forget(env_lock) in fork/exec

I stumbled upon this while doing triage for https://github.com/rust-lang/rust/issues/64718.
2022-12-14 17:17:57 +01:00
Matthias Krüger
35ff2cf295
Rollup merge of #105399 - mikebenfield:lfs, r=thomcc
Use more LFS functions.

On Linux, use mmap64, open64, openat64, and sendfile64 in place of their non-LFS counterparts.

This is relevant to #94173.

With these changes (together with rust-lang/backtrace-rs#501), the simple binaries I produce with rustc seem to have no non-LFS functions, so maybe #94173 is fixed. But I can't be sure if I've missed something and maybe some non-LFS functions could sneak in somehow.
2022-12-14 17:17:56 +01:00
Tavian Barnes
9fb7c5ae5e fs/tests: Fail fast on duplicate errors rather than looping indefinitely 2022-12-14 10:03:46 -05:00
Tavian Barnes
1550a2506d fs/tests: Explicitly kill the zombie rather than sleeping until it dies 2022-12-14 10:03:42 -05:00
joboet
f9b56846ef
std: use a more efficient Once on platforms without threads 2022-12-14 13:55:30 +01:00
bors
ba64ba8b0d Auto merge of #105690 - matthiaskrgr:rollup-khtq97k, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #105642 (Minor grammar nit.)
 - #105658 (Remove ..X from RELEASES.md)
 - #105663 (Adjust log line in `fuchsia-test-runner.py`)
 - #105664 (rustdoc: apply `pre-wrap` CSS to code-wrapped links)
 - #105665 (rustdoc: simplify popover CSS)
 - #105676 (rustdoc: add CSS margin between `impl` docblock and its items)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-14 12:46:08 +00:00
Matthias Krüger
549ba2e198
Rollup merge of #105642 - uberFoo:master, r=Dylan-DPC
Minor grammar nit.

I was browsing the documentation and noticed that this should be an adverb.
2022-12-14 10:58:46 +01:00
Matthias Krüger
e5fde968db
Rollup merge of #105523 - estebank:suggest-collect-vec, r=compiler-errors
Suggest `collect`ing into `Vec<_>`

Fix #105510.
2022-12-14 10:31:07 +01:00
Jakob Degen
b580f29b74 Address documentation suggestions 2022-12-14 01:10:43 -08:00
Jakob Degen
aca1bc5f37 Add documentation for custom mir 2022-12-14 01:10:41 -08:00
Jakob Degen
e59839454d Support more projections in custom mir 2022-12-14 01:10:19 -08:00
Jakob Degen
409f4d2adb Support common enum operations in custom mir 2022-12-14 01:10:16 -08:00
Thom Chiovoloni
f2d0366791
Use expose_addr() in fmt::Pointer 2022-12-13 20:53:14 -08:00
Chris AtLee
e0fd37dcf7 Improve wording for Option and Result 2022-12-13 14:49:10 -05:00
Chris AtLee
b486fd5d83 Add docs for question mark operator for Option 2022-12-13 14:45:12 -05:00
Esteban Küber
9d5e7d3c04 Suggest collecting into Vec<_> 2022-12-13 10:39:44 -08:00
Nilstrieb
8b2a7da3b0 Rename assert_uninit_valid intrinsic
It's not about "uninit" anymore but about "filling with 0x01 bytes" so
the name should at least try to reflect that.
2022-12-13 18:08:35 +01:00
Fabian Hintringer
083560b7d8
Add result example + rewording 2022-12-13 09:17:22 +01:00
Trevor Gross
b9558a15dc Add #[inline] marker to OnceCell/LazyCell/OnceLock/LazyLock 2022-12-13 02:18:15 -05:00
Keith T. Star
c3329ba63a Minor grammar nit. 2022-12-12 16:22:01 -07:00
Tavian Barnes
ba4dd464f5 fs: Fix #50619 (again) and add a regression test
Bug #50619 was fixed by adding an end_of_stream flag in #50630.
Unfortunately, that fix only applied to the readdir_r() path.  When I
switched Linux to use readdir() in #92778, I inadvertently reintroduced
the bug on that platform.  Other platforms that had always used
readdir() were presumably never fixed.

This patch enables end_of_stream for all platforms, and adds a
Linux-specific regression test that should hopefully prevent the bug
from being reintroduced again.
2022-12-12 17:17:26 -05:00
Ralf Jung
3465d5fb16 explain mem::forget(env_lock) in fork/exec 2022-12-12 21:02:49 +01:00
Matthias Krüger
f5852c41a0
Rollup merge of #105616 - est31:add_the, r=Dylan-DPC
Add a "the" to proc_macro documentation
2022-12-12 19:20:37 +01:00
est31
3c809b3c5c Add a "the" to proc_macro documentation 2022-12-12 16:19:18 +01:00
Albert Larsan
736342bb46
Correct typos in core::sync::Exclusive::get_{pin_mut, mut} 2022-12-12 09:19:17 +01:00
Tomoaki Kawada
6fbef06f26 kmc-solid: Synchronize with the read when sending a joining task ID to a joinee 2022-12-12 14:36:17 +09:00
Tomoaki Kawada
304c6dcaed kmc-solid: Synchronize the first update of ThreadInner::lifecycle with the second one on detach
The first update (swap RMW operation) must happen-before the second
update so that the latter can release `ThreadInner` safely.
2022-12-12 14:22:45 +09:00
raffimolero
46f6e39ac6
add assert messages if chunks/windows are length 0 2022-12-12 12:28:40 +08:00
Matthias Krüger
668976b80a
Rollup merge of #101648 - Timmmm:home_dir_docs, r=joshtriplett
Better documentation for env::home_dir()'s broken behaviour

This improves the documentation to say *why* it was deprecated. The reason was because it reads `HOME` on Windows which is meaningless there. Note that the PR that deprecated it stated that returning an empty string if `HOME` is set to an empty string was a problem, however I can find no evidence that this is the case. `cd` handles it fine whereas if `HOME` is unset it gives an explicit `HOME not set` error.

* Original deprecation reason: https://internals.rust-lang.org/t/deprecate-or-break-fix-std-env-home-dir/7315
* Original deprecation PR: https://github.com/rust-lang/rust/pull/51656

See #71684
2022-12-11 23:36:44 +01:00
bors
4de4d60779 Auto merge of #105508 - eduardosm:ptr-methods-inline-always, r=Mark-Simulacrum
Make pointer `sub` and `wrapping_sub` methods `#[inline(always)]`

Splitted from https://github.com/rust-lang/rust/pull/105262
2022-12-11 11:42:15 +00:00
Ayush Singh
a94793d8d1
Implement blocking output
This allows decoupling `Command::spawn` and `Command::output`. This is
useful for targets which do support launching programs in blocking mode
but do not support multitasking (Eg: UEFI).

This was originally conceived when working on https://github.com/rust-lang/rust/pull/100316

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-12-11 10:21:40 +05:30
Matthias Krüger
e47c96a9cf
Rollup merge of #105460 - mkroening:compiler-builtins-0.1.85, r=Mark-Simulacrum
Bump compiler-builtins to 0.1.85

This makes minimal floating point symbols available on `x86_64-unknown-none`.

See https://github.com/rust-lang/compiler-builtins/issues/509 and https://github.com/rust-lang/compiler-builtins/pull/510.
2022-12-11 00:30:19 +01:00
Matthias Krüger
7f4e7c159b
Rollup merge of #103146 - joboet:cleanup_pthread_condvar, r=Mark-Simulacrum
Cleanup timeouts in pthread condvar
2022-12-11 00:30:18 +01:00
Matthias Krüger
43bee03a67
Rollup merge of #105239 - gh2o:no-heap-alloc-on-thread-start, r=cuviper
Avoid heap allocation when truncating thread names

Ensure that heap allocation does not occur in a thread until `std::thread` is ready. This fixes issues with custom allocators that call `std:🧵:current()`, since doing so prematurely initializes `THREAD_INFO` and causes the following `thread_info::set()` to fail.
2022-12-10 15:01:44 +01:00
Xiretza
17a0740ebb libcore: make result of iter::from_generator Clone
This is currently only relevant with #![feature(generator_clone)].
2022-12-10 09:28:07 +01:00
Xiretza
a8b5d4b7f1 libcore: make result type of iter::from_generator concrete
This allows for propagating trait impls on the iterator type.
2022-12-10 09:27:07 +01:00
Matthias Krüger
f6c2add0ed
Rollup merge of #105522 - est31:remove_or_and_note, r=scottmcm
Remove wrong note for short circuiting operators

They *are* representable by traits, even if the short-circuiting behaviour requires a different approach than the non-short-circuiting operators. For an example proposal, see the postponed [RFC 2722](https://github.com/rust-lang/rfcs/pull/2722). As it is not accurate, remove most of the note.
2022-12-10 09:24:45 +01:00
Matthias Krüger
eb1159cbd8
Rollup merge of #104901 - krtab:filetype_compare, r=the8472
Implement masking in FileType comparison on Unix

Fixes: https://github.com/rust-lang/rust/issues/104900
2022-12-10 09:24:42 +01:00
Matthias Krüger
ae8794ce6a
Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-se
Reimplement std's thread parker on top of events on SGX

Mutex and Condvar are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore, the generic `Parker` needs to be replaced on all platforms where the new lock implementation will be used.

SGX enclaves have a per-thread event state, which allows waiting for and setting specific bits. This is already used by the current mutex implementation. The thread parker can however be much more efficient, as it only needs to store the `TCS` address of one thread. This address is stored in a state variable, which can also be set to indicate the thread was already notified.

`park_timeout` does not guard against spurious wakeups like the current condition variable does. This is allowed by the API of `Parker`, and I think it is better to let users handle these wakeups themselves as the guarding is quite expensive and might not be necessary.

`@jethrogb` as you wrote the initial SGX support for `std`, I assume you are the target maintainer? Could you help me test this, please? Lacking a x86_64 chip, I can't run SGX.
2022-12-10 09:24:40 +01:00
est31
f069e7159f Correct wrong note for short circuiting operators
They *are* representable by traits, even if the short-circuiting
behaviour requires a different approach than the non-short-circuiting
operators. For an example proposal, see the postponed RFC 2722.
As it is not accurate, reword the note.
2022-12-10 08:11:19 +01:00
Matthias Krüger
5156fbdc74
Rollup merge of #105453 - scottmcm:vecdeque_from_iter, r=the8472
Make `VecDeque::from_iter` O(1) from `vec(_deque)::IntoIter`

As suggested in https://github.com/rust-lang/rust/pull/105046#issuecomment-1330371695 by
r? ``@the8472``

`Vec` & `VecDeque`'s `IntoIter`s own the allocations, and even if advanced can be turned into `VecDeque`s in O(1).

This is just a specialization, not an API or doc commitment, so I don't think it needs an FCP.
2022-12-09 22:31:56 +01:00
Matthias Krüger
856027a73a
Rollup merge of #105265 - aDotInTheVoid:sum-product-on-unimplemented, r=estebank
Add `rustc_on_unimplemented` to `Sum` and `Product` trait.

Helps with #105184, but I don't think it fully fixes it.
2022-12-09 22:31:55 +01:00
Eduardo Sánchez Muñoz
3ed058bcbb Make <*{const,mut} T>::{,wrapping_}sub methods #[inline(always)] 2022-12-09 20:30:06 +01:00
bors
f058493307 Auto merge of #105262 - eduardosm:more-inline-always, r=thomcc
Make some trivial functions `#[inline(always)]`

This is some kind of follow-up of PRs like https://github.com/rust-lang/rust/pull/85218, https://github.com/rust-lang/rust/pull/84061, https://github.com/rust-lang/rust/pull/87150. Functions that do very basic operations are made `#[inline(always)]` to avoid pessimizing them in debug builds when compared to using built-in operations directly.
2022-12-09 15:42:18 +00:00
Arthur Carcano
24cd863a38 Replace hand-made masking by call to masked() method in FileType 2022-12-09 15:04:36 +01:00
Matthias Krüger
3d727315c5
Rollup merge of #105474 - RalfJung:typo, r=dtolnay
lib docs: fix typo

r? `@thomcc`
2022-12-09 07:25:48 +01:00
Matthias Krüger
0b4d57be53
Rollup merge of #105245 - RalfJung:align_to, r=Amanieu
attempt to clarify align_to docs

This is not intended the change the docs at all, but `@workingjubilee` said the current docs are incomprehensible to some people so this is an attempt to fix that. No idea if it helps, so -- feedback welcome.

(Please let's not use this to discuss *changing* the spec. Whoever wants to change the spec should please make a separate PR for that.)
2022-12-09 07:25:44 +01:00
Scott McMurray
6648134434 Apply review feedback; Fix no_global_oom_handling build 2022-12-08 22:08:55 -08:00
Gary Guo
5e44a65517 Implement allow-by-default multiple_supertrait_upcastable lint 2022-12-09 02:29:51 +00:00
Nixon Enraght-Moony
5626df9c90 Add rustc_on_unimplemented to Sum and Product trait. 2022-12-08 23:07:54 +00:00
Ralf Jung
a25791ee61 lib docs: fix typo 2022-12-08 22:36:57 +01:00
Martin Kröning
6324e5cb6a Bump compiler-builtins to 0.1.85 2022-12-08 15:34:46 +01:00
Ayush Singh
5479fe5f70
Add read_to_end for AnonPipe
Add `read_to_end` method for `sys::{target}::pipe::AnonPipe`. This allows
having a more optimized version of `read_to_end` for ChildStdout.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-12-08 18:12:15 +05:30
Matthias Krüger
433189b742
Rollup merge of #105434 - nbdd0121:lib, r=thomcc
Fix warning when libcore is compiled with no_fp_fmt_parse

Discovered when trying to compile Rust-for-Linux with Rust 1.66 beta.

It'll be helpful if this is backported to beta (should be trivial enough for backporting), so Rust-for-Linux's rust version bump wouldn't need to do `--cap-lints allow` for libcore.
2022-12-08 12:57:33 +01:00
Matthias Krüger
cd936cc812
Rollup merge of #105120 - solid-rs:patch/kmc-solid/maintainance, r=thomcc
kmc-solid: `std::sys` code maintenance

Includes a set of changes to fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets and make some other improvements.

- Address `fuzzy_provenance_casts` by using `expose_addr` and `from_exposed_addr` for pointer-integer casts
- Add a stub implementation of `is_terminal` (#98070)
- Address `unused_imports` and `unused_unsafe`
- Stop doing `Box::from_raw(&*(x: Box<T>) as *const T as *mut T)`
2022-12-08 12:57:29 +01:00
Scott McMurray
58e60ac211 Make VecDeque::from_iter O(1) from vec(_deque)::IntoIter 2022-12-08 01:42:45 -08:00
Gary Guo
a3c4c2ee1d Fix warning when libcore is compiled with no_fp_fmt_parse 2022-12-08 00:16:49 +00:00
Gavin Li
3c55af5b09 Avoid heap allocation when truncating thread names
Ensure that heap allocation does not occur in a thread until std::thread
is ready. This fixes issues with custom allocators that call
std:🧵:current(), since doing so prematurely initializes
THREAD_INFO and causes the following thread_info::set() to fail.
2022-12-07 13:12:29 -08:00
Michael Benfield
27011b4185 Use more LFS functions.
On Linux, use mmap64, open64, openat64, and sendfile64 in place of their
non-LFS counterparts.

This is relevant to #94173.

With these changes (together with rust-lang/backtrace-rs#501), the
simple binaries I produce with rustc seem to have no non-LFS functions,
so maybe #94173 is fixed. But I can't be sure if I've missed something
and maybe some non-LFS functions could sneak in somehow.
2022-12-07 19:58:04 +00:00
Eduardo Sánchez Muñoz
00e7b54d46 Make some trivial functions #[inline(always)] 2022-12-07 17:11:17 +01:00
bors
01fbc5ae78 Auto merge of #103459 - ChrisDenton:propagate-nulls, r=thomcc
Pass on null handle values to child process

Fixes #101645

In Windows, stdio handles are (semantically speaking) `Option<Handle>` where `Handle` is a non-zero value. When spawning a process with `Stdio::Inherit`, Rust currently turns zero values into `-1` values. This has the unfortunate effect of breaking console subprocesses (which typically need stdio) that are spawned from gui applications (that lack stdio by default) because the console process won't be assigned handles from the newly created console (as they usually would in that situation). Worse, `-1` is actually [a valid handle](https://doc.rust-lang.org/std/os/windows/io/struct.OwnedHandle.html) which means "the current process". So if a console process, for example, waits on stdin and it has a `-1` value then the process will end up waiting on itself.

This PR fixes it by propagating the nulls instead of converting them to `-1`.

While I think the current behaviour is a mistake, changing it (however justified) is an API change so I think this PR should at least have some input from t-libs-api. So choosing at random...

r? `@joshtriplett`
2022-12-07 13:52:52 +00:00
bors
91b8f34ac2 Auto merge of #104799 - pcc:linkage-fn, r=tmiasko
Support Option and similar enums as type of static variable with linkage attribute

Compiler MCP:
rust-lang/compiler-team#565
2022-12-07 10:24:59 +00:00
bors
023b5136b5 Auto merge of #105271 - eduardosm:inline-always-int-conv, r=scottmcm
Make integer-to-integer `From` impls `#[inline(always)]`

Splited from https://github.com/rust-lang/rust/pull/105262
2022-12-06 21:41:04 +00:00
Chris Denton
93b774a2a4
Don't set STARTF_USESTDHANDLES if none are set 2022-12-06 17:26:21 +00:00
Matthias Krüger
967085ecdf
Rollup merge of #105250 - Swatinem:async-rm-resumety, r=oli-obk
Replace usage of `ResumeTy` in async lowering with `Context`

Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces the raw pointer in `ResumeTy` and the `get_context` fn that pulls the correct lifetimes out of thin air.

fixes https://github.com/rust-lang/rust/issues/104828 and https://github.com/rust-lang/rust/pull/104321#issuecomment-1336363077

r? `@oli-obk`
2022-12-06 16:54:54 +01:00
Matthias Krüger
7d8e329194
Rollup merge of #105243 - RalfJung:no-op-let, r=Mark-Simulacrum
remove no-op 'let _ = '

Also see the discussion at https://github.com/rust-lang/rust/pull/93563#discussion_r1034057555.

I don't know why these `Drop` implementations exist to begin with, given that their body does literally nothing, but did not want to change that. (It might affect dropck.)

Cc `````@ibraheemdev````` `````@Amanieu`````
2022-12-06 13:27:42 +01:00
Arthur Carcano
4198d2975d Implement masking in FileType hashing on Unix
Commit 77005950f0 implemented masking of
FileType to fix an issue[^1] in the semantic of FileType comparison.
This commit introduces masking to Hash to maintain the invariant that
x == y => hash(x) == hash(y).

[^1]: https://github.com/rust-lang/rust/issues/104900
2022-12-06 10:35:34 +01:00
Arpad Borsos
cf031a3355
Replace usage of ResumeTy in async lowering with Context
Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces
the raw pointer in `ResumeTy` and the `get_context` fn that pulls the
correct lifetimes out of thin air.
2022-12-06 10:16:23 +01:00
Florian Bartels
980065ab23 Make sentinel value configurable
There are OSs that always return the lowest free value.
The algorithm in `lazy_init` always avoids keys with the
sentinel value.
In affected OSs, this means that each call to `lazy_init`
will always request two keys from the OS and returns/frees
the first one (with sentinel value) immediately afterwards.

By making the sentinel value configurable, affected OSs can
use a different value than zero to prevent this performance
issue.
2022-12-06 09:38:09 +01:00
Yuki Okushi
fa7d3ec630
Rollup merge of #105289 - Rageking8:fix-dupe-word-typos, r=cjgillot
Fix dupe word typos
2022-12-06 12:48:52 +09:00
Peter Collingbourne
b4278b02a7 Reimplement weak! using Option. 2022-12-05 15:05:43 -08:00
Matthias Krüger
e84e8f4165
Rollup merge of #105222 - devnexen:fbsd_update_img, r=petrochenkov
std update libc version and freebsd image build dependencies
2022-12-05 20:43:43 +01:00
Matthias Krüger
8ad447c479
Rollup merge of #104912 - RalfJung:per, r=Mark-Simulacrum
PartialEq: PERs are homogeneous

PartialEq claims that it corresponds to a PER, but that is only a well-defined statement when `Rhs == Self`. There is no standard notion of PER on a relation between two different sets/types. So move this out of the first paragraph and clarify this.
2022-12-05 20:43:40 +01:00
Markus Everling
ac583f18b7 Add O(1) Vec -> VecDeque conversion guarantee 2022-12-05 14:57:22 +01:00
Ralf Jung
ee21454e61 attempt to clarify align_to docs 2022-12-05 11:37:55 +01:00
bors
203c8765ea Auto merge of #105046 - scottmcm:vecdeque-vs-vec, r=Mark-Simulacrum
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-12-05 08:45:03 +00:00
Rageking8
58110572fb fix dupe word typos 2022-12-05 16:42:36 +08:00
Eduardo Sánchez Muñoz
2e51122647 Make integer-to-integer From impls #[inline(always)] 2022-12-04 22:55:18 +01:00
Ralf Jung
c823dfa8b2 remove no-op 'let _ = ' 2022-12-04 10:32:00 +01:00
bors
9e772114e6 Auto merge of #101514 - nvzqz:nvzqz/stabilize-nonzero-bits, r=thomcc
Stabilize `nonzero_bits`

Closes #94881, implemented by #93292.

This change stabilizes the associated `BITS` constant for `NonZero{U,I}{8,16,32,64,128,size}` integers, e.g.:

```rs
impl NonZeroUsize {
    pub const BITS: u32 = usize::BITS;
}
```
2022-12-04 08:28:22 +00:00
David CARLIER
71cf892235 std update libc version and freebsd image build dependencies 2022-12-03 19:01:55 +00:00
Matthias Krüger
6f0a2adf6e
Rollup merge of #105153 - oli-obk:fail_faster, r=compiler-errors
Create a hacky fail-fast mode that stops tests at the first failure

This is useful for not having to wait until all 10k+ ui tests have finished running and then having to crawl through hundreds of failure reports.

You now only get the first report when you turn on that env var and no new tests are run at all

This works like a charm, but is obviously welded on very crudely
2022-12-03 17:37:42 +01:00
Yuki Okushi
019795b162
Rollup merge of #105100 - jhpratt:fix-docs, r=JohnTitor
Add missing intra-doc link

Trivial change. This makes the plain text into inline code and makes it a link.

`@rustbot` label +A-docs
2022-12-03 12:51:28 +09:00
Yuki Okushi
9f3ccd4bf6
Rollup merge of #105032 - HintringerFabian:improve_docs, r=JohnTitor
improve doc of into_boxed_slice and impl From<Vec<T>> for Box<[T]>

Improves description of `into_boxed_slice`, and adds example to `impl From<Vec<T>> for Box<[T]>`.
Fixes #98908
2022-12-03 12:51:27 +09:00
bors
32e613bbaa Auto merge of #104999 - saethlin:immediate-abort-inlining, r=thomcc
Adjust inlining attributes around panic_immediate_abort

The goal of `panic_immediate_abort` is to permit the panic runtime and formatting code paths to be optimized away. But while poking through some disassembly of a small program compiled with that option, I found that was not the case. Enabling LTO did address that specific issue, but enabling LTO is a steep price to pay for this feature doing its job.

This PR fixes that, by tweaking two things:
* All the slice indexing functions that we `const_eval_select` on get `#[inline]`. `objdump -dC` told me that originally some `_ct` functions could end up in an executable. I won't pretend to understand what's going on there.
* Normalize attributes across all `panic!` wrappers: use `inline(never) + cold` normally, and `inline` when `panic_immediate_abort` is enabled.

But also, with LTO and `panic_immediate_abort` enabled, this patch knocks ~709 kB out of the `.text` segment of `librustc_driver.so`. That is slightly surprising to me, my best theory is that this shifts some inlining earlier in compilation, enabling some subsequent optimizations. The size improvement of `librustc_driver.so` with `panic_immediate_abort` due to this patch is greater with LTO than without LTO, which I suppose backs up this theory.

I do not know how to test this. I would quite like to, because I think what this is solving was an accidental regression. This only works with `-Zbuild-std` which is a cargo flag, and thus can't be used in a rustc codegen test.

r? `@thomcc`

---

I do not seriously think anyone is going to use a compiler built with `panic_immediate_abort`, but I wanted a big complicated Rust program to try this out on, and the compiler is such.
2022-12-02 20:07:23 +00:00
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
2fba07842b Make VecDeque::new const 2022-12-01 12:41:31 +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
76438d26b1 Add example for iterator_flatten 2022-11-28 23:01:15 +01: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
Andres Suarez
2c541786cf Implement DerefMut for PathBuf 2022-11-28 11:55:49 -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
Ralf Jung
9ae26c86c2 add ptr::from_{ref,mut} 2022-11-27 13:05:59 +01:00
Zachary Mayhew
123e2038d4
add link for string to as_ref docs 2022-11-26 17:30:17 -08: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
Zachary Mayhew
74e7709485
reword Option::as_ref and Option::map examples 2022-11-26 15:41:48 -08: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
Jonas Spinner
70bba3b62a rustdoc: Fix backoff doc to match implementation 2022-11-22 11:06:57 +01: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
Lukas Bergdoll
4b5844fbe9 Document all unsafe blocks
There were several unsafe blocks in the existing implementation that
were not documented with a SAFETY comment.
2022-11-21 14:30:56 +01:00
Lukas Bergdoll
1ec59cdcd1 Remove debug unused 2022-11-21 14:20:31 +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
Lukas Bergdoll
dbc0ed2a10 Unify stable and unstable sort implementations in same core module
This moves the stable sort implementation to the core::slice::sort module. By
virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort,
`buf` and `runs`, are modelled as custom types that implement the very limited
required `Vec` interface with the help of provided allocation and free
functions. This is done to allow future re-use of functions and logic between
stable and unstable sort. Such as `insert_head`.
2022-11-20 20:35:40 +01: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
Matthias Krüger
db5f005f35
Rollup merge of #104568 - RalfJung:realloc, r=Amanieu
clarify that realloc refreshes pointer provenance even when the allocation remains in-place

This [matches what C does](https://en.cppreference.com/w/c/memory/realloc):

> The original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place).

Cc `@rust-lang/wg-allocators`
2022-11-20 18:21:48 +01:00
Matthias Krüger
379d3365fd
Rollup merge of #104558 - thomcc:unalign-diriter, r=ChrisDenton
Don't assume `FILE_ID_BOTH_DIR_INFO` will be aligned

Fixes #104530. See that issue for info.

r? `@ChrisDenton`
2022-11-20 18:21:47 +01:00
Matthias Krüger
ddb12348ca
Rollup merge of #104537 - HintringerFabian:docs_default_min_stack_size, r=the8472
fix std::thread docs are unclear regarding stack sizes

Improves the documentation about the default stack size of a spawned thread
Fixes #102671
2022-11-20 18:21:47 +01:00
Felix S. Klock II
98993af828 add examples to chunks remainder methods. Also fixed some links to rchunk remainder methods. 2022-11-20 11:43:23 -05:00
Marvin Löbel
3fe37b8c6e Add get_many_mut methods to slice 2022-11-20 11:19:11 -05:00
Tshepang Mbambo
bebe5db517 replace unusual grammar 2022-11-20 17:28:34 +02:00
Ralf Jung
428ab59fb7 enable fuzzy_provenance_casts in libcore+tests 2022-11-20 16:04:16 +01:00
Markus Everling
a1bf25e2bd Update VecDeque implementation 2022-11-20 15:21:16 +01:00
bors
911cbf8e46 Auto merge of #104617 - RalfJung:miri, r=RalfJung
update Miri

r? `@thomcc` for the lib changes (removing a `cfg(miri)` that is no longer needed)
2022-11-20 12:57:48 +00:00