Commit Graph

12837 Commits

Author SHA1 Message Date
bors
abe34e9ab1 Auto merge of #118315 - WaffleLapkin:don't-repeat_byte, r=m-ou-se
Use `usize::repeat_u8` instead of implementing `repeat_byte` in `memchr.rs`

It's simpler that way and the tricks don't actually make a difference: https://godbolt.org/z/zrvYY1dGx
2023-11-29 13:39:19 +00:00
Matthias Krüger
afe2d7392f
Rollup merge of #118231 - RalfJung:const-raw-slice-empty, r=cuviper
also add is_empty to const raw slices

We have this on mutable raw slices but not const raw slices, which makes little sense.

Cc https://github.com/rust-lang/rust/issues/71146
2023-11-29 12:34:49 +01:00
bors
ec1f21cb04 Auto merge of #118433 - matthiaskrgr:rollup-fi9lrwg, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #116839 (Implement thread parking for xous)
 - #118265 (remove the memcpy-on-equal-ptrs assumption)
 - #118269 (Unify `TraitRefs` and `PolyTraitRefs` in `ValuePairs`)
 - #118394 (Remove HIR opkinds)
 - #118398 (Add proper cfgs in std)
 - #118419 (Eagerly return `ExprKind::Err` on `yield`/`await` in wrong coroutine context)
 - #118422 (Fix coroutine validation for mixed panic strategy)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-29 08:51:01 +00:00
Matthias Krüger
f8628a179d
Rollup merge of #118383 - shepmaster:unused-tuple-struct-field-cleanup-stdlib, r=m-ou-se
Address unused tuple struct fields in the standard library
2023-11-29 04:23:28 +01:00
Matthias Krüger
b7016ae205
Rollup merge of #118398 - mu001999:std/add_cfgs, r=thomcc
Add proper cfgs in std

Detected by #118257
2023-11-29 04:23:23 +01:00
Matthias Krüger
92a74e41b6
Rollup merge of #118265 - RalfJung:memcpy, r=cuviper
remove the memcpy-on-equal-ptrs assumption

One of the libc we support, musl, [defines `memcpy` with `restrict` pointers](https://git.musl-libc.org/cgit/musl/tree/src/string/memcpy.c#n5). This in fact matches the definition in the C standard. Calling that `memcpy` with overlapping pointers is clearly UB, who knows what the compiler did when optimizing this `memcpy` -- it certainly assumed source and destination to be disjoint.

Lucky enough, it does not seem like we actually need this assumption that `memcpy(p, p, n)` is always allowed. clang and GCC need it since they use `memcpy` to compile C assignments, but [we use memmove for similar code](https://godbolt.org/z/bcW85WYcM). There are no known cases where LLVM introduces calls to memcpy on equal pointers itself. (And if there were, that would be a soundness bug in rustc due to the musl issue mentioned above.)

This does mean we must make sure to never call the LLVM `memcpy` builtin on equal ranges even though the LangRef says that is allowed. Currently that is the case so we just need to make sure it remains the case. :) Cc `@rust-lang/opsem` `@rust-lang/wg-llvm`
2023-11-29 04:23:22 +01:00
Matthias Krüger
2eec51c27c
Rollup merge of #116839 - joboet:xous_thread_parking, r=m-ou-se
Implement thread parking for xous

This follows the pattern set by [the Windows parker](ddef56d5df/library/std/src/sys/windows/thread_parking.rs) when it uses keyed events. An atomic variable is used to track the state and optimize the fast path, while notifications are send via the ticktime server to block and unblock the thread.

ping `@xobs`
`@rustbot` label +T-libs +A-atomic
r? libs
2023-11-29 04:23:21 +01:00
bors
b1e56deada Auto merge of #114841 - bvanjoi:fix-114814, r=cuviper
add track_caller for arith ops

Fixes #114814

`#[track_caller]` is works, r? `@scottmcm`
2023-11-29 00:47:25 +00:00
Jake Goulding
115eac03bb Address unused tuple struct fields in the standard library 2023-11-28 12:00:54 -05:00
Matthias Krüger
97ef5a3b53
Rollup merge of #118222 - the8472:copy-use-vec-write, r=m-ou-se
unify read_to_end and io::copy impls for reading into a Vec

This ports over the initial probe (to avoid allocation) and the dynamic read sizing from the io::copy specialization to the `default_read_to_end` implementation which already had its own optimizations for different cases.

I think it should be a best-of-both now.

suggested by `@a1phyr` in https://github.com/rust-lang/rust/pull/117576#issuecomment-1803408492
2023-11-28 16:09:54 +01:00
Matthias Krüger
b8e1194ab2
Rollup merge of #118193 - max-heller:command-typo, r=m-ou-se
Add missing period in `std::process::Command` docs
2023-11-28 16:09:54 +01:00
bors
df0295f071 Auto merge of #110353 - the8472:in-place-flatten-chunks, r=cuviper
Expand in-place iteration specialization to Flatten, FlatMap and ArrayChunks

This enables the following cases to collect in-place:

```rust
let v = vec![[0u8; 4]; 1024]
let v: Vec<_> = v.into_iter().flatten().collect();

let v: Vec<Option<NonZeroUsize>> = vec![NonZeroUsize::new(0); 1024];
let v: Vec<_> = v.into_iter().flatten().collect();

let v = vec![u8; 4096];
let v: Vec<_> = v.into_iter().array_chunks::<4>().collect();
```

Especially the nicheful-option-flattening should be useful in real code.
2023-11-28 12:22:16 +00:00
Matthias Krüger
4f3ee302b7
Rollup merge of #118397 - Zalathar:nonzero, r=WaffleLapkin
Fix comments for unsigned non-zero `checked_add`, `saturating_add`

While looking at #118313, I happened to notice that two of the expanded comments appear to be slightly inaccurate.

For these two methods, `other` is an ordinary unsigned integer, so it can be zero.

Since the sum of non-zero and zero is always non-zero, the safety argument holds even when `other` is zero.
2023-11-28 09:28:39 +01:00
Matthias Krüger
7dbbffdc67
Rollup merge of #118314 - WaffleLapkin:rename_collectionstests, r=cuviper
Rename `{collections=>alloc}{tests,benches}`

The crate is named `alloc` so this makes more sense. Ig this is fallout from #42648?
2023-11-28 09:28:37 +01:00
Matthias Krüger
787f1a65df
Rollup merge of #118299 - frewsxcv:patch-2, r=cuviper
Update `OnceLock` documentation to give a concrete 'lazy static' example, and expand on the existing example.
2023-11-28 09:28:37 +01:00
Matthias Krüger
4704d49629
Rollup merge of #118236 - ksw2000:update_mod_comment, r=cuviper
Update mod comment

The comment of `ASCII_CASE_MASK` on line 477  is `If 6th bit is set ascii is lower case.` but the original comment of `*self ^ ((self.is_ascii_lowercase() as u8) * ASCII_CASE_MASK)` was `Toggle the fifth bit if this is a lowercase letter`
2023-11-28 09:28:36 +01:00
Matthias Krüger
4af1f99740
Rollup merge of #115331 - the8472:chars_advance, r=cuviper
optimize str::iter::Chars::advance_by

```
OLD:
    str::iter::chars_advance_by_0001  0.00ns/iter  +/- 0.00ns
    str::iter::chars_advance_by_0010 13.00ns/iter  +/- 1.00ns
    str::iter::chars_advance_by_1000  1.20µs/iter +/- 15.00ns

NEW:
    str::iter::chars_advance_by_0001  0.00ns/iter +/- 0.00ns
    str::iter::chars_advance_by_0010  6.00ns/iter +/- 0.00ns
    str::iter::chars_advance_by_1000 75.00ns/iter +/- 1.00ns
```
2023-11-28 09:28:36 +01:00
r0cky
c751bfa015 Add proper cfgs 2023-11-28 09:02:34 +08:00
Zalathar
00d5f18954 Fix comments for unsigned non-zero checked_add, saturating_add
For these two methods, `other` is an ordinary unsigned integer, so it can be zero.

Since the sum of non-zero and zero is always non-zero, the safety argument
holds even when `other` is zero.
2023-11-28 11:52:30 +11:00
The 8472
40cf1f9257 optimize str::iter::Chars::advance_by
this avoids part of the char decoding work by not looking at utf8 continuation bytes
2023-11-27 22:06:35 +01:00
The 8472
3f55e8665c benchmarks for Chars::advance_by 2023-11-27 22:06:35 +01:00
bors
a19161043a Auto merge of #118321 - WaffleLapkin:unspace-fn-pointer-fake-variadic, r=notriddle
rustdoc: Remove space from fake-variadic fn ptr impls

before: `for fn (T₁, T₂, …, Tₙ) -> Ret`
after: `for fn(T₁, T₂, …, Tₙ) -> Ret`

I don't think we usually have spaces there, so it looks weird.

cc `@notriddle` since you added the space in https://github.com/rust-lang/rust/pull/98180 (or rather, added the feature with a space included).
2023-11-27 06:16:15 +00:00
bors
601a42713c Auto merge of #118313 - WaffleLapkin:fixup_comments_in_some_nonzero_ops, r=thomcc
Improve some comments for non-zero ops

This makes them a bit more explicit/correct.
2023-11-27 04:18:54 +00:00
bors
1bcbb7c93b Auto merge of #117697 - WaffleLapkin:non-null-convenience-ops, r=Amanieu
Non null convenience ops

Based on https://github.com/rust-lang/libs-team/issues/251.

I went through all of the methods on `*mut` and added every method, which does not require additional safety conditions, to `NonNull`. (exceptions: `guaranteed_eq`, `guaranteed_ne`, `with_metadata_of`, it's unclear if they are useful here...)

I'm also not sure what types should the "second pointer parameter" be. `*mut`/`*const` might be more permissible, but given that `NonNull` doesn't coerce to them, it might also be annoying. For now I chose the "use `NonNull` everywhere" path, but I'm not sure it's the correct one...

<sub>I'm eepy, so I probably messed up somewhere while copying...</sub>

cc `@scottmcm`
r? libs-api
2023-11-26 18:41:55 +00:00
The 8472
bc7dd5fa6d unify read_to_end and io::copy impls for reading into a Vec 2023-11-26 18:13:36 +01:00
Maybe Waffle
e1b4e8a257 Add is_aligned{,_to} convenience methods to NonNull 2023-11-26 16:01:31 +00:00
Maybe Waffle
2bcaa9760e Add align_offset convenience method to NonNull 2023-11-26 16:01:30 +00:00
Maybe Waffle
4cc46df98c Add replace and swap convenience methods to NonNull 2023-11-26 16:01:30 +00:00
Maybe Waffle
4bcdd3bd92 Add offset_from-ish convenience methods to NonNull 2023-11-26 16:01:30 +00:00
Maybe Waffle
ebdc79497f Add offset-ish convenience methods to NonNull 2023-11-26 16:01:30 +00:00
Maybe Waffle
36a587fb62 Add read/write/copy convenience methods to NonNull 2023-11-26 15:57:01 +00:00
Maybe Waffle
1a3c5c40ca rustdoc: Remove space from fake-variadic fn ptr impls
before: `for fn (T₁, T₂, …, Tₙ) -> Ret`
after: `for fn(T₁, T₂, …, Tₙ) -> Ret`
2023-11-26 15:01:42 +00:00
Guillaume Gomez
c67613bef9
Rollup merge of #118302 - mu001999:dead_code/clean, r=cjgillot
Clean dead codes

Clean dead codes detected by #118257
2023-11-26 15:44:54 +01:00
Maybe Waffle
234e9500a4 Use usize::repeat_u8 instead of implementing repeat_byte in memchr.rs 2023-11-26 12:27:56 +00:00
Maybe Waffle
865ab921ab Rename {collections=>alloc}{tests,benches} 2023-11-26 12:04:56 +00:00
Maybe Waffle
c860ba1994 Improve some comments for non-zero ops 2023-11-26 11:47:08 +00:00
bors
9529a5d265 Auto merge of #110303 - nbdd0121:master, r=Mark-Simulacrum
Add `debug_assert_nounwind` and convert `assert_unsafe_precondition`

`assert_unsafe_precondition` checks non-CTFE-evaluable conditions in runtime and performs no-op in compile time, while many of its current usage can be checked during const eval.
2023-11-26 06:44:03 +00:00
r0cky
91aee2de15 Clean dead codes 2023-11-26 09:25:07 +08:00
Gary Guo
81cd49ddde Address review feedback 2023-11-25 23:58:51 +00:00
Gary Guo
97c1502066 Convert many assert_unsafe_precondition to debug_assert_nounwind 2023-11-25 23:58:51 +00:00
Gary Guo
4ccec4558f Add debug_assert_nounwind 2023-11-25 23:58:51 +00:00
Michael Goulet
fcb9fcc28c
Rollup merge of #117968 - Urgau:stabilize-ptr-addr-eq, r=dtolnay
Stabilize `ptr::addr_eq`

This PR stabilize the `ptr_addr_eq` library feature, representing:

```rust
// core::ptr

pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool;
```

FCP has already started [on the tracking issue](https://github.com/rust-lang/rust/issues/116324#issuecomment-1813008697) and is waiting on the final period comment.

Note: stabilizing this feature is somewhat of requirement for a new T-lang lint, cf. https://github.com/rust-lang/rust/pull/117758#issuecomment-1813183686.
2023-11-25 17:23:33 -05:00
Corey Farwell
a8a5704f1b
Update OnceLock documentation to give a concrete 'lazy static' example, and expand on existing example. 2023-11-25 16:30:43 -05:00
bors
37b2813a7b Auto merge of #118138 - Nilstrieb:one-previous-error, r=WaffleLapkin
Fixes error count display is different when there's only one error left

Supersedes #114759

### What did I do?

I did the small change in `rustc_errors` by hand. Then I did the other changes in `/compiler` by hand, those were just find replace on `*.rs` in the workspace. The changes in run-make are find replace for `run-make` in the workspace.

All other changes are blessed using `x test TEST --bless`. I blessed the tests that were blessed in #114759.

### how to review this nightmare

ping bors with an `r+`. You should check that my logic is sound and maybe quickly scroll through the diff, but fully verifying it seems fairly hard to impossible. I did my best to do this correctly.

Thank you `@adrianEffe` for bringing this up and your initial implementation.

cc `@flip1995,` you said you want to do a subtree sync asap
cc `@RalfJung` maybe you want to do a quick subtree sync afterwards as well for Miri

r? `@WaffleLapkin`
2023-11-24 21:40:54 +00:00
Ralf Jung
73042206dd remove the memcpy-on-equal-ptrs assumption 2023-11-24 21:32:16 +01:00
Nilstrieb
41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Michael Goulet
9c1b029559
Rollup merge of #118238 - RalfJung:memcpy, r=Mark-Simulacrum
memcpy assumptions: update GCC link

GCC now has this documented on an official website, not just in the bugtracker.
2023-11-24 07:29:12 -08:00
bors
b06258cde4 Auto merge of #118228 - Mark-Simulacrum:alloc-opt, r=scottmcm
Indicate that multiplication in Layout::array cannot overflow

Since https://github.com/rust-lang/rust/pull/113113, we have added a check that skips calling into the allocator at all if `capacity == 0`. The global, default allocator will not actually try to allocate though; it returns a dangling pointer explicitly. However, these two checks are not merged/deduplicated by LLVM and so we're comparing to zero twice whenever vectors are allocated/grown. Probably cheap, but also potentially expensive in code size and seems like an unfortunate miss.

This removes that extra check by telling LLVM that the multiplication as part of Layout::array can't overflow, turning the original non-zero value into a zero value afterwards. In my checks locally this successfully drops the duplicate comparisons.

See https://rust.godbolt.org/z/b6nPP9dcK for a code example.

```rust
pub fn foo(elements: usize) -> Vec<u32> {
    Vec::with_capacity(elements)
}
```

r? `@scottmcm` since you touched this in a32305a80f - curious if you have thoughts on doing this / can confirm my model of this being correct.
2023-11-24 11:19:34 +00:00
Ralf Jung
a5dff378f5 memcpy assumptions: update GCC link 2023-11-24 11:15:53 +01:00
Kashiwa
1928d82385 correct grammar 2023-11-24 17:23:49 +08:00