Commit Graph

13358 Commits

Author SHA1 Message Date
Matthias Krüger
f1713b0447
Rollup merge of #103730 - SOF3:nonzero-from-mut, r=Mark-Simulacrum,dtolnay
Added NonZeroXxx::from_mut(_unchecked)?

ACP: rust-lang/libs-team#129
Tracking issue: #106290
2024-01-20 09:37:24 +01:00
AngelicosPhosphoros
60208a0517 Tweak the threshold for chunked swapping
Thanks to 98892 for the tests I brought in here, as it demonstrated that 3×usize is currently suboptimal.
2024-01-19 23:00:34 -08:00
Jules Bertholet
b72af9fe9b
Stabilize round_ties_even 2024-01-19 18:05:53 -05:00
The 8472
5796b3c167 fix: Drop guard was deallocating with the incorrect size
InPlaceDstBufDrop holds onto the allocation before the shrinking happens
which means it must deallocate the destination elements but the source
allocation.
2024-01-19 23:05:30 +01:00
SOFe
596410eb36
Assign tracking issue number for feature(nonzero_from_mut) 2024-01-19 13:53:13 -08:00
SOFe
3acb445f15
Added assert_unsafe_precondition! check for NonZeroXxx::from_mut_unchecked 2024-01-19 13:52:17 -08:00
SOFe
4459be7bd5
Added NonZeroXxx::from_mut(_unchecked)? 2024-01-19 13:50:24 -08:00
Michael Goulet
f2ef88ba06 Consolidate logic around resolving built-in coroutine trait impls 2024-01-19 21:28:37 +00:00
George Bateman
803b810eac
Remove feature(offset_of) from tests 2024-01-19 20:38:51 +00:00
George Bateman
615946db4f
Stabilize simple offset_of 2024-01-19 20:38:51 +00:00
Nicholas Thompson
76659ae743 Clarify Panicking Behavior in Integer Division Docs 2024-01-19 15:33:19 -05:00
Nicholas Thompson
6b8eae0d24 Make saturating_div Docs Consistent with Others 2024-01-19 15:27:26 -05:00
Nicholas Thompson
724fe8fcfb Adjust Attributes of Integer Division Methods 2024-01-19 15:23:58 -05:00
Catherine Flores
5a4561749a Add new intrinsic is_constant and optimize pow
Fix overflow check

Make MIRI choose the path randomly and rename the intrinsic

Add back test

Add miri test and make it operate on `ptr`

Define `llvm.is.constant` for primitives

Update MIRI comment and fix test in stage2

Add const eval test

Clarify that both branches must have the same side effects

guaranteed non guarantee

use immediate type instead

Co-Authored-By: Ralf Jung <post@ralfj.de>
2024-01-19 13:46:27 -05:00
Matthias Krüger
455382d8df
Rollup merge of #119984 - kpreid:waker-noop, r=dtolnay
Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.

The advantage of this is that it does not need to be assigned to a variable to be used in a `Context` creation, which is the most common thing to want to do with a noop waker. It also avoids unnecessarily executing the dynamically dispatched drop function when the noop waker is dropped.

If an owned noop waker is desired, it can be created by cloning, but the reverse is harder to do since it requires declaring a constant. Alternatively, both versions could be provided, like `futures::task::noop_waker()` and `futures::task::noop_waker_ref()`, but that seems to me to be API clutter for a very small benefit, whereas having the `&'static` reference available is a large reduction in boilerplate.

[Previous discussion on the tracking issue starting here](https://github.com/rust-lang/rust/issues/98286#issuecomment-1862159766)
2024-01-19 19:27:01 +01:00
Matthias Krüger
64461dab01
Rollup merge of #117561 - tgross35:split-array, r=scottmcm
Stabilize `slice_first_last_chunk`

This PR does a few different things based around stabilizing `slice_first_last_chunk`. They are split up so this PR can be by-commit reviewed, I can move parts to a separate PR if desired.

This feature provides a very elegant API to extract arrays from either end of a slice, such as for parsing integers from binary data.

## Stabilize `slice_first_last_chunk`

ACP: https://github.com/rust-lang/libs-team/issues/69
Implementation: https://github.com/rust-lang/rust/issues/90091
Tracking issue: https://github.com/rust-lang/rust/issues/111774

This stabilizes the functionality from https://github.com/rust-lang/rust/issues/111774:

```rust
impl [T] {
    pub const fn first_chunk<const N: usize>(&self) -> Option<&[T; N]>;
    pub fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>;
    pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]>;
    pub fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>;
    pub const fn split_first_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])>;
    pub fn split_first_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T; N], &mut [T])>;
    pub const fn split_last_chunk<const N: usize>(&self) -> Option<(&[T], &[T; N])>;
    pub fn split_last_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T], &mut [T; N])>;
}
```

Const stabilization is included for all non-mut methods, which are blocked on `const_mut_refs`. This change includes marking the trivial function `slice_split_at_unchecked` const-stable for internal use (but not fully stable).

## Remove `split_array` slice methods

Tracking issue: https://github.com/rust-lang/rust/issues/90091
Implementation: https://github.com/rust-lang/rust/pull/83233#pullrequestreview-780315524

This PR also removes the following unstable methods from the `split_array` feature, https://github.com/rust-lang/rust/issues/90091:

```rust
impl<T> [T] {
    pub fn split_array_ref<const N: usize>(&self) -> (&[T; N], &[T]);
    pub fn split_array_mut<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]);

    pub fn rsplit_array_ref<const N: usize>(&self) -> (&[T], &[T; N]);
    pub fn rsplit_array_mut<const N: usize>(&mut self) -> (&mut [T], &mut [T; N]);
}
```

This is done because discussion at #90091 and its implementation PR indicate a strong preference for nonpanicking APIs that return `Option`. The only difference between functions under the `split_array` and `slice_first_last_chunk` features is `Option` vs. panic, so remove the duplicates as part of this stabilization.

This does not affect the array methods from `split_array`. We will want to revisit these once `generic_const_exprs` is further along.

## Reverse order of return tuple for `split_last_chunk{,_mut}`

An unresolved question for #111774 is whether to return `(preceding_slice, last_chunk)` (`(&[T], &[T; N])`) or the reverse (`(&[T; N], &[T])`), from `split_last_chunk` and `split_last_chunk_mut`. It is currently implemented as `(last_chunk, preceding_slice)` which matches `split_last -> (&T, &[T])`. The first commit changes these to `(&[T], &[T; N])` for these reasons:

- More consistent with other splitting methods that return multiple values: `str::rsplit_once`, `slice::split_at{,_mut}`, `slice::align_to` all return tuples with the items in order
- More intuitive (arguably opinion, but it is consistent with other language elements like pattern matching `let [a, b, rest @ ..] ...`
- If we ever added a varidic way to obtain multiple chunks, it would likely return something in order: `.split_many_last::<(2, 4)>() -> (&[T], &[T; 2], &[T; 4])`
- It is the ordering used in the `rsplit_array` methods

I think the inconsistency with `split_last` could be acceptable in this case, since for `split_last` the scalar `&T` doesn't have any internal order to maintain with the other items.

## Unresolved questions

Do we want to reserve the same names on `[u8; N]` to avoid inference confusion? https://github.com/rust-lang/rust/pull/117561#issuecomment-1793388647

---

`slice_first_last_chunk` has only been around since early 2023, but `split_array` has been around since 2021.

`@rustbot` label -T-libs +T-libs-api -T-libs +needs-fcp
cc `@rust-lang/wg-const-eval,` `@scottmcm` who raised this topic, `@clarfonthey` implementer of `slice_first_last_chunk` `@jethrogb` implementer of `split_array`

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Stabilizing.20array-from-slice.20*something*.3F

Fixes: #111774
2024-01-19 19:26:59 +01:00
Matthias Krüger
7219bd22ed
Rollup merge of #120110 - invpt:patch-1, r=the8472
Update documentation for Vec::into_boxed_slice to be more clear about excess capacity

Currently, the documentation for Vec::into_boxed_slice says that "if the vector has excess capacity, its items will be moved into a newly-allocated buffer with exactly the right capacity." This is misleading, as copies do not necessarily occur, depending on if the allocator supports in-place shrinking. I copied some of the wording from shrink_to_fit, though it could potentially still be worded better than this.
2024-01-19 08:15:05 +01:00
Matthias Krüger
332f8f73ea
Rollup merge of #120107 - shepmaster:dead-code-repr-transparent, r=Nilstrieb
dead_code treats #[repr(transparent)] the same as #[repr(C)]

In #92972 we enabled linting on unused fields in tuple structs. In #118297 that lint was enabled by default. That exposed issues like #119659, where the fields of a struct marked `#[repr(transparent)]` were reported by the `dead_code` lint. The language team [decided](https://github.com/rust-lang/rust/issues/119659#issuecomment-1885172045) that the lint should treat `repr(transparent)` the same as `#[repr(C)]`.

Fixes #119659
2024-01-19 08:15:05 +01:00
Matthias Krüger
48ba7217c6
Rollup merge of #119907 - asquared31415:fn_trait_docs, r=Nilstrieb
Update `fn()` trait implementation docs

Fixes #119903

This was FCP'd and approved for the 1.70.0 release, this is just a docs update to match that change.
2024-01-19 08:15:04 +01:00
Matthias Krüger
f9076bbcf1
Rollup merge of #119138 - AngelicosPhosphoros:use_proper_atomics_in_spinlock_example, r=Nilstrieb
Docs: Use non-SeqCst in module example of atomics

I done this for this reasons:
1. The example now shows that there is more Orderings than just SeqCst.
2. People who would copy from example would now have more suitable orderings for the job.
3. SeqCst is both much harder to reason about and not needed in most situations.

IMHO, we should encourage people to think and use memory orderings that is suitable to task instead of blindly defaulting to SeqCst.

r? `@m-ou-se`
2024-01-19 08:15:03 +01:00
Matthias Krüger
2d828cd253
Rollup merge of #118798 - GnomedDev:use-atomicu8-backtrace, r=Nilstrieb
Use AtomicU8 instead of AtomicUsize in backtrace.rs

Just a small inefficiency I saw when looking at std sources.
2024-01-19 08:15:02 +01:00
Matthias Krüger
122b3f9303
Rollup merge of #118665 - dtolnay:signedness, r=Nilstrieb
Consolidate all associated items on the NonZero integer types into a single impl block per type

**Before:**

```rust
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
pub struct NonZeroI8(i8);

impl NonZeroI8 {
    pub const fn new(n: i8) -> Option<Self> ...
    pub const fn get(self) -> i8 ...
}

impl NonZeroI8 {
    pub const fn leading_zeros(self) -> u32 ...
    pub const fn trailing_zeros(self) -> u32 ...
}

impl NonZeroI8 {
    pub const fn abs(self) -> NonZeroI8 ...
}
...
```

**After:**

```rust
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
pub struct NonZeroI8(i8);

impl NonZeroI8 {
    pub const fn new(n: i8) -> Option<Self> ...
    pub const fn get(self) -> i8 ...
    pub const fn leading_zeros(self) -> u32 ...
    pub const fn trailing_zeros(self) -> u32 ...
    pub const fn abs(self) -> NonZeroI8 ...
    ...
}
```

Having 6-7 different impl blocks per type is not such a problem in today's implementation, but becomes awful upon the switch to a generic `NonZero<T>` type (context: https://github.com/rust-lang/rust/issues/82363#issuecomment-921513910).

In the implementation from https://github.com/rust-lang/rust/pull/100428, there end up being **67** impl blocks on that type.

<img src="https://github.com/rust-lang/rust/assets/1940490/5b68bd6f-8a36-4922-baa3-348e30dbfcc1" width="200"><img src="https://github.com/rust-lang/rust/assets/1940490/2cfec71e-c2cd-4361-a542-487f13f435d9" width="200"><img src="https://github.com/rust-lang/rust/assets/1940490/2fe00337-7307-405d-9036-6fe1e58b2627" width="200">

Without the refactor to a single impl block first, introducing `NonZero<T>` would be a usability regression compared to today's separate pages per type. With all those blocks expanded, Ctrl+F is obnoxious because you need to skip 12&times; past every match you don't care about. With all the blocks collapsed, Ctrl+F is useless. Getting to a state in which exactly one type's (e.g. `NonZero<u32>`) impl blocks are expanded while the rest are collapsed is annoying.

After this refactor to a single impl block, we can move forward with making `NonZero<T>` a generic struct whose docs all go on the same rustdoc page. The rustdoc will have 12 impl blocks, one per choice of `T` supported by the standard library. The reader can expand a single one of those impl blocks e.g. `NonZero<u32>` to understand the entire API of that type.

Note that moving the API into a generic `impl<T> NonZero<T> { ... }` is not going to be an option until after `NonZero<T>` has been stabilized, which may be months or years after its introduction. During the period while generic `NonZero` is unstable, it will be extra important to offer good documentation on all methods demonstrating the API being used through the stable aliases such as `NonZeroI8`.

This PR follows a `key = $value` syntax for the macros which is similar to the macros we already use for producing a single large impl block on the integer primitives.

1dd4db5062/library/core/src/num/mod.rs (L288-L309)

Best reviewed one commit at a time.
2024-01-19 08:15:02 +01:00
invpt
35a9fc3472 Clarify docs for Vec::into_boxed_slice, Vec::shrink_to_fit 2024-01-18 18:01:36 -05:00
Jiahao XU
baa2cf5ea6
Update std::io::Error::downcast return type
and update its doc according to decision made by rust libs-api team.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2024-01-19 09:26:56 +11:00
The 8472
85d1787962 remove alignment-changing in-place collect
Currently stable users can't benefit from this because GlobaAlloc doesn't support
alignment-changing realloc and neither do most posix allocators.
So in practice it always results in an extra memcpy.
2024-01-18 22:50:14 +01:00
The 8472
b28a95391b update internal ASCII art comment for vec specializations 2024-01-18 22:47:20 +01:00
Jake Goulding
fb7762b1c5 Remove no-longer-needed allow(dead_code) from the standard library
`repr(transparent)` now silences the lint.
2024-01-18 13:14:42 -05:00
Kevin Reid
c48cdfe8ee Remove unnecessary lets and borrowing from Waker::noop() usage.
`Waker::noop()` now returns a `&'static Waker` reference, so it can be
passed directly to `Context` creation with no temporary lifetime issue.
2024-01-17 12:00:27 -08:00
Kevin Reid
6f8a944ba4 Change return type of unstable Waker::noop() from Waker to &Waker.
The advantage of this is that it does not need to be assigned to a
variable to be used in a `Context` creation, which is the most common
thing to want to do with a noop waker.

If an owned noop waker is desired, it can be created by cloning, but the
reverse is harder. Alternatively, both versions could be provided, like
`futures::task::noop_waker()` and `futures::task::noop_waker_ref()`, but
that seems to me to be API clutter for a very small benefit, whereas
having the `&'static` reference available is a large benefit.

Previous discussion on the tracking issue starting here:
https://github.com/rust-lang/rust/issues/98286#issuecomment-1862159766
2024-01-17 11:53:16 -08:00
Matthias Krüger
a2eefd2718
Rollup merge of #120044 - Storyyeller:patch-2, r=lqd
Fix typo in comments (in_place_collect)
2024-01-17 20:21:23 +01:00
Matthias Krüger
c9779afc9c
Rollup merge of #119855 - rellerreller:freebsd-static, r=wesleywiser
Enable Static Builds for FreeBSD

Enable crt-static for FreeBSD to enable statically compiled binaries.
2024-01-17 20:21:19 +01:00
Aldan Tanneo
1b9a01340b
specialize Bytes on StdinLock<'_> by using the underlying BufReader 2024-01-17 10:47:33 +01:00
Scott McMurray
aa72e549cf Un-hide iter::repeat_n 2024-01-16 21:45:24 -08:00
Robert Grosse
db7125f008
Fix typo in comments (in_place_collect) 2024-01-16 20:48:22 -08:00
novafacing
ee007ab187 proc_macro_c_str_literals: Implement Literal::c_string constructor 2024-01-16 13:27:58 -08:00
LegionMammal978
bc3fb5245a Rename pointer field on Pin
The internal, unstable field of `Pin` can conflict with fields from the
inner type accessed via the `Deref` impl. Rename it from `pointer` to
`__pointer`, to make it less likely to conflict with anything else.
2024-01-16 14:58:42 -05:00
bors
e64f8495e7 Auto merge of #120025 - matthiaskrgr:rollup-e9ai06k, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #118361 (stabilise bound_map)
 - #119816 (Define hidden types in confirmation)
 - #119900 (Inline `check_closure`, simplify `deduce_sig_from_projection`)
 - #119969 (Simplify `closure_env_ty` and `closure_env_param`)
 - #119990 (Add private `NonZero<T>` type alias.)
 - #119998 (Update books)
 - #120002 (Lint `overlapping_ranges_endpoints` directly instead of collecting into a Vec)
 - #120018 (Don't allow `.html` files in `tests/mir-opt/`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-16 17:33:12 +00:00
Matthias Krüger
ac3108f208
Rollup merge of #119990 - reitermarkus:nonzero-type-alias, r=dtolnay
Add private `NonZero<T>` type alias.

According to step 2 suggested in https://github.com/rust-lang/rust/pull/100428#pullrequestreview-1767139731.

This adds a private type alias for `NonZero<T>` so that some parts of the code can already start using `NonZero<T>` syntax.

Using `NonZero<T>` for `convert` and other parts which implement `From` doesn't work while it is a type alias, since this results in conflicting implementations.
2024-01-16 17:55:24 +01:00
Matthias Krüger
304a17a475
Rollup merge of #118361 - Dylan-DPC:80626/stab/bound-map, r=Amanieu
stabilise bound_map

Closes https://github.com/rust-lang/rust/issues/86026
2024-01-16 17:55:21 +01:00
bors
bf2637f4e8 Auto merge of #119954 - scottmcm:option-unwrap-failed, r=WaffleLapkin
Split out `option::unwrap_failed` like we have `result::unwrap_failed`

...and like `option::expect_failed`
2024-01-16 15:32:39 +00:00
David Tolnay
604d2083d3
Revert unrelated changes from PR 119990 2024-01-15 13:09:46 -08:00
bors
67e7b84425 Auto merge of #119987 - matthiaskrgr:rollup-f7lkx4w, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #119818 (Silence some follow-up errors [3/x])
 - #119870 (std: Doc blocking behavior of LazyLock)
 - #119897 (`OutputTypeParameterMismatch` -> `SignatureMismatch`)
 - #119963 (Fix `allow_internal_unstable` for `(min_)specialization`)
 - #119971 (Use `zip_eq` to enforce that things being zipped have equal sizes)
 - #119974 (Minor `trimmed_def_paths` improvements)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-15 16:45:41 +00:00
joboet
70b0364500
std: move OS String implementation into sys 2024-01-15 16:26:25 +01:00
Markus Reiter
f7602232a5
Add private NonZero<T> type alias. 2024-01-15 13:44:52 +01:00
bors
1ead4761e9 Auto merge of #119878 - scottmcm:inline-always-unwrap, r=workingjubilee
Tune the inlinability of `unwrap`

Fixes #115463
cc `@thomcc`

This tweaks `unwrap` on ~~`Option` &~~ `Result` to be two parts:
- `#[inline(always)]` for checking the discriminant
- `#[cold]` for actually panicking

The idea here is that checking the discriminant on a `Result` ~~or `Option`~~ should always be trivial enough to be worth inlining, even in `opt-level=z`, especially compared to passing it to a function.

As seen in the issue and codegen test, this will hopefully help particularly for things like `.try_into().unwrap()`s that are actually infallible, but in a way that's only visible with the inlining.

EDIT: I've restricted this to `Result` to avoid combining effects
2024-01-15 09:20:46 +00:00
Matthias Krüger
6f2670da7b
Rollup merge of #119870 - behnam-oneschema:lazylock-blocking-1, r=tgross35,ChrisDenton
std: Doc blocking behavior of LazyLock

Adding notes about blocking behavior of calls that can block the current thread, similar to those on https://doc.rust-lang.org/std/sync/struct.OnceLock.html

I'm not sure if the "This method never blocks." counterparts would be desired. If so, can add those, as well.
2024-01-15 08:44:48 +01:00
David Carlier
89cf17777b std::net: bind update for using backlog as -1 too.
Albeit not documented, macOs also support negative value for the backlog
argument.

ref: 2ff845c2e0/bsd/kern/uipc_socket.c (L1061)
2024-01-15 07:26:19 +00:00
bors
30dfb9e046 Auto merge of #119970 - GuillaumeGomez:rollup-p53c19o, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #119561 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 5))
 - #119742 (ARMv6K HorizonOS - Fix backlog for UnixListener)
 - #119960 (Inline 2 functions that appear in dep-graph profiles.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-14 21:15:48 +00:00
David Tolnay
cdee1feb49
Unbreak tidy's feature parser
tidy error: /git/rust/library/core/src/num/nonzero.rs:67: malformed stability attribute: missing `feature` key
    tidy error: /git/rust/library/core/src/num/nonzero.rs:82: malformed stability attribute: missing `feature` key
    tidy error: /git/rust/library/core/src/num/nonzero.rs:98: malformed stability attribute: missing the `since` key
    tidy error: /git/rust/library/core/src/num/nonzero.rs:112: malformed stability attribute: missing `feature` key
    tidy error: /git/rust/library/core/src/num/nonzero.rs:450: malformed stability attribute: missing `feature` key
    some tidy checks failed
2024-01-14 12:45:46 -08:00
David Tolnay
c53713274c
Move BITS into omnibus impl block 2024-01-14 12:45:46 -08:00
David Tolnay
66cda3b75f
Move signed MIN and MAX into signedness_dependent_methods 2024-01-14 12:45:45 -08:00
David Tolnay
7f7c5af097
Move unsigned MIN and MAX into signedness_dependent_methods 2024-01-14 12:45:44 -08:00
David Tolnay
441913626d
Move is_power_of_two into unsigned part of signedness_dependent_methods 2024-01-14 12:45:44 -08:00
David Tolnay
63256af236
Move nonzero_unsigned_signed_operations methods into the omnibus impl block 2024-01-14 12:45:43 -08:00
David Tolnay
c6d776ef4b
Work around rustfmt doc attribute indentation bug 2024-01-14 12:45:41 -08:00
David Tolnay
b21b9cc901
Unindent nonzero_integer_signedness_dependent_methods macro body 2024-01-14 12:45:37 -08:00
David Tolnay
4291b3ff62
Move signedness dependent methods into the omnibus impl block 2024-01-14 12:45:10 -08:00
David Tolnay
757ed25667
Move Neg impl into the macro that generates Div and Rem 2024-01-14 12:45:09 -08:00
Scott McMurray
23483664a2 Split out option::unwrap_failed like we have result::unwrap_failed
...and like `option::expect_failed`
2024-01-14 12:45:01 -08:00
David Tolnay
f846ed53e4
Move leading_zeros and trailing_zeros methods into nonzero_integer macro 2024-01-14 12:45:00 -08:00
David Tolnay
a78d9a6de1
Unindent nonzero_integer_impl_div_rem macro body 2024-01-14 12:43:51 -08:00
David Tolnay
81e1a7c6b5
Move impl Div and Rem into nonzero_integer macro 2024-01-14 12:43:50 -08:00
David Tolnay
3de0af1a4d
Move 'impl FromStr for NonZero' into nonzero_integer macro 2024-01-14 12:43:49 -08:00
David Tolnay
a6152cdd9a
Format nonzero_integer macro calls same way we do the primitive int impls
The `key = $value` style will be beneficial as we introduce some more
macro arguments here in later commits.
2024-01-14 12:43:49 -08:00
David Tolnay
9196d2a552
Unindent nonzero_integer macro body 2024-01-14 12:43:37 -08:00
David Tolnay
54cb822563
Define only a single NonZero type per macro call
Later in this stack, as the nonzero_integers macro is going to be
responsible for producing a larger fraction of the API for the NonZero
integer types, it will need to receive a number of additional arguments
beyond the ones currently seen here.

Additional arguments, especially named arguments across multiple lines,
will turn out clearer if everything in one macro call is for the same
NonZero type.

This commit adopts a similar arrangement to what we do for generating
the API of the integer primitives (`impl u8` etc), which also generate a
single type's API per top-level macro call, rather than generating all
12 impl blocks for the 12 types from one macro call.
2024-01-14 12:40:33 -08:00
David Tolnay
56df3bb70d
Move nonzero_integers macro call to bottom of module
This way all the other macros defined in this module, such as
nonzero_leading_trailing_zeros, are available to call within the expansion of
nonzero_integers.

(Macros defined by macro_rules cannot be called from the same module above the
location of the macro_rules.)

In this commit the ability to call things like nonzero_leading_trailing_zeros is
not immediately used, but later commits in this stack will be consolidating the
entire API of NonZeroT to be generated through nonzero_integers, and will need
to make use of some of the other macros to do that.
2024-01-14 12:40:18 -08:00
Guillaume Gomez
e401754717
Rollup merge of #119742 - Meziu:armv6k-nintendo-3ds, r=Mark-Simulacrum
ARMv6K HorizonOS - Fix backlog for UnixListener

Simple `#[cfg]` fix to avoid using `libc::SOMAXCONN`, which isn't defined for the `armv6k-nintendo-3ds` target.

Edit: This is similar to #119632.
2024-01-14 20:17:23 +01:00
bors
665d2c6f2c Auto merge of #119796 - androm3da:bcain/compiler_builtins_0_1_105, r=Mark-Simulacrum
Update compiler_builtins to 0.1.105

This provides the builtins for the hexagon architecture.
2024-01-14 19:15:37 +00:00
Behnam Esfahbod
a596159dca std: Doc blocking behavior of LazyLock methods 2024-01-14 10:28:13 -08:00
Guillaume Gomez
a9146ce683
Rollup merge of #119949 - clubby789:spec-newtype-comment, r=nnethercote
Add note on SpecOptionPartialEq to `newtype_index`

https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/.60SpecOptionPartialEq.60.20error

r? `@nnethercote`
2024-01-14 14:02:29 +01:00
clubby789
4ca6342eb3 Add note on SpecOptionPartialEq to newtype_index 2024-01-14 00:24:39 +00:00
Matthias Krüger
3a33a4b8f5
Rollup merge of #119935 - joboet:move_pal_personality, r=ChrisDenton
Move personality implementation out of PAL

The module already follows the new convention described in #117276. This PR also includes a small fix in the tidy pal check, that was just an oversight in #117285.
2024-01-13 22:35:09 +01:00
joboet
fa9a911a57
libs: use assert_unchecked instead of intrinsic 2024-01-13 20:10:00 +01:00
Mads Marquart
3b325bc25f Refactor uses of objc_msgSend to no longer have clashing definitions
This is very similar to what Apple's own headers encourage you to do (cast the function pointer before use instead of making new declarations).

Additionally, I'm documenting a few of the memory management rules we're following, ensuring that the `args` function doesn't leak memory (if you wrap it in an autorelease pool).
2024-01-13 19:48:07 +01:00
Sean Cross
50e4fede24 xous: thread: mark thread_main() as divergent
The thread wrapper function never returns, so we can mark it as
divergent.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:38:42 -08:00
Sean Cross
99b06594a8 std: xous: use constants for stdout and stderr
Use constants for the opcodes when writing to stdout or stderr.

There still is no stdin operation.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:38:42 -08:00
Sean Cross
aa73860628 std: xous: mark stdio structs as repr(C)
Ensure these structs have a well-defined ABI layout.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:38:42 -08:00
Sean Cross
aa8acc2215 xous: net: initial commit of network support
This is an initial commit of network support for Xous.

On hardware, is backed by smoltcp running via a Xous server in a
separate process space.

This patch adds TCP and UDP client and server support as well as DNS
resolution support using the dns Xous server.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:38:42 -08:00
joboet
cb052d57b3
std: move personality implementation out of PAL 2024-01-13 18:30:44 +01:00
Sean Cross
ef4f722835 std: xous: share allocator symbol in tests
When using the testing framework, a second copy of libstd is built and
linked. Use a global symbol for the `DLMALLOC` variable and mark it as
`extern` when building as a test.

This ensures we only have a single allocator even when running tests.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:56 -08:00
Sean Cross
007bf7a05a std: xous: fix thread_local_key under tests
When running tests, libstd gets implemented as a second library. Due to
this fact, the `create()` and `destroy()` functions come from different
libraries.

To work around this, stash the `destroy_tls()` pointer in the first
unused slot in the thread local storage pool. That way even if
the destruction comes from a different version of libstd, the correct
`DTORS` list will be consulted.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:56 -08:00
Sean Cross
762e58a218 std: once: use queue implementation on Xous
Use the global queue implementation of Once when running on Xous. This
gets us a thread-safe implementation, rather than using the
non-threadsafe `unsupported` implementation.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:56 -08:00
Sean Cross
eabd445053 std: xous: rewrite rwlock to be more robust
Add more checks to RwLock on Xous. As part of this, ensure the variable
is in a good state when unlocking.

Additionally, use the global `yield_now()` rather than platform-specific
`do_yield()`.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:56 -08:00
Sean Cross
b5c1c47990 std: xous: use blocking_scalars for mutex unlock
Use blocking scalars when unlocking a mutex. This ensures that mutexes
are unlocked immediately rather than dangling.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:56 -08:00
Sean Cross
f732d2bfe2 std: xous: pass entire memory range to flag updater
When updating memory flags via `update_memory_flags()`, ensure we
multiply the slice length by the element size to get the full memory
size.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:56 -08:00
Sean Cross
626926f073 std: xous: rework condvar to fix soundness issues
Rework the Condvar implementation on Xous to ensure notifications are
not missed. This involves keeping track of how many times a Condvar
timed out and synchronizing based on that.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:56 -08:00
bunnie
118e8f7840 xous: std: thread_parking: fix deadlocks
Fix a deadlock condition that can occur when a thread is awoken in
between the point at which it checks its wake state and the point where
it actually waits.

This change will cause the waker to continuously send Notify messages
until it actually wakes up the target thread.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:56 -08:00
Sean Cross
944dc21268 xous: ffi: correct size of freed memory
The amount of memory allocated was multiplied by sizeof::<T>(), so the
amount of memory to be freed should also be multiplied by sizeof::<T>().

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:55 -08:00
Sean Cross
dee1c260b8 xous: ffi: fix lend_impl() return values
The `ret1` and `ret2` return values from lend operations are returned in
$a1 and $a2. This function incorrectly pulled them from $a6 and $a7,
causing them to always be `0`.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13 09:13:55 -08:00
bors
c6c4abf584 Auto merge of #119927 - matthiaskrgr:rollup-885ws57, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #119587 (Varargs support for system ABI)
 - #119891 (rename `reported_signature_mismatch` to reflect its use)
 - #119894 (Allow `~const` on associated type bounds again)
 - #119896 (Taint `_` placeholder types in trait impl method signatures)
 - #119898 (Remove unused `ErrorReporting` variant from overflow handling)
 - #119902 (fix typo in `fn()` docs)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-13 16:09:45 +00:00
bors
1d8d7b16cb Auto merge of #117285 - joboet:move_platforms_to_pal, r=ChrisDenton
Move platform modules into `sys::pal`

This is the initial step of #117276. `sys` just re-exports everything from the current `sys` for now, I'll move the implementations for the individual features one-by-one after this PR merges.
2024-01-13 14:10:56 +00:00
Matthias Krüger
f53caa1106
Rollup merge of #119902 - asquared31415:patch-1, r=the8472
fix typo in `fn()` docs
2024-01-13 15:10:30 +01:00
joboet
0cfc995814
don't break a good link
Co-authored-by: klensy <klensy@users.noreply.github.com>
2024-01-13 09:18:36 +01:00
Zalathar
a655558b38 Remove special-case handling of vec.split_off(0) 2024-01-13 17:21:54 +11:00
asquared31415
46ad13136c update fn pointer trait impl docs 2024-01-12 22:09:38 +00:00
asquared31415
51afc0922c
fix typo in fn() docs 2024-01-12 15:51:18 -05:00
bors
2319be8e26 Auto merge of #119452 - AngelicosPhosphoros:make_nonzeroint_get_assume_nonzero, r=scottmcm
Add assume into `NonZeroIntX::get`

LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments.

Related to https://github.com/rust-lang/rust/issues/119422
Related to https://github.com/llvm/llvm-project/issues/76628
Related to https://github.com/rust-lang/rust/issues/49572
2024-01-12 20:18:04 +00:00
Scott McMurray
b858c591dd Tune the inlinability of Result::unwrap 2024-01-12 10:57:58 -08:00
bors
5431404b87 Auto merge of #118548 - Enselic:bench-padding, r=thomcc,ChrisDenton
libtest: Fix padding of benchmarks run as tests

### Summary

The first commit adds regression tests for libtest padding.

The second commit fixes padding for benches run as tests and updates the blessed output of the regression tests to make it clear what effect the fix has on padding.

Closes #104092 which is **E-help-wanted** and **regression-from-stable-to-stable**

### More details

Before this fix we applied padding _before_ manually doing what `convert_benchmarks_to_tests()` does which affects padding calculations. Instead use `convert_benchmarks_to_tests()` first if applicable and then apply padding afterwards so it becomes correct.

Benches should only be padded when run as benches to make it easy to compare the benchmark numbers. Not when run as tests.

r? `@ghost` until CI passes.
2024-01-12 05:06:03 +00:00
bors
6029085a6f Auto merge of #119430 - NCGThompson:int-pow-bench, r=cuviper
Add Benchmarks for int_pow Methods.

There is quite a bit of room for improvement in performance of the `int_pow` family of methods. I added benchmarks for those functions. In particular, there are benchmarks for small compile-time bases to measure the effect of  #114390. ~~I added a lot (245), but all but 22 of them are marked with `#[ignore]`. There are a lot of macros, and I would appreciate feedback on how to simplify them.~~

~~To run benches relevant to #114390, use `./x bench core --stage 1 -- pow_base_const --include-ignored`.~~
2024-01-12 03:04:45 +00:00
joboet
7c436a8af4
update paths in comments 2024-01-12 00:11:33 +01:00
joboet
d6efeadb06
std: fix module references on Windows 2024-01-11 20:26:20 +01:00
joboet
411f34b782
std: fix module references on UNIX 2024-01-11 20:26:06 +01:00
joboet
cac470cde1
std: fix module references on UEFI 2024-01-11 20:21:05 +01:00
joboet
4ab475dfb5
std: fix module reference on SGX 2024-01-11 20:18:17 +01:00
joboet
4da4958099
std: fix module references on hermit 2024-01-11 20:16:09 +01:00
joboet
99128b7e45
std: begin moving platform support modules into pal 2024-01-11 20:10:25 +01:00
Nicholas Thompson
c65c35b3ef Reduced amount of int_pow benches
Also simplified the macros
2024-01-11 14:00:01 -05:00
Matthias Krüger
b3d15ebb08
Rollup merge of #119853 - klensy:rustfmt-ignore, r=cuviper
rustfmt.toml: don't ignore just any tests path, only root one

Previously ignored any `tests` path, now only /tests at repo root.

For reference, https://git-scm.com/docs/gitignore#_pattern_format
2024-01-11 19:42:53 +01:00
Matthias Krüger
1a4d3c9c47
Rollup merge of #119845 - RalfJung:rint, r=nagisa
rint: further doc tweaks

r? ``@nagisa``
2024-01-11 19:42:52 +01:00
Matthias Krüger
6beb676990
Rollup merge of #119836 - hi-rustin:rustin-patch-docs-blank-line, r=ChrisDenton
chore: remove unnecessary blank line

It seems no need to add an unnecessary line here.
2024-01-11 19:42:50 +01:00
Nicholas Thompson
7dcce97686 Edited int_pow micro-benchmarks 2024-01-11 11:30:12 -05:00
Nicholas Thompson
33a47df84a Added int_pow micro-benchmarks 2024-01-11 11:30:12 -05:00
Nicholas Thompson
7c28a50a3a removed nonfunctioning benchmark
It could also have been fixed by removing a semicolon instead.
2024-01-11 11:30:12 -05:00
Nathan Reller
adce3fd99b Enable Static Builds for FreeBSD
Enable crt-static for FreeBSD to enable statically compiled binaries.
2024-01-11 15:26:16 +00:00
Ralf Jung
6b6f2a5a28 rint: further doc tweaks 2024-01-11 13:33:27 +01:00
klensy
aa696c5a22 apply fmt 2024-01-11 15:04:48 +03:00
Matthias Krüger
f92cde4f9a
Rollup merge of #119804 - tmccombs:stabilize-unpoison, r=cuviper
Stabilize mutex_unpoison feature

Closes #96469

`@rustbot` +T-libs-api
2024-01-11 03:02:44 +01:00
hi-rustin
784b50cece chore: remove unnecessary blank line
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-11 09:45:21 +08:00
Jakub Stasiak
4621357d14 Make is_global/is_unicast_global special address handling complete
IANA explicitly documents 192.0.0.9/32, 192.0.0.9/32 and 2001:30::/28 as
globally reachable[1][2] and the is_global implementations declare
following IANA so let's make this happen.

In case of 2002::/16 IANA says N/A so I think it's safe to say we
shouldn't return true there either.

[1] https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
[2] https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
2024-01-11 01:03:34 +01:00
The8472
37d26c719d Implement in-place iteratation markers for iter::{Copied, Cloned} 2024-01-10 19:03:57 +01:00
The8472
3aa73135cf bench trustedrandomaccess specialization in zip 2024-01-10 18:59:44 +01:00
The8472
451a3b1775 implement TrustedRandomAccess and TrustedLen for Skip 2024-01-10 18:59:42 +01:00
The8472
a2a7caacf7 implement TrustedLen for StepBy 2024-01-10 18:55:34 +01:00
Thayne McCombs
1ed855dedf Stabilize mutex_unpoison feature
Closes #96469

@rustbot +T-libs-api
2024-01-10 02:34:34 -07:00
Emil Gardström
075f2e0345
Add #[track_caller] to the "From implies Into" impl 2024-01-10 10:30:54 +01:00
zachs18
bfe04e08c0 Fix deallocation with wrong allocator in (A)Rc::from_box_in 2024-01-10 02:17:47 -06:00
Trevor Gross
500d6f6479 Stabilize slice_first_last_chunk
This stabilizes all methods under `slice_first_last_chunk`.

Additionally, it const stabilizes the non-mut functions and moves the `_mut`
functions under `const_slice_first_last_chunk`. These are blocked on
`const_mut_refs`.

As part of this change, `slice_split_at_unchecked` was marked const-stable for
internal use (but not fully stable).
2024-01-10 03:06:49 -05:00
Matthias Krüger
3fcddf19e7
Rollup merge of #119782 - RalfJung:rint, r=cuviper
rint intrinsics: caution against actually trying to check for floating-point exceptions
2024-01-10 06:28:45 +01:00
Brian Cain
d5c39d0638 Update compiler_builtins to 0.1.105
This provides the builtins for the hexagon architecture.
2024-01-09 20:30:56 -08:00
Ralf Jung
fa5bef849e rint intrinsics: caution against actually trying to check for floating-point exceptions 2024-01-09 22:19:25 +01:00
bors
190f4c9611 Auto merge of #116846 - krtab:slice_compare_no_memcmp_opt, r=the8472
A more efficient slice comparison implementation for T: !BytewiseEq

(This is a follow up PR on #113654)

This PR changes the implementation for `[T]` slice comparison when `T: !BytewiseEq`. The previous implementation using zip was not optimized properly by the compiler, which didn't leverage the fact that both length were equal. Performance improvements are for example 20% when testing that `[Some(0_u64); 4096].as_slice() == [Some(0_u64); 4096].as_slice()`.
2024-01-09 20:52:34 +00:00
Guillaume Gomez
d61b92f154
Rollup merge of #119768 - ojeda:panic-link, r=Nilstrieb
core: panic: fix broken link
2024-01-09 17:52:22 +01:00
Guillaume Gomez
87b0de6cb7
Rollup merge of #118645 - Patryk27:bump-compiler-builtins, r=Nilstrieb,dtolnay
chore: Bump compiler_builtins

Actually closes https://github.com/rust-lang/rust/issues/118079.
2024-01-09 17:52:20 +01:00
Guillaume Gomez
5e75d46b67
Rollup merge of #118241 - fortanix:raoul/gh-530-make_userspace_types_send, r=Nilstrieb,dtolnay
Making `User<T>` and `User<[T]>` `Send`

All `User` types in SGX point to owned memory in userspace. Special care is always needed when accessing this memory as it must be assumed that an attacker is always able to change its content. Therefore, we can also easily transfer this memory between thread boundaries.

cc: ``@mzohreva`` ``@vn971`` ``@belalH`` ``@jethrogb``
2024-01-09 17:52:19 +01:00
Miguel Ojeda
18a1ca6a17 core: panic: fix broken link
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-01-09 14:15:45 +01:00
Guillaume Gomez
df2f4ae4ac
Rollup merge of #118748 - devnexen:fbsd_getrandom_simpl, r=Nilstrieb,dtolnay
std: getrandom simplification for freebsd.

it is in the libcs' crate too now.
2024-01-09 13:23:16 +01:00
Guillaume Gomez
4a24b5bc05
Rollup merge of #117556 - obeis:static-mut-ref-lint, r=davidtwco
Disallow reference to `static mut` and adding `static_mut_ref` lint

Closes #114447

r? `@scottmcm`
2024-01-09 13:23:15 +01:00
Andrea Ciliberti
7a7bb3ef85 Backlog for HorizonOS UnixListener 2024-01-09 12:21:17 +01:00
Matthias Krüger
50982bd4ab
Rollup merge of #119632 - ivmarkov:master, r=Nilstrieb,dtolnay
Fix broken build for ESP IDF due to #119026

`target_os = "espidf"` in `libc` lacks the `SOMAXCONN` constant, but that's probably irrelevant in this context, as `UnixListener` is not supported on ESP IDF - it being a single process "OS" only.

The PR just re-uses the `128` constant so that the code builds. Trying to use the listener on ESP IDF will fail with `ENOSYS`, which is fine.

*UPDATE* Might not fail with `ENOSYS` - need to test what error code would be returned, but that doesn`t change anything.
2024-01-09 05:33:22 +01:00
Matthias Krüger
b0c492cd6e
Rollup merge of #118979 - ChrisDenton:unwrap-const, r=Nilstrieb,dtolnay
Use `assert_unsafe_precondition` for `char::from_u32_unchecked`

Use `assert_unsafe_precondition` in `char::from_u32_unchecked` so that it can be stabilized as `const`.
2024-01-09 05:33:21 +01:00
Matthias Krüger
668e8b5541
Rollup merge of #119598 - Laura7089:fix/deref-typo, r=Nilstrieb
Fix a typo in core::ops::Deref's doc
2024-01-09 00:19:33 +01:00
Arthur Carcano
5b041abc8c A more efficient slice comparison implementation for T: !BytewiseEq
The previous implementation was not optimized properly by the compiler,
which didn't leverage the fact that both length were equal.
2024-01-08 16:36:48 +01:00
Matthias Krüger
a9b6908e7f
Rollup merge of #116129 - fu5ha:better-pin-docs-2, r=Amanieu
Rewrite `pin` module documentation to clarify usage and invariants

The documentation of `pin` today does not give a complete treatment of pinning from first principles, nor does it adequately help build intuition and understanding for how the different elements of the pinning story fit together.

This rewrite attempts to address these in a way that makes the concept more approachable while also making the documentation more normative.

This PR picks up where `@mcy` left off in #88500 (thanks to him for the original work and `@Manishearth` for mentioning it such that I originally found it). I've directly incorporated much of the feedback left on the original PR and have rewritten and changed some of the main conceits of the prose to better adhere to the feedback from the reviewers on that PR or just explain something in (hopefully) a better way.
2024-01-08 00:38:33 +01:00
Manish Goregaokar
7fd841c098 link 2024-01-07 08:57:23 -08:00
Manish Goregaokar
df6d44961d Update library/core/src/pin.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-01-07 08:56:25 -08:00
Manish Goregaokar
b1830f130a clean up structural pinning 2024-01-07 08:56:24 -08:00
Manish Goregaokar
a573c7c409 footnote on dropping futures 2024-01-07 08:56:24 -08:00
Manish Goregaokar
6a54ed71c0 valid 2024-01-07 08:56:24 -08:00