Commit graph

10022 commits

Author SHA1 Message Date
Matthias Krüger db5f005f35
Rollup merge of #104568 - RalfJung:realloc, r=Amanieu
clarify that realloc refreshes pointer provenance even when the allocation remains in-place

This [matches what C does](https://en.cppreference.com/w/c/memory/realloc):

> The original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place).

Cc `@rust-lang/wg-allocators`
2022-11-20 18:21:48 +01:00
Matthias Krüger 379d3365fd
Rollup merge of #104558 - thomcc:unalign-diriter, r=ChrisDenton
Don't assume `FILE_ID_BOTH_DIR_INFO` will be aligned

Fixes #104530. See that issue for info.

r? `@ChrisDenton`
2022-11-20 18:21:47 +01:00
Matthias Krüger ddb12348ca
Rollup merge of #104537 - HintringerFabian:docs_default_min_stack_size, r=the8472
fix std::thread docs are unclear regarding stack sizes

Improves the documentation about the default stack size of a spawned thread
Fixes #102671
2022-11-20 18:21:47 +01:00
Felix S. Klock II 98993af828 add examples to chunks remainder methods. Also fixed some links to rchunk remainder methods. 2022-11-20 11:43:23 -05:00
Marvin Löbel 3fe37b8c6e Add get_many_mut methods to slice 2022-11-20 11:19:11 -05:00
Tshepang Mbambo bebe5db517 replace unusual grammar 2022-11-20 17:28:34 +02:00
Ralf Jung 428ab59fb7 enable fuzzy_provenance_casts in libcore+tests 2022-11-20 16:04:16 +01:00
Markus Everling a1bf25e2bd Update VecDeque implementation 2022-11-20 15:21:16 +01:00
bors 911cbf8e46 Auto merge of #104617 - RalfJung:miri, r=RalfJung
update Miri

r? `@thomcc` for the lib changes (removing a `cfg(miri)` that is no longer needed)
2022-11-20 12:57:48 +00:00
Tethys Svensson 00bf999fcf Incorporate review feedback 2022-11-20 12:30:14 +01:00
Ralf Jung c043a0e7d6 cfg(miri) no longer needed in sys/unix/time.rs 2022-11-20 12:13:48 +01:00
Ralf Jung e19bc6eb80 move core::arch into separate file 2022-11-20 10:28:14 +01:00
Fabian Hintringer 0f9384603a Improve documentation of Stack size 2022-11-20 09:58:30 +01:00
Ralf Jung 2bb28c174b avoid non-strict-provenance casts in libcore tests 2022-11-20 09:58:29 +01:00
bors e07425d55b Auto merge of #98914 - fee1-dead-contrib:min-deref-patterns, r=compiler-errors
Minimal implementation of implicit deref patterns for Strings

cc `@compiler-errors` `@BoxyUwU` https://github.com/rust-lang/lang-team/issues/88 #87121

~~I forgot to add a feature gate, will do so in a minute~~ Done
2022-11-20 07:16:42 +00:00
Yuki Okushi 785237d392
Rollup merge of #104435 - scottmcm:iter-repeat-n, r=thomcc
`VecDeque::resize` should re-use the buffer in the passed-in element

Today it always copies it for *every* appended element, but one of those clones is avoidable.

This adds `iter::repeat_n` (https://github.com/rust-lang/rust/issues/104434) as the primitive needed to do this.  If this PR is acceptable, I'll also use this in `Vec` rather than its custom `ExtendElement` type & infrastructure that is harder to share between multiple different containers:

101e1822c3/library/alloc/src/vec/mod.rs (L2479-L2492)
2022-11-20 13:15:59 +09:00
Yuki Okushi e69b84204a
Rollup merge of #104112 - yancyribbens:add-copy-to-repeat-description, r=JohnTitor
rustdoc: Add copy to the description of repeat

Small nit, but it's more clear to say `copy` here instead of defining `repeat` in terms of itself.
2022-11-20 13:15:58 +09:00
Yuki Okushi 0858ca97da
Rollup merge of #103901 - H4x5:fmt-arguments-as-str-tracking-issue, r=the8472
Add tracking issue for `const_arguments_as_str`

Tracking issue: #103900

The original PR didn't create a tracking issue.
2022-11-20 13:15:58 +09:00
Nilstrieb 6ee0dd97e3
Add unstable type_ascribe macro
This macro serves as a placeholder for future type ascription syntax to
make sure that the semantic implementation keeps working.
2022-11-19 22:16:42 +01:00
bors c5d82ed7a4 Auto merge of #102795 - lukas-code:constify-is-aligned-via-align-offset, r=oli-obk
Constify `is_aligned` via `align_offset`

Alternative to https://github.com/rust-lang/rust/pull/102753

Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`.

Tracking Issue: https://github.com/rust-lang/rust/issues/104203
2022-11-19 18:57:39 +00:00
Lukas Markeffsky c9c017dfb5 update provenance test
* fix allocation alignment for 16bit platforms
* add edge case where `stride % align != 0` on pointers with provenance
2022-11-19 16:58:02 +01:00
Lukas e90d15b247 Update comment on pointer-to-usize transmute
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-11-19 16:58:02 +01:00
Lukas Markeffsky 3d7e9c4b7f Revert "don't call align_offset during const eval, ever"
This reverts commit f3a577bfae376c0222e934911865ed14cddd1539.
2022-11-19 16:58:02 +01:00
Lukas Markeffsky 9e5d497b67 fix const align_offset implementation 2022-11-19 16:57:58 +01:00
Lukas Markeffsky 8a6053618f docs cleanup
* Fix doc examples for Platforms with underaligned integer primitives.
* Mutable pointer doc examples use mutable pointers.
* Fill out tracking issue.
* Minor formatting changes.
2022-11-19 16:47:42 +01:00
Lukas Markeffsky daccb8c11a always use align_offset in is_aligned_to + add assembly test 2022-11-19 16:47:42 +01:00
Lukas Markeffsky 4696e8906d Schrödinger's pointer
It's aligned *and* not aligned!
2022-11-19 16:47:42 +01:00
Lukas Markeffsky df0bcfe644 address more review comments
* `cfg` only the body of `align_offset`
* put explicit panics back
* explain why `ptr.align_offset(align) == 0` is slow
2022-11-19 16:47:42 +01:00
Lukas Markeffsky 093c02ed46 document is_aligned{,_to} 2022-11-19 16:47:42 +01:00
Lukas Markeffsky a906f6cb69 don't call align_offset during const eval, ever 2022-11-19 16:47:42 +01:00
Lukas Markeffsky 24e88066dc mark align_offset as #[must_use] 2022-11-19 16:47:42 +01:00
Lukas Markeffsky 2ef9a8ae0f add coretests for is_aligned 2022-11-19 16:47:42 +01:00
Lukas Markeffsky 6f6320a0a9 constify pointer::is_aligned{,_to} 2022-11-19 16:47:42 +01:00
Lukas Markeffsky 8cf6b16185 add coretests for const align_offset 2022-11-19 16:47:38 +01:00
bors 2a434286a9 Auto merge of #104607 - matthiaskrgr:rollup-9s589me, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #103117 (Use `IsTerminal` in place of `atty`)
 - #103969 (Partial support for running UI tests with `download-rustc`)
 - #103989 (Fix build of std for thumbv7a-pc-windows-msvc)
 - #104076 (fix sysroot issue which appears for ci downloaded rustc)
 - #104469 (Make "long type" printing type aware and trim types in E0275)
 - #104497 (detect () to avoid redundant <> suggestion for type)
 - #104577 (Don't focus on notable trait parent when hiding it)
 - #104587 (Update cargo)
 - #104593 (Improve spans for RPITIT object-safety errors)
 - #104604 (Migrate top buttons style to CSS variables)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-19 15:40:04 +00:00
Lukas Markeffsky 211743b2c8 make const align_offset useful 2022-11-19 16:36:08 +01:00
Lukas Markeffsky f13c4f4d6a constify exact_div intrinsic 2022-11-19 16:36:08 +01:00
Matthias Krüger 747f29fbab
Rollup merge of #103989 - arlosi:arm32-panic, r=Amanieu
Fix build of std for thumbv7a-pc-windows-msvc

Attempting to build std for the tier-3 target `thumbv7a-pc-windows-msvc` fails with the following error:
```
Building stage1 std artifacts (x86_64-pc-windows-msvc -> thumbv7a-pc-windows-msvc)
..
LLVM ERROR: WinEH not implemented for this target
error: could not compile `panic_unwind`
```

EH (unwinding) is not supported by LLVM for 32 bit arm msvc targets. This changes panic unwind to use the dummy implementation for `thumbv7a-pc-windows-msvc`.
2022-11-19 15:35:20 +01:00
bors 62c627c7a3 Auto merge of #104571 - clubby789:remove-vec-rc-opt, r=the8472
Revert Vec/Rc storage reuse opt

Remove the optimization for using storage added by #104205.
The perf wins were pretty small, and it relies on non-guarenteed behaviour. On platforms that don't implement shrinking in place, the performance will be significantly worse.

While it could be gated to platforms that do this (such as GNU), I don't think it's worth the overhead of maintaining it for very small gains. (#104565, #104563)

cc `@RalfJung` `@matthiaskrgr`

Fixes #104565
Fixes #104563
2022-11-19 12:44:57 +00:00
Dylan DPC 45bfb1cdf1
Rollup merge of #104553 - mwillsey:asinh-acosh-accuracy, r=thomcc
Improve accuracy of asinh and acosh

This PR addresses the inaccuracy of `asinh` and `acosh` identified by the [Herbie](http://herbie.uwplse.org/) tool, `@pavpanchekha,` `@finnbear` in #104548. It also adds a couple tests that failed in the existing implementations and now pass.

Closes #104548

r? rust-lang/libs
2022-11-19 11:54:45 +05:30
Dylan DPC 5caac92dc0
Rollup merge of #104528 - WaffleLapkin:lazy_lock_docfix, r=matklad
Properly link `{Once,Lazy}{Cell,Lock}` in docs

See https://github.com/rust-lang/rust/issues/74465#issuecomment-1317947443
2022-11-19 11:54:44 +05:30
Scott McMurray 71bb200225 Hide the items while waiting for the ACP 2022-11-18 19:46:18 -08:00
bors ff0ffda6b3 Auto merge of #104591 - Manishearth:rollup-b3ser4e, r=Manishearth
Rollup of 8 pull requests

Successful merges:

 - #102977 (remove HRTB from `[T]::is_sorted_by{,_key}`)
 - #103378 (Fix mod_inv termination for the last iteration)
 - #103456 (`unchecked_{shl|shr}` should use `u32` as the RHS)
 - #103701 (Simplify some pointer method implementations)
 - #104047 (Diagnostics `icu4x` based list formatting.)
 - #104338 (Enforce that `dyn*` coercions are actually pointer-sized)
 - #104498 (Edit docs for `rustc_errors::Handler::stash_diagnostic`)
 - #104556 (rustdoc: use `code-header` class to format enum variants)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-18 23:20:53 +00:00
Manish Goregaokar 24ee599195
Rollup merge of #104338 - compiler-errors:pointer-sized, r=eholk
Enforce that `dyn*` coercions are actually pointer-sized

Implement a perma-unstable, rudimentary `PointerSized` trait to enforce `dyn*` casts are `usize`-sized for now, at least to prevent ICEs and weird codegen issues from cropping up after monomorphization since currently we enforce *nothing*.

This probably can/should be removed in favor of a more sophisticated trait for handling `dyn*` conversions when we decide on one, but I just want to get something up for discussion and experimentation for now.

r? ```@eholk``` cc ```@tmandry``` (though feel free to claim/reassign)

Fixes #102141
Fixes #102173
2022-11-18 17:48:18 -05:00
Manish Goregaokar 19efa2599c
Rollup merge of #103701 - WaffleLapkin:__points-at-implementation__--this-can-be-simplified, r=scottmcm
Simplify some pointer method implementations

- Make `pointer::with_metadata_of` const (+simplify implementation) (cc #75091)
- Simplify implementation of various pointer methods

r? ```@scottmcm```

----

`from_raw_parts::<T>(this, metadata(self))` was annoying me for a while and I've finally figured out how it should _actually_ be done.
2022-11-18 17:48:17 -05:00
Manish Goregaokar e2301154e3
Rollup merge of #103456 - scottmcm:fix-unchecked-shifts, r=scottmcm
`unchecked_{shl|shr}` should use `u32` as the RHS

The other shift methods, such as https://doc.rust-lang.org/nightly/std/primitive.u64.html#method.checked_shr and https://doc.rust-lang.org/nightly/std/primitive.i16.html#method.wrapping_shl, use `u32` for the shift amount.  That's consistent with other things, like `count_ones`, which also always use `u32` for a bit count, regardless of the size of the type.

This PR changes `unchecked_shl` and `unchecked_shr` to also use `u32` for the shift amount (rather than Self).

cc #85122, the `unchecked_math` tracking issue
2022-11-18 17:48:17 -05:00
Manish Goregaokar 6b09d60f82
Rollup merge of #103378 - nagisa:fix-infinite-offset, r=scottmcm
Fix mod_inv termination for the last iteration

On usize=u64 platforms, the 4th iteration would overflow the `mod_gate` back to 0. Similarly for usize=u32 platforms, the 3rd iteration would overflow much the same way.

I tested various approaches to resolving this, including approaches with `saturating_mul` and `widening_mul` to a double usize. Turns out LLVM likes `mul_with_overflow` the best. In fact now, that LLVM can see the iteration count is limited, it will happily unroll the loop into a nice linear sequence.

You will also notice that the code around the loop got simplified somewhat. Now that LLVM is handling the loop nicely, there isn’t any more reasons to manually unroll the first iteration out of the loop (though looking at the code today I’m not sure all that complexity was necessary in the first place).

Fixes #103361
2022-11-18 17:48:16 -05:00
Manish Goregaokar 8aca6ccedd
Rollup merge of #102977 - lukas-code:is-sorted-hrtb, r=m-ou-se
remove HRTB from `[T]::is_sorted_by{,_key}`

Changes the signature of `[T]::is_sorted_by{,_key}` to match `[T]::binary_search_by{,_key}` and make code like https://github.com/rust-lang/rust/issues/53485#issuecomment-885393452 compile.

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

~~Do we need an ACP for something like this?~~ Edit: Filed ACP here: https://github.com/rust-lang/libs-team/issues/121
2022-11-18 17:48:16 -05:00
Zachary S 734f724472 Change undefined-behavior doctests from ignore to no_run. 2022-11-18 12:50:41 -06:00
zachs18 f542b068f2 Apply suggestions from code review
Fix spelling error.
2022-11-18 12:50:41 -06:00
Zachary S 8c38cb7709 Add examples to show when {Arc,Rc}::get_mut_unchecked is disallowed. 2022-11-18 12:50:41 -06:00
Zachary S 96650fc714 Clarify and restrict when {Arc,Rc}::get_mut_unchecked is allowed. 2022-11-18 12:50:41 -06:00
Michael Goulet da3c5397a6 Enforce that dyn* casts are actually pointer-sized 2022-11-18 18:23:48 +00:00
Matthias Krüger 6419151f8b
Rollup merge of #103594 - maniwani:fix-issue-91417, r=thomcc
Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets

This is a duplicate of #94100 (since the original author is unresponsive), which resolves #91417.

On `aarch64-apple-darwin` targets, the internal resolution of `Instant` is lower than that of `Duration`, so math between them becomes non-associative with small-enough durations.

This PR makes this target use the standard Unix implementation (where `Instant` has 1ns resolution), but with `CLOCK_UPTIME_RAW` so it still returns the same values as `mach_absolute_time`[^1].

(Edit: I need someone to confirm that this still works, I do not have access to an M1 device.)

[^1]: https://www.manpagez.com/man/3/clock_gettime/
2022-11-18 14:13:36 +01:00
clubby789 27019f10ae Remove Vec/Rc storage reuse opt 2022-11-18 10:39:50 +00:00
Ralf Jung d26659d611 clarify that realloc refreshes pointer provenance even when the allocation remains in-place 2022-11-18 10:43:40 +01:00
Thom Chiovoloni 56888c1e9b
Handle the case that even the filename array is unaligned. 2022-11-18 00:05:44 -08:00
Deadbeef 64a17a09a8 Rm diagnostic item, use lang item 2022-11-18 06:16:20 +00:00
Thom Chiovoloni b881f66cf9
Don't assume FILE_ID_BOTH_DIR_INFO will be aligned 2022-11-17 16:14:44 -08:00
Max Willsey 26b23f4a37 Improve accuracy of asinh and acosh 2022-11-17 12:50:33 -08:00
Philipp Krones 34a14349b7
Readd the matches_macro diag item
This is now used by Clippy
2022-11-17 19:32:28 +01:00
bors b6097f2e1b Auto merge of #104219 - bryangarza:async-track-caller-dup, r=eholk
Support `#[track_caller]` on async fns

Adds `#[track_caller]` to the generator that is created when we desugar the async fn.

Fixes #78840

Open questions:
- What is the performance impact of adding `#[track_caller]` to every `GenFuture`'s `poll(...)` function, even if it's unused (i.e., the parent span does not set `#[track_caller]`)? We might need to set it only conditionally, if the indirection causes overhead we don't want.
2022-11-17 13:47:03 +00:00
Deadbeef b2cb42d6a7 Minimal implementation of implicit deref patterns 2022-11-17 12:46:43 +00:00
Maybe Waffle 57e726108a Properly link {Once,Lazy}{Cell,Lock} in docs 2022-11-17 11:05:56 +00:00
bors 36db030a7c Auto merge of #104205 - clubby789:grow-rc, r=thomcc
Attempt to reuse `Vec<T>` backing storage for `Rc/Arc<[T]>`

If a `Vec<T>` has sufficient capacity to store the inner `RcBox<[T]>`, we can just reuse the existing allocation and shift the elements up, instead of making a new allocation.
2022-11-17 10:48:22 +00:00
bors 9340e5c1b9 Auto merge of #103779 - the8472:simd-str-contains, r=thomcc
x86_64 SSE2 fast-path for str.contains(&str) and short needles

Based on Wojciech Muła's [SIMD-friendly algorithms for substring searching](http://0x80.pl/articles/simd-strfind.html#sse-avx2)

The two-way algorithm is Big-O efficient but it needs to preprocess the needle
to find a "critical factorization" of it. This additional work is significant
for short needles. Additionally it mostly advances needle.len() bytes at a time.

The SIMD-based approach used here on the other hand can advance based on its
vector width, which can exceed the needle length. Except for pathological cases,
but due to being limited to small needles the worst case blowup is also small.

benchmarks taken on a Zen2, compiled with `-Ccodegen-units=1`:

```
OLD:
test str::bench_contains_16b_in_long                     ... bench:         504 ns/iter (+/- 14) = 5061 MB/s
test str::bench_contains_2b_repeated_long                ... bench:         948 ns/iter (+/- 175) = 2690 MB/s
test str::bench_contains_32b_in_long                     ... bench:         445 ns/iter (+/- 6) = 5732 MB/s
test str::bench_contains_bad_naive                       ... bench:         130 ns/iter (+/- 1) = 569 MB/s
test str::bench_contains_bad_simd                        ... bench:          84 ns/iter (+/- 8) = 880 MB/s
test str::bench_contains_equal                           ... bench:         142 ns/iter (+/- 7) = 394 MB/s
test str::bench_contains_short_long                      ... bench:         677 ns/iter (+/- 25) = 3768 MB/s
test str::bench_contains_short_short                     ... bench:          27 ns/iter (+/- 2) = 2074 MB/s

NEW:
test str::bench_contains_16b_in_long                     ... bench:          82 ns/iter (+/- 0) = 31109 MB/s
test str::bench_contains_2b_repeated_long                ... bench:          73 ns/iter (+/- 0) = 34945 MB/s
test str::bench_contains_32b_in_long                     ... bench:          71 ns/iter (+/- 1) = 35929 MB/s
test str::bench_contains_bad_naive                       ... bench:           7 ns/iter (+/- 0) = 10571 MB/s
test str::bench_contains_bad_simd                        ... bench:          97 ns/iter (+/- 41) = 762 MB/s
test str::bench_contains_equal                           ... bench:           4 ns/iter (+/- 0) = 14000 MB/s
test str::bench_contains_short_long                      ... bench:          73 ns/iter (+/- 0) = 34945 MB/s
test str::bench_contains_short_short                     ... bench:          12 ns/iter (+/- 0) = 4666 MB/s
```
2022-11-17 04:47:11 +00:00
bors 63c748ee23 Auto merge of #104481 - matthiaskrgr:rollup-hf8rev0, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #103484 (Add `rust` to `let_underscore_lock` example)
 - #103489 (Make `pointer::byte_offset_from` more generic)
 - #104193 (Shift no characters when using raw string literals)
 - #104348 (Respect visibility & stability of inherent associated types)
 - #104401 (avoid memory leak in mpsc test)
 - #104419 (Fix test/ui/issues/issue-30490.rs)
 - #104424 (rustdoc: remove no-op CSS `.popover { font-size: 1rem }`)
 - #104425 (rustdoc: remove no-op CSS `.main-header { justify-content }`)
 - #104450 (Fuchsia test suite script fix)
 - #104471 (Update PROBLEMATIC_CONSTS in style.rs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-16 10:27:24 +00:00
Matthias Krüger 4864a04c33
Rollup merge of #104401 - RalfJung:mpsc-leak, r=Amanieu
avoid memory leak in mpsc test

r? ```@Amanieu```
2022-11-16 08:36:12 +01:00
Matthias Krüger 91963cc244
Rollup merge of #103489 - WaffleLapkin:byte_offset_from_you, r=scottmcm
Make `pointer::byte_offset_from` more generic

As suggested by https://github.com/rust-lang/rust/issues/96283#issuecomment-1288792955 (cc ````@scottmcm),```` make `pointer::byte_offset_from` work on pointers of different types. `byte_offset_from` really doesn't care about pointer types, so this is totally fine and, for example, allows patterns like this:
```rust
ptr::addr_of!(x.b).byte_offset_from(ptr::addr_of!(x))
```

The only possible downside is that this removes the `T` == `U` hint to inference, but I don't think this matter much. I don't think there are a lot of cases where you'd want to use `byte_offset_from` with a pointer of unbounded type (and in such cases you can just specify the type).

````@rustbot```` label +T-libs-api
2022-11-16 08:36:10 +01:00
bors e702534763 Auto merge of #102935 - ajtribick:display-float-0.5-fixed-0, r=scottmcm
Fix inconsistent rounding of 0.5 when formatted to 0 decimal places

As described in #70336, when displaying values to zero decimal places the value of 0.5 is rounded to 1, which is inconsistent with the display of other half-integer values which round to even.

From testing the flt2dec implementation, it looks like this comes down to the condition in the fixed-width Dragon implementation where an empty buffer is treated as a case to apply rounding up. I believe the change below fixes it and updates only the relevant tests.

Nevertheless I am aware this is very much a core piece of functionality, so please take a very careful look to make sure I haven't missed anything. I hope this change does not break anything in the wider ecosystem as having a consistent rounding behaviour in floating point formatting is in my opinion a useful feature to have.

Resolves #70336
2022-11-16 07:20:30 +00:00
Mateusz Mikuła 10d0f1466b Reduce exceptions overallocation on non Windows x86_64
Addressing https://github.com/rust-lang/rust/pull/103894#discussion_r1020950196
2022-11-15 23:24:21 +01:00
Mateusz Mikuła c82353790a Fix building of aarch64-pc-windows-gnullvm
That change had been lost during rebase
2022-11-15 20:54:04 +01:00
bors a00f8ba7fc Auto merge of #104054 - RalfJung:byte-provenance, r=oli-obk
interpret: support for per-byte provenance

Also factors the provenance map into its own module.

The third commit does the same for the init mask. I can move it in a separate PR if you prefer.

Fixes https://github.com/rust-lang/miri/issues/2181

r? `@oli-obk`
2022-11-15 17:37:15 +00:00
The 8472 a2b2010891 - convert from core::arch to core::simd
- bump simd compare to 32bytes
- import small slice compare code from memmem crate
- try a few different probe bytes to avoid degenerate cases
  - but special-case 2-byte needles
2022-11-15 18:30:31 +01:00
The 8472 c37e8fae57 generalize str.contains() tests to a range of haystack sizes
The Big-O is cubic, but this is only called with ~70 chars so it's still fast enough
2022-11-15 18:30:07 +01:00
Matthias Krüger 55ff8bf847
Rollup merge of #104339 - compiler-errors:rustc_deny_explicit_impl, r=cjgillot
Add `rustc_deny_explicit_impl`

Also adjust `E0322` error message to be more general, since it's used for `DiscriminantKind` and `Pointee` as well.

Also add `rustc_deny_explicit_impl` on the `Tuple` and `Destruct` marker traits.
2022-11-15 10:44:12 +01:00
Matthias Krüger add6f14fbf
Rollup merge of #104241 - bjorn3:smaller_unwind_build_script, r=Mark-Simulacrum
Move most of unwind's build script to lib.rs

Only the android libunwind detection remains in the build script

* Reduces dependence on build scripts for building the standard library
* Reduces dependence on exact target names in favor of using semantic cfg(target_*) usage.
* Keeps almost all code related to linking of the unwinder in one file
2022-11-15 10:44:09 +01:00
Matthias Krüger e309b79050
Rollup merge of #103734 - Mark-Simulacrum:fix-version-stabilized, r=JohnTitor
Adjust stabilization version to 1.65.0 for wasi fds

See https://github.com/rust-lang/rust/pull/103308#issuecomment-1292277645 for this ask.

Backport of that PR to beta (1.65.0) will include a similar patch.
2022-11-15 10:44:08 +01:00
Scott McMurray d62b903892 VecDeque::resize should re-use the buffer in the passed-in element
Today it always copies it for *every* appended element, but one of those clones is avoidable.
2022-11-15 00:53:26 -08:00
bors ca92d90b59 Auto merge of #104428 - matthiaskrgr:rollup-jo3078i, r=matthiaskrgr
Rollup of 13 pull requests

Successful merges:

 - #103842 (Adding Fuchsia compiler testing script, docs)
 - #104354 (Remove leading newlines from `NonZero*` doc examples)
 - #104372 (Update compiler-builtins)
 - #104380 (rustdoc: remove unused CSS `code { opacity: 1 }`)
 - #104381 (Remove dead NoneError diagnostic handling)
 - #104383 (Remove unused symbols and diagnostic items)
 - #104391 (Deriving cleanups)
 - #104403 (Specify language of code comment to generate document)
 - #104404 (Fix missing minification for static files)
 - #104413 ([llvm-wrapper] adapt for LLVM API change)
 - #104415 (rustdoc: fix corner case in search keyboard commands)
 - #104422 (Fix suggest associated call syntax)
 - #104426 (Add test for #102154)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-15 06:43:28 +00:00
Matthias Krüger 2c29b05fb2
Rollup merge of #104383 - WaffleLapkin:rustc_undiagnostic_item, r=compiler-errors
Remove unused symbols and diagnostic items

As the title suggests, this removes unused symbols from `sym::` and `#[rustc_diagnostic_item]` annotations that weren't mentioned anywhere.

Originally I tried to use grep, to find symbols and item names that are never mentioned via `sym::name`, however this produced a lot of false positives (?), for example clippy matching on `Symbol::as_str` or macros "implicitly" adding `sym::`. I ended up fixing all these false positives (?) by hand, but tbh I'm not sure if it was worth it...
2022-11-15 01:40:44 +01:00
Matthias Krüger 83b6e85181
Rollup merge of #104372 - Ayush1325:compiler-builtins, r=JohnTitor
Update compiler-builtins

This was originally a part of https://github.com/rust-lang/rust/pull/100316. However, extracting it to a seperate PR should help with any extra testing that might be needed.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-15 01:40:43 +01:00
Matthias Krüger 1b41a38f52
Rollup merge of #104354 - lukas-code:blank-lines-2, r=JohnTitor
Remove leading newlines from `NonZero*` doc examples

Like https://github.com/rust-lang/rust/pull/103045, but for `NonZero*`.

`@rustbot` label A-docs
2022-11-15 01:40:42 +01:00
The 8472 3d4a8482b9 x86_64 SSE2 fast-path for str.contains(&str) and short needles
Based on Wojciech Muła's "SIMD-friendly algorithms for substring searching"[0]

The two-way algorithm is Big-O efficient but it needs to preprocess the needle
to find a "criticla factorization" of it. This additional work is significant
for short needles. Additionally it mostly advances needle.len() bytes at a time.

The SIMD-based approach used here on the other hand can advance based on its
vector width, which can exceed the needle length. Except for pathological cases,
but due to being limited to small needles the worst case blowup is also small.

benchmarks taken on a Zen2:

```
16CGU, OLD:
test str::bench_contains_short_short                     ... bench:          27 ns/iter (+/- 1)
test str::bench_contains_short_long                      ... bench:         667 ns/iter (+/- 29)
test str::bench_contains_bad_naive                       ... bench:         131 ns/iter (+/- 2)
test str::bench_contains_bad_simd                        ... bench:         130 ns/iter (+/- 2)
test str::bench_contains_equal                           ... bench:         148 ns/iter (+/- 4)


16CGU, NEW:
test str::bench_contains_short_short                     ... bench:           8 ns/iter (+/- 0)
test str::bench_contains_short_long                      ... bench:         135 ns/iter (+/- 4)
test str::bench_contains_bad_naive                       ... bench:         130 ns/iter (+/- 2)
test str::bench_contains_bad_simd                        ... bench:         292 ns/iter (+/- 1)
test str::bench_contains_equal                           ... bench:           3 ns/iter (+/- 0)


1CGU, OLD:
test str::bench_contains_short_short                     ... bench:          30 ns/iter (+/- 0)
test str::bench_contains_short_long                      ... bench:         713 ns/iter (+/- 17)
test str::bench_contains_bad_naive                       ... bench:         131 ns/iter (+/- 3)
test str::bench_contains_bad_simd                        ... bench:         130 ns/iter (+/- 3)
test str::bench_contains_equal                           ... bench:         148 ns/iter (+/- 6)

1CGU, NEW:
test str::bench_contains_short_short                     ... bench:          10 ns/iter (+/- 0)
test str::bench_contains_short_long                      ... bench:         111 ns/iter (+/- 0)
test str::bench_contains_bad_naive                       ... bench:         135 ns/iter (+/- 3)
test str::bench_contains_bad_simd                        ... bench:         274 ns/iter (+/- 2)
test str::bench_contains_equal                           ... bench:           4 ns/iter (+/- 0)
```


[0] http://0x80.pl/articles/simd-strfind.html#sse-avx2
2022-11-14 23:03:16 +01:00
The 8472 467b299e53 update str.contains benchmarks 2022-11-14 23:03:16 +01:00
The 8472 4844e5162c black_box test strings in str.contains(str) benchmarks 2022-11-14 23:01:25 +01:00
Tethys Svensson 089475a44e Fix doc example for wrapping_abs
The `max` variable is unused. This change introduces the `min_plus`
variable, to make the example similar to the one from `saturating_abs`.
An alternative would be to remove the unused variable.
2022-11-14 19:44:01 +01:00
Matthias Krüger 43bb507d12
Rollup merge of #104332 - Elarcis:maybe_uninit_doc_fix, r=m-ou-se
Fixed some `_i32` notation in `maybe_uninit`’s doc

This PR just changed two lines in the documentation for `MaybeUninit`:

```rs
let val = 0x12345678i32;
```
was changed to:
```rs
let val = 0x12345678_i32;
```
in two doctests, making the values a tad easier to read.

It does not seem like there are other literals needing this change in the file.
2022-11-14 19:26:17 +01:00
Matthias Krüger 8c77da87d7
Rollup merge of #102470 - est31:stabilize_const_char_convert, r=joshtriplett
Stabilize const char convert

Split out `const_char_from_u32_unchecked` from `const_char_convert` and stabilize the rest, i.e. stabilize the following functions:

```Rust
impl char {
    pub const fn from_u32(self, i: u32) -> Option<char>;
    pub const fn from_digit(self, num: u32, radix: u32) -> Option<char>;
    pub const fn to_digit(self, radix: u32) -> Option<u32>;
}

// Available through core::char and std::char
mod char {
    pub const fn from_u32(i: u32) -> Option<char>;
    pub const fn from_digit(num: u32, radix: u32) -> Option<char>;
}
```

And put the following under the `from_u32_unchecked` const stability gate as it needs `Option::unwrap` which isn't const-stable (yet):

```Rust
impl char {
    pub const unsafe fn from_u32_unchecked(i: u32) -> char;
}

// Available through core::char and std::char
mod char {
    pub const unsafe fn from_u32_unchecked(i: u32) -> char;
}
```

cc the tracking issue #89259 (which I'd like to keep open for `const_char_from_u32_unchecked`).
2022-11-14 19:26:15 +01:00
Matthias Krüger 9f3786b2b1
Rollup merge of #101967 - jmillikin:linux-abstract-socket-addr, r=joshtriplett
Move `unix_socket_abstract` feature API to `SocketAddrExt`.

The pre-stabilized API for abstract socket addresses exposes methods on `SocketAddr` that are only enabled for `cfg(any(target_os = "android", target_os = "linux"))`. Per discussion in <https://github.com/rust-lang/rust/issues/85410>, moving these methods to an OS-specific extension trait is required before stabilization can be considered.

This PR makes four changes:
1. The internal module `std::os::net` contains logic for the unstable feature `tcp_quickack` (https://github.com/rust-lang/rust/issues/96256). I moved that code into `linux_ext/tcp.rs` and tried to adjust the module tree so it could accommodate a second unstable feature there.
2. Moves the public API out of `impl SocketAddr`, into `impl SocketAddrExt for SocketAddr` (the headline change).
3. The existing function names and docs for `unix_socket_abstract` refer to addresses as being created from abstract namespaces, but a more accurate description is that they create sockets in *the* abstract namespace. I adjusted the function signatures correspondingly and tried to update the docs to be clearer.
4. I also tweaked `from_abstract_name` so it takes an `AsRef<[u8]>` instead of `&[u8]`, allowing `b""` literals to be passed directly.

Issues:
1. The public module `std::os::linux::net` is marked as part of `tcp_quickack`. I couldn't figure out how to mark a module as being part of two unstable features, so I just left the existing attributes in place. My hope is that this will be fixed as a side-effect of stabilizing either feature.
2022-11-14 19:26:14 +01:00
Cameron f4f515973e macos, aarch64, and not(miri) 2022-11-14 09:19:12 -08:00
bjorn3 53852ee4eb Move most of unwind's build script to lib.rs
Only the android libunwind detection remains in the build script

* Reduces dependence on build scripts for building the standard library
* Reduces dependence on exact target names in favor of using semantic
  cfg(target_*) usage.
* Keeps almost all code related to linking of the unwinder in one file
2022-11-14 14:24:12 +00:00
yancy f4ffdbfaad rustdoc: Add copy to the description of repeat 2022-11-14 15:21:02 +01:00
Ralf Jung 5fd561dea2 avoid memory leak in mpsc test 2022-11-14 13:38:53 +01:00
bors 96ddd32c4b Auto merge of #104387 - Manishearth:rollup-9e551p5, r=Manishearth
Rollup of 9 pull requests

Successful merges:

 - #103709 (ci: Upgrade dist-x86_64-netbsd to NetBSD 9.0)
 - #103744 (Upgrade cc for working is_flag_supported on cross-compiles)
 - #104105 (llvm: dwo only emitted when object code emitted)
 - #104158 (Return .efi extension for EFI executable)
 - #104181 (Add a few known-bug tests)
 - #104266 (Regression test for coercion of mut-ref to dyn-star)
 - #104300 (Document `Path::parent` behavior around relative paths)
 - #104304 (Enable profiler in dist-s390x-linux)
 - #104362 (Add `delay_span_bug` to `AttrWrapper::take_for_recovery`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-14 06:30:18 +00:00
Michael Goulet b5b6467810 Add rustc_deny_explicit_impl 2022-11-14 03:23:41 +00:00
Manish Goregaokar c7004f934f
Rollup merge of #104300 - tbu-:pr_path_parent_caveats, r=Mark-Simulacrum
Document `Path::parent` behavior around relative paths

A relative path with just one component will return `Some("")` as its parent, which wasn't clear to me from the documentation.

The parent of `""` is `None`, which was missing from the documentation as well.
2022-11-13 21:49:27 -05:00
Manish Goregaokar c9fc5cbeb5
Rollup merge of #103744 - palfrey:unwind-upgrade-cc, r=Mark-Simulacrum
Upgrade cc for working is_flag_supported on cross-compiles

https://github.com/rust-lang/rust/pull/85806 fixed unwind v.s gcc support on later Android ndks using `is_flag_supported`. However, due to https://github.com/rust-lang/cc-rs/issues/675, this didn't work properly on cross-compiles. 3eeb50b391 fixes this, and was released in cc 1.0.74, hence the upgrade
2022-11-13 21:49:24 -05:00
clubby789 8424c24837 Add Vec storage optimization to Arc and add tests 2022-11-14 02:30:18 +00:00
clubby789 1c813c4d11 Reuse Vec<T> backing storage for Rc<[T]>
Co-authored-by: joboet <jonas.boettiger@icloud.com>
2022-11-14 01:15:18 +00:00
bors 338cfd3cce Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini
Bump bootstrap compiler to 1.66

This PR:

- Bumps version placeholders to release
- Bumps to latest beta
- cfg-steps code

r? `@pietroalbini`
2022-11-14 00:07:19 +00:00
Maybe Waffle 29fe28fcfc Fix clippy and rustdoc
please, please, don't match on `Symbol::as_str`s, every time you do,
somewhere in the world another waffle becomes sad...
2022-11-13 22:58:20 +00:00
bors 7b513af6c4 Auto merge of #103894 - mati865:gnullvm-libunwind-changes, r=thomcc
Change the way libunwind is linked for *-windows-gnullvm targets

I have no idea why previous way works for `x86_64-fortanix-unknown-sgx` (assuming it actually works...) but not for `gnullvm`. It fails when linking libtest during Rust build (unless somebody adds `RUSTFLAGS='-Clinkarg=-lunwind'`).
Also fixes exception handling on AArch64.
2022-11-13 21:12:48 +00:00
Cameron 015ab659c2 just use libc::clockid_t 2022-11-13 12:33:21 -08:00
Joy 5008a317ce Fix non-associativity of Instant math on aarch64-apple-darwin targets 2022-11-13 12:01:42 -08:00
Maybe Waffle 409c3ce441 Remove unused diagnostic items 2022-11-13 18:49:21 +00:00
Ayush Singh cd2fb430da
Update compiler-builtins
This was originally a part of https://github.com/rust-lang/rust/pull/100316.
However, extracting it to a seperate PR should help with any extra
testing that might be needed.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-13 23:07:35 +05:30
Matthias Krüger eefea28dea
Rollup merge of #104320 - fee1-dead-contrib:use-derive-const-in-std, r=oli-obk
Use `derive_const` and rm manual StructuralEq impl

This does not change any semantics of the impl except for the const stability. It should be fine because trait methods and const bounds can never be used in stable without enabling `const_trait_impl`.

cc `@oli-obk`
2022-11-13 17:37:37 +01:00
Matthias Krüger a1b0702ea5
Rollup merge of #103996 - SUPERCILEX:docs, r=RalfJung
Add small clarification around using pointers derived from references

r? `@RalfJung`

One question about your example from https://github.com/rust-lang/libs-team/issues/122: at what point does UB arise? If writing 0 does not cause UB and the reference `x` is never read or written to (explicitly or implicitly by being wrapped in another data structure) after the call to `foo`, does UB only arise when dropping the value? I don't really get that since I thought references were always supposed to point to valid data?

```rust
fn foo(x: &mut NonZeroI32)  {
  let ptr = x as *mut NonZeroI32;
  unsafe { ptr.cast::<i32>().write(0); } // no UB here
  // What now? x is considered garbage when?
}
```
2022-11-13 17:37:36 +01:00
bors afd7977c85 Auto merge of #93563 - ibraheemdev:crossbeam-channel, r=Amanieu
Merge crossbeam-channel into `std::sync::mpsc`

This PR imports the [`crossbeam-channel`](https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel#crossbeam-channel) crate into the standard library as a private module, `sync::mpmc`. `sync::mpsc` is now implemented as a thin wrapper around `sync::mpmc`. The primary purpose of this PR is to resolve https://github.com/rust-lang/rust/issues/39364. The public API intentionally remains the same.

The reason https://github.com/rust-lang/rust/issues/39364 has not been fixed in over 5 years is that the current channel is *incredibly* complex. It was written many years ago and has sat mostly untouched since. `crossbeam-channel` has become the most popular alternative on crates.io, amassing over 30 million downloads. While crossbeam's channel is also complex, like all fast concurrent data structures, it avoids some of the major issues with the current implementation around dynamic flavor upgrades. The new implementation decides on the datastructure to be used when the channel is created, and the channel retains that structure until it is dropped.

Replacing `sync::mpsc` with a simpler, less performant implementation has been discussed as an alternative. However, Rust touts itself as enabling *fearless concurrency*, and having the standard library feature a subpar implementation of a core concurrency primitive doesn't feel right. The argument is that slower is better than broken, but this PR shows that we can do better.

As mentioned before, the primary purpose of this PR is to fix https://github.com/rust-lang/rust/issues/39364, and so the public API intentionally remains the same. *After* that problem is fixed, the fact that `sync::mpmc` now exists makes it easier to fix the primary limitation of `mpsc`, the fact that it only supports a single consumer. spmc and mpmc are two other common concurrency patterns, and this change enables a path to deprecating `mpsc` and exposing a general `sync::channel` module that supports multiple consumers. It also implements other useful methods such as `send_timeout`. That said, exposing MPMC and other new functionality is mostly out of scope for this PR, and it would be helpful if discussion stays on topic :)

For what it's worth, the new implementation has also been shown to be more performant in [some basic benchmarks](https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel/benchmarks#results).

cc `@taiki-e`

r? rust-lang/libs
2022-11-13 12:08:42 +00:00
Lukas Markeffsky ce10ac0d6a remove leading newlines from NonZero* doc examples 2022-11-13 11:32:57 +01:00
Ibraheem Ahmed a2f58ab2cb avoid using channels in thread-local tests 2022-11-12 23:44:52 -05:00
Ibraheem Ahmed a22426916d avoid calling thread::current in channel destructor 2022-11-12 23:13:58 -05:00
bors 6284998a26 Auto merge of #103913 - Neutron3529:patch-1, r=thomcc
Improve performance of `rem_euclid()` for signed integers

such code is copy from
https://github.com/rust-lang/rust/blob/master/library/std/src/f32.rs and
https://github.com/rust-lang/rust/blob/master/library/std/src/f64.rs
using `r+rhs.abs()` is faster than calc it with an if clause. Bench result:
```
$ cargo bench
   Compiling div-euclid v0.1.0 (/me/div-euclid)
    Finished bench [optimized] target(s) in 1.01s
     Running unittests src/lib.rs (target/release/deps/div_euclid-7a4530ca7817d1ef)

running 7 tests
test tests::it_works ... ignored
test tests::bench_aaabs     ... bench:  10,498,793 ns/iter (+/- 104,360)
test tests::bench_aadefault ... bench:  11,061,862 ns/iter (+/- 94,107)
test tests::bench_abs       ... bench:  10,477,193 ns/iter (+/- 81,942)
test tests::bench_default   ... bench:  10,622,983 ns/iter (+/- 25,119)
test tests::bench_zzabs     ... bench:  10,481,971 ns/iter (+/- 43,787)
test tests::bench_zzdefault ... bench:  11,074,976 ns/iter (+/- 29,633)

test result: ok. 0 passed; 0 failed; 1 ignored; 6 measured; 0 filtered out; finished in 19.35s
```
It seems that, default `rem_euclid` triggered a branch prediction, thus `bench_default` is faster than `bench_aadefault` and `bench_aadefault`, which shuffles the order of calculations. but all of them slower than what it was in `f64`'s and `f32`'s `rem_euclid`, thus I submit this PR.

bench code:
```rust
#![feature(test)]
extern crate test;

fn rem_euclid(a:i32,rhs:i32)->i32{
    let r = a % rhs;
    if r < 0 { r + rhs.abs() } else { r }
}

#[cfg(test)]
mod tests {
    use super::*;
    use test::Bencher;
    use rand::prelude::*;
    use rand::rngs::SmallRng;
    const N:i32=1000;
    #[test]
    fn it_works() {
        let a: i32 = 7; // or any other integer type
        let b = 4;

        let d:Vec<i32>=(-N..=N).collect();
        let n:Vec<i32>=(-N..0).chain(1..=N).collect();

        for i in &d {
            for j in &n {
                assert_eq!(i.rem_euclid(*j),rem_euclid(*i,*j));
            }
        }

        assert_eq!(rem_euclid(a,b), 3);
        assert_eq!(rem_euclid(-a,b), 1);
        assert_eq!(rem_euclid(a,-b), 3);
        assert_eq!(rem_euclid(-a,-b), 1);
    }

    #[bench]
    fn bench_aaabs(b: &mut Bencher) {
        let mut d:Vec<i32>=(-N..=N).collect();
        let mut n:Vec<i32>=(-N..0).chain(1..=N).collect();
        let mut rng=SmallRng::from_seed([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,21]);
        n.shuffle(&mut rng);
        d.shuffle(&mut rng);
        n.shuffle(&mut rng);
        b.iter(||{
            let mut res=0;
            for i in &d {
                for j in &n {
                    res+=rem_euclid(*i,*j);
                }
            }
            res
        });
    }
    #[bench]
    fn bench_aadefault(b: &mut Bencher) {
        let mut d:Vec<i32>=(-N..=N).collect();
        let mut n:Vec<i32>=(-N..0).chain(1..=N).collect();
        let mut rng=SmallRng::from_seed([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,21]);
        n.shuffle(&mut rng);
        d.shuffle(&mut rng);
        n.shuffle(&mut rng);
        b.iter(||{
            let mut res=0;
            for i in &d {
                for j in &n {
                    res+=i.rem_euclid(*j);
                }
            }
            res
        });
    }

    #[bench]
    fn bench_abs(b: &mut Bencher) {
        let d:Vec<i32>=(-N..=N).collect();
        let n:Vec<i32>=(-N..0).chain(1..=N).collect();
        b.iter(||{
            let mut res=0;
            for i in &d {
                for j in &n {
                    res+=rem_euclid(*i,*j);
                }
            }
            res
        });
    }
    #[bench]
    fn bench_default(b: &mut Bencher) {
        let d:Vec<i32>=(-N..=N).collect();
        let n:Vec<i32>=(-N..0).chain(1..=N).collect();
        b.iter(||{
            let mut res=0;
            for i in &d {
                for j in &n {
                    res+=i.rem_euclid(*j);
                }
            }
            res
        });
    }

    #[bench]
    fn bench_zzabs(b: &mut Bencher) {
        let mut d:Vec<i32>=(-N..=N).collect();
        let mut n:Vec<i32>=(-N..0).chain(1..=N).collect();
        let mut rng=SmallRng::from_seed([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,21]);
        d.shuffle(&mut rng);
        n.shuffle(&mut rng);
        d.shuffle(&mut rng);
        b.iter(||{
            let mut res=0;
            for i in &d {
                for j in &n {
                    res+=rem_euclid(*i,*j);
                }
            }
            res
        });
    }
    #[bench]
    fn bench_zzdefault(b: &mut Bencher) {
        let mut d:Vec<i32>=(-N..=N).collect();
        let mut n:Vec<i32>=(-N..0).chain(1..=N).collect();
        let mut rng=SmallRng::from_seed([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,21]);
        d.shuffle(&mut rng);
        n.shuffle(&mut rng);
        d.shuffle(&mut rng);
        b.iter(||{
            let mut res=0;
            for i in &d {
                for j in &n {
                    res+=i.rem_euclid(*j);
                }
            }
            res
        });
    }
}
```
2022-11-12 20:48:27 +00:00
Elarcis d8c0fef188 Fixed some _i32 notation in maybe_uninit’s doc 2022-11-12 19:22:28 +01:00
Guillaume Gomez f48dba1422
Rollup merge of #104308 - scottmcm:no-more-validalign, r=thomcc
Remove the old `ValidAlign` name

Since it looks like there won't be any reverts needed in `Layout` for https://github.com/rust-lang/rust/issues/101899#issuecomment-1290805223, finish off this change that I'd left out of #102072.

r? ``@thomcc``
cc tracking issue #102070
2022-11-12 17:25:03 +01:00
Guillaume Gomez cd4b3ac379
Rollup merge of #104263 - albertlarsan68:add-ilog2-to-leading-zeroes-docs, r=scottmcm
Add a reference to ilog2 in leading_zeros integer docs

Fixes #104248
2022-11-12 17:25:03 +01:00
Deadbeef 4b217e4624 Use derive_const and rm manual StructuralEq impl 2022-11-12 12:57:10 +00:00
Mateusz Mikuła 7333ee092b Use correct EH personality on *-windows-gnu-* 2022-11-12 12:19:14 +01:00
Mateusz Mikuła 2a902a8857 Bump unwinder private data size for AArch64 Windows
This fixes unwinding on `aarch64-*-windows-gnu*`.
2022-11-12 12:19:14 +01:00
Dylan DPC 4b0b89827d
Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk
Add the `#[derive_const]` attribute

Closes #102371. This is a minimal patchset for the attribute to work. There are no restrictions on what traits this attribute applies to.

r? `````@oli-obk`````
2022-11-12 12:02:50 +05:30
Scott McMurray fed105381b Remove the old ValidAlign name
Since it looks like there won't be any reverts needed in `Layout`, finish off this change.
2022-11-11 21:44:27 -08:00
bors b0c6527912 Auto merge of #103150 - joboet:remove_lock_wrappers, r=m-ou-se
Remove lock wrappers in `sys_common`

This moves the lazy allocation to `sys` (SGX and UNIX). While this leads to a bit more verbosity, it will simplify future improvements by making room in `sys_common` for platform-independent implementations.

This also removes the condvar check on SGX as it is not necessary for soundness and will be removed anyway once mutex has been made movable.

For simplicity's sake, `libunwind` also uses lazy allocation now on SGX. This will require an update to the C definitions before merging this (CC `@raoulstrackx).`

r? `@m-ou-se`
2022-11-12 01:31:39 +00:00
Tobias Bucher 461d147249 Document Path::parent behavior around relative paths
A relative path with just one component will return `Some("")` as its
parent, which wasn't clear to me from the documentation.

The parent of `""` is `None`, which was missing from the documentation
as well.
2022-11-11 21:38:00 +01:00
Albert Larsan a1909b7b07
Try another way 2022-11-11 12:17:32 +01:00
Albert Larsan fb98796892
Apply suggestions 2022-11-11 11:14:09 +01:00
Albert Larsan d85b61460a
Add a reference to ilog2 in leading_zeros integer docs
Asked in #104248
2022-11-11 00:47:52 +01:00
Manish Goregaokar 150e0ec393
Rollup merge of #104060 - ink-feather-org:const_hash, r=fee1-dead
Make `Hash`, `Hasher` and `BuildHasher` `#[const_trait]` and make `Sip` const `Hasher`

This PR enables using Hashes in const context.

r? ``@fee1-dead``
2022-11-10 10:47:38 -05:00
Ibraheem Ahmed 209168655a tidy 2022-11-09 23:20:02 -05:00
Ibraheem Ahmed f2b5e27a60 spin less in mpsc::SyncSender::send 2022-11-09 23:20:02 -05:00
Ibraheem Ahmed f2966d1d0c remove extra spinning from mpsc parker 2022-11-09 23:20:02 -05:00
Ibraheem Ahmed 8dddb22943 sync::mpsc: quadratic backoff 2022-11-09 23:20:02 -05:00
Ibraheem Ahmed 7b721ed0cd sync::mpsc: reload state after spinning on CAS failure 2022-11-09 23:20:02 -05:00
Ibraheem Ahmed 8c17a3e7cb remove extra spinning from mpsc::Receiver::recv 2022-11-09 23:20:02 -05:00
Ibraheem Ahmed cb394c026a remove mention of rust-lang#39364 from mpsc docs 2022-11-09 23:20:02 -05:00
Ibraheem Ahmed 8a68b40432 add test case for rust-lang#39364 2022-11-09 23:20:02 -05:00
Ibraheem Ahmed 31dc5bba89 implement sync::mpsc as a wrapper around sync::mpmc 2022-11-09 23:20:00 -05:00
Ibraheem Ahmed a43da5a097 initial port of crossbeam-channel 2022-11-09 23:18:06 -05:00
Bryan Garza fa99cb8269 Allow and add track_caller to generators
This patch allows the usage of the `track_caller` annotation on
generators, as well as sets them conditionally if the parent also has
`track_caller` set.

Also add this annotation on the `GenFuture`'s `poll()` function.
2022-11-09 23:27:14 +00:00
Tom Parker-Shemilt 18129b67a0 Upgrade cc to 1.0.76 2022-11-09 21:52:10 +00:00
Manish Goregaokar 67c0bff934
Rollup merge of #104015 - alex:remove-kernel, r=oli-obk
Remove linuxkernel targets

These are not used by the actual Rust-for-Linux project, so they're mostly just confusing.
2022-11-09 15:39:05 -05:00
Manish Goregaokar 3f11d39eec
Rollup merge of #103464 - JakobDegen:mir-parsing, r=oli-obk
Add support for custom mir

This implements rust-lang/compiler-team#564 . Details about the design, motivation, etc. can be found in there.

r? ```@oli-obk```
2022-11-09 15:39:03 -05:00
Manish Goregaokar 46bc12c95a
Rollup merge of #103307 - b4den:master, r=estebank
Add context to compiler error message

Changed `creates a temporary which is freed while still in use` to `creates a temporary value which is freed while still in use`.
2022-11-09 15:39:02 -05:00
Dylan DPC 062f2fc50f
Rollup merge of #104125 - ink-feather-org:const_cmp_tuples, r=fee1-dead
Const Compare for Tuples

Makes the impls for Tuples of ~const `PartialEq` types also `PartialEq`, impls for Tuples of ~const `PartialOrd` types also `PartialOrd`, for Tuples of ~const `Ord` types also `Ord`.

behind the `#![feature(const_cmp)]` gate.

~~Do not merge before #104113 is merged because I want to use this feature to clean up the new test that I added there.~~

r? ``@fee1-dead``
2022-11-09 19:21:25 +05:30
Dylan DPC 64e737c07c
Rollup merge of #104111 - yancyribbens:add-mutable-to-the-description-for-as-simd-mut, r=scottmcm
rustdoc: Add mutable to the description

Add mutable the description to differentiate [as_simd](https://github.com/rust-lang/rust/blob/master/library/core/src/slice/mod.rs#L3654) from [as_simd_mut](https://github.com/rust-lang/rust/blob/master/library/core/src/slice/mod.rs#L3654).
2022-11-09 19:21:24 +05:30
Dylan DPC b457d707e8
Rollup merge of #103694 - WaffleLapkin:mask_doc_example, r=scottmcm
Add documentation examples for `pointer::mask`

The examples are somewhat convoluted, but I don't know how to make this better :(
2022-11-09 19:21:22 +05:30
Dylan DPC 1db7f690b1
Rollup merge of #103570 - lukas-code:stabilize-ilog, r=scottmcm
Stabilize integer logarithms

Stabilizes feature `int_log`.

I've also made the functions const stable, because they don't depend on any unstable const features. `rustc_allow_const_fn_unstable` is just there for `Option::expect`, which could be replaced with a `match` and `panic!`. cc ``@rust-lang/wg-const-eval``

closes https://github.com/rust-lang/rust/issues/70887 (tracking issue)

~~blocked on FCP finishing: https://github.com/rust-lang/rust/issues/70887#issuecomment-1289028216~~
FCP finished: https://github.com/rust-lang/rust/issues/70887#issuecomment-1302121266
2022-11-09 19:21:21 +05:30
onestacked f6658479a8 const Compare Tuples 2022-11-09 09:52:04 +01:00
Jakob Degen ba359d8a51 Add support for custom MIR parsing 2022-11-08 23:13:15 -08:00
Guillaume Gomez ed38562d76
Rollup merge of #104139 - ferrocene:pa-channel-licensing, r=pnkfelix
Clarify licensing situation of MPSC and SPSC queue

Originally, these two files were licensed under the `BSD-2-Clause` license, as they were based off sample code on a blog licensing those snippets under that license:

* `library/std/src/sync/mpsc/mpsc_queue.rs`
* `library/std/src/sync/mpsc/spsc_queue.rs`

In 2017 though, the author of that blog agreed to relicense their code under the standard `MIT OR Apache-2.0` license in https://github.com/rust-lang/rust/pull/42149. This PR clarifies the situation in the files by expanding the comment at the top of the file.

r? ``@pnkfelix``
2022-11-08 20:40:53 +01:00
Guillaume Gomez 02db37a18a
Rollup merge of #104113 - ink-feather-org:fix_const_fn_ref_impls, r=compiler-errors
Fix `const_fn_trait_ref_impl`, add test for it

#99943 broke `#[feature(const_fn_trait_ref_impl)]`, this PR fixes this and adds a test for it.

r? ````@fee1-dead````
2022-11-08 20:40:51 +01:00
Guillaume Gomez c39cf7acaa
Rollup merge of #104109 - yancyribbens:add-mutable-to-comment-for-align-to-mut, r=thomcc
rustdoc: Add mutable to the description

`mutable` is missing from the description.  Currently the description for [align_to](https://github.com/rust-lang/rust/blob/master/library/core/src/slice/mod.rs#L3498) is the same as [align_to_mut](https://github.com/rust-lang/rust/blob/master/library/core/src/slice/mod.rs#L3559)
2022-11-08 20:40:51 +01:00
Guillaume Gomez 53b6a894ca
Rollup merge of #104097 - RalfJung:miri-alloc-benches, r=thomcc
run alloc benchmarks in Miri and fix UB

Miri since recently has a "fake monotonic clock" that works even with isolation. Its measurements are not very meaningful but it means we can run these benches and check them for UB.

And that's a good thing since there was UB here: fixes https://github.com/rust-lang/rust/issues/104096.

r? ``@thomcc``
2022-11-08 20:40:50 +01:00
Guillaume Gomez afaba1997d
Rollup merge of #104093 - RalfJung:test-sizes, r=thomcc
disable btree size tests on Miri

Seems fine not to run these in Miri, they can't have UB anyway. And this lets us do layout randomization in Miri.

r? ``@thomcc``
2022-11-08 20:40:49 +01:00
onestacked 56e59bcb27 Test const Hash, fix nits 2022-11-08 17:39:40 +01:00
Pietro Albini 807a7bfcee
clarify licensing situation of mpsc and spsc queue 2022-11-08 09:36:08 +01:00
Dylan DPC b695ed3f20
Rollup merge of #103446 - the8472:tra-array-chunks, r=Mark-Simulacrum
Specialize `iter::ArrayChunks::fold` for TrustedRandomAccess iterators

```
OLD:
test iter::bench_trusted_random_access_chunks                      ... bench:         368 ns/iter (+/- 4)
NEW:
test iter::bench_trusted_random_access_chunks                      ... bench:          30 ns/iter (+/- 0)
```

The resulting assembly is similar to #103166 but the specialization kicks in under different (partially overlapping) conditions compared to that PR. They're complementary.

In principle a TRA-based specialization could be applied to all `ArrayChunks` methods, including `next()` as we do for `Zip` but that would have all the same hazards as the Zip specialization. Only doing it for `fold` is far less hazardous. The downside is that it only helps with internal, exhaustive iteration. I.e. `for _ in` or `try_fold` will not benefit.

Note that the regular, `try_fold`-based and the specialized `fold()` impl have observably slightly different behavior. Namely the specialized variant does not fetch the remainder elements from the underlying iterator. We do have a few other places in the standard library where beyond-the-end-of-iteration side-effects are being elided under some circumstances but not others.

Inspired by https://old.reddit.com/r/rust/comments/yaft60/zerocost_iterator_abstractionsnot_so_zerocost/
2022-11-08 11:23:50 +05:30
The 8472 3925fc0c8e document and improve array Guard type
The type is unsafe and now exposed to the whole crate.
Document it properly and add an unsafe method so the
caller can make it visible that something unsafe is happening.
2022-11-08 00:13:26 +01:00
The 8472 43c353fff7 simplification: do not process the ArrayChunks remainder in fold() 2022-11-07 21:44:25 +01:00
The 8472 cfcce8e684 specialize iter::ArrayChunks::fold for TrustedRandomAccess iters
This is fairly safe use of TRA since it consumes the iterator so
no struct in an unsafe state will be left exposed to user code
2022-11-07 21:44:25 +01:00
The 8472 eb3f001d37 make the array initialization guard available to other modules 2022-11-07 21:44:25 +01:00
The 8472 b00666ed09 add benchmark for iter::ArrayChunks::fold specialization
This also updates the existing iter::Copied::next_chunk benchmark so
that the thing it benches doesn't get masked by the ArrayChunks specialization
2022-11-07 21:44:24 +01:00
bors 73c9eaf214 Auto merge of #103934 - notriddle:notriddle/backtrace-deps, r=Mark-Simulacrum
std: sync "Dependencies of the `backtrace` crate" with `backtrace`

Compare:

07872f28cd/Cargo.toml (L43)

160b194295/library/std/Cargo.toml (L26)
2022-11-07 20:05:09 +00:00
onestacked 0c9896bfaa Fix const_fn_trait_ref_impl, add test for it 2022-11-07 17:41:58 +01:00
yancy f67ee43fe3 rustdoc: Add mutable to the description 2022-11-07 17:02:48 +01:00
yancy d62582f92a rustdoc: Add mutable to the description 2022-11-07 16:51:23 +01:00
onestacked cebce1e616 Removed unnecessary Trait bound 2022-11-07 15:34:43 +01:00
Ralf Jung 29d451ccb3 fmt 2022-11-07 15:24:49 +01:00
Dylan DPC 81b8db2675
Rollup merge of #104090 - wanghaha-dev:master, r=Dylan-DPC
Modify comment syntax error

Modify comment syntax error
2022-11-07 18:35:26 +05:30
Ralf Jung 780952f922 run alloc benchmarks in Miri and fix UB 2022-11-07 10:34:04 +01:00
Ralf Jung 17044c1d00 disable btree size tests on Miri 2022-11-07 09:29:14 +01:00
wanghaha-dev 009f80b987 Modify comment syntax error 2022-11-07 14:33:33 +08:00
Yuki Okushi 7ca833efe0
Rollup merge of #104074 - yancyribbens:add-example-to-round, r=Mark-Simulacrum
rustdoc: Add an example for round that is different from truncate

The current examples for [round](https://github.com/rust-lang/rust/blob/master/library/std/src/f64.rs#L75) would have the same results as the example for [truncate](https://github.com/rust-lang/rust/blob/master/library/std/src/f64.rs#L95).  This PR adds one more example to `round` that will have a different result from `truncate`.
2022-11-07 09:46:29 +09:00
Yuki Okushi 57daec5989
Rollup merge of #104056 - ripytide:patch-1, r=Mark-Simulacrum
Vec: IntoIterator signature consistency

Also makes the code dryer.
2022-11-07 09:46:26 +09:00
Mark Rousskov 01a2a57ac9 Fix rebase errors 2022-11-06 17:38:47 -05:00
Mark Rousskov b3242f4f13 Fix rustdoc lints 2022-11-06 17:21:22 -05:00
Mark Rousskov 40290505fb cfg-step code 2022-11-06 17:21:21 -05:00
Mark Rousskov 455a7bc685 Bump version placeholders to release 2022-11-06 17:11:02 -05:00
yancy a398e09e42 rustdoc: Add an example for round that is different from truncate 2022-11-06 23:05:16 +01:00
Alex Saveau 28ea002340
Add small clarification around using pointers derived from references
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-06 12:09:55 -08:00
bors 7eef946fc0 Auto merge of #99943 - compiler-errors:tuple-trait, r=jackh726
Implement `std::marker::Tuple`, use it in `extern "rust-call"` and `Fn`-family traits

Implements rust-lang/compiler-team#537

I made a few opinionated decisions in this implementation, specifically:
1. Enforcing `extern "rust-call"` on fn items during wfcheck,
2. Enforcing this for all functions (not just ones that have bodies),
3. Gating this `Tuple` marker trait behind its own feature, instead of grouping it into (e.g.) `unboxed_closures`.

Still needing to be done:
1. Enforce that `extern "rust-call"` `fn`-ptrs are well-formed only if they have 1/2 args and the second one implements `Tuple`. (Doing this would fix ICE in #66696.)
2. Deny all explicit/user `impl`s of the `Tuple` trait, kinda like `Sized`.
3. Fixing `Tuple` trait built-in impl for chalk, so that chalkification tests are un-broken.

Open questions:
1. Does this need t-lang or t-libs signoff?

Fixes #99820
2022-11-06 17:48:33 +00:00
onestacked dc1f1a8e97 Added const_hash tracking issue id 2022-11-06 18:01:44 +01:00
onestacked 5f9899b289 Made Sip const Hasher 2022-11-06 17:46:38 +01:00
ripytide 743726e352
Vec: IntoIterator signature consistency
Also makes the code dryer.
2022-11-06 15:25:00 +00:00
joboet b231835179
std: fix double-free of mutex 2022-11-06 15:32:59 +01:00
joboet 98815742cf
std: remove lock wrappers in sys_common 2022-11-06 15:32:59 +01:00
Ralf Jung 6b7f6b98c7 remove no-longer-needed work-arounds from the standard library 2022-11-06 14:20:09 +01:00
Matthias Krüger d93b5200d5
Rollup merge of #104002 - RalfJung:unsafecell-new, r=JohnTitor
fix a comment in UnsafeCell::new

There are several safe methods that access the inner value: `into_inner` has existed since forever and `get_mut` also exists since recently. So this comment seems just wrong. But `&self` methods return raw pointers and thus require unsafe code (though the methods themselves are still safe).
2022-11-06 08:35:27 +01:00
Michael Goulet d9891563d3 Merge conflicts and rebase onto master 2022-11-05 18:05:44 +00:00
Michael Goulet 2786acce98 Enforce Tuple trait on Fn traits 2022-11-05 17:34:47 +00:00
Alex Gaynor c33ee13391
Remove linuxkernel targets
These are not used by the actual Rust-for-Linux project, so they're mostly just confusing.
2022-11-05 12:30:28 -04:00
Ralf Jung dad327090a fix a comment in UnsafeCell::new 2022-11-05 12:27:43 +01:00
Dylan DPC 47e6304e32
Rollup merge of #103995 - SUPERCILEX:typos, r=Dylan-DPC
Small round of typo fixes
2022-11-05 11:31:30 +05:30
Alex Saveau 849d89b031
Small round of typo fixes
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-04 20:06:18 -07:00
Arlo Siemsen 7c60236036 Fix build of thumbv7a-pc-windows-msvc 2022-11-04 14:35:56 -07:00
onestacked 3ea4165a77 Make BuildHasher const_trait 2022-11-04 21:30:47 +01:00
onestacked 1bcf9fae03 Made Hash and Hasher const_trait 2022-11-04 21:30:46 +01:00
Matthias Krüger c38ee06b62
Rollup merge of #103681 - RalfJung:libtest-thread, r=thomcc
libtest: run all tests in their own thread, if supported by the host

This reverts the threading changes of https://github.com/rust-lang/rust/pull/56243, which made it so that with `-j1`, the test harness does not spawn any threads. Those changes were done to enable Miri to run the test harness, but Miri supports threads nowadays, so this is no longer needed. Using a thread for each test is useful because the thread's name can be set to the test's name which makes panic messages consistent between `-j1` and `-j2` runs and also a bit more readable.

I did not revert the HashMap changes of https://github.com/rust-lang/rust/pull/56243; using a deterministic map seems fine for the test harness and the more deterministic testing is the better.

Fixes https://github.com/rust-lang/rust/issues/59122
Fixes https://github.com/rust-lang/rust/issues/70492
2022-11-04 18:52:26 +01:00
Matthias Krüger dabb6c6bd7
Rollup merge of #103367 - chbaker0:update-std-getrandom, r=thomcc
Remove std's transitive dependency on cfg-if 0.1

After https://github.com/rust-lang/rust/pull/101946 this completes the move to cfg-if 1.0 by:
* Updating getrandom 0.1.14->0.1.16
* Updating panic_abort's and unwind's dep to cfg-if 1.0

Fixes https://github.com/rust-lang/rust/issues/103365
2022-11-04 18:52:25 +01:00
Matthias Krüger 9398676635
Rollup merge of #103941 - douweschulte:patch-1, r=jyn514
Fixed typos

Fixed a typo that has been found on two locations in comments.
2022-11-04 12:18:02 +01:00