Commit Graph

15226 Commits

Author SHA1 Message Date
Mara Bos
1dc7952303 Fix deprecation version. 2024-06-12 13:15:17 +02:00
Mara Bos
cae18fa7b0 Clarify doc comment. 2024-06-12 13:15:10 +02:00
bors
bbe9a9c20b Auto merge of #126319 - workingjubilee:rollup-lendnud, r=workingjubilee
Rollup of 16 pull requests

Successful merges:

 - #123374 (DOC: Add FFI example for slice::from_raw_parts())
 - #124514 (Recommend to never display zero disambiguators when demangling v0 symbols)
 - #125978 (Cleanup: HIR ty lowering: Consolidate the places that do assoc item probing & access checking)
 - #125980 (Nvptx remove direct passmode)
 - #126187 (For E0277 suggest adding `Result` return type for function when using QuestionMark `?` in the body.)
 - #126210 (docs(core): make more const_ptr doctests assert instead of printing)
 - #126249 (Simplify `[T; N]::try_map` signature)
 - #126256 (Add {{target}} substitution to compiletest)
 - #126263 (Make issue-122805.rs big endian compatible)
 - #126281 (set_env: State the conclusion upfront)
 - #126286 (Make `storage-live.rs` robust against rustc internal changes.)
 - #126287 (Update a cranelift patch file for formatting changes.)
 - #126301 (Use `tidy` to sort crate attributes for all compiler crates.)
 - #126305 (Make PathBuf less Ok with adding UTF-16 then `into_string`)
 - #126310 (Migrate run make prefer rlib)
 - #126314 (fix RELEASES: we do not support upcasting to auto traits)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-12 11:10:50 +00:00
Jubilee
3862f01655
Rollup merge of #126305 - workingjubilee:fix-os-string-to-string-utf8-invariant, r=joboet
Make PathBuf less Ok with adding UTF-16 then `into_string`

Fixes #126291 which is, as far as I can tell, a regression introduced by #96869.

try-job: x86_64-msvc
2024-06-12 03:57:25 -07:00
Jubilee
ac73965719
Rollup merge of #126287 - nnethercote:reformat-cranelift-patch, r=bjorn3
Update a cranelift patch file for formatting changes.

PR #125443 will reformat all the use declarations in the repo. This would break a patch kept in `rustc_codegen_cranelift` that gets applied to `library/std/src/sys/pal/windows/rand.rs`.

So this commit formats the use declarations in `library/std/src/sys/pal/windows/rand.rs` in advance of #125443 and updates the patch file accordingly.

The motivation is that #125443 is a huge change and we want to get fiddly little changes like this out of the way so it can be nothing more than an `x fmt --all`.

r? ``@bjorn3``
2024-06-12 03:57:24 -07:00
Jubilee
0805ab47c9
Rollup merge of #126281 - ChrisDenton:env, r=jhpratt
set_env: State the conclusion upfront

People tend to skim or skip over long explanations so we should be very upfront that `set_var` and `remove_var` are being made unsafe for a very good reason.

This is just the conclusion restated almost verbatim but earlier in the docs and separated from the explanation:

0c960618b5/library/std/src/env.rs (L338-L339)

I think this may help with people who may not be entirely comfortable with #125937 being rejected.
2024-06-12 03:57:23 -07:00
Jubilee
4de77b6d8a
Rollup merge of #126249 - workingjubilee:simplify-try-map-signature, r=scottmcm
Simplify `[T; N]::try_map` signature

People keep making fun of this signature for being so gnarly.
Associated type bounds admit a much simpler scribbling.

r? ````@scottmcm````
2024-06-12 03:57:21 -07:00
Jubilee
3a37293e92
Rollup merge of #126210 - lolbinarycat:ptr_doctest_assert, r=workingjubilee
docs(core): make more const_ptr doctests assert instead of printing

improves on #124669
2024-06-12 03:57:21 -07:00
Jubilee
8d3b9a19cf
Rollup merge of #123374 - mgeier:doc-slice-from-raw-parts, r=scottmcm
DOC: Add FFI example for slice::from_raw_parts()

For some discussion, see https://users.rust-lang.org/t/missing-guidance-on-converting-ffi-ptr-length-to-slice/106048

See also #120608.
2024-06-12 03:57:18 -07:00
Oli Scherer
0bc2001879 Require any function with a tait in its signature to actually constrain a hidden type 2024-06-12 08:53:59 +00:00
Oli Scherer
39e7bf6826 Revert "Rollup merge of #125362 - joboet:tait_hack, r=Nilstrieb"
This reverts commit 1e4bde1cb9, reversing
changes made to 4ee97fc3db.
2024-06-12 08:47:49 +00:00
Jubilee Young
af04418a05 Make PathBuf less Ok with adding UTF-16 then into_string 2024-06-12 01:00:21 -07:00
Nicholas Nethercote
7e7da49f2a Update a cranelift patch file for formatting changes.
PR #125443 will reformat all the use declarations in the repo. This
would break a patch kept in `rustc_codegen_cranelift` that gets applied
to `library/std/src/sys/pal/windows/rand.rs`.

So this commit formats the use declarations in
`library/std/src/sys/pal/windows/rand.rs` in advance of #125443 and
updates the patch file accordingly.

The motivation is that #125443 is a huge change and we want to get
fiddly little changes like this out of the way so it can be nothing more
than an `x fmt --all`.
2024-06-12 08:52:40 +10:00
Kevin Reid
27ecb71635 UniqueRc: support allocators and T: ?Sized.
Added the following (all unstable):

* Defaulted type pararameter `A: Allocator`.
* `UniqueRc::new_in()`.
* `T:  ?Sized` where possible.
* `impl CoerceUnsized for UniqueRc`.
* Drive-by doc polish: links and periods at the end of sentences.

These changes are motivated by supporting the implementation of unsized
`Rc::make_mut()` (PR #116113), but are also intended to be obvious
generalizations of `UniqueRc` to support the things `Rc` does.
2024-06-11 15:16:47 -07:00
Chris Denton
751143ef40
set_env: State the conclusion upfront 2024-06-11 17:12:20 +00:00
Eduardo Sánchez Muñoz
6a04dfe78c Rename std::fs::try_exists to std::fs::exists and stabilize fs_try_exists 2024-06-11 18:33:40 +02:00
Tobias Bucher
bb8eb44511 Unify guarantees about the default allocator
`std::alloc` said that the default allocator is unspecified for all
crrate types except `cdylib` and `staticlib`. Adjust
`std::alloc::System` documentation to say the same.

Fixes #125870.
2024-06-11 17:13:26 +02:00
Pietro Albini
cd2ed56502
remove cfg(bootstrap) 2024-06-11 16:52:04 +02:00
Pietro Albini
be9e27e490
replace version placeholder 2024-06-11 16:52:02 +02:00
Mara Bos
a6e23b126b Formatting. 2024-06-11 15:47:00 +02:00
Mara Bos
a345c3daf6 Bump deprecation of std's PanicInfo alias to 1.82.0. 2024-06-11 15:47:00 +02:00
Mara Bos
de07c1a928 Add PanicHookInfo::payload_as_str(). 2024-06-11 15:47:00 +02:00
Mara Bos
fb0990d1e1 Fix display of panic message in recursive panic. 2024-06-11 15:47:00 +02:00
Mara Bos
877a26f6c9 Mention core's PanicInfo in error.md. 2024-06-11 15:47:00 +02:00
Mara Bos
32bfe703e2 Add note on panic payload type. 2024-06-11 15:47:00 +02:00
Mara Bos
ce0bc8bd58 Downcast panic payload to String too in example. 2024-06-11 15:47:00 +02:00
Mara Bos
f5fe82fdca Move deprecation of std::panic::PanicInfo to 1.80.0. 2024-06-11 15:47:00 +02:00
Mara Bos
3854357ad2 Fix deprecation version. 2024-06-11 15:47:00 +02:00
Mara Bos
64e56db72a Rename std::panic::PanicInfo to PanicHookInfo. 2024-06-11 15:47:00 +02:00
Mara Bos
b6180a9185 Formatting. 2024-06-11 15:47:00 +02:00
Mara Bos
6b2d7c4707 Fix invalid markdown/html. 2024-06-11 15:47:00 +02:00
Mara Bos
bab26b02c7 Reorder body of begin_panic for consistency.
In the other functions, we put the struct and impl blocks first,
such that the return expression can be at the end of the body as usual.
2024-06-11 15:46:59 +02:00
Mara Bos
1642de33d3 Impl Display for PanicPayload to simplify things. 2024-06-11 15:46:59 +02:00
Mara Bos
22f7399b32 Use unnamed lifetimes for [..]Payload impl blocks. 2024-06-11 15:46:59 +02:00
Mara Bos
4e356f3184 Move downcasting panic payload to str to a function. 2024-06-11 15:46:59 +02:00
Mara Bos
0087d89983 Mark some PanicInfo methods as #[inline] for consistency. 2024-06-11 15:46:59 +02:00
Mara Bos
0642cb2994 Remove std::panic::PanicInfo::internal_constructor+set_payload.
We can just set the payload immediately in the constructor,
and the constructor does not need to be public.
2024-06-11 15:46:59 +02:00
Mara Bos
0266bbf6e4 Remove core::panic::PanicInfo::internal_constructor.
It no longer needs to be public.
2024-06-11 15:46:59 +02:00
Mara Bos
83dd214f06 Update doc comment about core::panicking. 2024-06-11 15:46:59 +02:00
Mara Bos
331b8a3edd Fix doc link. 2024-06-11 15:46:59 +02:00
Mara Bos
16dfc6ddc1 Add core::panic::PanicInfo::payload() for compatibility. 2024-06-11 15:46:59 +02:00
Mara Bos
a519dc85f8 Document difference between core and std's PanicInfo. 2024-06-11 15:46:59 +02:00
Mara Bos
e3e815370e Split core's PanicInfo and std's PanicInfo. 2024-06-11 15:46:59 +02:00
Jubilee Young
d6955445f5 Simplify [T; N]::try_map signature
People keep making fun of this signature for being so gnarly.
Associated type bounds lend it a much simpler scribbling.
ChangeOutputType can also come along for the ride.
2024-06-11 01:50:43 -07:00
Jane Losare-Lusby
6e3134972e Simplify provider api to improve llvm ir 2024-06-10 13:20:22 -07:00
Matthias Krüger
b59507874e
Rollup merge of #126212 - SteveLauC:fix/haiku, r=joboet
fix: build on haiku

## What does this PR do

The std is broken on haiku, this PR fixes it.

## To reproduce the issue

```sh
$ cargo +nightly --version
cargo 1.81.0-nightly (b1feb75d0 2024-06-07)

$ cargo new hello
$ cd hello
$ cargo +nightly check -Zbuild-std --target x86_64-unknown-haiku -q
error[E0433]: failed to resolve: use of undeclared crate or module `std`
   --> ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/pal/unix/os.rs:468:13
    |
468 |             std::ptr::null_mut(),
    |             ^^^ use of undeclared crate or module `std`
    |
help: consider importing one of these items
    |
8   + use core::ptr;
    |
8   + use crate::ptr;
    |
help: if you import `ptr`, refer to it directly
    |
468 -             std::ptr::null_mut(),
468 +             ptr::null_mut(),
    |

error[E0433]: failed to resolve: use of undeclared crate or module `std`
   --> ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/pal/unix/os.rs:470:13
    |
470 |             std::ptr::null_mut(),
    |             ^^^ use of undeclared crate or module `std`
    |
help: consider importing one of these items
    |
8   + use core::ptr;
```
2024-06-10 21:12:27 +02:00
Matthias Krüger
146f4b316e
Rollup merge of #126191 - ivan-shrimp:nonzero_doc, r=scottmcm
Fix `NonZero` doctest inconsistencies

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
`NonZero`'s doctests contain both `?` and `.unwrap()` with no obvious reason for the difference, so this changes all of them to `?`. Also removes an explicit `std::num::NonZero`.
2024-06-10 21:12:26 +02:00
Chris Denton
8bd8f599eb
Bump windows-bindgen to 0.57 2024-06-10 13:51:29 +00:00
许杰友 Jieyou Xu (Joe)
bd6fca2015 Clarify Command::new behavior if passed programs with arguments 2024-06-10 12:25:05 +00:00
Nicholas Nethercote
29629d0075 Remove some unused crate dependencies.
I found these by setting the `unused_crate_dependencies` lint
temporarily to `Warn`.
2024-06-10 19:55:49 +10:00
Steve Lau
63ec8dd24f fix: build on haiku 2024-06-10 10:38:00 +08:00
binarycat
fe52b5439e docs(core): make more const_ptr doctests assert instead of printing
fixes #124669
2024-06-09 20:22:46 -04:00
bors
a70b2ae577 Auto merge of #126205 - jieyouxu:rollup-s64z5ng, r=jieyouxu
Rollup of 4 pull requests

Successful merges:

 - #126172 (Weekly `cargo update`)
 - #126176 (rustdoc-search: use lowercase, non-normalized name for type search)
 - #126190 (Autolabel run-make tests, remind to update tracking issue)
 - #126194 (Migrate more things to `WinError`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-09 21:03:04 +00:00
许杰友 Jieyou Xu (Joe)
61671a7e34
Rollup merge of #125253 - sunsided:feature/FRAC_1_SQRT_PI, r=Mark-Simulacrum
Add `FRAC_1_SQRT_2PI` constant to f16/f32/f64/f128

This adds the `FRAC_1_SQRT_2PI` to the `f16`, `f32`, `f64` and `f128` as [`1/√(2π)`](https://www.wolframalpha.com/input?i=1%2Fsqrt%282*pi%29). The rationale is that while `FRAC_1_SQRT_PI` already exists, [Gaussian calculations](https://en.wikipedia.org/wiki/Gaussian_function) for random normal distributions require a `1/(σ√(2π))` term, which could then be directly expressed e.g. as `f32::FRAC_1_SQRT_2PI / sigma`.

The actual value is approximately `1/√(2π) = 0.3989422804014326779399460599343818684758586311649346576659258296…`. Truncated/rounded forms were used for the individual types.

---

~~I did not any of the `#[unstable]` attributes since I am not aware of their implications.~~

**Edit:** I applied the stability attributes from the surrounding types according to what seemed most likely correct. I believe the `more_float_constants` feature marker is incorrectly applied, but I wasn't sure how to proceed.
2024-06-09 19:16:19 +01:00
Chris Denton
3606818010
Migrate more things to WinError 2024-06-09 14:29:28 +00:00
ivan-shrimp
041e204e0d fix NonZero doctest inconsistencies 2024-06-09 19:45:12 +08:00
Matthias Krüger
cfd44ec7e4
Rollup merge of #126168 - devnexen:current_exe_haiku_simpl, r=ChrisDenton
std::unix::os current_exe implementation simplification for haiku.

_get_net_image_info is a bit overkill as it allows to get broader informations about the process.
2024-06-09 10:17:09 +02:00
Matthias Krüger
d24d937a55
Rollup merge of #126146 - devnexen:signal_fbsd, r=ChrisDenton
std::unix::process adding few specific freebsd signals to be able to id.
2024-06-09 10:17:08 +02:00
David Carlier
75607b7a5a
std::unix::os current_exe implementation simplification for haiku.
_get_net_image_info is a bit overkill as it allows to get broader
informations about the process.
2024-06-08 17:37:48 +01:00
bors
e484b3efa5 Auto merge of #125966 - schvv31n:impl_os_string_pathbuf_leak, r=workingjubilee
Implement `os_string_pathbuf_leak`

implementation of #125965

ACP: https://github.com/rust-lang/libs-team/issues/389 [ Accepted ]
2024-06-08 13:17:06 +00:00
David Carlier
cf3966dd9c std::unix::process adding few specific freebsd signals to be able to id. 2024-06-08 08:31:35 +01:00
León Orell Valerian Liehr
733a6f1a1c
Rollup merge of #126138 - wbk:patch-1, r=lqd
Fix typo in docs for std::pin
2024-06-08 04:25:46 +02:00
León Orell Valerian Liehr
ba31a0a920
Rollup merge of #125998 - devnexen:get_mode_illumos, r=Nilstrieb
std::unix::fs::get_mode implementation for illumos/solaris.

they both support the F_GETFL fctnl flag/O_ACCMODE mask to get the file descriptor access modes.
2024-06-08 04:25:44 +02:00
León Orell Valerian Liehr
cbda797b77
Rollup merge of #125951 - slanterns:error_in_core_stabilization, r=Amanieu
Stabilize `error_in_core`

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

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

r? libs-api
2024-06-08 04:25:44 +02:00
Walter Kalata
f82f0530f3
Fix typo in docs for std::pin 2024-06-07 12:18:43 -07:00
Stefan Lankes
1f125a6716 add HermitOS support of vectored read/write operations
In general, the I/O interface of hermit-abi is more POSIX-like
interface. Consequently, platform abstraction layer for HermitOS
has slightly adjusted and some inaccuracies remove.
2024-06-07 20:48:30 +02:00
Matthias Krüger
ccbd6c29b4
Rollup merge of #126089 - wutchzone:option_take_if, r=scottmcm
Stabilize Option::take_if

Closes #98934

ed: FCP complete in https://github.com/rust-lang/rust/issues/98934#issuecomment-2104627082
2024-06-07 20:14:31 +02:00
Matthias Krüger
3689adf5a4
Rollup merge of #126030 - ChrisDenton:update-wingen-readme, r=Mark-Simulacrum
Update `./x fmt` command in library/std/src/sys/pal/windows/c/README.md

`./x fmt` no longer accepts paths so the command in the readme won't work.
2024-06-07 20:14:29 +02:00
Matthias Krüger
0acb5b8513
Rollup merge of #124012 - slanterns:as_slice_stabilize, r=BurntSushi
Stabilize `binary_heap_as_slice`

This PR stabilizes `binary_heap_as_slice`:

```rust
// std::collections::BinaryHeap

impl BinaryHeap<T> {
    pub fn as_slice(&self) -> &[T]
}
```

<br>

Tracking issue: https://github.com/rust-lang/rust/issues/83659.
Implementation PR: https://github.com/rust-lang/rust/pull/82331.

FCPs already completed in the tracking issue.

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

r? libs-api
2024-06-07 20:14:27 +02:00
bors
e3c3ce62d7 Auto merge of #126110 - workingjubilee:backtrace-0.3.73, r=workingjubilee
Update backtrace to 0.3.73

Fixes #126109

r? `@ghost`
2024-06-07 14:44:46 +00:00
Jubilee Young
49c2a1dda9 Update backtrace to 0.3.73 2024-06-06 22:50:45 -07:00
Jubilee
c6cdd457eb
Rollup merge of #125606 - diondokter:opt-size-int-fmt, r=cuviper
Size optimize int formatting

Let's use the new feature flag!

This uses a simpler algorithm to format integers.
It is slower, but also smaller.
It also saves having to import the 200 byte rodata lookup table.

In a test of mine this saves ~300 bytes total of a cortex-m binary that does integer formatting.
For a 16KB device, that's almost 2%.

Note though that for opt-level 3 the text size actually grows by 116 bytes.
Still a win in total. I'm not sure why the generated code is bigger than the more fancy algo. Maybe the smaller algo lends itself more to inlining and duplicating?
2024-06-06 21:10:08 -07:00
Slanterns
c6f1934d34
fix doc comments about error_generic_member_access 2024-06-07 08:30:08 +08:00
Slanterns
76065f5b27
Stabilize error_in_core 2024-06-07 08:30:00 +08:00
schvv31n
2bdc53b153 fixed memory leaks in PathBuf::leak & OsString::leak tests 2024-06-06 23:18:01 +01:00
Jubilee
efd8959ab1
Rollup merge of #126096 - c410-f3r:tests-tests-tests, r=jhpratt
[RFC-2011] Allow `core_intrinsics` when activated

Fix #120612
2024-06-06 14:46:25 -07:00
Caio
a8084dcec1 [RFC-2011] Allow core_intrinsics when activated 2024-06-06 16:30:05 -03:00
Daniel Sedlak
26dc8bd5b0 Stabilize Option::take_if 2024-06-06 20:01:59 +02:00
Jubilee Young
878107436a Raise DEFAULT_MIN_STACK_SIZE to at least 64KiB
Prevent copy-paste errors from producing new starved-for-resources
threaded platforms by raising `DEFAULT_MIN_STACK_SIZE` from 4096 bytes
to at least 64KiB.

Two platforms "affected" by this have no actual threads:
- UEFI
- "unsupported"

Platforms that this actually affects:
- wasm32-wasi with "atomics" enabled
- wasm32-wasi-p1-threads

Two exceptions:
- SGX: a "secure code execution" platform, stays at 4096B
- TEEOS: also a "secure code execution" platform, stays at 8192B

I believe either of these may have sufficiently "interesting" semantics
around threads, or significant external library support. Either would
mean making any choices here for them is suspect.
2024-06-05 23:22:37 -07:00
bors
72fdf913c5 Auto merge of #126038 - matthiaskrgr:rollup-h4rm3x2, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #124840 (resolve: mark it undetermined if single import is not has any bindings)
 - #125622 (Winnow private method candidates instead of assuming any candidate of the right name will apply)
 - #125648 (Remove unused(?) `~/rustsrc` folder from docker script)
 - #125672 (Add more ABI test cases to miri (RFC 3391))
 - #125800 (Fix `mut` static task queue in SGX target)
 - #125871 (Orphanck[old solver]: Consider opaque types to never cover type parameters)
 - #125893 (Handle all GVN binops in a single place.)
 - #126008 (Port `tests/run-make-fulldeps/issue-19371` to ui-fulldeps)
 - #126032 (Update description of the `IsTerminal` example)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-05 20:53:32 +00:00
Daniel Paoliello
537f531b4e Promote arm64ec-pc-windows-msvc to tier 2 2024-06-05 11:37:21 -07:00
Matthias Krüger
fa58891f99
Rollup merge of #126032 - ChrisDenton:update-docs, r=joboet
Update description of the `IsTerminal` example

The example code prompts for input if stdin is a terminal.
2024-06-05 18:21:15 +02:00
Matthias Krüger
fcc0b641e9
Rollup merge of #125800 - fortanix:raoul/rte-99-fix_mut_static_task_queue, r=jethrogb
Fix `mut` static task queue in SGX target

[PR 125046](https://github.com/rust-lang/rust/pull/125046) prevents mutable references to statics with `#[linkage]`. Such a construct was used with the tests for the `x86_64-fortanix-unknown-sgx` target. This PR fixes this and cleans up code a bit in 5 steps. Each step passes CI:

- The `mut` static is removed, and `Task` explicitly implements `Send`
- Renaming of the `task_queue::lock` function
- Pass function for `Thread` as `Send` to `Thread::imp` and update when `Packet<'scope, T>` implements `Sync`
- Storing `Task::p` as a type that implements `Send`
- Letting the compiler auto implement `Send` for `Task`

cc: ``@jethrogb``
2024-06-05 18:21:13 +02:00
Matthias Krüger
808ad606f1
Rollup merge of #125940 - devnexen:unix_fs_netbsd_get_path, r=cuviper
std::unix::fs::get_path: using fcntl codepath for netbsd instead.

on netbsd, procfs is not as central as on linux/solaris thus can be perfectly not mounted.
Thus using fcntl with F_GETPATH, the kernel deals with MAXPATHLEN internally too.
2024-06-05 18:21:12 +02:00
Chris Denton
e704858b0b
Update description of the IsTerminal example 2024-06-05 14:28:42 +00:00
Chris Denton
a272f8ed44
Update ./x fmt command 2024-06-05 13:53:46 +00:00
Jubilee
6b6b698988
Rollup merge of #125995 - kpreid:const-uninit-stable, r=Nilstrieb
Use inline const blocks to create arrays of `MaybeUninit`.

This PR contains 2 changes enabled by the fact that [`inline_const` is now stable](https://github.com/rust-lang/rust/pull/104087), and was split out of #125082.

1. Use inline const instead of `unsafe` to construct arrays in `MaybeUninit` examples.

   Rationale: Demonstrate good practice of avoiding `unsafe` code where it is not strictly necessary.

4. Use inline const instead of `unsafe` to implement `MaybeUninit::uninit_array()`.

    This is arguably giving the compiler more work to do, in exchange for eliminating just one single internal unsafe block, so it's less certain that this is good on net.

r​? `@Nilstrieb`
2024-06-05 01:14:33 -07:00
Jubilee
448159c8e6
Rollup merge of #125982 - xTachyon:fix-linked-list, r=jhpratt
Make deleting on LinkedList aware of the allocator

Fixed #125950
2024-06-05 01:14:33 -07:00
Jubilee
9ccc7b78ec
Rollup merge of #123168 - joshtriplett:size-of-prelude, r=Amanieu
Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude

(Note: need to update the PR to add `align_of` and `align_of_val`, and remove the second commit with the myriad changes to appease the lint.)

Many, many projects use `size_of` to get the size of a type. However,
it's also often equally easy to hardcode a size (e.g. `8` instead of
`size_of::<u64>()`). Minimizing friction in the use of `size_of` helps
ensure that people use it and make code more self-documenting.

The name `size_of` is unambiguous: the name alone, without any prefix or
path, is self-explanatory and unmistakeable for any other functionality.
Adding it to the prelude cannot produce any name conflicts, as any local
definition will silently shadow the one from the prelude. Thus, we don't
need to wait for a new edition prelude to add it.
2024-06-05 01:14:29 -07:00
David Carlier
c6073174ab std::unix::fs::get_mode implementation for illumos/solaris.
they both support the F_GETFL fctnl flag/O_ACCMODE mask to get the file
descriptor access modes.
2024-06-04 23:33:35 +00:00
Kevin Reid
ec8fa17719 Use inline const instead of unsafe to implement MaybeUninit::uninit_array(). 2024-06-04 14:40:22 -07:00
Kevin Reid
ac96fa44fa Use inline const instead of unsafe to construct arrays in MaybeUninit examples. 2024-06-04 14:40:21 -07:00
Guillaume Gomez
b6b1a46631
Rollup merge of #125932 - schvv31n:patch-1, r=lqd
Fix typo in the docs of `HashMap::raw_entry_mut`

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
2024-06-04 21:41:36 +02:00
Guillaume Gomez
d9e149d9d8
Rollup merge of #125927 - ferrocene:lw-alloc-unwind-test, r=pietroalbini
Ignore `vec_deque_alloc_error::test_shrink_to_unwind` test on non-unwind targets

https://github.com/rust-lang/rust/pull/123803 added this test which requires unwinding to succeed. This conditionally ignores the test on non-unwind targets (as is the case with other tests using `catch_unwind`).
2024-06-04 21:41:35 +02:00
Guillaume Gomez
ee04e0f35e
Rollup merge of #125696 - workingjubilee:please-dont-say-you-are-lazy, r=Nilstrieb
Explain differences between `{Once,Lazy}{Cell,Lock}` types

The question of "which once-ish cell-ish type should I use?" has been raised multiple times, and is especially important now that we have stabilized the `LazyCell` and `LazyLock` types. The answer for the `Lazy*` types is that you would be better off using them if you want to use what is by far the most common pattern: initialize it with a single nullary function that you would call at every `get_or_init` site. For everything else there's the `Once*` types.

"For everything else" is a somewhat weak motivation, as it only describes by negation. While contrasting them is inevitable, I feel positive motivations are more understandable. For this, I now offer a distinct example that helps explain why `OnceLock` can be useful, despite `LazyLock` existing: you can do some cool stuff with it that `LazyLock` simply can't support due to its mere definition.

The pair of `std::sync::*Lock`s are usable inside a `static`, and can serve roles in async or multithreaded (or asynchronously multithreaded) programs that `*Cell`s cannot. Because of this, they received most of my attention.

Fixes #124696
Fixes #125615
2024-06-04 21:41:34 +02:00
Guillaume Gomez
190f221dba
Rollup merge of #106186 - rossmacarthur:ft/iter-chain, r=Amanieu
Add function `core::iter::chain`

The addition of `core::iter::zip` (#82917) set a precedent for adding plain functions for iterator adaptors. Adding `chain` makes it a little easier to `chain` two iterators.

```rust
for (x, y) in chain(xs, ys) {}
// vs.
for (x, y) in xs.into_iter().chain(ys) {}
```

There is prior art for the utility of this in [`itertools::chain`](https://docs.rs/itertools/latest/itertools/fn.chain.html).

Approved ACP https://github.com/rust-lang/libs-team/issues/154
2024-06-04 21:41:33 +02:00
Andrei Damian
2bad3d1392 Make deleting on LinkedList aware of the allocator 2024-06-04 18:49:13 +03:00
schvv31n
fd5777c4c5 impl OsString::leak & PathBuf::leak 2024-06-04 11:53:59 +01:00
Ross MacArthur
6a84995fae
Add function core::iter::chain
The addition of `core::iter::zip` (#82917) set a precedent for adding
plain functions for iterator adaptors. Adding `chain` makes it a little
easier to `chain` two iterators.

```
for (x, y) in chain(xs, ys) {}
// vs.
for (x, y) in xs.into_iter().chain(ys) {}
```
2024-06-04 10:51:05 +02:00
许杰友 Jieyou Xu (Joe)
a04a6038bb
Rollup merge of #125919 - tbu-:pr_fix_typo, r=lqd
Remove stray "this"
2024-06-04 08:25:49 +01:00
许杰友 Jieyou Xu (Joe)
d5a04221ef
Rollup merge of #125504 - mqudsi:once_nominal, r=cuviper
Change pedantically incorrect OnceCell/OnceLock wording

While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby [technically allowing it to be written to again](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=415c023a6ae1ef35f371a2d3bb1aa735)

Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole *categorically* prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract).

To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference.

```@rustbot``` label +A-rustdocs
2024-06-04 08:25:46 +01:00
Raoul Strackx
8db363c44b Let compiler auto impl Send for Task 2024-06-04 08:46:45 +02:00
Raoul Strackx
b8c6008fbc Store Task::p as dyn FnOnce() + Send 2024-06-04 08:46:38 +02:00
Raoul Strackx
9b2e41a218 Pass function for Thread as Send to Thread::imp 2024-06-04 08:45:48 +02:00
bors
27529d5c25 Auto merge of #125525 - joboet:tls_accessor, r=cuviper
Make TLS accessors closures that return pointers

The current TLS macros generate a function that returns an `Option<&'static T>`. This is both risky as we lie about lifetimes, and necessitates that those functions are `unsafe`. By returning a `*const T` instead, the accessor function do not have safety requirements any longer and can be made closures without hassle. This PR does exactly that!

For native TLS, the closure approach makes it trivial to select the right accessor function at compile-time, which could result in a slight speed-up (I have the hope that the accessors are now simple enough for the MIR-inliner to kick in).
2024-06-04 05:03:52 +00:00
David Carlier
fd648a3c76 std::unix::fs::get_path: using fcntl codepath for netbsd instead.
on netbsd, procfs is not as central as on linux/solaris thus
can be perfectly not mounted.
Thus using fcntl with F_GETPATH, the kernel deals with MAXPATHLEN
internally too.
2024-06-04 04:36:48 +00:00
Tim Kurdov
9436fbe00d
Fix typo in the docs of HashMap::raw_entry_mut 2024-06-03 17:35:58 +01:00
Lukas Wirth
d392c50ca3 Ignore vec_deque_alloc_error::test_shrink_to_unwind test on non-unwind targets 2024-06-03 13:46:56 +02:00
bors
8768db9912 Auto merge of #125912 - nnethercote:rustfmt-tests-mir-opt, r=oli-obk
rustfmt `tests/mir-opt`

Continuing the work started in #125759. Details in individual commit log messages.

r? `@oli-obk`
2024-06-03 10:25:12 +00:00
Tobias Bucher
45760276fd Remove stray "this" 2024-06-03 12:20:19 +02:00
Jubilee Young
9ed7cfc952 Add "OnceList" example to motivate OnceLock
While slightly verbose, it helps explain "why bother with OnceLock?"
This is a point of confusion that has been raised multiple times
shortly before and after the stabilization of LazyLock.
2024-06-02 22:53:41 -07:00
Jubilee Young
2d0ebca979 Move first OnceLock example to LazyLock
This example is spiritually an example of LazyLock, as it computes a
variable at runtime but accepts no inputs into that process.
It is also slightly simpler and thus easier to understand.
Change it to an even-more concise version and move it to LazyLock.

The example now editorializes slightly more. This may be unnecessary,
but it can be educational for the reader.
2024-06-02 22:53:41 -07:00
Jubilee Young
fdb96f2123 Differ LazyLock vs. OnceLock in std::sync overview 2024-06-02 22:53:41 -07:00
Jubilee Young
940594ff18 Explain LazyCell in core::cell overview 2024-06-02 22:53:41 -07:00
Nicholas Nethercote
ac24299636 Reformat mir! macro invocations to use braces.
The `mir!` macro has multiple parts:
- An optional return type annotation.
- A sequence of zero or more local declarations.
- A mandatory starting anonymous basic block, which is brace-delimited.
- A sequence of zero of more additional named basic blocks.

Some `mir!` invocations use braces with a "block" style, like so:
```
mir! {
    let _unit: ();
    {
	let non_copy = S(42);
	let ptr = std::ptr::addr_of_mut!(non_copy);
	// Inside `callee`, the first argument and `*ptr` are basically
	// aliasing places!
	Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue())
    }
    after_call = {
	Return()
    }
}
```
Some invocations use parens with a "block" style, like so:
```
mir!(
    let x: [i32; 2];
    let one: i32;
    {
	x = [42, 43];
	one = 1;
	x = [one, 2];
	RET = Move(x);
	Return()
    }
)
```
And some invocations uses parens with a "tighter" style, like so:
```
mir!({
    SetDiscriminant(*b, 0);
    Return()
})
```
This last style is generally used for cases where just the mandatory
starting basic block is present. Its braces are placed next to the
parens.

This commit changes all `mir!` invocations to use braces with a "block"
style. Why?

- Consistency is good.

- The contents of the invocation is a block of code, so it's odd to use
  parens. They are more normally used for function-like macros.

- Most importantly, the next commit will enable rustfmt for
  `tests/mir-opt/`. rustfmt is more aggressive about formatting macros
  that use parens than macros that use braces. Without this commit's
  changes, rustfmt would break a couple of `mir!` macro invocations that
  use braces within `tests/mir-opt` by inserting an extraneous comma.
  E.g.:
  ```
  mir!(type RET = (i32, bool);, { // extraneous comma after ';'
      RET.0 = 1;
      RET.1 = true;
      Return()
  })
  ```
  Switching those `mir!` invocations to use braces avoids that problem,
  resulting in this, which is nicer to read as well as being valid
  syntax:
  ```
  mir! {
      type RET = (i32, bool);
      {
	  RET.0 = 1;
	  RET.1 = true;
	  Return()
      }
  }
  ```
2024-06-03 13:24:44 +10:00
Jubilee
72ea7e9220
Rollup merge of #125898 - RalfJung:typo, r=Nilstrieb
typo: depending from -> on
2024-06-02 12:58:10 -07:00
Jubilee
890770d7bc
Rollup merge of #125884 - Rua:integer_sign_cast, r=Mark-Simulacrum
Implement feature `integer_sign_cast`

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

Since this is my first time making a library addition I wasn't sure where to place the new code relative to existing code. I decided to place it near the top where there are already some other basic bitwise manipulation functions. If there is an official guideline for the ordering of functions, please let me know.
2024-06-02 12:58:08 -07:00
Jubilee
713cdcd803
Rollup merge of #121062 - RustyYato:f32-midpoint, r=the8472
Change f32::midpoint to upcast to f64

This has been verified by kani as a correct optimization

see: https://github.com/rust-lang/rust/issues/110840#issuecomment-1942587398

The new implementation is branchless and only differs in which NaN values are produced (if any are produced at all), which is fine to change. Aside from NaN handling, this implementation produces bitwise identical results to the original implementation.

Question: do we need a codegen test for this? I didn't add one, since the original PR #92048 didn't have any codegen tests.
2024-06-02 12:58:07 -07:00
Rua
b181e8106c Wording of the documentation 2024-06-02 21:03:24 +02:00
Ralf Jung
361c6a5c3a typo: depending from -> on 2024-06-02 18:15:50 +02:00
bors
eda9d7f987 Auto merge of #125577 - devnexen:netbsd_stack_min, r=joboet
std::pal::unix::thread fetching min stack size on netbsd.

PTHREAD_STACK_MIN is not defined however sysconf/_SC_THREAD_STACK_MIN returns it as it can vary from arch to another.
2024-06-02 15:42:33 +00:00
Rua
d23d340858 Implement feature integer_sign_cast 2024-06-02 12:01:07 +02:00
RustyYato
849c5254af Change f32::midpoint to upcast to f64
This has been verified by kani as a correct optimization

see: https://github.com/rust-lang/rust/issues/110840#issuecomment-1942587398

The new implementation is branchless, and only differs in which NaN
values are produced (if any are produced at all). Which is fine to change.
Aside from NaN handling, this implementation produces bitwise identical
results to the original implementation.

The new implementation is gated on targets that have a fast 64-bit
floating point implementation in hardware, and on WASM.
2024-06-01 17:29:31 -07:00
bors
12b5d3c29c Auto merge of #124294 - tspiteri:ilog-first-iter, r=the8472
Unroll first iteration of checked_ilog loop

This follows the optimization of #115913. As shown in https://github.com/rust-lang/rust/pull/115913#issuecomment-2066788006, the performance was improved in all important cases, but some regressions were introduced for the benchmarks `u32_log_random_small`, `u8_log_random` and `u8_log_random_small`.

Basically, #115913 changed the implementation from one division per iteration to one multiplication per iteration plus one division. When there are zero iterations, this is a regression from zero divisions to one division.

This PR avoids this by avoiding the division if we need zero iterations by returning `Some(0)` early. It also reduces the number of multiplications by one in all other cases.
2024-06-02 00:05:32 +00:00
coekjan
7cee7c664b
stablize const_binary_heap_constructor & create an unstable feature const_binary_heap_new_in for BinaryHeap::new_in 2024-06-01 12:44:19 +08:00
Matthias Krüger
e9046602c5
Rollup merge of #125730 - mu001999-contrib:clippy-fix, r=oli-obk
Apply `x clippy --fix` and `x fmt` on Rustc

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Just run `x clippy --fix` and `x fmt`, and remove some changes like `impl Default`.
2024-05-31 17:05:24 +02:00
bors
99cb42c296 Auto merge of #124662 - zetanumbers:needs_async_drop, r=oli-obk
Implement `needs_async_drop` in rustc and optimize async drop glue

This PR expands on #121801 and implements `Ty::needs_async_drop` which works almost exactly the same as `Ty::needs_drop`, which is needed for #123948.

Also made compiler's async drop code to look more like compiler's regular drop code, which enabled me to write an optimization where types which do not use `AsyncDrop` can simply forward async drop glue to `drop_in_place`. This made size of the async block from the [async_drop test](67980dd6fb/tests/ui/async-await/async-drop.rs) to decrease by 12%.
2024-05-31 10:12:24 +00:00
Raoul Strackx
7cd732f990 Avoid mut and simplify initialization of TASK_QUEUE 2024-05-30 16:16:48 +02:00
bors
91c0823ee6 Auto merge of #124636 - tbu-:pr_env_unsafe, r=petrochenkov
Make `std::env::{set_var, remove_var}` unsafe in edition 2024

Allow calling these functions without `unsafe` blocks in editions up until 2021, but don't trigger the `unused_unsafe` lint for `unsafe` blocks containing these functions.

Fixes #27970.
Fixes #90308.
CC #124866.
2024-05-30 12:17:06 +00:00
Matthias Krüger
a4d00ff8e4
Rollup merge of #125746 - jmillikin:duration-from-weeks-typo, r=lqd
Fix copy-paste error in `Duration::from_weeks` panic message.
2024-05-30 10:23:08 +02:00
Matthias Krüger
60c2d80482
Rollup merge of #125739 - RalfJung:drop-in-place-docs, r=workingjubilee
drop_in_place: weaken the claim of equivalence with drop(ptr.read())

The two are *not* semantically equivalent in all cases, so let's not be so definite about this.

Fixes https://github.com/rust-lang/rust/issues/112015
2024-05-30 10:23:07 +02:00
Matthias Krüger
70e7b49cf2
Rollup merge of #125342 - tbu-:pr_doc_write, r=ChrisDenton
Document platform-specifics for `Read` and `Write` of `File`
2024-05-30 10:23:06 +02:00
Ralf Jung
5c68a15e41 explain what the open questions are, and add a Miri test for that 2024-05-30 09:07:06 +02:00
r0cky
dabd05bbab Apply x clippy --fix and x fmt 2024-05-30 09:51:27 +08:00
John Millikin
a8234d5f87 Fix copy-paste error in Duration::from_weeks panic message. 2024-05-30 08:40:48 +09:00
León Orell Valerian Liehr
1ae1388d2a
Rollup merge of #125733 - compiler-errors:async-fn-assoc-item, r=fmease
Add lang items for `AsyncFn*`, `Future`, `AsyncFnKindHelper`'s associated types

Adds lang items for `AsyncFnOnce::Output`, `AsyncFnOnce::CallOnceFuture`, `AsyncFnMut::CallRefFuture`, and uses them in the new solver. I'm mostly interested in doing this to help accelerate uplifting the new trait solver into a separate crate.

The old solver is kind of spaghetti, so I haven't moved that to use these lang items (i.e. it still uses `item_name`-based comparisons).

update: Also adds lang items for `Future::Output` and `AsyncFnKindHelper::Upvars`.

cc ``@lcnr``
2024-05-30 01:12:37 +02:00
Tobias Bucher
d7680e3556 Elaborate about modifying env vars in multi-threaded programs 2024-05-29 23:42:27 +02:00
Tobias Bucher
8cf4980648 Add note about safety of std::env::set_var on Windows 2024-05-29 23:42:27 +02:00
Tobias Bucher
5d8f9b4dc1 Make std::env::{set_var, remove_var} unsafe in edition 2024
Allow calling these functions without `unsafe` blocks in editions up
until 2021, but don't trigger the `unused_unsafe` lint for `unsafe`
blocks containing these functions.

Fixes #27970.
Fixes #90308.
CC #124866.
2024-05-29 23:42:27 +02:00
Ralf Jung
5c497cb3f0 drop_in_place: weaken the claim of equivalence with drop(ptr.read()) 2024-05-29 21:53:44 +02:00
Michael Goulet
a03ba7fd2d Add lang item for AsyncFnKindHelper::Upvars 2024-05-29 14:28:53 -04:00
Michael Goulet
a9c7e024c0 Add lang item for Future::Output 2024-05-29 14:22:56 -04:00
Michael Goulet
7f11d6f4bf Add lang items for AsyncFn's associated types 2024-05-29 14:09:19 -04:00
Scott McMurray
0d63e6b608 [ACP 362] genericize ptr::from_raw_parts 2024-05-29 09:34:16 -07:00
Markus Mayer
54bb08d538
Add FRAC_1_SQRT_2PI doc alias to FRAC_1_SQRT_TAU
This is create symmetry between the already existing TAU constant (2pi)
and the newly-introduced FRAC_1_SQRT_2PI, keeping the more common
name while increasing visibility.
2024-05-29 14:58:37 +02:00
Folkert
14c1f740f2
make ptr::rotate smaller when using optimize_for_size
code to reproduce https://github.com/folkertdev/optimize_for_size-slice-rotate

In the example the size of `.text` goes down from 1624 to 276 bytes.
2024-05-29 13:51:55 +02:00
Daria Sukhonina
2892302aef Add safety comment to fix tidy 2024-05-29 12:57:01 +03:00
Daria Sukhonina
7cdd95e1a6 Optimize async drop glue for some old types 2024-05-29 12:56:59 +03:00
Markus Mayer
eb72938049
Add FRAC_1_SQRT_2PI constant to f16/f32/f64/f128 2024-05-29 09:30:28 +02:00
许杰友 Jieyou Xu (Joe)
3cc59aeaae
Rollup merge of #125226 - madsmtm:fix-mac-catalyst-tests, r=workingjubilee
Make more of the test suite run on Mac Catalyst

Combined with https://github.com/rust-lang/rust/pull/125225, the only failing parts of the test suite are in `tests/rustdoc-js`, `tests/rustdoc-js-std` and `tests/debuginfo`. Tested with:
```console
./x test --target=aarch64-apple-ios-macabi library/std
./x test --target=aarch64-apple-ios-macabi --skip=tests/rustdoc-js --skip=tests/rustdoc-js-std --skip=tests/debuginfo tests
```

Will probably put up a PR later to enable _running_ on (not just compiling for) Mac Catalyst in CI, though not sure where exactly I should do so? `src/ci/github-actions/jobs.yml`?

Note that I've deliberately _not_ enabled stack overflow handlers on iOS/tvOS/watchOS/visionOS (see https://github.com/rust-lang/rust/issues/25872), but rather just skipped those tests, as it uses quite a few APIs that I'd be weary about getting rejected by the App Store (note that Swift doesn't do it on those platforms either).

r? ``@workingjubilee``

CC ``@thomcc``

``@rustbot`` label O-ios O-apple
2024-05-29 03:25:08 +01:00