Commit Graph

13802 Commits

Author SHA1 Message Date
joboet
5e343e76e8
std: move locks to sys on teeos 2024-02-16 12:10:49 +01:00
joboet
c2d0f8452f
std: move locks to sys on SGX 2024-02-16 12:10:48 +01:00
joboet
0cd21cc549
std: move locks to sys on µITRON 2024-02-16 12:10:07 +01:00
bors
dfa88b328f Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkin
Implement intrinsics with fallback bodies

fixes #93145 (though we can port many more intrinsics)
cc #63585

The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for

* codegen_ssa (so llvm and gcc)
* codegen_cranelift

other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body).

cc `@scottmcm` `@WaffleLapkin`

### todo

* [ ] miri support
* [x] default intrinsic name to name of function instead of requiring it to be specified in attribute
* [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16 09:53:01 +00:00
bors
1be468815c Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay
Use generic `NonZero` internally.

Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-16 07:46:31 +00:00
bors
0f806a9812 Auto merge of #120889 - Ayush1325:uefi-instant, r=joshtriplett
Implement Instant for UEFI

- Uses Timestamp Protocol if present. Else use rdtsc for x86 and x86-64
2024-02-16 02:24:44 +00:00
Guillaume Gomez
2a216bb53b
Rollup merge of #121155 - tspiteri:strict-doc-overflow, r=Nilstrieb
doc: add note about panicking examples for strict_overflow_ops

The first commit adds a note before the panicking examples for strict_overflow_ops to make it clearer that the following examples should panic and why, without needing the reader to hover the mouse over the information icon.

The second commit adds panicking examples for division by zero operations for strict division operations on unsigned numbers. The signed numbers already have two panicking examples each: one for division by zero and one for overflowing division (`MIN/-1`); this commit includes the division by zero examples for the unsigned numbers.
2024-02-16 00:27:35 +01:00
Guillaume Gomez
1630e04509
Rollup merge of #120971 - PizzasBear:patch-1, r=Nilstrieb
Fix comment in core/src/str/validations.rs

Fix minor issue in the comment
2024-02-16 00:27:31 +01:00
Guillaume Gomez
3803469473
Rollup merge of #120777 - Marcondiro:unicode15-1, r=Manishearth
Bump Unicode to version 15.1.0, regenerate tables

r? ```@Manishearth```
2024-02-16 00:27:31 +01:00
Trevor Spiteri
675d092e3e doc: panicking division by zero examples for unsigned strict div ops 2024-02-15 18:41:30 +01:00
Trevor Spiteri
fdc56b6886 doc: add note before panicking examples for strict_overflow_ops 2024-02-15 18:38:36 +01:00
bors
cbddf31863 Auto merge of #121142 - GuillaumeGomez:rollup-5qmksjw, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #120449 (Document requirements for unsized {Rc,Arc}::from_raw)
 - #120505 (Fix BTreeMap's Cursor::remove_{next,prev})
 - #120672 (std::thread update freebsd stack guard handling.)
 - #121088 (Implicitly enable evex512 if avx512 is enabled)
 - #121104 (Ignore unsized types when trying to determine the size of the original type)
 - #121107 (Fix msg for verbose suggestions with confusable capitalization)
 - #121113 (Continue compilation even if inherent impl checks fail)
 - #121120 (Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-15 17:00:55 +00:00
Johannes Lade
17066870cd
Fix typo in VecDeque::handle_capacity_increase() doc comment.
Strategies B and C both show a full buffer before the capacity increase, while strategy A had one empty element left. Filled the last element in.
2024-02-15 17:33:37 +01:00
bors
62fb0db9a5 Auto merge of #119863 - tmiasko:will-wake, r=m-ou-se
Waker::will_wake: Compare vtable address instead of its content

Optimize will_wake implementation by comparing vtable address instead of its content.

The existing best practice to avoid false negatives from will_wake is to define a waker vtable as a static item. That approach continues to works with the new implementation.

While this potentially changes the observable behaviour, the function is documented to work on a best-effort basis. The PartialEq impl for RawWaker remains as it was.
2024-02-15 14:43:29 +00:00
Guillaume Gomez
06f53dd316
Rollup merge of #121120 - nnethercote:LitKind-Err-guar, r=fmease
Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.

Similar to recent work doing the same for `ExprKind::Err` (#120586) and `TyKind::Err` (#121109).

r? `@oli-obk`
2024-02-15 14:33:03 +01:00
Guillaume Gomez
bf323ba3ac
Rollup merge of #120672 - devnexen:update_thread_stack_guardpages_fbsd, r=m-ou-se
std::thread update freebsd stack guard handling.

up to now, it had been assumed the stack guard setting default is not touched in the field but some user might just want to disable it or increase it. checking it once at runtime should be enough.
2024-02-15 14:33:00 +01:00
Guillaume Gomez
472c820eb3
Rollup merge of #120505 - Amanieu:fix-btreemap-cursor-remove, r=m-ou-se
Fix BTreeMap's Cursor::remove_{next,prev}

These would incorrectly leave `current` as `None` after a failed attempt to remove an element (due to the cursor already being at the start/end).
2024-02-15 14:33:00 +01:00
Guillaume Gomez
9fdab38877
Rollup merge of #120449 - udoprog:document-unsized-rc-arc-from-raw, r=m-ou-se
Document requirements for unsized {Rc,Arc}::from_raw

This seems to be implied due to these types supporting operation-less unsized coercions. Taken together with the [established behavior of a wide to thin pointer cast](https://github.com/rust-lang/reference/pull/1451) it would enable unsafe downcasting of these containers.

Note that the term "data pointer" is adopted from https://github.com/rust-lang/rfcs/pull/3559

See also this [internals thread](https://internals.rust-lang.org/t/can-unsafe-smart-pointer-downcasts-be-correct/20229/2).
2024-02-15 14:32:59 +01:00
Matthias Krüger
15d9e2c0f1
Rollup merge of #121098 - ShoyuVanilla:thread-local-unnecessary-else, r=Nilstrieb
Remove unnecessary else block from `thread_local!` expanded code

Some expanded codes make ["unnecessary else block" warnings](https://github.com/rust-lang/rust-analyzer/issues/16556#issuecomment-1944271716) for Rust Analyzer
2024-02-15 09:20:20 +01:00
Matthias Krüger
e5186aaf4d
Rollup merge of #121082 - peterjoel:atomic-docs, r=cuviper
Clarified docs on non-atomic oprations on owned/mut refs to atomics

I originally misinterpreted the documentation to mean that the compiler can/will automatically optimise away atomic operations whenever the data is owned or mutably referenced.

On re-reading I think it is not technically incorrect, but specifically mentioning _how_ the atomic operations can be avoided also prevents this misunderstanding.
2024-02-15 09:20:19 +01:00
Matthias Krüger
09776009ea
Rollup merge of #118749 - ChrisDenton:winsys, r=cuviper
Make contributing to windows bindings easier

This PR does three things:

- Automatically sorts bindings so contributors don't have to. I should have done this to begin with but was lazy.
- Renames `windows_sys.lst` to `bindings.txt`. This [matches the windows-rs repository](8e71051ea8/crates/tools/sys/bindings.txt) (and repos that copy it). I believe consistency with other projects helps get people orientated.
- Adds a `README.md` file explaining what this is about and how to add bindings. This has the benefit of being directly editable and it's rendered when viewed online. Also people are understandably jumping right into the `windows_sys.rs` file via ripgrep or github search and so missing that it's generated. A `README.md` alongside it is at least slightly more obvious in that case. There is still a small note at the top of `windows_sys` in case people do read from the beginning.

None of this has any impact on the actual code generated. It's purely to make the new contributors workflow a bit nicer.
2024-02-15 09:20:17 +01:00
Matthias Krüger
0238d2619f
Rollup merge of #111106 - Stargateur:doc/format_args, r=m-ou-se
Add known issue of let binding to format_args doc

Simply add doc about https://github.com/rust-lang/rust/issues/92698.

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

 r? `@GuillaumeGomez`
2024-02-15 09:20:16 +01:00
Markus Reiter
a90cc05233
Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
Markus Reiter
746a58d435
Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
Nicholas Nethercote
25ed6e43b0 Add ErrorGuaranteed to ast::LitKind::Err, token::LitKind::Err.
This mostly works well, and eliminates a couple of delayed bugs.

One annoying thing is that we should really also add an
`ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's
difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`,
so we have to fake it.
2024-02-15 14:46:08 +11:00
Peter Hall
9cccf20899 Clarified docs on non-atomic oprations on owned/mut refs to atomics 2024-02-14 20:14:45 +00:00
Shoyu Vanilla
fa1e35c833 Remove unnecessary else block from thread_local! expanded code 2024-02-15 02:35:37 +09:00
bors
340bb19fea Auto merge of #121078 - oli-obk:rollup-p11zsav, r=oli-obk
Rollup of 13 pull requests

Successful merges:

 - #116387 (Additional doc links and explanation of `Wake`.)
 - #118738 (Netbsd10 update)
 - #118890 (Clarify the lifetimes of allocations returned by the `Allocator` trait)
 - #120498 (Uplift `TypeVisitableExt` into `rustc_type_ir`)
 - #120530 (Be less confident when `dyn` suggestion is not checked for object safety)
 - #120915 (Fix suggestion span for `?Sized` when param type has default)
 - #121015 (Optimize `delayed_bug` handling.)
 - #121024 (implement `Default` for `AsciiChar`)
 - #121039 (Correctly compute adjustment casts in GVN)
 - #121045 (Fix two UI tests with incorrect directive / invalid revision)
 - #121049 (Do not point at `#[allow(_)]` as the reason for compat lint triggering)
 - #121071 (Use fewer delayed bugs.)
 - #121073 (Fix typos in `OneLock` doc)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-14 12:04:03 +00:00
Oli Scherer
96635da982
Rollup merge of #121073 - IgorLaborieWefox:patch-1, r=workingjubilee
Fix typos in `OneLock` doc
2024-02-14 11:53:43 +01:00
Oli Scherer
c1a80211f5
Rollup merge of #121024 - joseluis:feat-asciichar-default, r=scottmcm
implement `Default` for `AsciiChar`

This implements `Default` for `AsciiChar` in order to match `char`'s implementation.

From all the different possible ways to do this I think the clearest one is to have both `char` and `AsciiChar` impls together.

I've also updated the doc-comment of the default variant since rustdoc doesn't seem to indicate it otherwise. Probably the text could be improved, though. I couldn't find any similar examples in the codebase and suggestions are welcomed.

r? `@scottmcm`
2024-02-14 11:53:40 +01:00
Oli Scherer
407de0ee33
Rollup merge of #118890 - Amanieu:allocator-lifetime, r=Mark-Simulacrum
Clarify the lifetimes of allocations returned by the `Allocator` trait

The previous definition (accidentally) disallowed the implementation of stack-based allocators whose memory would become invalid once the lifetime of the allocator type ended.

This also ensures the validity of the following blanket implementation:
```rust
impl<A: Allocator> Allocator for &'_ A {}
```
2024-02-14 11:53:38 +01:00
Oli Scherer
1c7a9996f0
Rollup merge of #118738 - devnexen:netbsd10_update, r=cuviper
Netbsd10 update
2024-02-14 11:53:38 +01:00
Oli Scherer
5d114f3c99
Rollup merge of #116387 - kpreid:wake-doc, r=cuviper
Additional doc links and explanation of `Wake`.

This is intended to clarify:

* That `Wake` exists and can be used instead of `RawWaker`.
* How to construct a `Waker` when you are looking at `Wake` (which was previously only documented in the example).
2024-02-14 11:53:37 +01:00
bors
81b757c670 Auto merge of #100603 - tmandry:zst-guards, r=dtolnay
Optimize away poison guards when std is built with panic=abort

> **Note**: To take advantage of this PR, you will have to use `-Zbuild-std` or build your own toolchain. rustup toolchains always link to a libstd that was compiled with `panic=unwind`, since it's compatible with `panic=abort` code.

When std is compiled with `panic=abort` we can remove a lot of the poison machinery from the locks. This changes the `Flag` and `Guard` types to be ZSTs. It also adds an uninhabited member to `PoisonError` so the compiler knows it can optimize away the `Result::Err` paths, and make `LockResult<T>` layout-equivalent to `T`.

### Is this a breaking change?

`PoisonError::new` now panics if invoked from a libstd built with `panic="abort"` (or any non-`unwind` strategy). It is unclear to me whether to consider this a breaking change.

In order to encounter this behavior, **both of the following must be true**:

#### Using a libstd with `panic="abort"`

This is pretty uncommon. We don't build libstd with that in rustup, except in (Tier 2-3) platforms that do not support unwinding, **most notably wasm**.

Most people who do this are using cargo's `-Z build-std` feature, which is unstable.

`panic="abort"` is not a supported option in Rust's build system. It is possible to configure it using `CARGO_TARGET_xxx_RUSTFLAGS`, but I believe this only works on **non-host** platforms.

#### Creating `PoisonError` manually

This is also unlikely. The only common use case I can think of is in tests, and you can't run tests with `panic="abort"` without the unstable `-Z panic_abort_tests` flag.

It's possible that someone is implementing their own locks using std's `PoisonError` **and** defining "thread failure" to mean something other than "panic". If this is the case then we would break their code if it was used with a `panic="abort"` libstd. The locking crates I know of don't replicate std's poison API, but I haven't done much research into this yet.

I've touched on a fair number of considerations here. Which ones do people consider relevant?
2024-02-14 10:07:01 +00:00
Chris Denton
846315ddc9
Automatically sort windows_sys bindings 2024-02-14 06:49:39 -03:00
Chris Denton
adcbeb7fdb
Add windows_sys readme 2024-02-14 06:49:37 -03:00
Chris Denton
a261f8edd8
Move windows_sys.lst to bindings.txt 2024-02-14 06:46:19 -03:00
Igor
b06f89187b
Fix typos in OneLock doc 2024-02-14 07:41:28 +01:00
Noah Lev
cd3ba4a885
Fix incorrect use of compile_fail
`compile_fail` should only be used when the code is meant to show
what *not* to do. In other words, there should be a fundamental flaw
in the code. However, in this case, the example is just incomplete,
so we should use `ignore` to avoid confusing readers.
2024-02-13 14:03:59 -05:00
GnomedDev
601f2d192e
Store core::str::CharSearcher::utf8_size as u8 2024-02-13 18:28:48 +00:00
Amanieu d'Antras
8e9c8dd10a Add information about allocation lifetime to Allocator::allocate 2024-02-13 14:12:51 +00:00
joseLuís
1c7ea307cf implement Default for AsciiChar 2024-02-13 12:04:44 +01:00
Ayush Singh
dee2d0f333
Implement Instant for UEFI
- Uses Timestamp Protocol if present. Else use rdtsc for x86 and x86-64

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-02-13 14:13:02 +05:30
bors
fd9bb7fdde Auto merge of #121003 - matthiaskrgr:rollup-u5wyztn, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #120696 (Properly handle `async` block and `async fn` in `if` exprs without `else`)
 - #120751 (Provide more suggestions on invalid equality where bounds)
 - #120802 (Bail out of drop elaboration when encountering error types)
 - #120967 (docs: mention round-to-even in precision formatting)
 - #120973 (allow static_mut_ref in some tests that specifically test mutable statics)
 - #120974 (llvm-wrapper: adapt for LLVM API change: Add support for EXPORTAS name types)
 - #120986 (iterator.rs: remove "Basic usage" text)
 - #120987 (remove redundant logic)
 - #120988 (fix comment)
 - #120995 (PassWrapper: adapt for llvm/llvm-project@93cdd1b5cf)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-13 07:19:39 +00:00
Matthias Krüger
5d1e919db4
Rollup merge of #120986 - tshepang:extraneous, r=cuviper
iterator.rs: remove "Basic usage" text

Only one example is given (for each method)
2024-02-13 06:27:40 +01:00
Matthias Krüger
134de26337
Rollup merge of #120967 - LeoDog896:master, r=cuviper
docs: mention round-to-even in precision formatting

_Note_: Not quite sure exactly how to format this documentation.

Mentions round-to-even usage in precision formatting. (should this also be mentioned in `f64::round`?)

From https://github.com/rust-lang/rust/issues/70336
2024-02-13 06:27:38 +01:00
bors
09d73fab08 Auto merge of #120938 - Ayush1325:uefi-thread, r=joboet,Nilstrieb
Implement sys/thread for UEFI

Since UEFI has no concept of threads, most of this module can be ignored. However, implementing parts that make sense.

- Implement sleep
- Implement available_parallelism
2024-02-13 05:04:55 +00:00
Tristan F
0f53e720a8 docs: use correct link, use secondary example 2024-02-12 20:17:47 -05:00
Tshepang Mbambo
142ab9e882 iterator.rs: remove "Basic usage" text
Only one example is given (for each method)
2024-02-12 22:22:14 +02:00
Oli Scherer
f35a2bd401 Support safe intrinsics with fallback bodies
Turn `is_val_statically_known` into such an intrinsic to demonstrate. It is perfectly safe to call after all.
2024-02-12 17:55:36 +00:00
Oli Scherer
6b73fe2d09 Give const_deallocate a default body 2024-02-12 17:52:05 +00:00
Oli Scherer
9a0743747f Teach llvm backend how to fall back to default bodies 2024-02-12 17:50:39 +00:00
Oli Scherer
531505f182 Check signature of intrinsics with fallback bodies 2024-02-12 17:44:53 +00:00
Matthias Krüger
8305686126
Rollup merge of #120936 - ripytide:master, r=Amanieu
improve `btree_cursors` functions documentation

As suggested by ``@Amanieu`` (and others) in #107540 (https://github.com/rust-lang/rust/issues/107540#issuecomment-1937760547)

Improvements:
- Document exact behavior of `{upper/lower}_bound{,_mut}` with each of the three `Bound` types using unambigous words `{greatest,greater,smallest,smaller,before,after}`.
- Added another doc-example for the `Bound::Unbounded` for each of the methods
- Changed doc-example to use From<[T; N]> rather than lots of `insert()`s which requires a mutable map which clutters the example when `mut` may not be required for the method (such as for `{upper,lower}_bound`.
- Removed `# Panics` section from `insert_{before,after}` methods since they were changed to return an error instead a while ago.
- Reworded some phrases to be more consistent with the more regular `BTreeMap` methods such as calling entries "key-value" rather than "element"s.
2024-02-12 18:04:10 +01:00
Tristan F.
30f6665953 style: fmt 2024-02-12 14:43:19 +00:00
Amanieu d'Antras
fb5ed2986e Clarify the lifetimes of allocations returned by the Allocator trait
The previous definition (accidentally) disallowed the implementation of
stack-based allocators whose memory would become invalid once the
lifetime of the allocator type ended.

This also ensures the validity of the following blanket implementation:
```rust
impl<A: Allocator> Allocator for &'_ A {}
```
2024-02-12 14:02:30 +00:00
PizzasBear
fffcb4c877
Fix comment in core/src/str/validations.rs 2024-02-12 16:00:15 +02:00
Tristan F
730560b982
docs: mention round-to-even in precision formatting 2024-02-12 08:20:13 -05:00
bors
b17491c8f6 Auto merge of #110211 - joboet:queue_lock, r=Amanieu
Replace pthread `RwLock` with custom implementation

This is one of the last items in #93740. I'm doing `RwLock` first because it is more self-contained and has less tradeoffs to make. The motivation is explained in the documentation, but in short: the pthread rwlock is slow and buggy and `std` can do much better. I considered implementing a parking lot, as was discussed in the tracking issue, but settled for the queue-based version because writing self-balancing binary trees is not fun in Rust...

This is a rather complex change, so I have added quite a bit of documentation to help explain it. Please point out any part that could be explained better.

~~The read performance is really good, I'm getting 4x the throughput of the pthread version and about the same performance as usync/parking_lot on an Apple M1 Max in the usync benchmark suite, but the write performance still falls way behind what usync and parking_lot achieve. I tried using a separate queue lock like what usync uses, but that didn't help. I'll try to investigate further in the future, but I wanted to get some eyes on this first.~~ [Resolved](https://github.com/rust-lang/rust/pull/110211#issuecomment-1513682336)

r? `@m-ou-se`
CC `@kprotty`
2024-02-12 09:45:22 +00:00
Oli Scherer
92281c7e81 Implement intrinsics with fallback bodies 2024-02-12 09:44:22 +00:00
Matthias Krüger
d71154f80f
Rollup merge of #120888 - saethlin:unsafe-precondition-cleanup, r=RalfJung
assert_unsafe_precondition cleanup

I moved the polymorphic `is_nonoverlapping` into the `Cell` function that uses it and renamed `intrinsics::is_nonoverlapping_mono` to just `intrinsics::is_nonoverlapping`.

We now also have some docs for `intrinsics::debug_assertions`.

r? RalfJung
2024-02-11 23:19:10 +01:00
Matthias Krüger
3d7d709925
Rollup merge of #120880 - RalfJung:vtable-fnptr-partialeq, r=cuviper
add note on comparing vtables / function pointers

Fixes https://github.com/rust-lang/rust/issues/99388
Fixes https://github.com/rust-lang/rust/issues/117047
2024-02-11 23:19:09 +01:00
Matthias Krüger
f64bc316f6
Rollup merge of #120740 - ChrisDenton:cmaths, r=Mark-Simulacrum
Make cmath.rs a single file

It makes sense to have this all in one file. There's essentially only one target that has missing symbols and that's easy enough to handle inline.

Note that the Windows definitions used to use `c_float` and `c_double` whereas the other platforms all used `f32` and `f64`. They've now been made consistent. However, `c_float` and `c_double` have the expected definitions on all Windows platforms we support.
2024-02-11 23:19:08 +01:00
Matthias Krüger
251a09e151
Rollup merge of #110483 - tleibert:thin-box-try-new, r=dtolnay
Create try_new function for ThinBox

The `allocator_api` feature has proven very useful in my work in the FreeBSD kernel. I've found a few places where a `ThinBox` #92791 would be useful, but it must be able to be fallibly allocated for it to be used in the kernel.

This PR proposes a change to add such a constructor for ThinBox.

ACP: https://github.com/rust-lang/libs-team/issues/213
2024-02-11 23:19:07 +01:00
Ralf Jung
aaa6d3bec2 add comparison warning to RawWakerVTable as well 2024-02-11 23:06:09 +01:00
ripytide
f34d9da7db
fix intra-doc links 2024-02-11 20:26:05 +00:00
David Tolnay
ea6944a065
Address ThinBox::try_new PR review 2024-02-11 11:28:01 -08:00
Ayush Singh
af428db01f
Implement sys/thread for UEFI
Since UEFI has no concept of threads, most of this module can be
ignored. However, implementing parts that make sense.

- Implement sleep
- Implement available_parallelism

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-02-11 23:48:53 +05:30
bors
a166af7729 Auto merge of #120903 - matthiaskrgr:rollup-tmsuzth, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics)
 - #120272 (Suppress suggestions in derive macro)
 - #120773 (large_assignments: Allow moves into functions)
 - #120874 (Take empty `where` bounds into account when suggesting predicates)
 - #120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches)
 - #120883 (interpret: rename ReadExternStatic → ExternStatic)
 - #120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.)
 - #120895 (don't skip coercions for types with errors)
 - #120896 (Print kind of coroutine closure)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-11 17:43:51 +00:00
Ben Kimock
f0de10039c Cleanup around the new assert_unsafe_precondition
Make the polymorphic is_nonoverlapping private

Fix assert_unsafe_precondition doc typos

Add docs for intrinsics::debug_assertions
2024-02-11 12:35:44 -05:00
ripytide
f415339052
fix incorrect doctest 2024-02-11 16:18:40 +00:00
ripytide
792fa24595
improve btree_cursors functions documentation 2024-02-11 15:51:07 +00:00
joboet
04282db5b3
add doc-comment to unlock_queue 2024-02-11 13:59:00 +01:00
David Carlier
114b0c799d std: enabling new netbsd (10) calls.
Introducing a new config for this purpose as NetBSD 9 or 8 will be still around
for a good while. For now, we re finally enabling sys::unix::rand::getrandom.
2024-02-11 08:48:02 +00:00
Matthias Krüger
3a198077c9
Rollup merge of #120459 - rytheo:handle-conversion-docs, r=Mark-Simulacrum
Document various I/O descriptor/handle conversions

Related to #51430
2024-02-11 08:25:43 +01:00
Matthias Krüger
ba405a47bd
Rollup merge of #120307 - djc:duration-constructors, r=Mark-Simulacrum
core: add Duration constructors

Add more `Duration` constructors.

Tracking issue: #120301.

These match similar convenience constructors available on both `chrono::Duration` and `time::Duration`.

What's the best ordering for these with respect to the existing constructors?
2024-02-11 08:25:42 +01:00
Matthias Krüger
0c5d8d3d3e
Rollup merge of #119449 - Nilstrieb:library-clippy, r=cuviper
Fix `clippy::correctness` in the library

needs https://github.com/rust-lang/backtrace-rs/pull/579 to be complete

for https://github.com/rust-lang/compiler-team/issues/709
2024-02-11 08:25:42 +01:00
Matthias Krüger
a576e81b1d
Rollup merge of #119242 - BenWiederhake:dev-from-nanos, r=joshtriplett
Suggest less bug-prone construction of Duration in docs

std::time::Duration has a well-known quirk: Duration::as_nanos() returns u128 [1], but Duration::from_nanos() takes u64 [2]. So these methods cannot easily roundtrip [3]. It is not possible to simply accept u128 in from_nanos [4], because it requires breaking other API [5].

It seems to me that callers have basically only two options:
1. `Duration::from_nanos(d.as_nanos() as u64)`, which is the "obvious" and buggy approach.
2. `Duration::new(d.as_secs(), d.subsecs_nanos())`, which only becomes apparent after reading and digesting the entire Duration struct documentation.

I suggest that the documentation of `from_nanos` is changed to make option 2 more easily discoverable.

There are two major usecases for this:
- "Weird math" operations that should not be supported directly by `Duration`, like squaring.
- "Disconnected roundtrips", where the u128 value is passed through various other stack frames, and perhaps reconstructed into a Duration on a different machine.

In both cases, it seems like a good idea to not tempt people into thinking "Eh, u64 is good enough, what could possibly go wrong!". That's why I want to add a note that points out the similarly-easy and *safe* way to reconstruct a Duration.

[1] https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.as_nanos
[2] https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.from_nanos
[3] https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fa6bab2b6b72f20c14b5243610ea1dde
[4] https://github.com/rust-lang/rust/issues/103332
[5] https://github.com/rust-lang/rust/issues/51107#issuecomment-392353166
2024-02-11 08:25:41 +01:00
Matthias Krüger
1843dfd0d5
Rollup merge of #118307 - scottmcm:tuple-eq-simpler, r=joshtriplett
Remove an unneeded helper from the tuple library code

Thanks to https://github.com/rust-lang/rust/pull/107022, this is just what `==` does, so we don't need the helper here anymore.
2024-02-11 08:25:41 +01:00
Matthias Krüger
f4e6818bff
Rollup merge of #117740 - majaha:format_docs, r=joshtriplett
Add some links and minor explanatory comments to `std::fmt`

I thought the documentation for the `#` flag could do with a link to the explanation of the `?xXbo` flags, because at that point they haven't been explained yet and it's a bit confusing.

I also added that the `0` flag overrides the fill character and alignment flag, here's a [Rust Playgrond](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0d580b7b78b8a2d8c08a2fc7a936ef17) that shows what I mean.
2024-02-11 08:25:41 +01:00
Kevin Reid
a6c91f0ae3 Remove the link. 2024-02-10 22:17:11 -08:00
Kevin Reid
cef46f9e3d URL-encode chars in fragment. 2024-02-10 22:17:11 -08:00
Kevin Reid
ccd6513c67 Additional doc links and explanation of Wake.
This is intended to clarify:

* That `Wake` exists and can be used instead of `RawWaker`.
* How to construct a `Waker` when you are looking at `Wake`
  (which was previously only documented in the example).
2024-02-10 22:17:11 -08:00
bors
0cbef48150 Auto merge of #120232 - c272:json-buildstd, r=Mark-Simulacrum
Add support for custom JSON targets when using build-std.

Currently, when building with `build-std`, some library build scripts check properties of the target by inspecting the target triple at `env::TARGET`, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to fetch target information instead, allowing JSON target files describing platforms without `restricted_std` to build correctly when using `-Z build-std`. There are some weak assertions here (for example, `nintendo && newlib`), however this seems at least a marginal improvement on the existing solution.

Fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/60.
2024-02-11 02:10:17 +00:00
Matthias Krüger
5f9457c851
Rollup merge of #119213 - RalfJung:simd_shuffle, r=workingjubilee
simd intrinsics: add simd_shuffle_generic and other missing intrinsics

Also tweak the simd_shuffle docs a bit.

r? `@calebzulawski`
2024-02-11 01:37:54 +01:00
Ralf Jung
1383657a46 add note on comparing vtables / function pointers 2024-02-10 14:58:37 +01:00
Matthias Krüger
83544703f5
Rollup merge of #120823 - LegionMammal978:clarify-atomic-align, r=RalfJung
Clarify that atomic and regular integers can differ in alignment

The documentation for atomic integers says that they have the "same in-memory representation" as their underlying integers. This might be misconstrued as implying that they have the same layout. Therefore, clarify that atomic integers' alignment is equal to their size.
2024-02-10 13:12:29 +01:00
Matthias Krüger
2eda0c7b2e
Rollup merge of #120764 - Alfriadox:master, r=m-ou-se
Add documentation on `str::starts_with`

Add documentation about a current footgun of `str::starts_with`
2024-02-10 13:12:29 +01:00
Ralf Jung
3bc490d814 various docs tweaks 2024-02-10 10:19:57 +01:00
Ralf Jung
aa64c73f14 simd_scatter: mention left-to-right order 2024-02-10 10:13:15 +01:00
Ralf Jung
5219af6ae0 add more missing simd intrinsics 2024-02-10 10:13:14 +01:00
Ralf Jung
d96f0c382f simd intrinsics: add simd_shuffle_generic 2024-02-10 10:13:14 +01:00
bors
757b8efed4 Auto merge of #120712 - compiler-errors:async-closures-harmonize, r=oli-obk
Harmonize `AsyncFn` implementations, make async closures conditionally impl `Fn*` traits

This PR implements several changes to the built-in and libcore-provided implementations of `Fn*` and `AsyncFn*` to address two problems:
1. async closures do not implement the `Fn*` family traits, leading to breakage: https://crater-reports.s3.amazonaws.com/pr-120361/index.html
2. *references* to async closures do not implement `AsyncFn*`, as a consequence of the existing blanket impls of the shape `AsyncFn for F where F: Fn, F::Output: Future`.

In order to fix (1.), we implement `Fn` traits appropriately for async closures. It turns out that async closures can:
* always implement `FnOnce`, meaning that they're drop-in compatible with `FnOnce`-bound combinators like `Option::map`.
* conditionally implement `Fn`/`FnMut` if they have no captures, which means that existing usages of async closures should *probably* work without breakage (crater checking this: https://github.com/rust-lang/rust/pull/120712#issuecomment-1930587805).

In order to fix (2.), we make all of the built-in callables implement `AsyncFn*` via built-in impls, and instead adjust the blanket impls for `AsyncFn*` provided by libcore to match the blanket impls for `Fn*`.
2024-02-10 07:15:15 +00:00
Venus Xeon-Blonde
d7263d7aad
Change wording 2024-02-09 22:24:57 -05:00
bors
d44e3b95cb Auto merge of #120852 - matthiaskrgr:rollup-01pr8gj, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #120351 (Implement SystemTime for UEFI)
 - #120354 (improve normalization of `Pointee::Metadata`)
 - #120776 (Move path implementations into `sys`)
 - #120790 (better error message on download CI LLVM failure)
 - #120806 (Clippy subtree update)
 - #120815 (Improve `Option::inspect` docs)
 - #120822 (Emit more specific diagnostics when enums fail to cast with `as`)
 - #120827 (Print image input file and checksum in CI only)
 - #120836 (hide impls if trait bound is proven from env)
 - #120844 (Build DebugInfo for async closures)
 - #120851 (Remove duplicate release note)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-09 21:06:12 +00:00
David Carlier
6686ca08a2 std::thread update freebsd stack guard handling.
up to now, it had been assumed the stack guard setting default is not
touched in the field but some user might just want to disable it or
increase it. checking it once at runtime should be enough.
2024-02-09 20:10:47 +00:00
Matthias Krüger
40f998d7e9
Rollup merge of #120815 - camsteffen:inspect-docs, r=m-ou-se
Improve `Option::inspect` docs

* Refer to the function as "a function" instead of "the provided closure" since it is not necessarily a closure.
* State that the original Option/Result is returned.
* Adjust the example for `Option::inspect` to use chaining.
2024-02-09 19:21:17 +01:00
Matthias Krüger
434f080895
Rollup merge of #120776 - joboet:move_pal_path, r=ChrisDenton
Move path implementations into `sys`

Part of #117276.

r? `@ChrisDenton`
2024-02-09 19:21:16 +01:00
Matthias Krüger
1e3d2fb417
Rollup merge of #120351 - Ayush1325:uefi-time, r=m-ou-se
Implement SystemTime for UEFI

- Uses SystemTable->RuntimeServices->GetTime()
- Uses the algorithm described [here](https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html) for conversion to UNIX time
2024-02-09 19:21:15 +01:00
bors
f4cfd87202 Auto merge of #120676 - Mark-Simulacrum:bootstrap-bump, r=clubby789
Bump bootstrap compiler to just-built 1.77 beta

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-02-09 18:09:02 +00:00
joboet
ff44ae7428
address review comments 2024-02-09 18:01:25 +01:00
Marcondiro
01fa7209d5
Bump Unicode to version 15.1.0, regenerate tables 2024-02-09 17:35:46 +01:00
joboet
3fa5a40737
be more explicit about why adding backlinks eagerly makes sense 2024-02-09 16:53:36 +01:00
Cameron Steffen
e9059cb8aa Improve Option::inspect docs 2024-02-09 09:53:30 -06:00
bors
e28fae52d9 Auto merge of #120843 - matthiaskrgr:rollup-med37z5, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #113671 (Make privacy visitor use types more (instead of HIR))
 - #120308 (core/time: avoid divisions in Duration::new)
 - #120693 (Invert diagnostic lints.)
 - #120704 (A drive-by rewrite of `give_region_a_name()`)
 - #120809 (Use `transmute_unchecked` in `NonZero::new`.)
 - #120817 (Fix more `ty::Error` ICEs in MIR passes)
 - #120828 (Fix `ErrorGuaranteed` unsoundness with stash/steal.)
 - #120831 (Startup objects disappearing from sysroot)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-09 15:34:48 +00:00
joboet
69f55de5ac
format using latest rustfmt 2024-02-09 14:58:38 +01:00
joboet
1fd9f7898e
inline some single-use functions, add documentation 2024-02-09 14:58:38 +01:00
joboet
16aae04f68
queue_rwlock: use a separate QUEUE_LOCKED bit to synchronize waiter queue updates 2024-02-09 14:58:38 +01:00
joboet
8db64b5e2d
use exponential backoff in lock_contended 2024-02-09 14:58:38 +01:00
joboet
61ce691522
immediately register writer node if threads are queued 2024-02-09 14:58:38 +01:00
joboet
709ccf98b8
avoid unnecessary Thread handle allocation 2024-02-09 14:58:37 +01:00
joboet
280cbc5dae
use braces to make operator precedence less ambiguous 2024-02-09 14:58:37 +01:00
joboet
2e652e59f6
adjust code documentation 2024-02-09 14:58:37 +01:00
joboet
934eb8b391
std: replace pthread RwLock with custom implementation inspired by usync 2024-02-09 14:58:35 +01:00
Matthias Krüger
475c47a3c1
Rollup merge of #120809 - reitermarkus:generic-nonzero-constructors, r=Nilstrieb
Use `transmute_unchecked` in `NonZero::new`.

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

See https://github.com/rust-lang/rust/pull/120521#discussion_r1482615129.
2024-02-09 14:41:51 +01:00
Matthias Krüger
8b8adfd05d
Rollup merge of #120308 - utkarshgupta137:duration-opt, r=m-ou-se
core/time: avoid divisions in Duration::new

In our (decently large) code base, we use `SystemTime::UNIX_EPOCH.elapsed()` in a lot of places & often in a loop or in the hot path. On [Unix](https://github.com/rust-lang/rust/blob/1.75.0/library/std/src/sys/unix/time.rs#L153-L162) at least, it seems we do calculations before hand to ensure that nanos is within the valid range, yet `Duration::new()` still checks it again, using 2 divisions. It seems like adding a branch can make this function 33% faster on ARM64 in the cases where nanos is already in the valid range & seems to have no effect in the other case.

Benchmarks:
M1 Pro (14-inch base model):
```
duration/current/checked
                        time:   [1.5945 ns 1.6167 ns 1.6407 ns]
Found 5 outliers among 100 measurements (5.00%)
  2 (2.00%) high mild
  3 (3.00%) high severe
duration/current/unchecked
                        time:   [1.5941 ns 1.6051 ns 1.6179 ns]
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe

duration/branched/checked
                        time:   [1.1997 ns 1.2048 ns 1.2104 ns]
Found 8 outliers among 100 measurements (8.00%)
  4 (4.00%) high mild
  4 (4.00%) high severe
duration/branched/unchecked
                        time:   [1.5881 ns 1.5957 ns 1.6039 ns]
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe
```
EC2 c7gd.16xlarge (Graviton 3):
```
duration/current/checked
                        time:   [2.7996 ns 2.8000 ns 2.8003 ns]
Found 5 outliers among 100 measurements (5.00%)
  2 (2.00%) low severe
  3 (3.00%) low mild
duration/current/unchecked
                        time:   [2.9922 ns 2.9925 ns 2.9928 ns]
Found 7 outliers among 100 measurements (7.00%)
  4 (4.00%) low severe
  1 (1.00%) low mild
  2 (2.00%) high mild

duration/branched/checked
                        time:   [2.0830 ns 2.0843 ns 2.0857 ns]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) low severe
  1 (1.00%) low mild
  1 (1.00%) high mild
duration/branched/unchecked
                        time:   [2.9879 ns 2.9886 ns 2.9893 ns]
Found 5 outliers among 100 measurements (5.00%)
  3 (3.00%) low severe
  2 (2.00%) low mild
```
EC2 r7iz.16xlarge (Intel Xeon Scalable-based (Sapphire Rapids)):
```
duration/current/checked
                        time:   [980.60 ps 980.79 ps 980.99 ps]
Found 10 outliers among 100 measurements (10.00%)
  4 (4.00%) low severe
  2 (2.00%) low mild
  3 (3.00%) high mild
  1 (1.00%) high severe
duration/current/unchecked
                        time:   [979.53 ps 979.74 ps 979.96 ps]
Found 6 outliers among 100 measurements (6.00%)
  2 (2.00%) low severe
  1 (1.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe

duration/branched/checked
                        time:   [938.72 ps 938.96 ps 939.22 ps]
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
  2 (2.00%) high severe
duration/branched/unchecked
                        time:   [1.0103 ns 1.0110 ns 1.0118 ns]
Found 10 outliers among 100 measurements (10.00%)
  2 (2.00%) low mild
  7 (7.00%) high mild
  1 (1.00%) high severe
```

Bench code (ran using stable 1.75.0 & criterion latest 0.5.1):
I couldn't find any benches for `Duration` in this repo, so I just copied the relevant types & recreated it.
```rust
use criterion::{black_box, criterion_group, criterion_main, Criterion};

pub fn duration_bench(c: &mut Criterion) {
    const NANOS_PER_SEC: u32 = 1_000_000_000;

    #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
    #[repr(transparent)]
    struct Nanoseconds(u32);

    impl Default for Nanoseconds {
        #[inline]
        fn default() -> Self {
            // SAFETY: 0 is within the valid range
            unsafe { Nanoseconds(0) }
        }
    }

    #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
    pub struct Duration {
        secs: u64,
        nanos: Nanoseconds, // Always 0 <= nanos < NANOS_PER_SEC
    }

    impl Duration {
        #[inline]
        pub const fn new_current(secs: u64, nanos: u32) -> Duration {
            let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) {
                Some(secs) => secs,
                None => panic!("overflow in Duration::new"),
            };
            let nanos = nanos % NANOS_PER_SEC;
            // SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range
            Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }
        }

        #[inline]
        pub const fn new_branched(secs: u64, nanos: u32) -> Duration {
            if nanos < NANOS_PER_SEC {
                // SAFETY: nanos < NANOS_PER_SEC, therefore nanos is within the valid range
                Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }
            } else {
                let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) {
                    Some(secs) => secs,
                    None => panic!("overflow in Duration::new"),
                };
                let nanos = nanos % NANOS_PER_SEC;
                // SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range
                Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }
            }
        }
    }

    let mut group = c.benchmark_group("duration/current");
    group.bench_function("checked", |b| {
        b.iter(|| black_box(Duration::new_current(black_box(1_000_000_000), black_box(1_000_000))));
    });
    group.bench_function("unchecked", |b| {
        b.iter(|| {
            black_box(Duration::new_current(black_box(1_000_000_000), black_box(2_000_000_000)))
        });
    });
    drop(group);
    let mut group = c.benchmark_group("duration/branched");
    group.bench_function("checked", |b| {
        b.iter(|| {
            black_box(Duration::new_branched(black_box(1_000_000_000), black_box(1_000_000)))
        });
    });
    group.bench_function("unchecked", |b| {
        b.iter(|| {
            black_box(Duration::new_branched(black_box(1_000_000_000), black_box(2_000_000_000)))
        });
    });
}

criterion_group!(duration_benches, duration_bench);
criterion_main!(duration_benches);
```
2024-02-09 14:41:49 +01:00
bors
8fb67fb37f Auto merge of #120594 - saethlin:delayed-debug-asserts, r=oli-obk
Toggle assert_unsafe_precondition in codegen instead of expansion

The goal of this PR is to make some of the unsafe precondition checks in the standard library available in debug builds. Some UI tests are included to verify that it does that.

The diff is large, but most of it is blessing mir-opt tests and I've also split up this PR so it can be reviewed commit-by-commit.

This PR:
1. Adds a new intrinsic, `debug_assertions` which is lowered to a new MIR NullOp, and only to a constant after monomorphization
2. Rewrites `assume_unsafe_precondition` to check the new intrinsic, and be monomorphic.
3. Skips codegen of the `assume` intrinsic in unoptimized builds, because that was silly before but with these checks it's *very* silly
4. The checks with the most overhead are `ptr::read`/`ptr::write` and `NonNull::new_unchecked`. I've simply added `#[cfg(debug_assertions)]` to the checks for `ptr::read`/`ptr::write` because I was unable to come up with any (good) ideas for decreasing their impact. But for `NonNull::new_unchecked` I found that the majority of callers can use a different function, often a safe one.

Yes, this PR slows down the compile time of some programs. But in our benchmark suite it's never more than 1% icount, and the average icount change in debug-full programs is 0.22%. I think that is acceptable for such an improvement in developer experience.

https://github.com/rust-lang/rust/issues/120539#issuecomment-1922687101
2024-02-09 13:33:38 +00:00
bors
972452c447 Auto merge of #120238 - joboet:always_confirm_lock_success, r=Mark-Simulacrum
Always check the result of `pthread_mutex_lock`

Fixes #120147.

Instead of manually adding a list of "good" platforms, I've simply made the check unconditional. pthread's mutex is already quite slow on most platforms, so one single well-predictable branch shouldn't hurt performance too much.
2024-02-09 10:27:16 +00:00
LegionMammal978
c94bbb24db Clarify that atomic and regular integers can differ in alignment
The documentation for atomic integers says that they have the "same
in-memory representation" as their underlying integers. This might be
misconstrued as implying that they have the same layout. Therefore,
clarify that atomic integers' alignment is equal to their size.
2024-02-08 22:59:36 -05:00
Ben Kimock
dbf817bae1 Add and use Unique::as_non_null_ptr 2024-02-08 19:56:30 -05:00
Markus Reiter
24e2cf01d3
Make NonZero::get generic. 2024-02-08 21:57:46 +01:00
Markus Reiter
d70d3204b7
Use transmute_unchecked in NonZero::new. 2024-02-08 20:44:32 +01:00
Ayush Singh
92d4060176
Implement SystemTime for UEFI
- Uses SystemTable->RuntimeServices->GetTime()

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-02-09 00:21:36 +05:30
Ben Kimock
88d6e9f868 Reduce use of NonNull::new_unchecked in library/ 2024-02-08 11:52:16 -05:00
Ben Kimock
b0ea682a2c Remove a now-obviated debug_assert! 2024-02-08 11:52:16 -05:00
Ben Kimock
61118ffd04 Rewrite assert_unsafe_precondition around the new intrinsic 2024-02-08 11:52:14 -05:00
Ben Kimock
55fabf35b1 Add a new debug_assertions intrinsic 2024-02-08 11:49:07 -05:00
Mark Rousskov
9a5034a20e Step all bootstrap cfgs forward
This also takes care of other bootstrap-related changes.
2024-02-08 07:44:34 -05:00
Mark Rousskov
8043821b3a Bump version placeholders 2024-02-08 07:43:38 -05:00
joboet
c0d9776562
std: move path into sys 2024-02-08 12:51:35 +01:00
bors
870a01a30e Auto merge of #120558 - oli-obk:missing_impl_item_ice, r=estebank
Stop bailing out from compilation just because there were incoherent traits

fixes #120343

but also has a lot of "type annotations needed" fallout. Some are fixed in the second commit.
2024-02-08 05:01:09 +00:00
Venus Xeon-Blonde
8ff1994ec0
Fix whitespace issues that tidy caught 2024-02-07 23:37:34 -05:00
Venus Xeon-Blonde
f0c6f5a7fe
Add documentation on str::starts_with
Add documentation about a current footgun of `str::starts_with`
2024-02-07 23:29:22 -05:00
bors
384b02c082 Auto merge of #120521 - reitermarkus:generic-nonzero-constructors, r=dtolnay
Make `NonZero` constructors generic.

This makes `NonZero` constructors generic, so that `NonZero::new` can be used without turbofish syntax.

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

~~I cannot figure out how to make this work with `const` traits. Not sure if I'm using it wrong or whether there's a bug:~~

```rust
101 |         if n == T::ZERO {
    |            ^^^^^^^^^^^^ expected `host`, found `true`
    |
    = note: expected constant `host`
               found constant `true`
```

r? `@dtolnay`
2024-02-08 03:00:34 +00:00
bors
6894f435d3 Auto merge of #120381 - fee1-dead-contrib:reconstify-add, r=compiler-errors
Reconstify `Add`

r? project-const-traits

I'm not happy with the ui test changes (or failures because I did not bless them and include the diffs in this PR). There is at least some bugs I need to look and try fix:

1. A third duplicated diagnostic when a consumer crate that does not have `effects` enabled has a trait selection error for an upstream const_trait trait. See tests/ui/ufcs/ufcs-qpath-self-mismatch.rs.
2. For some reason, making `Add` a const trait would stop us from suggesting `T: Add` when we try to add two `T`s without that bound. See tests/ui/suggestions/issue-97677.rs
2024-02-08 00:04:14 +00:00
Benoît du Garreau
0a42a540c6 Make io::BorrowedCursor::advance safe
This also keeps the old `advance` method under `advance_unchecked` name.

This makes pattern like `std::io::default_read_buf` safe to write.
2024-02-07 16:46:28 +01:00
Chris Denton
be9ac5632c
Make cmath.rs a single file 2024-02-07 12:02:24 -03:00
Markus Reiter
5d65418e73
Replace transmute_copy with ptr::read. 2024-02-07 16:01:58 +01:00
Markus Reiter
af48cf63ee
Don't use assert_unsafe_precondition twice. 2024-02-07 16:01:58 +01:00
bors
0809f78c19 Auto merge of #120527 - GnomedDev:atomicu32-handle, r=petrochenkov
Switch OwnedStore handle count to AtomicU32

This is already panics if overflowing a u32, so let's use the smaller int size to save a tiny bit of memory.
2024-02-07 11:57:50 +00:00
Markus Reiter
a67b72c74e
Make NonZero constructors generic. 2024-02-07 12:47:49 +01:00
Markus Reiter
58d70d6805
Simplify impl_zeroable_primitive macro. 2024-02-07 12:47:48 +01:00
r0cky
c7519d42c2 Update tests 2024-02-07 10:42:01 +08:00
bors
256b6fb19a Auto merge of #117905 - RalfJung:no-const-mut, r=lcnr
revert stabilization of const_intrinsic_copy

`@rust-lang/wg-const-eval`  I don't know what we were thinking when we approved https://github.com/rust-lang/rust/pull/97276... const-eval isn't supposed to be able to mutate anything yet! It's also near impossible to actually call `copy` in const on stable since `&mut` expressions are generally unstable. However, there's one exception...

```rust
static mut INT: i32 = unsafe {
    let val = &mut [1]; // `&mut` on arrays is allowed in `static mut`
    (val as *mut [i32; 1]).copy_from(&[42], 1);
    val[0]
};

fn main() { unsafe {
    dbg!(INT);
} }
```

Inside `static mut`, we accept some `&mut` since ~forever, to make `static mut FOO: &mut [T] = &mut [...];` work. We reject any attempt to actually write to that mutable reference though... except for the `copy` functions.

I think we should revert stabilizing these functions that take `*mut`, and then re-stabilize them together with `ptr.write` once mutable references are stable.

(This will likely fail on PowerPC until https://github.com/rust-lang/stdarch/pull/1497 lands. But we'll need a crater run first anyway.)
2024-02-06 21:43:11 +00:00
Michael Goulet
0dd40786b5 Harmonize blanket implementations for AsyncFn* traits 2024-02-06 17:20:40 +00:00
bors
4a2fe4491e Auto merge of #120361 - compiler-errors:async-closures, r=oli-obk
Rework support for async closures; allow them to return futures that borrow from the closure's captures

This PR implements a new lowering for async closures via `TyKind::CoroutineClosure` which handles the curious relationship between the closure and the coroutine that it returns.

I wrote up a bunch in [this hackmd](https://hackmd.io/`@compiler-errors/S1HvqQxca)` which will be copied to the dev guide after this PR lands, and hopefully left sufficient comments in the source code explaining why this change is as large as it is.

This also necessitates that they begin implementing the `AsyncFn`-family of traits, rather than the `Fn`-family of traits -- if you need `Fn` implementations, you should probably use the non-sugar `|| async {}` syntax instead.

Notably this PR does not yet implement `async Fn()` syntax sugar for bounds, but I expect to add those soon (**edit:** #120392). For now, users must use `AsyncFn()` traits directly, which necessitates adding the `async_fn_traits` feature gate as well. I will add this as a follow-up very soon.

r? oli-obk

This is based on top of #120322, but that PR is minimal.
2024-02-06 15:04:01 +00:00
bors
ff95e52665 Auto merge of #120326 - tmandry:abort-in-tests, r=cuviper
Actually abort in -Zpanic-abort-tests

When a test fails in panic=abort, it can be useful to have a debugger or other tooling hook into the `abort()` call for debugging. Doing this some other way would require it to hard code details of Rust's panic machinery.

There's no reason we couldn't have done this in the first place; using a single exit code for "success" or "failed" was just simpler. Now we are aware of the special exit codes for posix and windows platforms, logging a special error if an unrecognized code is used on those platforms, and falling back to just "failure" on other platforms.

This continues to account for `#[should_panic]` inside the test process itself, so there's no risk of misinterpreting a random call to `abort()` as an expected panic. Any exit code besides `TR_OK` is logged as a test failure.

As an added benefit, this would allow us to support panic=immediate_abort (but not `#[should_panic]`), without noise about unexpected exit codes when a test fails.
2024-02-06 04:15:41 +00:00
Michael Goulet
881b6b5149 Bless tests, add comments 2024-02-06 02:22:58 +00:00
Michael Goulet
a82bae2172 Teach typeck/borrowck/solvers how to deal with async closures 2024-02-06 02:22:58 +00:00
Ralf Jung
0184ca695b revert stabilization of const_intrinsic_copy 2024-02-05 20:58:31 +01:00
bors
ea37e8091f Auto merge of #117372 - Amanieu:stdarch_update, r=Mark-Simulacrum
Update stdarch submodule

Splits up #27731 into multiple tracking issues.

Closes #27731
2024-02-05 15:41:40 +00:00
Lawrence Tang
1ecb08409d Add support for custom JSON targets when using build-std.
Currently, when building with `build-std`, some library build scripts
check properties of the target by inspecting the target triple at
`env::TARGET`, which is simply set to the filename of the JSON file
when using JSON target files.

This patch alters these build scripts to use `env::CARGO_CFG_*` to
fetch target information instead, allowing JSON target files
describing platforms without `restricted_std` to build correctly when
using `-Z build-std`.

Fixes wg-cargo-std-aware/#60.
2024-02-05 10:20:42 +00:00
Oli Scherer
a59a1e7c2c Remove some invalid cfg(doc) code 2024-02-05 10:17:35 +00:00
Matthias Krüger
13ea09b22f
Rollup merge of #120657 - mu001999:clean, r=Nilstrieb
Remove unused struct

Detected by #118257
2024-02-05 11:07:28 +01:00
Matthias Krüger
2624bfbc0d
Rollup merge of #120384 - wackbyte:array-equality-generics, r=Mark-Simulacrum
Use `<T, U>` for array/slice equality `impl`s

Makes the trait implementation documentation for arrays and slices appear more consistent.

[Example](https://doc.rust-lang.org/1.75.0/std/primitive.array.html): mixed `A`, `B`, and `U`.
![List of PartialEq implementations for arrays](https://github.com/wackbyte/rust/assets/29505620/823c010e-ee57-4de1-885b-a1cd6dcaf85f)

This change makes them all `U`.
2024-02-05 11:07:27 +01:00
Matthias Krüger
80e8c7e125
Rollup merge of #118960 - tvallotton:local_waker, r=Mark-Simulacrum
Add LocalWaker and ContextBuilder types to core, and LocalWake trait to alloc.

Implementation for  #118959.
2024-02-05 11:07:26 +01:00
Matthias Krüger
fd8ea25882
Rollup merge of #115386 - RalfJung:partial-eq-chain, r=dtolnay
PartialEq, PartialOrd: update and synchronize handling of transitive chains

It was brought up in https://internals.rust-lang.org/t/total-equality-relations-as-std-eq-rhs/19232 that we currently have a gap in our `PartialEq` rules, which this PR aims to close:

> For example, with PartialEq's conditions you may have a = b = c = d ≠ a (where a and c are of type A, b and d are of type B).

The second commit fixes https://github.com/rust-lang/rust/issues/87067 by updating PartialOrd to handle the requirements the same way PartialEq does.
2024-02-05 11:07:25 +01:00
Matthias Krüger
13e84f2a3d
Rollup merge of #113833 - WiktorPrzetacznik:master, r=dtolnay
`std::error::Error` -> Trait Implementations: lifetimes consistency improvement

This cleans up `std::error::Error` trait implementations lifetime inconsistency (`'static` -> `'a`)

**Reasoning:**

Trait implementations for `std::error::Error`, like:
`impl From<&str> for Box<dyn Error + 'static, Global>`
`impl<'a> From<&str> for Box<dyn Error + Sync + Send + 'a, Global>`
use different lifetime annotations misleadingly implying using different life annotations here is a conscious, nonaccidental decision.

[(Related forum discussion here)](https://users.rust-lang.org/t/confusing-std-error-source-code/97011/5?u=wiktor)
2024-02-05 11:07:25 +01:00
Matthias Krüger
d8e9ddc843
Rollup merge of #120607 - conradludgate:fix-120603, r=dtolnay
fix #120603 by adding a check in default_read_buf

Fixes #120603 by checking the returned read n is in-bounds of the cursor.

Interestingly, I noticed that `BorrowedBuf` side-steps this issue by using checked accesses. Maybe this can be switched to unchecked to mirror what BufReader does bf3c6c5bed/library/core/src/io/borrowed_buf.rs (L95)
2024-02-05 06:37:16 +01:00
Matthias Krüger
16200db7aa
Rollup merge of #120572 - pheki:update-libc, r=Mark-Simulacrum
Update libc to 0.2.153

Bumps libc dependency to 0.2.153, which includes this fix, required for building std for the vita: https://github.com/rust-lang/libc/pull/3552
2024-02-05 06:37:15 +01:00
Matthias Krüger
9838e943f3
Rollup merge of #120458 - rytheo:cstr-conversion-doc, r=Mark-Simulacrum
Document `&CStr` to `CString` conversion

Related to #51430
2024-02-05 06:37:14 +01:00
Matthias Krüger
7158b3d3fb
Rollup merge of #119481 - romanows:fix-doc-select-nth-unstable, r=Mark-Simulacrum
Clarify ambiguity in select_nth_unstable docs

Original docs for `select_nth_unstable` family of functions were ambiguous as to whether "the element at `index`" was the element at `index` before the function reordered the elements or after the function reordered the elements.

The most helpful change in this PR is to change the given examples to make this absolutely clear.  Before, "the element at `index`" was the same value before and after the reordering, so it didn't help disambiguate the meaning.  I've changed the example for `select_nth_unstable` and `select_nth_unstable_by` so that "the element at `index`" is different before and after the reordering, which clears up the ambiguity.  The function `select_nth_unstable_by_key` already had an example that was unambiguous.

In an attempt to clear up the ambiguity from the get-go, I've added a bit of redundancy to the text.  Now the docs refer to "the element at `index` *after the reordering*".
2024-02-05 06:37:13 +01:00
r0cky
8266657338 Remove unused struct 2024-02-05 10:04:36 +08:00
bors
268dbbbc4b Auto merge of #120624 - matthiaskrgr:rollup-3gvcl20, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #120484 (Avoid ICE when is_val_statically_known is not of a supported type)
 - #120516 (pattern_analysis: cleanup manual impls)
 - #120517 (never patterns: It is correct to lower `!` to `_`.)
 - #120523 (Improve `io::Read::read_buf_exact` error case)
 - #120528 (Store SHOULD_CAPTURE as AtomicU8)
 - #120529 (Update data layouts in custom target tests for LLVM 18)
 - #120531 (Remove a bunch of `has_errors` checks that have no meaningful or the wrong effect)
 - #120533 (Correct paths for hexagon-unknown-none-elf platform doc)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-04 20:51:28 +00:00
Ryan Lowe
5a74532aa1 Document various I/O handle conversions 2024-02-04 12:14:53 -05:00
Deadbeef
c9192be561 Reconstify Add 2024-02-04 11:30:59 +08:00
Matthias Krüger
3e24351677
Rollup merge of #120528 - GnomedDev:atomicu8-backtrace-style, r=cuviper
Store SHOULD_CAPTURE as AtomicU8

`BacktraceStyle` easily fits into a u8, so `SHOULD_CAPTURE`, which is just `Atomic<Option<BacktraceStyle>>`, should be stored as `AtomicU8`
2024-02-03 22:25:16 +01:00
Matthias Krüger
a3ea64719b
Rollup merge of #120523 - a1phyr:improve_read_buf_exact, r=the8472
Improve `io::Read::read_buf_exact` error case

- Use `const_io_error` instead of `Error::new`
- Use the same message as `read_exact`
2024-02-03 22:25:15 +01:00
Conrad Ludgate
4c694db252 add another test to make sure it still works with full reads 2024-02-03 11:46:54 +00:00
Conrad Ludgate
a27e45a71b fix #120603 by adding a check in default_read_buf 2024-02-03 11:30:26 +00:00
Ralf Jung
61d1ebe50b
fix typo
Co-authored-by: teor <teor@riseup.net>
2024-02-02 20:12:37 +01:00
Aphek
ee8703315e Update libc to 0.2.153 2024-02-01 23:58:42 -03:00
Oli Scherer
6ac035df44 Revert unsound libcore changes of #119911 2024-02-01 22:53:25 +00:00
Kornel
fee4992fb1 Make File::read_to_end less special
Follow-up to #117925
2024-01-31 23:27:05 +00:00
GnomedDev
7ea4dbbadb
Store SHOULD_CAPTURE as AtomicU8 2024-01-31 13:58:52 +00:00
GnomedDev
3cc601ac7e
Switch OwnedStore handle count to AtomicU32 2024-01-31 13:36:37 +00:00
Nadrieril
a7d5382e5c
Rollup merge of #120430 - devnexen:fix_tls_dtor_fbsd, r=cuviper
std: thread_local::register_dtor fix proposal for FreeBSD.

following-up 5d3d347 commit, rust started to spin
__cxa_thread_call_dtors warnings even without any TLS usage. using instead home made TLS destructor handler `register_dtor_fallback`.

close #120413
2024-01-31 12:10:51 +01:00
Nadrieril
03daaa6f07
Rollup merge of #120355 - the8472:doc-vec-fromiter, r=cuviper
document `FromIterator for Vec` allocation behaviors

[t-libs discussion](https://rust-lang.zulipchat.com/#narrow/stream/259402-t-libs.2Fmeetings/topic/Meeting.202024-01-24/near/417686526) about #120091 didn't reach a strong consensus, but it was agreed that if we keep the current behavior it should at least be documented even though it is an implementation detail.

The language is intentionally non-committal. The previous (non-existent) documentation permits a lot of implementation leeway and we want retain that. In some cases we even must retain it to be able to rip out some code paths that rely on unstable features.
2024-01-31 12:10:50 +01:00
Benoît du Garreau
a158fb33ef Improve io::Read::read_buf_exact error case
- Use `const_io_error` instead of `Error::new`
- Use the same message as `read_exact`
2024-01-31 11:06:19 +01:00
Tyler Mandry
f622e832d4 Actually abort in panic-abort-tests 2024-01-30 18:19:49 -08:00
the8472
39dc3153c5 Apply suggestions from code review
Co-authored-by: Josh Stone <cuviper@gmail.com>
2024-01-30 22:37:07 +01:00
The 8472
c780fe6b27 document FromIterator for Vec allocation behaviors 2024-01-30 22:37:07 +01:00
Amanieu d'Antras
adb7607189 Fix BTreeMap's Cursor::remove_{next,prev}
These would incorrectly leave `current` as `None` after a failed attempt
to remove an element (due to the cursor already being at the start/end).
2024-01-30 17:51:20 +00:00
Guillaume Gomez
27bc496564
Rollup merge of #120485 - chenyukang:yukang-add-query-instability-check, r=michaelwoerister
add missing potential_query_instability for keys and values in hashmap

From https://github.com/rust-lang/rust/pull/120435#discussion_r1468883787,

These API are also returning iterator, so we need add `potential_query_instability` for them?
2024-01-30 16:57:51 +01:00
Guillaume Gomez
a5aa355ab3
Rollup merge of #120445 - Nemo157:arc-plug, r=Mark-Simulacrum
Fix some `Arc` allocator leaks

This doesn't matter for the stable `Global` allocator as it is a ZST singleton, but other allocators may rely on all instances being dropped.
2024-01-30 16:57:50 +01:00
Guillaume Gomez
d10f33a8d1
Rollup merge of #120434 - fmease:revert-speeder, r=petrochenkov
Revert outdated version of "Add the wasm32-wasi-preview2 target"

An outdated version of #119616 was merged in rollup #120309.
This reverts those changes to enable #119616 to “retain the intended diff” after a rebase.
```@rylev``` has agreed that this would be the cleanest approach with respect to the history.
Unblocks #119616.

r? ```@petrochenkov``` or compiler or libs
2024-01-30 16:57:49 +01:00
Guillaume Gomez
4f4ceefe16
Rollup merge of #120295 - reitermarkus:remove-ffi-nonzero, r=dtolnay
Remove `raw_os_nonzero` feature.

This feature is superseded by a generic `NonZero` type: https://github.com/rust-lang/rust/issues/120257

Closes https://github.com/rust-lang/rust/issues/82363.
2024-01-30 16:57:48 +01:00
Guillaume Gomez
d5e8d85249
Rollup merge of #120452 - alexcrichton:update-windows-seek-write-docs, r=ChrisDenton
std: Update documentation of seek_write on Windows

Currently the documentation of `FileExt::seek_write` on Windows indicates that writes beyond the end of the file leave intermediate bytes uninitialized. This commentary dates back to the original inclusion of these functions in #35704 (wow blast from the past!). At the time the functionality here was implemented using `WriteFile`, but nowadays the `NtWriteFile` method is used instead. The documentation for `NtWriteFile` explicitly states:

> If Length and ByteOffset specify a write operation past the current
> end-of-file mark, NtWriteFile automatically extends the file and updates
> the end-of-file mark; any bytes that are not explicitly written between
> such old and new end-of-file marks are defined to be zero.

This commentary has had a downstream impact in the `system-interface` crate where it tries to handle this by explicitly writing zeros, but I don't believe that's necessary any more. I'm sending a PR upstream here to avoid future confusion and codify that zeros are written in the intermediate bytes matching what Windows currently provides.
2024-01-30 11:19:18 +01:00
Guillaume Gomez
6e046fef29
Rollup merge of #120424 - RalfJung:raw-ptr-meta, r=Nilstrieb
raw pointer metadata API: data address -> data pointer

A pointer consists of [more than just an address](https://github.com/rust-lang/rfcs/pull/3559), so let's not equate "pointer" and "address" in these docs.
2024-01-30 11:19:16 +01:00
Guillaume Gomez
5db58538cf
Rollup merge of #119991 - kornelski:endless-read, r=the8472
Reject infinitely-sized reads from io::Repeat

These calls would always run out of memory.

Related to #117925
2024-01-30 11:19:12 +01:00
bors
5c9c3c7871 Auto merge of #117925 - kornelski:read-to-oom, r=Amanieu
Handle out of memory errors in io:Read::read_to_end()

#116570 got stuck due to a [procedural confusion](https://github.com/rust-lang/rust/pull/116570#issuecomment-1768271068). Retrying so that it can get FCP with the proper team now. cc `@joshtriplett` `@BurntSushi`

----

I'd like to propose handling of out-of-memory errors in the default implementation of `io::Read::read_to_end()` and `fs::read()`. These methods create/grow a `Vec` with a size that is external to the program, and could be arbitrarily large.

Due to being I/O methods, they can already fail in a variety of ways, in theory even including `ENOMEM` from the OS too, so another failure case should not surprise anyone.

While this may not help much Linux with overcommit, it's useful for other platforms like WASM. [Internals thread](https://internals.rust-lang.org/t/io-read-read-to-end-should-handle-oom/19662).

I've added documentation that makes it explicit that the OOM handling is a nice-to-have, and not a guarantee of the trait.

I haven't changed the implementation of `impl Read for &[u8]` and `VecDeque` out of caution, because in these cases users could assume `read` can't fail.

This code uses `try_reserve()` + `extend_from_slice()` which is optimized since #117503.
2024-01-30 05:10:11 +00:00
Amanieu d'Antras
ab8b661667 Disable conversions between portable_simd and stdarch on big-endian ARM
stdarch no longer provide SIMD on big-endian ARM due to
https://github.com/rust-lang/stdarch/issues/1484
2024-01-30 04:47:01 +00:00
yukang
ad526d831e add missing potential_query_instability for keys and values in hashmap 2024-01-30 12:43:10 +08:00
Amanieu d'Antras
31007f51ed Add stdarch_wasm_atomic_wait feature in std 2024-01-30 03:34:30 +00:00
Amanieu d'Antras
9a39e41637 Update feature names for new stdarch 2024-01-30 03:33:12 +00:00
Amanieu d'Antras
f8d4b2a150 Update stdarch submodule 2024-01-30 03:33:12 +00:00
Kornel
60f46289cf Handle out of memory errors in fs::read/read_to_string 2024-01-29 23:53:45 +00:00
Kornel
03545161e6 Handle out of memory errors in io:Read::read_to_end() 2024-01-29 23:53:09 +00:00
Markus Reiter
bf4de3a874
Remove raw_os_nonzero feature. 2024-01-29 22:02:11 +01:00
joboet
1df1ebf6ad
std: always check the result of pthread_mutex_lock 2024-01-29 19:24:26 +01:00