Commit graph

10911 commits

Author SHA1 Message Date
Matthias Krüger fbc121fdfd
Rollup merge of #104363 - WaffleLapkin:bonk_box_new, r=Nilstrieb
Make `unused_allocation` lint against `Box::new` too

Previously it only linted against `box` syntax, which likely won't ever be stabilized, which is pretty useless. Even now I'm not sure if it's a meaningful lint, but it's at least something 🤷

This means that code like the following will be linted against:
```rust
Box::new([1, 2, 3]).len();
f(&Box::new(1)); // where f : &i32 -> ()
```
The lint works by checking if a `Box::new` (or `box`) expression has an a borrow adjustment, meaning that the code that first stores the box in a variable won't be linted against:
```rust
let boxed = Box::new([1, 2, 3]); // no lint
boxed.len();
```
2023-03-11 15:43:11 +01:00
Matthias Krüger 5e52ada714
Rollup merge of #108927 - Ayush1325:pal-cleanup, r=workingjubilee
Move __thread_local_inner to sys

Move `__thread_local_inner` macro in `crate:🧵:local` to `crate::sys`. Initially, I was thinking about removing this macro completely, but I could not find a way to create the generic statics without macros, so in the end, I just moved to code around.

This probably will need a rebase once https://github.com/rust-lang/rust/pull/108917 is merged

r? ``@workingjubilee``
2023-03-11 12:55:43 +01:00
Matthias Krüger 790d9f349b
Rollup merge of #106276 - Sp00ph:unify_slice_ranges, r=the8472
Fix `vec_deque::Drain` FIXME

In my original `VecDeque` rewrite, I didn't use `VecDeque::slice_ranges` in `Drain::as_slices`, even though that's basically the exact use case for `slice_ranges`. The reason for this was that a `VecDeque` wrapped in a `Drain` actually has its length set to `drain_start`, so that there's no potential use after free if you `mem::forget` the `Drain`. I modified `slice_ranges` to accept an explicit `len` parameter instead, which it now uses to bounds check the given range. This way, `Drain::as_slices` can use `slice_ranges` internally instead of having to basically just copy paste the `slice_ranges` code. Since `slice_ranges` is just an internal helper function, this shouldn't change the user facing behavior in any way.
2023-03-11 12:55:41 +01:00
bors e350fe4e60 Auto merge of #109001 - matthiaskrgr:rollup-a3agnwp, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #105798 (Relax ordering rules for `asm!` operands)
 - #105962 (Stabilize path_as_mut_os_str)
 - #106085 (use problem matchers for tidy CI)
 - #107711 (Stabilize movbe target feature)
 - #108017 (Add `--no-undefined-version` link flag and fix associated breakage)
 - #108891 (Remove an extraneous include)
 - #108902 (no more do while :<)
 - #108912 (Document tool lints)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-11 07:28:44 +00:00
Matthias Krüger a69a9b3038
Rollup merge of #105962 - zertosh:stabilize_path_as_mut_os_str, r=dtolnay
Stabilize path_as_mut_os_str

Closes #105021

r? ```@dtolnay```
2023-03-10 21:15:43 +01:00
Matthias Krüger b90277e37b
Rollup merge of #106921 - madsmtm:cell-memory-layout, r=dtolnay
Add documentation about the memory layout of `Cell`

https://github.com/rust-lang/rust/pull/101717 guaranteed the memory layout of `UnsafeCell<T>`.

This property (a guaranteed memory layout) can be useful to have on `Cell<T>` as well.

(Note that `Cell<u8>` [already doesn't trigger the `improper_ctypes` lint](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=34af59ef60b96d8a8bdaec1d52cb5420) since it is `#[repr(transparent)]`).

The concrete use-case is for the crate [`objc2`](https://github.com/madsmtm/objc2) to specify that `Cell<T>` is safe to use as an instance variable when `T` is.

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

---

I'm unsure if we should specify less, for example say that the `Cell` may have extra restrictions on when it may be accessed, or if that's implicit in the (deliberately minimal) way I've worded it here?
2023-03-10 19:59:17 +01:00
Ayush Singh 5828910ff4
Moved thread_local implementation to sys::common
This allows removing all the platform-dependent code from `library/std/src/thread/local.rs` and `library/std/src/thread/mod.rs`

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-03-10 23:25:32 +05:30
Ayush Singh 45d50216a9
Split __thread_local_inner macro
Split the __thread_local_inner macro to make it more readable. Also move
everything to crate::sys::common::thread_local.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-03-10 17:35:24 +05:30
Ayush Singh ffa9019134
Move __thread_local_inner to sys
Move __thread_local_inner macro in crate:🧵:local to crate::sys.
Currently, the tidy check does not fail for `library/std/src/thread/local.rs` even though it contains platform specific code. This is beacause target_family did not exist at the time the tidy checks were written [1].

[1]: https://github.com/rust-lang/rust/pull/105861#discussion_r1125841678

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-03-10 17:35:24 +05:30
Matthias Krüger df74b70b9e
Rollup merge of #108964 - majaha:ptr_metadata_doc, r=workingjubilee
Fix the docs for pointer method with_metadata_of

The name of the argument to `{*const T, *mut T}::with_metadata_of` was changed from `val` to `meta` recently, but the docs weren't updated to match.

Relevant pull request: #103701
2023-03-10 12:32:02 +01:00
Matthias Krüger 65db3cb794
Rollup merge of #108956 - Raekye:master, r=scottmcm
Make ptr::from_ref and ptr::from_mut in #106116 const.

As per https://github.com/rust-lang/rust/issues/106116#issuecomment-1462571833
2023-03-10 12:32:01 +01:00
Matt Harding ccb552e4f5 Fix docs for ptr method with_metadata_of() 2023-03-10 02:14:09 +00:00
Raekye e8fbf6205e Make ptr::from_ref and ptr::from_mut in #106116 const. 2023-03-09 16:36:20 -05:00
bmoxb b439189236 Add examples section which demonstrates the behaviour (specifically the sign positive aspect) 2023-03-09 20:44:11 +00:00
bmoxb 8d2bdb89c6 Add missing comment for f64 2023-03-09 20:37:04 +00:00
bmoxb 73016bb8d4 Indicate that 0.0 refers to positive 0.0 2023-03-09 20:36:29 +00:00
bmoxb d5bb6056f1 Document the resulting values produced when using From<bool> on floats 2023-03-09 18:55:33 +00:00
bors 39f2657d11 Auto merge of #108920 - matthiaskrgr:rollup-qrr9a0u, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #108754 (Retry `pred_known_to_hold_modulo_regions` with fulfillment if ambiguous)
 - #108759 (1.41.1 supported 32-bit Apple targets)
 - #108839 (Canonicalize root var when making response from new solver)
 - #108856 (Remove DropAndReplace terminator)
 - #108882 (Tweak E0740)
 - #108898 (Set `LIBC_CHECK_CFG=1` when building Rust code in bootstrap)
 - #108911 (Improve rustdoc-gui/tester.js code a bit)
 - #108916 (Remove an unused return value in `rustc_hir_typeck`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-09 08:21:17 +00:00
Tomasz Miąsko 7c75e39790 panic_immediate_abort requires abort as a panic strategy
Guide `panic_immediate_abort` users away from `-Cpanic=unwind` and
towards `-Cpanic=abort` to avoid an accidental use of the feature with
the unwind strategy, e.g., on a targets where unwind is the default.

The `-Cpanic=unwind` combination doesn't offer the same benefits, since
the code would still be generated under the assumption that functions
implemented in Rust can unwind.
2023-03-08 22:32:15 +01:00
Matthias Krüger 4e84fbf8a0
Rollup merge of #108856 - Zeegomo:remove-drop-and-rep, r=tmiasko
Remove DropAndReplace terminator

#107844 made DropAndReplace unused, let's remove it completely from the codebase.
2023-03-08 21:26:51 +01:00
Arpad Borsos 9f03cfc207
Remove identity_future indirection
This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]` annotation.
2023-03-08 15:37:14 +01:00
Michael Goulet a439c0293c may not => cannot 2023-03-08 00:00:18 +00:00
Giacomo Pasini c5d4e4d907
Remove DropAndReplace terminator
PR 107844 made DropAndReplace unused, let's remove it completely
from the codebase.
2023-03-07 14:25:22 +01:00
bors 160c2ebeca Auto merge of #108763 - scottmcm:indexing-nuw-lengths, r=cuviper
Use `nuw` when calculating slice lengths from `Range`s

An `assume` would definitely not be worth it, but since the flag is almost free we might as well tell LLVM this, especially on `_unchecked` calls where there's no obvious way for it to deduce it.

(Today neither safe nor unsafe indexing gets it: <https://rust.godbolt.org/z/G1jYT548s>)
2023-03-07 13:17:59 +00:00
bors 0a3b557d52 Auto merge of #95317 - Jules-Bertholet:round_ties_to_even, r=pnkfelix,m-ou-se,scottmcm
Add `round_ties_even` to `f32` and `f64`

Tracking issue: #96710

Redux of #82273. See also #55107

Adds a new method, `round_ties_even`, to `f32` and `f64`, that rounds the float to the nearest integer , rounding halfway cases to the number with an even least significant bit. Uses the `roundeven` LLVM intrinsic to do this.

Of the five IEEE 754 rounding modes, this is the only one that doesn't already have a round-to-integer function exposed by Rust (others are `round`, `floor`, `ceil`, and `trunc`).  Ties-to-even is also the rounding mode used for int-to-float and float-to-float `as` casts, as well as float arithmentic operations. So not having an explicit rounding method for it seems like an oversight.

Bikeshed: this PR currently uses `round_ties_even` for the name of the method. But maybe `round_ties_to_even` is better, or `round_even`, or `round_to_even`?
2023-03-07 09:43:12 +00:00
Konrad Borowski dfe4c49e9b Use Edition 2021 :pat in matches macro
This makes the macro syntax used in documentation more readable.
2023-03-06 21:21:06 +01:00
Noam Ta Shma 620544e0ba issue-108706-fix 2023-03-06 21:51:50 +02:00
Tomasz Miąsko defa245624 Implement read_buf for a few more types
Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout,
ChildStderr (and internally for AnonPipe, Handle, Socket), so
that it skips buffer initialization.

The other provided methods like read_to_string and read_to_end are
implemented in terms of read_buf and so benefit from the optimization
as well.

This commit also implements read_vectored and is_read_vectored where
applicable.
2023-03-06 12:24:15 +01:00
Scott McMurray 3554036280 Use nuw when calculating slice lengths from Ranges
An `assume` would definitely not be worth it, but since the flag is almost free we might as well tell LLVM this, especially on `_unchecked` calls where there's no obvious way for it to deduce it.

(Today neither safe nor unsafe indexing gets it: <https://rust.godbolt.org/z/G1jYT548s>)
2023-03-05 15:15:22 -08:00
bors 816f958ac3 Auto merge of #108157 - scottmcm:tuple-gt-via-partialcmp, r=dtolnay
Use `partial_cmp` to implement tuple `lt`/`le`/`ge`/`gt`

In today's implementation, `(A, B)::gt` contains calls to *both* `A::eq` *and* `A::gt`.

That's fine for primitives, but for things like `String`s it's kinda weird -- `(String, usize)::gt` has a call to both `bcmp` and `memcmp` (<https://rust.godbolt.org/z/7jbbPMesf>) because when `bcmp` says the `String`s aren't equal, it turns around and calls `memcmp` to find out which one's bigger.

This PR changes the implementation to instead implement `(A, …, C, Z)::gt` using `A::partial_cmp`, `…::partial_cmp`, `C::partial_cmp`, and `Z::gt`.  (And analogously for `lt`, `le`, and `ge`.)  That way expensive comparisons don't need to be repeated.

Technically this is an observable change on stable, so I've marked it `needs-fcp` + `T-libs-api` and will
r? rust-lang/libs-api

I'm hoping that this will be non-controversial, however, since it's very similar to the observable changes that were made to the derives (#81384 #98655) -- like those, this only changes behaviour if a type overrode behaviour in a way inconsistent with the rules for the various traits involved.

(The first commit here is #108156, adding the codegen test, which I used to make sure this doesn't regress behaviour for primitives.)

Zulip conversation about this change: <https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60.3E.60.20on.20Tuples/near/328392927>.
2023-03-05 22:02:26 +00:00
bors 7820b62d20 Auto merge of #105117 - pitaj:debug_asserts, r=the8472
Add more debug assertions to unsafe functions

related to #51713
2023-03-05 19:35:44 +00:00
Peter Jaszkowiak cd35794d5e Comment for why char boundaries aren't checked 2023-03-04 15:11:24 -07:00
Dylan DPC e700d02374
Rollup merge of #108660 - xfix:remove-ne-method-from-str, r=thomcc
Remove ne implementations from strings

As far as I can tell, there isn't really a reason for those.
2023-03-04 15:24:39 +05:30
bors 0fbfc3e769 Auto merge of #89518 - a1phyr:unix_file_vectored_at, r=workingjubilee
Add vectored positioned I/O on Unix

Add methods for vectored I/O with an offset on `File` for `unix` under `#![feature(unix_file_vectored_at)]`.

The new methods are wrappers around `preadv` and `pwritev`.

Tracking issue: #89517
2023-03-04 05:26:35 +00:00
Tobias Decking db2c6e0385 Update comment. 2023-03-04 00:31:17 +01:00
Tobias Decking dd45f01411 typo 2023-03-04 00:23:50 +01:00
Tobias Decking b69de64202 Add inlining annotations 2023-03-04 00:10:52 +01:00
Matthias Krüger 7a228ce9a6
Rollup merge of #108688 - est31:backticks_matchmaking_library, r=jyn514
Match unmatched backticks in library/

Found with GNU grep:

```
grep -rEn '^(([^`]*`){2})*[^`]*`[^`]*$' library/ | rg -v '\s*[//]?.{1,2}```'
```

split out from #108685 as per advice.
2023-03-03 20:45:03 +01:00
Matthias Krüger 041f6668b5
Rollup merge of #108540 - WaffleLapkin:atomic_thingy_from_thingy_pointer, r=m-ou-se
Add `Atomic*::from_ptr`

This PR adds functions in the following form to all atomic types:
```rust
impl AtomicT {
    pub const unsafe fn from_ptr<'a>(ptr: *mut T) -> &'a AtomicT;
}
```
r? `@m-ou-se` (we've talked about it before)

I'm not sure about docs & safety requirements, I'd appreciate some feedback on them.
2023-03-03 20:45:00 +01:00
Maybe Waffle 7f5338a122 fix an alloc test 2023-03-03 17:47:48 +00:00
Maybe Waffle 9ac0da8f39 Make unused_allocation lint warn against Box::new 2023-03-03 12:02:55 +00:00
Benoît du Garreau 92f35b32b2 Use weak linkage for preadv and pwritev on MacOS and iOS 2023-03-03 10:40:10 +01:00
est31 999405059c Match unmatched backticks in library/ 2023-03-03 03:03:29 +01:00
Konrad Borowski e248d0c837 Remove manual implementation of String::ne 2023-03-02 16:32:23 +01:00
Konrad Borowski bc3f6542f3 Remove manual implementation of str::ne 2023-03-02 16:32:04 +01:00
Léo Lanteri Thauvin bfe5189904 Revert "Stabilize #![feature(target_feature_11)]"
This reverts commit b379d216ee.
2023-03-02 13:41:17 +01:00
Maybe Waffle a2baba09a2 Fill-in tracking issue for feature("atomic_from_ptr") 2023-03-02 12:00:26 +00:00
Benoît du Garreau 23cd4cee05 Add basic tests 2023-03-02 11:51:20 +01:00
Benoît du Garreau 1e63f08c85 Take shared references as parameter 2023-03-02 11:50:27 +01:00
Benoît du Garreau 2fc23c2dfe Use weak linkage on Android 2023-03-02 11:12:24 +01:00
bors 864b6258fc Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubilee
Add support for QNX Neutrino to standard library

This change:

- adds standard library support for QNX Neutrino (7.1).
- upgrades `libc` to version `0.2.139` which supports QNX Neutrino

`@gh-tr`

⚠️ Backtraces on QNX require https://github.com/rust-lang/backtrace-rs/pull/507 which is not yet merged! (But everything else works without these changes) ⚠️

Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
2023-03-02 02:41:42 +00:00
bors 0b4ba4cf0e Auto merge of #108483 - scottmcm:unify-bytewise-eq-traits, r=the8472
Merge two different equality specialization traits in `core`

Arrays and slices each had their own version of this, without a matching set of `impl`s.

Merge them into one (still-`pub(crate)`) `cmp::BytewiseEq` trait, so we can stop doing all these things twice.

And that means that the `[T]::eq` → `memcmp` specialization picks up a bunch of types where that previously only worked for arrays, so examples like <https://rust.godbolt.org/z/KjsG8MGGT> will use it now instead of emitting loops.

r? the8472
2023-03-01 23:34:37 +00:00
Scott McMurray 44eec1d9b0 Merge two different equality specialization traits in core 2023-03-01 14:42:06 -08:00
Dylan DPC 093a53f134
Rollup merge of #108462 - pommicket:fix-vecdeque-zst-overflow, r=Amanieu
Fix `VecDeque::append` capacity overflow for ZSTs

Fixes #108454.
2023-03-01 23:40:20 +05:30
bors 5423745db8 Auto merge of #105871 - llogiq:option-as-slice, r=scottmcm
Add `Option::as_`(`mut_`)`slice`

This adds the following functions:

* `Option<T>::as_slice(&self) -> &[T]`
* `Option<T>::as_mut_slice(&mut self) -> &[T]`

The `as_slice` and `as_mut_slice_mut` functions benefit from an optimization that makes them completely branch-free. ~~Unfortunately, this optimization is not available on by-value Options, therefore the `into_slice` implementations use the plain `match` + `slice::from_ref` approach.~~

Note that the optimization's soundness hinges on the fact that either the niche optimization makes the offset of the `Some(_)` contents zero or the mempory layout of `Option<T>` is equal to that of `Option<MaybeUninit<T>>`.

The idea has been discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Option.3A.3Aas_slice). Notably the idea for the `as_slice_mut` and `into_slice´ methods came from `@cuviper` and `@Sp00ph` hardened the optimization against niche-optimized Options.

The [rust playground](https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=74f8e4239a19f454c183aaf7b4a969e0) shows that the generated assembly of the optimized method is basically only a copy while the naive method generates code containing a `test dx, dx` on x86_64.

---

EDIT from reviewer: ACP is https://github.com/rust-lang/libs-team/issues/150
2023-03-01 12:32:57 +00:00
bors 64165aac68 Auto merge of #108476 - saethlin:remove-library-rustc-box, r=thomcc
Remove or document uses of #[rustc_box] in library

r? `@thomcc`

Only one of these uses is tested for in the rustc-perf benchmark suite. The impact there on compile time is somewhat dramatic, but I am inclined to make this change as a simplification to the library and wait for people to complain if it explodes their compilation time. I think in the absence of data or reports from users about what code paths really matter, if we are optimizing for compilation time, it's hard to argue against using `#[rustc_box]` everywhere we currently call `Box::new`.
2023-03-01 09:13:23 +00:00
Florian Bartels a510715749
Update library/std/src/os/nto/mod.rs
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2023-03-01 06:42:40 +01:00
Matthias Krüger 3abc41a45c
Rollup merge of #108558 - RalfJung:core-tests, r=thomcc
add missing feature in core/tests

https://github.com/rust-lang/rust/pull/104265 introduced the `ip_in_core` feature. For some reason core tests seem to still build without that feature -- no idea how that is possible. Might be related to https://github.com/rust-lang/rust/issues/15702? I was under the impression that `pub use` with different stability doesn't actually work. That's why `intrinsics::transmute` is stable, for example.

Either way, core tests fail to build in miri-test-libstd, and adding the feature fixes that.

r? ```@thomcc```
2023-03-01 01:20:26 +01:00
Matthias Krüger 24551850a9
Rollup merge of #108531 - Coca162:rustdoc-repeat-const-array, r=thomcc
rustdoc: Show that repeated expression arrays can be made with constant values

The [rust reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) currently says that repeated values for arrays can be constant or `Copy`
> repeat operand is [Copy](https://doc.rust-lang.org/reference/special-types-and-traits.html#copy) or that it must be a [path](https://doc.rust-lang.org/reference/expressions/path-expr.html) to a constant item

This updates the rust documentation on primitive arrays to reflect what the rust reference says (and also compiler suggestions if you do not use a `const` item)
2023-03-01 01:20:23 +01:00
Andre Bogus 41da875fae Add Option::as_slice(_mut)
This adds the following functions:

* `Option<T>::as_slice(&self) -> &[T]`
* `Option<T>::as_slice_mut(&mut self) -> &[T]`

The `as_slice` and `as_slice_mut` functions benefit from an
optimization that makes them completely branch-free.

Note that the optimization's soundness hinges on the fact that either
the niche optimization makes the offset of the `Some(_)` contents zero
or the mempory layout of `Option<T>` is equal to that of
`Option<MaybeUninit<T>>`.
2023-03-01 00:05:31 +01:00
The 8472 e44836faf6 relax bounds on iterator adapter Default impls 2023-02-28 21:16:33 +01:00
The 8472 a4bdfe24c5 Support allocators in various Default for IntoIter impls
Global implements Default so we can use that as bound for all allocators
2023-02-28 21:00:01 +01:00
The 8472 2b32b315f9 rewrite iterator Default tests as doctests 2023-02-28 21:00:00 +01:00
The 8472 05c7330ca0 Implement Default for some alloc/core iterators
This way one can `mem::take()` them out of structs or #[derive(Default)] on structs containing them.

These changes will be insta-stable.
2023-02-28 21:00:00 +01:00
Florian Bartels cef9d4cbc1
Retry to spawn/fork up to 3 times when it failed because of an interruption 2023-02-28 15:59:53 +01:00
Florian Bartels 3ce2cd059f
Add QNX Neutrino support to libstd
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-28 15:59:47 +01:00
bors 31f858d9a5 Auto merge of #107987 - EFanZh:inline-poll-methods, r=Mark-Simulacrum
Inline `Poll` methods

With `opt-level="z"`, the `Poll::map*` methods are sometimes not inlined (see <https://godbolt.org/z/ca5ajKTEK>). This PR adds `#[inline]` to these methods. I have a project that can benefit from this change, but do we want to enable this behavior universally?

Fixes #101080.
2023-02-28 12:32:04 +00:00
Ralf Jung 229aef1f7d add missing feature in core/tests 2023-02-28 10:07:57 +01:00
bors fd1f1fa0d1 Auto merge of #106774 - Nugine:master, r=Amanieu
Stabilize cmpxchg16b_target_feature

Tracking issue for target features
+ #44839

stdarch issue
+ https://github.com/rust-lang/stdarch/issues/827

stdarch PR
+ https://github.com/rust-lang/stdarch/pull/1358

reference PR
+ https://github.com/rust-lang/reference/pull/1331

It's my first time contributing to rust-lang/rust. Please tell me if I missed something.
2023-02-28 04:12:34 +00:00
Ben Kimock 5448123a11 Remove or justify use of #[rustc_box] 2023-02-27 20:54:55 -05:00
bors b583ede652 Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank
Stabilize `#![feature(target_feature_11)]`

## Stabilization report

### Summary

Allows for safe functions to be marked with `#[target_feature]` attributes.

Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot be assigned to safe function pointers, and don't implement the `Fn*` traits.

However, calling them from other `#[target_feature]` functions with a superset of features is safe.

```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}

fn foo() {
    // Calling `avx2` here is unsafe, as we must ensure
    // that AVX is available first.
    unsafe {
        avx2();
    }
}

#[target_feature(enable = "avx2")]
fn bar() {
    // Calling `avx2` here is safe.
    avx2();
}
```

### Test cases

Tests for this feature can be found in [`src/test/ui/rfcs/rfc-2396-target_feature-11/`](b67ba9ba20/src/test/ui/rfcs/rfc-2396-target_feature-11/).

### Edge cases

- https://github.com/rust-lang/rust/issues/73631

Closures defined inside functions marked with `#[target_feature]` inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits.

```rust
#[target_feature(enable = "avx2")]
fn qux() {
    let my_closure = || avx2(); // this call to `avx2` is safe
    let f: fn() = my_closure;
}
```

This means that in order to call a function with `#[target_feature]`, you must show that the target-feature is available while the function executes *and* for as long as whatever may escape from that function lives.

### Documentation

- Reference: https://github.com/rust-lang/reference/pull/1181

---
cc tracking issue #69098
r? `@ghost`
2023-02-28 01:14:56 +00:00
Maybe Waffle 4a2c555904 Add Atomic*::from_ptr 2023-02-27 19:05:19 +00:00
Matthias Krüger 3fe4023370
Rollup merge of #107110 - strega-nil:mbtwc-wctmb, r=ChrisDenton
[stdio][windows] Use MBTWC and WCTMB

`MultiByteToWideChar` and `WideCharToMultiByte` are extremely well optimized, and therefore should probably be used when we know we can (specifically in the Windows stdio stuff).

Fixes #107092
2023-02-27 18:48:48 +01:00
Matthias Krüger cf04603dca
Rollup merge of #104265 - faern:move-ipaddr-to-core, r=joshtriplett
Move IpAddr, SocketAddr and V4+V6 related types to `core`

Implements RFC https://github.com/rust-lang/rfcs/pull/2832. The RFC has completed FCP with disposition merge, but is not yet merged.

Moves IP types to `core` as specified in the RFC.

The full list of moved types is: `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, `SocketAddrV6`, `Ipv6MulticastScope` and `AddrParseError`.

Doing this move was one of the main driving arguments behind #78802.
2023-02-27 18:48:47 +01:00
Coca162 22b65fc275
Clarify that Copy is a trait in array docs 2023-02-27 15:16:39 +00:00
Coca162 dc9732620d
Update docs to show [expr; N] can repeat const expr 2023-02-27 13:51:10 +00:00
Benoît du Garreau 351c154cb4 Add vectored positioned I/O on Unix 2023-02-27 10:10:13 +01:00
Stefan Lankes ae27762ceb use as_ptr to determine the address of atomics 2023-02-27 09:59:57 +01:00
Stefan Lankes daf31a113c remove unused imports 2023-02-26 23:13:58 +01:00
Josh Triplett 1291216ac9 Add tracking issue 2023-02-26 13:50:10 +01:00
Linus Färnstrand 6cb34492a6 Move IpAddr and SocketAddr to core 2023-02-26 13:50:08 +01:00
Matthias Krüger 9c27fc7d34
Rollup merge of #108484 - Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂LangItemFromFn˃˃˃꞉꞉from, r=cjgillot
Remove `from` lang item

It was probably a leftover from the old `?` desugaring but anyways, it's unused now except for clippy, which can just use a diagnostics item.
2023-02-26 12:05:01 +01:00
Matthias Krüger be23b326dc
Rollup merge of #108475 - Sp00ph:fix_shrink_to, r=thomcc
Fix `VecDeque::shrink_to` and add tests.

Fixes #108453.

Also adds both a specific test with the code from #108453 and an exhaustive test that checks all possible head positions, lengths and target capacities for deques with capacity 16.

cc `@trinity-1686a` `@scottmcm`
2023-02-26 12:05:00 +01:00
Matthias Krüger 3d2319f1d6
Rollup merge of #108299 - scottmcm:literal-bits, r=Nilstrieb
Require `literal`s for some `(u)int_impl!` parameters

The point of these is to be seen *lexically* in the docs, so they should always be passed as the correct literal, not as an expression.

(Otherwise we could just compute `Min`/`Max` from `BITS`, for example.)

r? Nilstrieb
2023-02-26 12:04:57 +01:00
joboet 4e9e465bd4 std: disconnect senders before discarding messages 2023-02-26 11:57:27 +01:00
joboet fdbf109b63
std: use random HashMap keys on Hermit 2023-02-26 11:33:28 +01:00
Nilstrieb 312020ef6a Remove from_fn lang item
It was probably a leftover from the old `?` desugaring but anyways, it's
unused now except for clippy, which can just use a diagnostics item.
2023-02-26 09:15:54 +00:00
Markus Everling 4a4f43e4e9 Disambiguate comments 2023-02-26 03:13:56 +01:00
Markus Everling 9e22516877 Fix VecDeque::shrink_to and add tests.
This adds both a test specific to #108453 as well as an exhaustive test
that goes through all possible combinations of head index, length and target capacity
for a deque with capacity 16.
2023-02-26 03:13:44 +01:00
Matthias Krüger 4ab1c74b77
Rollup merge of #108432 - klensy:test-deps, r=Mark-Simulacrum
test: drop unused deps

Looks unused. Anyway, tests should catch any breakage.
2023-02-26 00:46:26 +01:00
Matthias Krüger fa10a21bd2
Rollup merge of #107890 - obeis:mapping-to-unit, r=cjgillot
Lint against `Iterator::map` receiving a callable that returns `()`

Close #106991
2023-02-26 00:46:25 +01:00
bors 34e6673a04 Auto merge of #107405 - hermitcore:bsd, r=bjorn3
add support of RustyHermit's BSD socket layer

RustyHermit is a tier 3 platform and publishes a new kernel interface. The new version supports a common BSD socket layer. By supporting this interface, the implementation of `std` can be harmonized to other operating systems. In `sys_common/mod.rs` we remove only a special case for RustyHermit. All changes are done in the RustyHermit specific directories.

To realize this socket layer, the handling of file descriptors is also harmonized to other operating systems.
2023-02-25 19:43:00 +00:00
Nicole Mazzuca 7f25580512 [stdio][windows] Use MBTWC and WCTMB 2023-02-25 11:15:23 -08:00
pommicket 12f959ba39 Add test for VecDeque::append ZST capacity overflow 2023-02-25 13:50:56 -05:00
bors 31448badfd Auto merge of #108450 - matthiaskrgr:rollup-rqvfgu3, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #108354 (Update `fuchsia-test-runner.py` and docs)
 - #108404 (support `x fmt` for sub and outside of rust directories)
 - #108407 (docs: use intra-doc links for `Vec::get(_mut)`)
 - #108410 (rustdoc: avoid including `<li>` tags in item table short desc)
 - #108412 (Fix GUI test navigation bug)
 - #108433 (Wrap missing provider message correctly)
 - #108434 (Migrate `rustc_hir_analysis` to session diagnostic [Part One])

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-25 16:48:04 +00:00
pommicket 379b18bb0a Use checked_add in VecDeque::append for ZSTs to avoid overflow 2023-02-25 11:05:21 -05:00
Matthias Krüger 7c562ee5a6
Rollup merge of #108407 - notriddle:notriddle/vec-get-mut, r=thomcc
docs: use intra-doc links for `Vec::get(_mut)`

Now that #63351 is fixed, there's no reason not to.

CC #75672
2023-02-25 11:31:33 +01:00
bors 26c98689f2 Auto merge of #108233 - ChrisDenton:move-std-tests, r=thomcc
Move some std tests from `tests/ui-fulldeps` into `library/std`

This allows them to be tested normally along with other `./x test std` tests. Moving `rename_directory` is simple enough but `create_dir_all_bare` needed to be an std integration test.

Additionally, some tests that I couldn't move atm have instead been placed in an `std` subdirectory. These tests include ones that do fun things with processes or that intentionally abort the test process.

r? libs
2023-02-25 10:26:57 +00:00
Tatsuyuki Ishi 116bb4dfb2 binary_heap: Unify Extend implementation.
Previously the bulk rebuild specialization was only available with Vec, and
for general iterators Extend only provided pre-allocation through reserve().

By using a drop guard, we can safely bulk rebuild even if the iterator may
panic. This allows benefiting from the bulk rebuild optimization without
collecting iterator elements into a Vec beforehand, which would nullify any
performance gains from bulk rebuild.
2023-02-25 17:05:09 +09:00
Tatsuyuki Ishi 11c589c046 binary_heap: Make RebuildOnDrop a common helper.
This helper was written for retain() but will also be useful for extend().
2023-02-25 16:59:32 +09:00
bors 6ffabf3c8f Auto merge of #107638 - zhangyunhao116:pdqsort-rand, r=cuviper
Optimize break patterns

Use `wyrand` instead of calling `XORSHIFT` 2 times in break patterns for the 64-bit platform. The new PRNG is 2x faster than the previous one.

Bench result(via https://gist.github.com/zhangyunhao116/11ef41a150f5c23bb47d86255fbeba89):
```
old                     time:   [1.3258 ns 1.3262 ns 1.3266 ns]
                        change: [+0.5901% +0.6731% +0.7791%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 13 outliers among 100 measurements (13.00%)
  7 (7.00%) high mild
  6 (6.00%) high severe

new                     time:   [657.65 ps 657.89 ps 658.18 ps]
                        change: [-1.6910% -1.6110% -1.5256%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  2 (2.00%) high mild
  4 (4.00%) high severe
```
2023-02-25 03:01:40 +00:00
klensy c3749ddf4c test: drop unused deps 2023-02-24 20:45:00 +03:00
Stefan Lankes af8ee641a8 avoid the usage of libc during the creation of documentation 2023-02-24 15:30:14 +01:00
Stefan Lankes 90162a78a9 remove code duplications 2023-02-24 15:30:14 +01:00
Stefan Lankes b5fb4f3d9b move IO traits to std/src/os/hermit
By moving the IO traits, the RustyHermit support is harmonized to
of other operating systems.
2023-02-24 15:30:14 +01:00
Stefan Lankes 7143379a52 add support of RustyHermit's BSD socket layer
RustHermit publishs a new kernel interface and supports
a common BSD socket layer. By supporting this interface,
the implementation can be harmonized to other operating systems.

To realize this socket layer, the handling of file descriptors
is also harmonized to other operating systems.
2023-02-24 15:30:14 +01:00
Dylan DPC 353827a044
Rollup merge of #108391 - sunfishcode:sunfishcode/is-terminal-file-length, r=ChrisDenton
Fix `is_terminal`'s handling of long paths on Windows.

As reported in sunfishcode/is-terminal#18, there are situations where `GetFileInformationByHandleEx` can write a file name length that is longer than the provided buffer. To avoid deferencing memory past the end of the buffer, use a bounds-checked function to form a slice to the buffer and handle the out-of-bounds case.

This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal` implementation.
2023-02-24 12:02:45 +05:30
Dylan DPC f94c3c9da1
Rollup merge of #108370 - fbq:time-doc-fix, r=thomcc
std: time: Avoid to use "was created" in elapsed() description

".. since this instant was created" is inaccurate and misleading, consider the following case:
```rust
	let i1 = Instant::now(); // i1 is created at T1
	let i2 = i1 + Duration::from_nanos(0); // i2 is "created" at T2
	i2.elapsed(); // at T3
```
Per the current description, `elapsed()` at T3 should return T3 - T2?

To avoid the inaccuracy, removes the "was created" in the description of {Instant,SystemTime}::elapsed().
And since these types represent times, it's OK to use prepostions with them, e.g. "since this instant".
2023-02-24 12:02:42 +05:30
Dylan DPC b3657f92d1
Rollup merge of #106918 - dtolnay:heapretain, r=the8472
Rebuild BinaryHeap on unwind from retain

This closes the hole identified in https://github.com/rust-lang/rust/issues/71503#issuecomment-1383251315 which had made it possible for the caller to end up with a heap in invalid state. As of #105851, heaps in invalid state are not supposed to exist.
2023-02-24 12:02:41 +05:30
Dylan DPC 8c135eecac
Rollup merge of #106541 - fee1-dead-contrib:no-const-check-no, r=thomcc
implement const iterator using `rustc_do_not_const_check`

Previous experiment: #102225.

Explanation: rather than making all default methods work under `const` all at once, this uses `rustc_do_not_const_check` as a workaround to "trick" the compiler to not run any checks on those other default methods. Any const implementations are only required to implement the `next` method. Any actual calls to the trait methods other than `next` will either error in compile time (at CTFE runs), or run the methods correctly if they do not have any non-const operations. This is extremely easy to maintain, remove, or improve.
2023-02-24 12:02:40 +05:30
Trevor Gross 318be2bee9 Stabilize atomic_as_ptr 2023-02-23 23:29:10 -05:00
Michael Howell a402cb0f9b docs: use intra-doc links for Vec::get(_mut)
Now that #63351 is fixed, there's no reason not to.
2023-02-23 12:26:14 -07:00
Dan Gohman c0c1925774 Fix is_terminal's handling of long paths on Windows.
As reported in sunfishcode/is-terminal#18, there are situations where
`GetFileInformationByHandleEx` can write a file name length that is
longer than the provided buffer. To avoid deferencing memory past the
end of the buffer, use a bounds-checked function to form a slice to
the buffer and handle the out-of-bounds case.

This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal`
implementation.
2023-02-23 06:29:11 -08:00
Obei Sideg a914f37409 Add lint against Iterator::map receiving a callable that returns () 2023-02-23 13:57:06 +03:00
Scott McMurray 5c7ae251b1 Require literals for some (u)int_impl! parameters
The point of these is to be seen lexically in the docs, so they should always be passed as the correct literal, not as an expression.

(Otherwise we could just compute `Min`/`Max` from `BITS`, for example.)
2023-02-22 23:26:22 -08:00
Matthias Krüger c4a4bce695
Rollup merge of #108218 - ChrisDenton:cmd-escape, r=cuviper
Windows: Quote more batch file arguments

Make sure to always quote batch file arguments that contain command prompt special characters.

Additionally add `/d` command line parameter to disable any autorun scripts that may change the way variable expansion works. This makes it more consistent across systems and may help avoid surprises.

## Background Info

[`CreateProcess`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) with the `lpApplicationName` set can only be used to run `.exe` files and not script files such as `.bat`. However, for historical reasons, we do have special handling so that `.bat` files will be correctly run with `cmd.exe` as the application.

In Windows, command line arguments are passed as a single string (not an array). Applications can parse this string however they like but most follow the standard MSVC C/C++ convention. But `cmd.exe` uses different argument parsing rules to other Windows programs (because it emulates old DOS).  This PR aims to help smooth over some of the differences.

r? libs
2023-02-23 06:18:06 +01:00
Boqun Feng b54a5fdca0 std: time: Avoid to use "was created" in elapsed() description
".. since this instant was created" is inaccurate and misleading,
consider the following case:

	let i1 = Instant::now(); // i1 is created at T1
	let i2 = i1 + Duration::from_nanos(0); // i2 is "created" at T2
	i2.elapsed(); // at T3

Per the current description, `elapsed()` at T3 should return T3 - T2?

Therefore removes the "was created" in the description of
{Instant,SystemTime}::elapsed(). And since these types represent times,
it's OK to use prepostions with them, e.g. "since this instant".
2023-02-22 14:40:43 -08:00
Matthias Krüger 0982eab839
Rollup merge of #107736 - tgross35:atomic-as-ptr, r=m-ou-se
Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893)

Originally discussed in https://github.com/rust-lang/rust/issues/66893#issuecomment-1419198623

~~This uses #107706 as a base to avoid a merge conflict once that gets rolled up (so disregard const changes in the diff until it does)~~ all merged & rebased

`@rustbot` label +T-libs-api
r? m-ou-se
2023-02-22 20:05:57 +01:00
zhangyunhao e107ca0f0b Optimize break patterns 2023-02-22 16:02:35 +00:00
Chris Denton 0b7c867ec5
Quote more batch file arguments
Make sure to quote batch file arguments that contain command prompt special characters.

Additionally add `/d` command line parameter to disable any commands that may change the way variable expansion works.
2023-02-22 04:27:35 +00:00
Chris Denton 0f221cc034
Exclude SGX from create_dir_all_bare test
And emscripten too.
2023-02-21 18:33:20 +00:00
Chris Denton 9b18b4440a
Make create_dir_all_bare an std integration test
Moving `create_dir_all` out of `ui-fulldeps` is complicated by the fact it sets the current directory. This means it can't be a unit test. Instead, move it to its own integration test.
2023-02-21 18:33:19 +00:00
Chris Denton f7a132f428
Move rename_directory from ui-fulldeps to std
std has had a `TempDir` implementation for a long time now.
2023-02-21 18:33:19 +00:00
Tomasz Miąsko 7867aa8aee Remove unused FileDesc::get_cloexec 2023-02-21 18:52:25 +01:00
Dylan DPC 7dcf7fe737
Rollup merge of #108272 - MrNossiom:master, r=thomcc
docs: wrong naming convention in struct keyword doc

Noticed that the naming convention mentioned is not the right one.

As far as I know, PacalCase is the naming convention used for structs names. PacalCase is not the same as camelCase
2023-02-21 14:20:00 +05:30
Dylan DPC e781a6ff3b
Rollup merge of #108105 - majaha:patch-1, r=cuviper
Explain the default panic hook better

This changes the documentation of `std::panic::set_hook` and `take_hook` to explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs.

I also reworded a few things for clarity.
2023-02-21 14:19:59 +05:30
Matt Harding ec9a4ce19e Explain the default panic hook better
This changes the documentation of `std::panic::set_hook` and `take_hook` to better explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs.
2023-02-20 23:37:19 +00:00
Milo Moisson 18f5f0c473
use UpperCamelCase 2023-02-20 23:44:21 +01:00
Markus Everling acc876e42f Changes according to review 2023-02-20 23:25:26 +01:00
Matthias Krüger 4f532dacfc
Rollup merge of #108279 - Nilstrieb:int, r=scottmcm
Use named arguments for `{,u}int_impls` macro

This makes it way easier to understand.

r? `@scottmcm`
2023-02-20 22:12:20 +01:00
Nilstrieb eb5d82bc9c Use named arguments for int_impl macro
This makes it easier to understand.
2023-02-20 18:18:49 +00:00
Nilstrieb d3b46bb74e Use named arguments for uint_impl macro
This makes it easier to understand.
2023-02-20 18:10:51 +00:00
Milo Moisson 76ac2705a5
docs: wrong naming convention in struct keyword doc 2023-02-20 16:40:46 +01:00
Matthias Krüger fde38f1174
Rollup merge of #108124 - kornelski:cstr_c_char, r=thomcc
Document that CStr::as_ptr returns a type alias

Rustdoc resolves type aliases too eagerly #15823 which makes the [std re-export](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.as_ptr) of `CStr::as_ptr` show `i8` instead of `c_char`. To work around this I've added info about `c_char` in the method's description.

BTW, I've also added a comment to what-not-to-do example in case someone copypasted it without reading the surrounding text.
2023-02-20 14:32:54 +01:00
Chris Denton 77de724f92
Distribute libntdll.a with windows-gnu toolchains
This allows loading some essential functions (e.g. read/write file) at load time instead of lazily.
2023-02-20 10:05:45 +00:00
Ben Kimock 738c8b08d5 Remove the assume(!is_null) from Vec::as_ptr 2023-02-19 14:30:21 -05:00
Tomasz Miąsko b118569268 Use custom implementation of read_buf in Read for &'a FileDesc
This allows to skip an unnecessary buffer initialization.
2023-02-19 13:06:38 +01:00
Dylan DPC 0257e288f5
Rollup merge of #108130 - tshepang:just-one-example, r=workingjubilee
"Basic usage" is redundant for there is just one example
2023-02-19 13:03:42 +05:30
Dylan DPC e802713941
Rollup merge of #106933 - schuelermine:fix/doc/102451, r=Amanieu
Update documentation of select_nth_unstable and select_nth_unstable_by to state O(n^2) complexity

See #102451
2023-02-19 13:03:40 +05:30
Dylan DPC 47ec320ce6
Rollup merge of #104659 - tshepang:reflow, r=workingjubilee
reflow the stack size story
2023-02-19 13:03:39 +05:30
bors 4507fdaaa2 Auto merge of #106241 - Sp00ph:vec_deque_iter_methods, r=the8472
Implement more methods for `vec_deque::IntoIter`

This implements a couple `Iterator` methods on `vec_deque::IntoIter` (`(try_)fold`, `(try_)rfold` `advance_(back_)by`, `next_chunk`, `count` and `last`) to allow these to be more efficient than their default implementations, also allowing many other `Iterator` methods that use these under the hood to take advantage of these manual implementations. `vec::IntoIter` has similar implementations for many of these methods. This PR does not yet implement `TrustedRandomAccess` and friends, as I'm not very familiar with the required safety guarantees.

r? `@the8472` (since you also took over my last PR)
2023-02-18 20:12:35 +00:00
Anselm Schüler f1e649b378 Update documentation of select_nth_unstable and select_nth_unstable_by and select_nth_unstable_by_key to state O(n log n) worst case complexity
Also remove erronious / in doc comment
2023-02-18 16:18:34 +01:00
bors 3701bdc633 Auto merge of #107329 - joboet:optimize_lazylock, r=m-ou-se
Optimize `LazyLock` size

The initialization function was unnecessarily stored separately from the data to be initialized. Since both cannot exist at the same time, a `union` can be used, with the `Once` acting as discriminant. This unfortunately requires some extra methods on `Once` so that `Drop` can be implemented correctly and efficiently.

`@rustbot` label +T-libs +A-atomic
2023-02-18 09:29:21 +00:00
Scott McMurray 4492793e0d Add a slightly-contrived tuple comparison benchmark 2023-02-17 11:46:19 -08:00
joboet 642a324746 std: add regression test for #107466
Tests that messages are immediately dropped once the last receiver is destroyed.
2023-02-17 15:58:15 +01:00
joboet 746331edf3 std: drop all messages in bounded channel when destroying the last receiver 2023-02-17 15:47:58 +01:00
Scott McMurray 680e21687d Use partial_cmp to implement tuple lt/le/ge/gt 2023-02-16 23:59:13 -08:00
Matthias Krüger 6379c727ac
Rollup merge of #104068 - yancyribbens:partial-cmp-doc-update, r=scottmcm
rustdoc: Add PartialOrd trait to doc comment explanation

The doc comments for [partial_cmp](https://github.com/rust-lang/rust/blob/master/library/core/src/iter/traits/iterator.rs#L3478) is the exact same as the doc comment for [cmp](https://github.com/rust-lang/rust/blob/master/library/core/src/iter/traits/iterator.rs#L3413).  This PR adds to the description `partial_cmp` to disambiguate the description from `cmp.`
2023-02-17 00:19:33 +01:00
yancy ced962975b rustdoc: Update the description to include PartialOrd elements 2023-02-16 19:46:11 +01:00
Tshepang Mbambo 6da64379ab "Basic usage" is redundant for there is just one example 2023-02-16 19:49:31 +02:00
Kornel fd89470956 Document that CStr::as_ptr returns a type alias
Workaround for #15823
2023-02-16 14:22:08 +00:00
Dylan DPC 323e5e823b
Rollup merge of #108084 - ink-feather-org:const_range, r=dtolnay
Constify `RangeBounds`, `RangeX::contains` and `RangeX::is_empty` (where applicable).

cc `@fee1-dead`

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

Tracking issue: #108082
2023-02-16 11:40:20 +05:30
Dylan DPC 0c5bbca12d
Rollup merge of #106372 - joboet:solid_id_parking, r=m-ou-se
Use id-based thread parking on SOLID

By using the [`slp_tsk`/`wup_tsk`](https://cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/embedded/uITRON-4.0-specification.pdf) system functions instead of an event-flag structure, `Parker` becomes cheaper to construct and SOLID can share the implementation used by NetBSD and SGX.

ping ``@kawadakk``
r? ``@m-ou-se``
``@rustbot`` label +T-libs
2023-02-16 11:40:19 +05:30
Matthias Krüger 55471015a0
Rollup merge of #108094 - kornelski:fsdocs, r=cuviper
Demonstrate I/O in File examples

I've noticed that some Rust novices unnecessarily reinvent `std::fs::{read,write}`, presumably because they search for equivalents of `fopen` + `fwrite`. I've added links to `std::fs::{read,write}` in the docs.

The `File` examples were only showing how to open a file, but not how to use the opened handle, unnecessarily leaving out the next step. I've added a variety of different uses of file handles to their examples in docs.
2023-02-15 21:31:00 +01:00
soc 3aa9f76a3a
Remove #![feature(option_result_contains)] from library/core/tests/lib.rs 2023-02-15 19:30:02 +00:00
Kornel 4c2d48ee80 Suggest simpler fs helper methods in File::{open,create} 2023-02-15 18:58:38 +00:00
soc 094365e23c
Drop unstable Option::contains, Result::contains, Result::contains_err 2023-02-15 18:57:00 +00:00
Kornel 15adc7b5e4 Demonstrate I/O in File examples 2023-02-15 18:47:50 +00:00
Callum Leslie 29621ba288
clarify correctness of black_box 2023-02-15 16:22:08 +00:00
onestacked a14a4fc3d0 Constify RangeBounds, RangeX::contains and RangeX::is_empty. 2023-02-15 15:50:54 +01:00
Florian Bartels 8f41570e91
Use libc which supports QNX Neutrino
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-15 13:57:57 +01:00
Dylan DPC ef6de70c77
Rollup merge of #108060 - ChrisDenton:rtlgenrandom, r=thomcc
Revert to using `RtlGenRandom` as a fallback

This is required due to `BCryptGenRandom` failing to load a dll it depends on.

Fixes #108059
2023-02-15 12:24:56 +05:30
bors 0416b1a6f6 Auto merge of #108056 - matthiaskrgr:rollup-oa6bxvh, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #107573 (Update the minimum external LLVM to 14)
 - #107626 (Fix `x fix` on the standard library itself)
 - #107673 (update ICU4X to 1.1.0)
 - #107733 (Store metrics from `metrics.json` to CI PGO timer)
 - #108007 (Use `is_str` instead of string kind comparison)
 - #108033 (add an unstable `#[rustc_coinductive]` attribute)
 - #108039 (Refactor refcounted structural_impls via functors)
 - #108040 (Use derive attributes for uninteresting traversals)
 - #108044 (interpret: rename Pointer::from_addr → from_addr_invalid)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-14 21:07:04 +00:00
Chris Denton dfd0afb991
Revert to using RtlGenRandom
This is required due to `BCryptGenRandom` failing to load the necessary dll on some systems.
2023-02-14 19:37:05 +00:00
Matthias Krüger edcdab08a4
Rollup merge of #108033 - lcnr:coinductive-attr, r=compiler-errors
add an unstable `#[rustc_coinductive]` attribute

useful to test coinduction, especially in the new solver.

as this attribute should remain permanently unstable I don't think this needs any official approval. cc ``@rust-lang/types``

had to weaken the check for stable query results in the solver to prevent an ICE if there's a coinductive cycle with constraints.

r? ``@compiler-errors``
2023-02-14 18:24:42 +01:00
Matthias Krüger a1ba861190
Rollup merge of #107573 - cuviper:drop-llvm-13, r=nagisa
Update the minimum external LLVM to 14

With this change, we'll have stable support for LLVM 14 through 16 (pending release).
For reference, the previous increase to LLVM 13 was #100460.
2023-02-14 18:24:40 +01:00
Matthias Krüger d599be0af2
Rollup merge of #108023 - JulianKnodt:smaller_benchmark, r=workingjubilee
Shrink size of array benchmarks

Might've overdone it with the size of these benchmarks, as there's no need for them to be quite as large.

Fixes #108011
2023-02-14 18:02:52 +01:00
Matthias Krüger 3eb57319f2
Rollup merge of #108016 - tshepang:just-one-example, r=thomcc
"Basic usage" is redundant for there is just one example
2023-02-14 18:02:52 +01:00
lcnr 646e667200 add a #[rustc_coinductive] attribute 2023-02-14 11:53:22 +01:00
kadmin 826abcc728 Shrink size of array benchmarks 2023-02-14 05:01:24 +00:00
Tshepang Mbambo ef6a59b7a9 "Basic usage" is redundant for there is just one example 2023-02-14 01:43:41 +02:00
Matthias Krüger 56193b0e60
Rollup merge of #107985 - alesito85:master, r=ChrisDenton
Added another error to be processed in fallback

This pull request addresses the problem of Rust not being able to read file/directory metadata because the current user doesn't have permission to read the file and are thus inaccessible.

One particular example is `System Volume Information`. But any example can be made by having a file/directory, which the current user can't access even though the system does allow to view the metadata, which is handled by the fallback.

The fallback exists to get the metadata but it was limited to one error type. Having added ERROR_ACCESS_DENIED per Chris Denton's suggestion, file/directory properties are now properly read.

Solution suggested by Chris Denton https://github.com/nushell/nushell/issues/6857#issuecomment-1426847135
2023-02-13 23:25:13 +01:00
alesito85 f72eb4704a Add another error to Windows file open fallback
Added another error to be processed in fallback

Solution suggested by Chris Denton https://github.com/nushell/nushell/issues/6857#issuecomment-1426847135
2023-02-13 11:50:25 +01:00
bors 2d91939bb7 Auto merge of #107634 - scottmcm:array-drain, r=thomcc
Improve the `array::map` codegen

The `map` method on arrays [is documented as sometimes performing poorly](https://doc.rust-lang.org/std/primitive.array.html#note-on-performance-and-stack-usage), and after [a question on URLO](https://users.rust-lang.org/t/try-trait-residual-o-trait-and-try-collect-into-array/88510?u=scottmcm) prompted me to take another look at the core [`try_collect_into_array`](7c46fb2111/library/core/src/array/mod.rs (L865-L912)) function, I had some ideas that ended up working better than I'd expected.

There's three main ideas in here, split over three commits:
1. Don't use `array::IntoIter` when we can avoid it, since that seems to not get SRoA'd, meaning that every step writes things like loop counters into the stack unnecessarily
2. Don't return arrays in `Result`s unnecessarily, as that doesn't seem to optimize away even with `unwrap_unchecked` (perhaps because it needs to get moved into a new LLVM type to account for the discriminant)
3. Don't distract LLVM with all the `Option` dances when we know for sure we have enough items (like in `map` and `zip`).  This one's a larger commit as to do it I ended up adding a new `pub(crate)` trait, but hopefully those changes are still straight-forward.

(No libs-api changes; everything should be completely implementation-detail-internal.)

It's still not completely fixed -- I think it needs pcwalton's `memcpy` optimizations still (#103830) to get further -- but this seems to go much better than before.  And the remaining `memcpy`s are just `transmute`-equivalent (`[T; N] -> ManuallyDrop<[T; N]>` and `[MaybeUninit<T>; N] -> [T; N]`), so hopefully those will be easier to remove with LLVM16 than the previous subobject copies 🤞

r? `@thomcc`

As a simple example, this test
```rust
pub fn long_integer_map(x: [u32; 64]) -> [u32; 64] {
    x.map(|x| 13 * x + 7)
}
```
On nightly <https://rust.godbolt.org/z/xK7548TGj> takes `sub rsp, 808`
```llvm
start:
  %array.i.i.i.i = alloca [64 x i32], align 4
  %_3.sroa.5.i.i.i = alloca [65 x i32], align 4
  %_5.i = alloca %"core::iter::adapters::map::Map<core::array::iter::IntoIter<u32, 64>, [closure@/app/example.rs:2:11: 2:14]>", align 8
```
(and yes, that's a 6**5**-element array `alloca` despite 6**4**-element input and output)

But with this PR it's only `sub rsp, 520`
```llvm
start:
  %array.i.i.i.i.i.i = alloca [64 x i32], align 4
  %array1.i.i.i = alloca %"core::mem::manually_drop::ManuallyDrop<[u32; 64]>", align 4
```

Similarly, the loop it emits on nightly is scalar-only and horrifying
```nasm
.LBB0_1:
        mov     esi, 64
        mov     edi, 0
        cmp     rdx, 64
        je      .LBB0_3
        lea     rsi, [rdx + 1]
        mov     qword ptr [rsp + 784], rsi
        mov     r8d, dword ptr [rsp + 4*rdx + 528]
        mov     edi, 1
        lea     edx, [r8 + 2*r8]
        lea     r8d, [r8 + 4*rdx]
        add     r8d, 7
.LBB0_3:
        test    edi, edi
        je      .LBB0_11
        mov     dword ptr [rsp + 4*rcx + 272], r8d
        cmp     rsi, 64
        jne     .LBB0_6
        xor     r8d, r8d
        mov     edx, 64
        test    r8d, r8d
        jne     .LBB0_8
        jmp     .LBB0_11
.LBB0_6:
        lea     rdx, [rsi + 1]
        mov     qword ptr [rsp + 784], rdx
        mov     edi, dword ptr [rsp + 4*rsi + 528]
        mov     r8d, 1
        lea     esi, [rdi + 2*rdi]
        lea     edi, [rdi + 4*rsi]
        add     edi, 7
        test    r8d, r8d
        je      .LBB0_11
.LBB0_8:
        mov     dword ptr [rsp + 4*rcx + 276], edi
        add     rcx, 2
        cmp     rcx, 64
        jne     .LBB0_1
```

whereas with this PR it's unrolled and vectorized
```nasm
	vpmulld	ymm1, ymm0, ymmword ptr [rsp + 64]
	vpaddd	ymm1, ymm1, ymm2
	vmovdqu	ymmword ptr [rsp + 328], ymm1
	vpmulld	ymm1, ymm0, ymmword ptr [rsp + 96]
	vpaddd	ymm1, ymm1, ymm2
	vmovdqu	ymmword ptr [rsp + 360], ymm1
```
(though sadly still stack-to-stack)
2023-02-13 10:18:48 +00:00
bors 20081880ad Auto merge of #107980 - Dylan-DPC:rollup-u4b19bl, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #107654 (reword descriptions of the deprecated int modules)
 - #107915 (Add `array::map` benchmarks)
 - #107961 (Avoid copy-pasting the `ilog` panic string in a bunch of places)
 - #107962 (Add a doc note about why `Chain` is not `ExactSizeIterator`)
 - #107966 (Update browser-ui-test version to 0.14.3)
 - #107970 (Hermit: Remove floor symbol)
 - #107973 (Fix unintentional UB in SIMD tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-13 07:07:33 +00:00
EFanZh 4bb0a5ed7f Inline Poll methods 2023-02-13 14:17:45 +08:00
Dylan DPC 55f36ed0a4
Rollup merge of #107970 - hermitcore:hermit-rm-floor, r=thomcc
Hermit: Remove floor symbol

This symbol should be provided by Hermit.

It was introduced in 2019 (https://github.com/rust-lang/rust/pull/65167). Since 2020, Hermit provides these math functions on its own (https://github.com/hermitcore/rusty-hermit/pull/37). I think moving this to Hermit was merely an oversight.

Related:
* https://github.com/hermitcore/libhermit-rs/pull/654
* https://github.com/hermitcore/rusty-hermit/pull/406

CC: `@stlankes`
2023-02-13 11:12:51 +05:30
Dylan DPC f7caaa573e
Rollup merge of #107962 - scottmcm:why-not-exact, r=Mark-Simulacrum
Add a doc note about why `Chain` is not `ExactSizeIterator`

Inspired by <https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Why.20isn't.20Chain.3CA.2C.20B.3E.20an.20ExactSizeIterator.3F/near/327395874>.
2023-02-13 11:12:50 +05:30
Dylan DPC 2ec6aebb41
Rollup merge of #107961 - scottmcm:unify-ilog-panics, r=Mark-Simulacrum
Avoid copy-pasting the `ilog` panic string in a bunch of places

I also ended up changing the implementations to `if let` because it doesn't work to
```rust
self.checked_ilog2().unwrap_or_else(panic_for_nonpositive_argument)
```
due to the `!`.  But as a bonus that meant I could remove the `rustc_allow_const_fn_unstable` too.
2023-02-13 11:12:50 +05:30
Dylan DPC c0d1e324d5
Rollup merge of #107915 - JulianKnodt:array_benches, r=Mark-Simulacrum
Add `array::map` benchmarks

Since there were no previous benchmarks for `array::map`, and it is known to have mediocre/poor performance, add some simple benchmarks. These benchmarks vary the length of the array and size of each item.
2023-02-13 11:12:49 +05:30
Dylan DPC 47358298f6
Rollup merge of #107654 - pitaj:reword-integral-modules, r=thomcc
reword descriptions of the deprecated int modules

Based on recommendation by `@est31` here: https://github.com/rust-lang/rust/pull/107587#issuecomment-1416131590

This is meant to make it more clear, when looking at the `std` or `core` docs, that these are deprecated modules - not deprecated integer types (a common misunderstanding).

Before:
![image](https://user-images.githubusercontent.com/803701/216733011-fabc22e1-4e77-4a47-96e3-a765ac4690b6.png)

After:
![image](https://user-images.githubusercontent.com/803701/216733660-02071ced-883d-4ab5-8c0a-d28547d1d5db.png)
2023-02-13 11:12:49 +05:30
bors 96834f0231 Auto merge of #107191 - Voultapher:reverse-timsort-scan-direction, r=thomcc
Reverse Timsort scan direction

Another PR in the series of stable sort improvements. Best reviewed by looking at the individual commits.

The main perf gain here is for fully ascending (sorted) or reversed inputs for cheap to compare types such as `u64`, these see a ~1.5x speedup.

![timsort_evo2_hot_u64_10k](https://user-images.githubusercontent.com/6864584/213913351-cfdf452f-a37c-4bc6-a811-d10c60e66eca.png)

![timsort_evo2_hot_string_10k](https://user-images.githubusercontent.com/6864584/213913354-d9cc395a-2b48-4f54-b687-09174b9e35ce.png)

Types such as string with indirect pre-fetching see only minor changes. Further speedups are planned in future PRs so, I wouldn't spend too much time for benchmarks here.
2023-02-13 04:06:04 +00:00
Martin Kröning 913a566c22 Hermit: Remove floor symbol
This symbol should be provided by Hermit.
2023-02-12 23:37:58 +01:00
Matthias Krüger 454ae9fb8b
Rollup merge of #107954 - RalfJung:tree-borrows-fix, r=m-ou-se
avoid mixing accesses of ptrs derived from a mutable ref and parent ptrs

``@Vanille-N`` is working on a successor for Stacked Borrows. It will mostly accept strictly more code than Stacked Borrows did, with one exception: the following pattern no longer works.
```rust
let mut root = 6u8;
let mref = &mut root;
let ptr = mref as *mut u8;
*ptr = 0; // Write
assert_eq!(root, 0); // Parent Read
*ptr = 0; // Attempted Write
```
This worked in Stacked Borrows kind of by accident: when doing the "parent read", under SB we Disable `mref`, but the raw ptrs derived from it remain usable. The fact that we can still use the "children" of a reference that is no longer usable is quite nasty and leads to some undesirable effects (in particular it is the major blocker for resolving https://github.com/rust-lang/unsafe-code-guidelines/issues/257). So in Tree Borrows we no longer do that; instead, reading from `root` makes `mref` and all its children read-only.

Due to other improvements in Tree Borrows, the entire Miri test suite still passes with this new behavior, and even the entire libcore and liballoc test suite, except for these 2 cases this PR fixes. Both of these involve code where the programmer wrote `&mut` but then used pointers derived from that reference in ways that alias with the parent pointer, which arguably is violating uniqueness. They are fixed by properly using raw pointers throughout.
2023-02-12 22:29:49 +01:00
Matthias Krüger 4b91b673b7
Rollup merge of #107943 - compiler-errors:document-pointer-like, r=jyn514
Document `PointerLike`

I forgot to document this, and even though it's currently more of an implementation detail, the old doc was kinda embarrassing 😅
2023-02-12 22:29:48 +01:00
Scott McMurray 79d2430e99 Add a doc note about why Chain is not ExactSizeIterator 2023-02-12 10:37:25 -08:00
Ralf Jung c3a2e7a809 avoid mixing accesses of ptrs derived from a mutable ref and parent ptrs 2023-02-12 15:16:27 +01:00
bors adb4bfd25d Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcm
Use associated items of `char` instead of freestanding items in `core::char`

The associated functions and constants on `char` have been stable since 1.52 and the freestanding items have soft-deprecated since 1.62 (https://github.com/rust-lang/rust/pull/95566). This PR ~~marks them as "deprecated in future", similar to the integer and floating point modules (`core::{i32, f32}` etc)~~ replaces all uses of `core::char::*` with `char::*` to prepare for future deprecation of `core::char::*`.
2023-02-12 11:09:06 +00:00
bors b7089e0dd3 Auto merge of #107894 - Voultapher:improve-heapsort-fallback, r=scottmcm
Speedup heapsort by 1.5x by making it branchless

`slice::sort_unstable` will fall back to heapsort if it repeatedly fails to find a good pivot. By making the core child update code branchless it is much faster. On Zen3 sorting 10k `u64` and forcing the sort to pick heapsort, results in:

455us -> 278us
2023-02-12 03:30:10 +00:00
Michael Goulet cca82fd997 Document PointerLike 2023-02-12 01:23:02 +00:00
bors d094016128 Auto merge of #106677 - tbu-:pr_less_doc_hidden_pub, r=scottmcm
Remove a couple of `#[doc(hidden)] pub fn` and their `#[feature]` gates
2023-02-11 23:57:05 +00:00
bors 8dabf5da9e Auto merge of #107167 - the8472:rawvec-simpler-layout, r=thomcc
simplify layout calculations in rawvec

The use of `Layout::array` was introduced in #83706 which lead to a [perf regression](https://github.com/rust-lang/rust/pull/83706#issuecomment-1048377719).

This PR basically reverts that change since rust currently only supports stride == size types, but to be on the safe side it leaves a const-assert there to make sure this gets caught if those assumptions ever change.
2023-02-11 15:08:30 +00:00
Lukas Bergdoll ee0376c368 Split branches in heapsort child selection
This allows even better code-gen, cmp + adc. While also more clearly
communicating the intent.
2023-02-11 09:32:52 +01:00
Dylan DPC a50c379fcd
Rollup merge of #107900 - ChrisDenton:zero-header, r=thomcc
Zero the `REPARSE_MOUNTPOINT_DATA_BUFFER` header

Makes sure the full header is correctly initialized.

Fixes #107884
2023-02-11 11:15:58 +05:30
Dylan DPC dfc242220f
Rollup merge of #107878 - workingjubilee:new-size-means-bytes, r=scottmcm
Clarify `new_size` for realloc means bytes

Minor docs fix requested by https://github.com/rust-lang/rust/issues/107875
2023-02-11 11:15:57 +05:30
Dylan DPC 0e8f0b03cd
Rollup merge of #106001 - sdroege:glibc-skip-over-null-argv, r=ChrisDenton
Stop at the first `NULL` argument when iterating `argv`

Some C commandline parsers (e.g. GLib and Qt) are replacing already handled arguments in `argv` with `NULL` and move them to the end. That means that `argc` might be bigger than the actual number of non-`NULL` pointers in `argv` at this point.

To handle this we simply stop iterating at the first `NULL` argument.

`argv` is also guaranteed to be `NULL`-terminated so any non-`NULL` arguments after the first `NULL` can safely be ignored.

Fixes https://github.com/rust-lang/rust/issues/105999
2023-02-11 11:15:54 +05:30
kadmin cbd1b81bd2 Add array::map benchmarks 2023-02-11 04:23:53 +00:00
Trevor Gross 787b1116e8 Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893) 2023-02-10 20:46:14 -05:00
Josh Stone ffdbd58d85 Drop llvm14-builtins-abi with compiler_builtins 0.1.87 2023-02-10 16:13:31 -08:00
Scott McMurray 404e9c5e3a Have a function for the log(0) panic, rather than copy-pasting the string constant 2023-02-10 12:50:17 -08:00
Chris Denton 59b11e8fa3
Zero the REPARSE_MOUNTPOINT_DATA_BUFFER header
Makes sure the full header is correctly initialized, including reserve parameters.
2023-02-10 18:14:53 +00:00
Lukas Bergdoll 7e072199a6 Speedup heapsort by 1.5x by making it branchless
`slice::sort_unstable` will fall back to heapsort if it repeatedly fails to find
a good pivot. By making the core child update code branchless it is much faster.
On Zen3 sorting 10k `u64` and forcing the sort to pick heapsort, results in:

455us -> 278us
2023-02-10 18:05:12 +01:00
Jubilee 1af9b4f347
Clarify new_size for realloc means bytes 2023-02-09 23:56:20 -08:00
Tobias Bucher 77c85e9cba Remove a couple of #[doc(hidden)] pub fn and their #[feature] gates 2023-02-10 08:06:35 +01:00
Dan Gohman 4b1157509f Allow wasi-libc to initialize its environment variables lazily.
Use `__wasilibc_get_environ()` to read the environment variable list
from wasi-libc instead of using `environ`. `environ` is a global
variable which effectively requires wasi-libc to initialize the
environment variables eagerly, and `__wasilibc_get_environ()` is
specifically designed to be an alternative that lets wasi-libc
intiailize its environment variables lazily.

This should have the side effect of fixing at least some of the cases
of #107635.
2023-02-09 19:03:42 -08:00
Dylan DPC 188dd72b5f
Rollup merge of #107655 - notriddle:notriddle/small-url-encode, r=GuillaumeGomez
rustdoc: use the same URL escape rules for fragments as for examples

Carries over improvements from #107284
2023-02-09 23:18:34 +05:30
Michael Goulet aee4570adf
Rollup merge of #107429 - tgross35:from-bytes-until-null-stabilization, r=dtolnay
Stabilize feature `cstr_from_bytes_until_nul`

This PR seeks to stabilize `cstr_from_bytes_until_nul`.

Partially addresses #95027

This function has only been on nightly for about 10 months, but I think it is simple enough that there isn't harm discussing stabilization. It has also had at least a handful of mentions on both the user forum and the discord, so it seems like it's already in use or at least known.

This needs FCP still.

Comment on potential discussion points:
- eventual conversion of `CStr` to be a single thin pointer: this function will still be useful to provide a safe way to create a `CStr` after this change.
- should this return a length too, to address concerns about the `CStr` change? I don't see it as being particularly useful, and it seems less ergonomic (i.e. returning `Result<(&CStr, usize), FromBytesUntilNulError>`). I think users that also need this length without the additional `strlen` call are likely better off using a combination of other methods, but this is up for discussion
- `CString::from_vec_until_nul`: this is also useful, but it doesn't even have a nightly implementation merged yet. I propose feature gating that separately, as opposed to blocking this `CStr` implementation on that

Possible alternatives:

A user can use `from_bytes_with_nul` on a slice up to `my_slice[..my_slice.iter().find(|c| c == 0).unwrap()]`. However; that is significantly less ergonomic, and is a bit more work for the compiler to optimize compared the direct `memchr` call that this wraps.

## New stable API

```rs
// both in core::ffi

pub struct FromBytesUntilNulError(());

impl CStr {
    pub const fn from_bytes_until_nul(
        bytes: &[u8]
    ) -> Result<&CStr, FromBytesUntilNulError>
}
```

cc ```@ericseppanen``` original author, ```@Mark-Simulacrum``` original reviewer, ```@m-ou-se``` brought up some issues on the thin pointer CStr

```@rustbot``` modify labels: +T-libs-api +needs-fcp
2023-02-08 20:01:24 -08:00
Michael Goulet a478b836fa
Rollup merge of #107317 - ids1024:asfd-rc, r=dtolnay
Implement `AsFd` and `AsRawFd` for `Rc`

Fixes https://github.com/rust-lang/rust/issues/105931.
2023-02-08 20:01:24 -08:00
Matthias Krüger c7c66e1b12
Rollup merge of #107793 - joboet:raw_os_error_ty_tracking, r=Dylan-DPC
Add missing tracking issue for `RawOsError`

I forgot to add it in the original PR…

See #107792.

```@rustbot``` label +T-libs-api -T-libs
2023-02-08 18:32:44 +01:00
Matthias Krüger 562581c2db
Rollup merge of #105641 - Amanieu:btree_cursor, r=m-ou-se
Implement cursors for BTreeMap

See the ACP for an overview of the API: https://github.com/rust-lang/libs-team/issues/141

The implementation is split into 2 commits:
- The first changes the internal insertion functions to return a handle to the newly inserted element. The lifetimes involved are a bit hairy since we need a mutable handle to both the `BTreeMap` itself (which holds the root) and the nodes allocated in memory. I have tested that this passes the standard library testsuite under miri.
- The second commit implements the cursor API itself. This is more straightforward to follow but still involves some unsafe code to deal with simultaneous mutable borrows of the tree root and the node that is currently being iterated.
2023-02-08 18:32:41 +01:00
joboet 6a5331146c
std: add tracking issue for RawOsError 2023-02-08 12:35:27 +01:00
Matthias Krüger 5e467f5dfa
Rollup merge of #107776 - dbrgn:docs-string-reserve-headings, r=cuviper
Docs: Fix format of headings in String::reserve

It was inconsistent with other doc comments in the same module (and the rest of the rust std docs).
2023-02-08 07:13:28 +01:00
Matthias Krüger fabefe3f31
Rollup merge of #107769 - compiler-errors:pointer-like, r=eholk
Rename `PointerSized` to `PointerLike`

The old name was unnecessarily vague. This PR renames a nightly language feature that I added, so I don't think it needs any additional approval, though anyone can feel free to speak up if you dislike the rename.

It's still unsatisfying that we don't the user which of {size, alignment} is wrong, but this trait really is just a stepping stone for a more generalized mechanism to create `dyn*`, just meant for nightly testing, so I don't think it really deserves additional diagnostic machinery for now.

Fixes #107696, cc ``@RalfJung``
r? ``@eholk``
2023-02-08 07:13:26 +01:00
Danilo Bargen 4f36673e15 Docs: Fix format of headings in String::reserve 2023-02-07 21:32:28 +01:00
Michael Goulet 2b70cbb8a5 Rename PointerSized to PointerLike 2023-02-07 19:05:53 +00:00
Matthias Krüger e45984b774
Rollup merge of #107706 - tgross35:atomic-as-mut-ptr, r=m-ou-se
Mark 'atomic_mut_ptr' methods const

There's nothing that would block these methods from being const (just an UnsafeCell get), and it would be helpful for FFI interfaces in static contexts

Related tracking issue: #66893
2023-02-07 17:57:16 +01:00
Matthias Krüger 7343f748cb
Rollup merge of #107720 - tshepang:consistency, r=Mark-Simulacrum
end entry paragraph with a period (.)
2023-02-06 21:16:42 +01:00
Matthias Krüger 7c4e6edb05
Rollup merge of #107714 - Wilfred:round_docs, r=m-ou-se
Clarify wording on f64::round() and f32::round()

"Round half-way cases" is a little confusing (it's a 'garden path sentence' as it's not immediately clear whether round is an adjective or verb).

Make this sentence longer and clearer.
2023-02-06 21:16:41 +01:00
bors 044a28a409 Auto merge of #103761 - chenyukang:yukang/fix-103320-must-use, r=compiler-errors
Add explanatory message for [#must_use] in ops

Fixes #103320
2023-02-06 12:57:37 +00:00
Tshepang Mbambo c58202eb9b end entry paragprah with a period (.) 2023-02-06 11:22:44 +02:00
Wilfred Hughes 4a7a9b4e74 Clarify wording on f64::round() and f32::round()
"Round half-way cases" is a little confusing (it's a 'garden path
sentence' as it's not immediately clear whether round is an adjective
or verb).

Make this sentence longer and clearer.
2023-02-05 19:44:21 -08:00
Trevor Gross b51d3b9443 Mark 'atomic_mut_ptr' methods const 2023-02-05 17:03:46 -05:00
Kiran Shila f5c45ad284
Fix typo in HashMap::with_capacity 2023-02-05 10:13:30 -08:00
Markus Everling 1e114a88bd Add slice_ranges safety comment 2023-02-05 02:16:43 +01:00
Scott McMurray 5bc328fdef Allow canonicalizing the array::map loop in trusted cases 2023-02-04 16:44:51 -08:00
Scott McMurray 52df0558ea Stop forcing array::map through an unnecessary Result 2023-02-04 16:41:35 -08:00
Scott McMurray 5a7342c3dd Stop using into_iter in array::map 2023-02-04 16:41:35 -08:00
Michael Howell fa6c3a2d2a docs: update fragment for Result impls 2023-02-03 19:03:17 -07:00
Peter Jaszkowiak d1052349af reword descriptions of the deprecated int modules 2023-02-03 16:50:49 -07:00
Michael Goulet 13bd75f425
Rollup merge of #107632 - ameknite:issue-107622-fix, r=jyn514
Clarifying that .map() returns None if None.

Fix #107622
2023-02-03 14:15:24 -08:00
Michael Goulet e99e05d135
Rollup merge of #107551 - fee1-dead-contrib:rm_const_fnmut_helper, r=oli-obk
Replace `ConstFnMutClosure` with const closures

Also fixes a parser bug. cc `@oli-obk` for compiler changes
2023-02-03 14:15:22 -08:00
Michael Goulet beb5cc9cf7
Rollup merge of #107519 - joboet:raw_os_error_ty, r=Amanieu
Add type alias for raw OS errors

Implement rust-lang/libs-team#173.

`@rustbot` label +S-waiting-on-ACP +T-libs-api
2023-02-03 14:15:21 -08:00
Ame b384692f4c nit fixed 2023-02-03 13:57:53 -06:00
Ame c2b65ffe29 Clarifying that .map() returns None if None. 2023-02-03 13:57:53 -06:00
yukang cb55d10eb2 Fix #103320, add explanatory message for [#must_use] 2023-02-04 00:27:03 +08:00
Deadbeef b886a4de15 Replace ConstFnMutClosure with const closures 2023-02-03 14:43:13 +00:00
Matthias Krüger 86015515b5
Rollup merge of #107598 - chenyukang:yukang/fix-core-bench, r=thomcc
Fix benchmarks in library/core with black_box

Fixes #107590
2023-02-03 06:30:24 +01:00
yukang fe84cecf60 fix #107590, Fix benchmarks in library/core with black_box 2023-02-03 00:33:36 +08:00
Léo Lanteri Thauvin b379d216ee Stabilize #![feature(target_feature_11)] 2023-02-01 08:53:02 +01:00
Trevor Gross 877e9f5d3a Change 'from_bytes_until_nul' to const stable 2023-02-01 02:14:07 -05:00
Trevor Gross 83b05ef0ee Stabilize feature 'cstr_from_bytes_until_nul' 2023-02-01 02:14:07 -05:00
Matthias Krüger 1dbb5efff3
Rollup merge of #107442 - lukas-code:slice-panics, r=cuviper
improve panic message for slice windows and chunks

before:
```text
thread 'main' panicked at 'size is zero', /rustc/1e225413a21fa69570bd3fefea9eb05e33f8b917/library/core/src/slice/mod.rs:809:44
```
```text
thread 'main' panicked at 'assertion failed: `(left != right)`
  left: `0`,
 right: `0`: chunks cannot have a size of zero', /rustc/1e225413a21fa69570bd3fefea9eb05e33f8b917/library/core/src/slice/mod.rs:843:9
```

after:
```text
thread 'main' panicked at 'chunk size must be non-zero', src/main.rs:4:22
```

fixes https://github.com/rust-lang/rust/issues/107437
2023-02-01 05:54:38 +01:00
Matthias Krüger 0d2ab67742
Rollup merge of #107389 - zvavybir:master, r=estebank
Fixing confusion between mod and remainder

Like many programming languages, rust too confuses remainder and modulus.  The `%` operator and the associated `Rem` trait is (as the trait name suggests) the remainder, but since most people are linguistically more familiar with the modulus the documentation sometimes claims otherwise.  This PR tries to fix this problem in rustc.
2023-02-01 05:54:37 +01:00
Nugine a4f2d14875
Stabilize cmpxchg16b_target_feature 2023-02-01 10:54:43 +08:00
Amanieu d'Antras 36831b3ccb BTreeMap: Add Cursor and CursorMut 2023-02-01 00:16:15 +00:00
Amanieu d'Antras eb70c82d29 BTreeMap: Change internal insert function to return a handle
This is a prerequisite for cursor support for `BTreeMap`.
2023-02-01 00:08:59 +00:00
Lukas Markeffsky 2fbe9274aa improve panic message for slice windows and chunks 2023-01-31 23:49:42 +01:00
Guillaume Gomez adc3f8a44b
Rollup merge of #107535 - dcompoze:tcp-doc-unwrap, r=cuviper
Replace unwrap with ? in TcpListener doc

The example in TcpListener doc returns `std::io::Result<()>` but the code inside the function uses `unwrap()` instead of `?`.
2023-01-31 23:38:55 +01:00
Daniel Chmielewski 943f833314
Replace unwrap with ? in TcpListener doc 2023-01-31 21:04:49 +00:00
bors dc1d9d50fb Auto merge of #107297 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini
Bump bootstrap compiler to 1.68

This also changes our stage0.json to include the rustc component for the rustfmt pinned nightly toolchain, which is currently necessary due to rustfmt dynamically linking to that toolchain's librustc_driver and libstd.

r? `@pietroalbini`
2023-01-31 19:24:29 +00:00