Commit Graph

10677 Commits

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

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

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

Implement rust-lang/libs-team#173.

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

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

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

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

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

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

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

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

r? `@pietroalbini`
2023-01-31 19:24:29 +00:00
Deadbeef
6bf2c4d739 implement const iterator using rustc_do_not_const_check 2023-01-31 17:09:30 +00:00
joboet
42cc28ac8b
std: add type alias for raw OS errors
Implement rust-lang/libs-team#173.
2023-01-31 17:23:35 +01:00
Markus Everling
8ca25b8e49 Fix vec_deque::Drain FIXME 2023-01-31 15:04:39 +01:00
Yuki Okushi
150340bafd
Rollup merge of #107494 - lebensterben:patch-1, r=JohnTitor
fix link in std::path::Path::display()

The link `Debug` points to should be the trait `Debug`, not the macro `Debug`.
2023-01-31 11:46:26 +09:00
Yuki Okushi
39d2639f81
Rollup merge of #107445 - Swatinem:rm-genfuture, r=cuviper
Remove `GenFuture` from core

The handling of async constructs in the compiler does not rely on `GenFuture` anymore since `1.67`, so this code can now be removed from `core`.
2023-01-31 11:46:23 +09:00
Lucius Hu
3c408d82a3
fix link in std::path::Path::display()
The link `Debug` points to should be the trait `Debug`, not the macro `Debug`.
2023-01-31 00:20:27 +00:00
Matthias Kaak
8d7b092a11
Improved wording of error messages of missing remainder implementations 2023-01-30 19:54:33 +00:00
Mark Rousskov
5b08c9f397 stage-step cfgs 2023-01-30 13:09:09 -05:00
Matthias Krüger
b3b9383f8d
Rollup merge of #107424 - bpeel:clone-into-from-share-code, r=scottmcm
Make Vec::clone_from and slice::clone_into share the same code

In the past, `Vec::clone_from` was implemented using `slice::clone_into`. The code from `clone_into` was later duplicated into `clone_from` in 8725e4c337, which is the commit that adds custom allocator support to Vec. Presumably this was done because the `slice::clone_into` method only works for vecs with the default allocator so it would have the wrong type to clone into `Vec<T, A>`.

Later on in 361398009b the code for the two methods diverged because the `Vec::clone_from` version gained a specialization to optimize the case when T is Copy. In order to reduce code duplication and make them both be able to take advantage of this specialization, this PR moves the specialization into the slice module and makes vec use it again.
2023-01-30 17:50:10 +01:00
bors
006ca9b14d Auto merge of #107080 - Urgau:cleanup-bootstrap-extra-check-cfgs, r=Mark-Simulacrum
bootstrap: cleanup the list of extra check cfgs

This PR performs some cleanups on the `EXTRA_CHECK_CFGS` list in bootstrap.

- `target_os=watchos`: no longer relevant because there are now proper targets `*-apple-watchos`
 - `target_arch=nvptx64`: target `nvptx64-nvidia-cuda` makes it useless
 - `target_arch=le32`: target was removed (https://github.com/rust-lang/rust/pull/45041)
 - `release`: was removed from rustfmt (https://github.com/rust-lang/rustfmt/pull/5375 and https://github.com/rust-lang/rustfmt/pull/5449)
 - `dont_compile_me`: was removed from stdarch (https://github.com/rust-lang/stdarch/pull/1308)

Also made some external cfg exception mode clear and only activated for rustc and rustc tools (as to not have the Standard Library unintentionally depend on them).
2023-01-30 13:56:40 +00:00
Dylan DPC
da56c44ba2
Rollup merge of #107459 - tshepang:cosistency, r=WaffleLapkin
end entry paragraph with a period (.)
2023-01-30 15:11:47 +05:30
Dylan DPC
f01b8f5cf4
Rollup merge of #107452 - y21:get-mut-unchecked-typo, r=Mark-Simulacrum
Fix typo in `{Rc, Arc}::get_mut_unchecked` docs

Just a correction in the documentation of `{Rc, Arc}::get_mut_unchecked`.
2023-01-30 15:11:46 +05:30
Dylan DPC
28340bab88
Rollup merge of #101569 - m-ou-se:alloc-no-rexport-argumentv1, r=thomcc
Don't re-export private/unstable ArgumentV1 from `alloc`.

The `alloc::fmt::ArgumentV1` re-export was marked as `#[stable]` even though the original `core::fmt::ArgumentV1` is `#[unstable]` (and `#[doc(hidden)]`).

(It wasn't usable though:

```
error[E0658]: use of unstable library feature 'fmt_internals': internal to format_args!
 --> src/main.rs:4:12
  |
4 |     let _: alloc::fmt::ArgumentV1 = todo!();
  |            ^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: add `#![feature(fmt_internals)]` to the crate attributes to enable
```
)

Part of #99012
2023-01-30 15:11:44 +05:30
Tshepang Mbambo
72360191f1 end entry paragraph with a period (.) 2023-01-30 07:37:02 +02:00
Mara Bos
67bb7ba3ea Don't re-export private/unstable ArgumentV1 from alloc. 2023-01-29 20:15:02 +01:00
y21
61b18b58ab fix typo in {Rc, Arc}::get_mut_unchecked docs 2023-01-29 20:11:36 +01:00
Matthias Krüger
392265419a
Rollup merge of #107431 - notriddle:notriddle/colon, r=thomcc
docs: remove colon from time header

It's not used anywhere else; the inconsistency is weird.
2023-01-29 20:03:38 +01:00
Matthias Krüger
782da867c8
Rollup merge of #106798 - scottmcm:signum-via-cmp, r=Mark-Simulacrum
Implement `signum` with `Ord`

Rather than needing to do things like #105840 for `signum` too, might as well just implement that method using `Ord`, since it's doing the same "I need `-1`/`0`/`+1`" behaviour that `cmp` is already doing.

This also seems to slightly improve the assembly: <https://rust.godbolt.org/z/5oEEqbxK1>
2023-01-29 20:03:36 +01:00
Matthias Krüger
192eecd53a
Rollup merge of #106769 - lenko-d:libtest-print_why_a_test_was_ignored_if_its_the_only_test_specified, r=Mark-Simulacrum
libtest: Print why a test was ignored if it's the only test specified.

Fixes [#106659](https://github.com/rust-lang/rust/issues/106659)
Needed by [106763](https://github.com/rust-lang/rust/pull/106763)
2023-01-29 20:03:36 +01:00
Arpad Borsos
5372e66884
Remove GenFuture from core
The handling of async constructs in the compiler does not rely on `GenFuture`
anymore since `1.67`, so this code can now be removed from `core`.
2023-01-29 15:20:03 +01:00
bors
d117135f5a Auto merge of #106253 - nbdd0121:upcast, r=compiler-errors
Skip possible where_clause_object_safety lints when checking `multiple_supertrait_upcastable`

Fix #106247

To achieve this, I lifted the `WhereClauseReferencesSelf` out from `object_safety_violations` and move it into `is_object_safe` (which is changed to a new query).

cc `@dtolnay`
r? `@compiler-errors`
2023-01-29 10:20:25 +00:00
Matthias Krüger
33da3c3df0
Rollup merge of #107154 - glaubitz:m68k-alloc, r=JohnTitor
library/std/sys_common: Define MIN_ALIGN for m68k-unknown-linux-gnu

This PR adds the missing definition of MIN_ALIGN for the m68k-unknown-linux target.
2023-01-29 06:14:17 +01:00
Matthias Krüger
0f86ada9d8
Rollup merge of #106618 - jmillikin:os-net-rustdoc-wasm32, r=JohnTitor
Disable `linux_ext` in wasm32 and fortanix rustdoc builds.

The `std::os::unix` module is stubbed out when building docs for these target platforms. The introduction of Linux-specific extension traits caused `std::os::net` to depend on sub-modules of `std::os::unix`, which broke rustdoc for the `wasm32-unknown-unknown` target.

Adding an additional `#[cfg]` guard solves that rustdoc failure by not declaring `linux_ext` on targets with a stubbed `std::os::unix`.

Fixes #105467
2023-01-29 06:14:16 +01:00
Michael Howell
2cdec46275 docs: remove colon from time header
It's not used anywhere else; the inconsistency is weird.
2023-01-28 16:07:34 -07:00
Neil Roberts
a34f11c006 vec: Use SpecCloneIntoVec::clone_into to implement Vec::clone_from
In the past, Vec::clone_from was implemented using slice::clone_into.
The code from clone_into was later duplicated into clone_from in
8725e4c337, which is the commit that adds custom allocator support to
Vec. Presumably this was done because the slice::clone_into only works
for vecs with the default allocator so it would have the wrong type to
clone into Vec<T, A>.

Now that the clone_into implementation is moved out into a specializable
trait anyway we might as well use that to share the code between the two
methods.
2023-01-28 20:37:01 +01:00
Neil Roberts
ba80c662f4 slice: Add a specialization for clone_into when T is Copy
The implementation for the ToOwned::clone_into method on [T] is a copy
of the code for vec::clone_from. In 361398009b the code for
vec::clone_from gained a specialization for when T is Copy. This commit
copies that specialization over to the clone_into implementation.
2023-01-28 20:37:01 +01:00
Gary Guo
66f3ab90a1 Reintroduce multiple_supertrait_upcastable lint 2023-01-28 15:08:07 +00:00
Matthias Krüger
c95707a29b
Rollup merge of #107398 - scottmcm:its-their-funeral, r=dtolnay
Remove `ControlFlow::{BREAK, CONTINUE}`

Libs-API decided to remove these in #102697.

Follow-up to #107023, which removed them from `compiler/`, but a couple new ones showed up since that was merged.

r? libs
2023-01-28 11:11:09 +01:00
Matthias Krüger
45430a5351
Rollup merge of #105524 - Ayush1325:libc-free, r=ChrisDenton
Replace libc::{type} with crate::ffi::{type}

Replace libc::{type} imports with crate::ffi::{type} outside of `std::sys` and `std::os`.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-01-28 11:11:06 +01:00
Matthias Krüger
36ef4f15d3
Rollup merge of #104252 - faern:stabilize-const_socketaddr, r=JohnTitor
Stabilize the const_socketaddr feature

Stabilizes `#![feature(const_socketaddr)]`. Tracking issue: #82485
Closes #82485

This has been unstably const for over a year now. And the code change simplifying the constness of the `new` constructors has been in stable Rust since 1.64 (a bit over a full release cycle). I'm not aware of any blockers to this stabilization.
2023-01-28 11:11:06 +01:00
Ayush Singh
c50d3e28ab
Replace libc::{type} with crate::ffi::{type}
Replace libc::{type} imports with crate::ffi::{type} outside of
`std::sys` and `std::os`.

Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-01-28 11:24:13 +05:30
Matthias Krüger
7b78b6a78d
Rollup merge of #107022 - scottmcm:ordering-option-eq, r=m-ou-se
Implement `SpecOptionPartialEq` for `cmp::Ordering`

Noticed as I continue to explore options for having code using `partial_cmp` optimize better.

Before:
```llvm
; Function Attrs: mustprogress nofree nosync nounwind willreturn uwtable
define noundef zeroext i1 `@ordering_eq(i8` noundef %0, i8 noundef %1) unnamed_addr #0 {
start:
  %2 = icmp eq i8 %0, 2
  br i1 %2, label %bb1.i, label %bb3.i

bb1.i:                                            ; preds = %start
  %3 = icmp eq i8 %1, 2
  br label %"_ZN55_$LT$T$u20$as$u20$core..option..SpecOptionPartialEq$GT$2eq17hb7e7beacecde585fE.exit"

bb3.i:                                            ; preds = %start
  %.not.i = icmp ne i8 %1, 2
  %4 = icmp eq i8 %0, %1
  %spec.select.i = and i1 %.not.i, %4
  br label %"_ZN55_$LT$T$u20$as$u20$core..option..SpecOptionPartialEq$GT$2eq17hb7e7beacecde585fE.exit"

"_ZN55_$LT$T$u20$as$u20$core..option..SpecOptionPartialEq$GT$2eq17hb7e7beacecde585fE.exit": ; preds = %bb1.i, %bb3.i
  %.0.i = phi i1 [ %3, %bb1.i ], [ %spec.select.i, %bb3.i ]
  ret i1 %.0.i
}
```

After:
```llvm
; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone willreturn uwtable
define noundef zeroext i1 `@ordering_eq(i8` noundef %0, i8 noundef %1) unnamed_addr #1 {
start:
  %2 = icmp eq i8 %0, %1
  ret i1 %2
}
```

(Which <https://alive2.llvm.org/ce/z/-rop5r> says LLVM *could* just do itself, but there's probably an issue already open for that problem from when this was originally looked at for `Option<NonZeroU8>` and friends.)
2023-01-28 05:20:15 +01:00
Scott McMurray
868d099a72 Remove ControlFlow::{BREAK, CONTINUE}
Libs-API decided to remove these in #102697.

Follow-up to #107023, which removed them from `compiler/`, but a couple new ones showed up since that was merged.
2023-01-27 19:46:42 -08:00
Scott McMurray
3e9d1e40cb Link to the LLVM issue from a comment on SpecOptionPartialEq 2023-01-27 19:09:52 -08:00
Matthias Kaak
e02517d753
Fixed confusement between mod and remainder 2023-01-27 21:01:07 +00:00
joboet
6520488e37
std: add safety comment in LazyLock::get 2023-01-27 10:11:42 +01:00
joboet
7165e610a2
std: fix Debug implementation on LazyLock 2023-01-27 10:09:38 +01:00
Yuki Okushi
bf321ece1e
Rollup merge of #106856 - vadorovsky:fix-atomic-annotations, r=joshtriplett
core: Support variety of atomic widths in width-agnostic functions

Before this change, the following functions and macros were annotated with `#[cfg(target_has_atomic = "8")]` or
`#[cfg(target_has_atomic_load_store = "8")]`:

* `atomic_int`
* `strongest_failure_ordering`
* `atomic_swap`
* `atomic_add`
* `atomic_sub`
* `atomic_compare_exchange`
* `atomic_compare_exchange_weak`
* `atomic_and`
* `atomic_nand`
* `atomic_or`
* `atomic_xor`
* `atomic_max`
* `atomic_min`
* `atomic_umax`
* `atomic_umin`

However, none of those functions and macros actually depend on 8-bit width and they are needed for all atomic widths (16-bit, 32-bit, 64-bit etc.). Some targets might not support 8-bit atomics (i.e. BPF, if we would enable atomic CAS for it).

This change fixes that by removing the `"8"` argument from annotations, which results in accepting the whole variety of widths.

Fixes #106845
Fixes #106795

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2023-01-27 12:57:54 +09:00
Yuki Okushi
4b4aeae359
Rollup merge of #105784 - yanns:update_stdarch, r=Amanieu
update stdarch

This will allow using miri on simd instructions
https://github.com/rust-lang/stdarch/issues/1347#issuecomment-1353664361
2023-01-27 12:57:53 +09:00
Ian Douglas Scott
c13669e00b Implement AsFd and AsRawFd for Rc
Fixes https://github.com/rust-lang/rust/issues/105931.
2023-01-26 08:08:13 -08:00
bors
c62665e09c Auto merge of #107328 - matthiaskrgr:rollup-lfqwo0o, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #106904 (Preserve split DWARF files when building archives.)
 - #106971 (Handle diagnostics customization on the fluent side (for one specific diagnostic))
 - #106978 (Migrate mir_build's borrow conflicts)
 - #107150 (`ty::tls` cleanups)
 - #107168 (Use a type-alias-impl-trait in `ObligationForest`)
 - #107189 (Encode info for Adt in a single place.)
 - #107322 (Custom mir: Add support for some remaining, easy to support constructs)
 - #107323 (Disable ConstGoto opt in cleanup blocks)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-26 15:58:08 +00:00
joboet
c1cced8d04
std: optimize LazyLock size 2023-01-26 16:16:03 +01:00
Matthias Krüger
c87996a8ad
Rollup merge of #107322 - JakobDegen:custom-mir, r=tmiasko
Custom mir: Add support for some remaining, easy to support constructs

Some documentation for previous changes and support for `Deinit`, checked binops, len, and array repetition

r? ```@oli-obk``` or ```@tmiasko```
2023-01-26 15:02:22 +01:00
bors
3e97763872 Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk
Move format_args!() into AST (and expand it during AST lowering)

Implements https://github.com/rust-lang/compiler-team/issues/541

This moves FormatArgs from rustc_builtin_macros to rustc_ast_lowering. For now, the end result is the same. But this allows for future changes to do smarter things with format_args!(). It also allows Clippy to directly access the ast::FormatArgs, making things a lot easier.

This change turns the format args types into lang items. The builtin macro used to refer to them by their path. After this change, the path is no longer relevant, making it easier to make changes in `core`.

This updates clippy to use the new language items, but this doesn't yet make clippy use the ast::FormatArgs structure that's now available. That should be done after this is merged.
2023-01-26 12:44:47 +00:00
Jakob Degen
d7f59e91e0 Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
Yann Simon
2e8162a0b0 fix alphabetical sort 2023-01-26 11:09:32 +01:00
Yann Simon
a499862948 remove avx512 prefix for gfni, vaes and vpclmulqdq 2023-01-26 11:01:44 +01:00
bors
40fda7b3fe Auto merge of #107318 - matthiaskrgr:rollup-776kd81, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #97373 (impl DispatchFromDyn for Cell and UnsafeCell)
 - #106625 (Remove backwards compat for LLVM 12 coverage format)
 - #106779 (Avoid __cxa_thread_atexit_impl on Emscripten)
 - #106811 (Append .dwp to the binary filename instead of replacing the existing extension.)
 - #106836 (Remove optimistic spinning from `mpsc::SyncSender`)
 - #106946 (implement Hash for proc_macro::LineColumn)
 - #107074 (remove unnecessary check for opaque types)
 - #107287 (Improve fn pointer notes)
 - #107304 (Use `can_eq` to compare types for default assoc type error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-26 09:14:05 +00:00
Matthias Krüger
d667105681
Rollup merge of #106946 - dtolnay:hashlinecolumn, r=m-ou-se
implement Hash for proc_macro::LineColumn

For use in `HashMap<LineColumn, TokenTree>` or `HashMap<LineColumn, Comment>`, for example.

[Here is an example of one case complicated by the absence of this impl.](71bc45e417/src/comments.rs (L25-L34))

Tracking issue: https://github.com/rust-lang/rust/issues/54725
2023-01-26 07:53:24 +01:00
Matthias Krüger
35a8d6fea4
Rollup merge of #106836 - ibraheemdev:sync-sender-spin, r=Amanieu
Remove optimistic spinning from `mpsc::SyncSender`

Per https://github.com/rust-lang/rust/pull/106701#issuecomment-1381649679.
Closes #106804

r? `@Amanieu`
2023-01-26 07:53:23 +01:00
Matthias Krüger
cc92bdb9c9
Rollup merge of #106779 - RReverser:patch-2, r=Mark-Simulacrum
Avoid __cxa_thread_atexit_impl on Emscripten

 - Fixes https://github.com/rust-lang/rust/issues/91628.
 - Fixes https://github.com/emscripten-core/emscripten/issues/15722.

See discussion in both issues.

The TL;DR is that weak linkage causes LLVM to produce broken Wasm, presumably due to pointer mismatch. The code is casting a void pointer to a function pointer with specific signature, but Wasm is very strict about function pointer compatibility, so the resulting code is invalid.

Ideally LLVM should catch this earlier in the process rather than emit invalid Wasm, but it currently doesn't and this is an easy and valid fix, given that Emcripten doesn't have `__cxa_thread_atexit_impl` these days anyway.

Unfortunately, I can't add a regression test as even after looking into this issue for a long time, I couldn't reproduce it with any minimal Rust example, only with extracted LLVM IR or on a large project involving Rust + C++.
2023-01-26 07:53:22 +01:00
Matthias Krüger
e0d71f500c
Rollup merge of #97373 - dimpolo:cell_dispatch_from_dyn, r=dtolnay
impl DispatchFromDyn for Cell and UnsafeCell

After some fruitful discussion on [Internals](https://internals.rust-lang.org/t/impl-dispatchfromdyn-for-cell-2/16520) here's my first PR to rust-lang/rust 🎉

Please let me know if there's something I missed.

This adds `DispatchFromDyn` impls for `Cell`, `UnsafeCell` and `SyncUnsafeCell`.
An existing test is also expanded to test the `Cell` impl (which requires the `UnsafeCell` impl)

The different `RefCell` types can not implement `DispatchFromDyn` since they have more than one (non ZST) field.

&nbsp;

**Edit:**
### What:
These changes allow one to make types like `MyRc`(code below), to be object safe method receivers after implementing `DispatchFromDyn` and `Deref` for them.

This allows for code like this:
```rust
struct MyRc<T: ?Sized>(Cell<NonNull<RcBox<T>>>);

/* impls for DispatchFromDyn, CoerceUnsized and Deref for MyRc*/

trait Trait {
    fn foo(self: MyRc<Self>);
}

let impls_trait = ...;
let rc = MyRc::new(impls_trait) as MyRc<dyn Trait>;
rc.foo();
```

Note: `Cell` and `UnsafeCell` won't directly become valid method receivers since they don't implement `Deref`. Making use of these changes requires a wrapper type and nightly features.

### Why:
A custom pointer type with interior mutability allows one to store extra information in the pointer itself.
These changes allow for such a type to be a method receiver.

### Examples:
My use case is a cycle aware custom `Rc` implementation that when dropping a cycle marks some references dangling.

On the [forum](https://internals.rust-lang.org/t/impl-dispatchfromdyn-for-cell/14762/8) andersk mentioned that they track if a `Gc` reference is rooted with an extra bit in the reference itself.
2023-01-26 07:53:21 +01:00
Matthias Krüger
8ae5116fae
Rollup merge of #106407 - mejrs:attr_check, r=compiler-errors
Improve proc macro attribute diagnostics

Closes https://github.com/rust-lang/rust/issues/102923
2023-01-26 06:15:23 +01:00
Linus Färnstrand
50f29d48bd Stabilize the const_socketaddr feature 2023-01-25 22:23:34 +01:00
Matthias Krüger
22e62a4fca
Rollup merge of #106944 - Nilstrieb:there-once-was-a-diagnostic, r=WaffleLapkin
Suggest using a lock for `*Cell: Sync` bounds

I mostly did this for `OnceCell<T>` at first because users will be confused to see that the `OnceCell<T>` in `std` isn't `Sync` but then extended it to `Cell<T>` and `RefCell<T>` as well.
2023-01-25 22:19:52 +01:00
Mark Rousskov
3653254f91 Set version placeholders to 1.68 2023-01-25 09:44:29 -05:00
Urgau
dde74fe092 Remove outdated cfg on le32
See https://github.com/rust-lang/rust/pull/45041 for the removal of the
target (le32-unknown-nacl).
2023-01-25 15:07:57 +01:00
Dylan DPC
24066910ca
Rollup merge of #107223 - ChayimFriedman2:patch-5, r=WaffleLapkin
`sub_ptr()` is equivalent to `usize::try_from().unwrap_unchecked()`, not `usize::from().unwrap_unchecked()`

`usize::from()` gives a `usize`, not `Result<usize>`, and `usize: From<isize>` is not implemented.
2023-01-25 17:01:43 +05:30
Dylan DPC
0c53b215de
Rollup merge of #106823 - m-ou-se:format-args-as-str-guarantees, r=dtolnay
Allow fmt::Arguments::as_str() to return more Some(_).

This adjusts the documentation to allow optimization of format_args!() to be visible through fmt::Arguments::as_str().

This allows for future changes like https://github.com/rust-lang/rust/pull/106824.
2023-01-25 17:01:42 +05:30
Dylan DPC
9e6873f788
Rollup merge of #106767 - chbaker0:disable-unstable-features, r=Mark-Simulacrum
Allow setting CFG_DISABLE_UNSTABLE_FEATURES to 0

Two locations check whether this build-time environment variable is defined. Allowing it to be explicitly disabled with a "0" value is useful, especially for integrating with external build systems.
2023-01-25 17:01:41 +05:30
Michal Rostecki
474ea87943 core: Support variety of atomic widths in width-agnostic functions
Before this change, the following functions and macros were annotated
with `#[cfg(target_has_atomic = "8")]` or
`#[cfg(target_has_atomic_load_store = "8")]`:

* `atomic_int`
* `strongest_failure_ordering`
* `atomic_swap`
* `atomic_add`
* `atomic_sub`
* `atomic_compare_exchange`
* `atomic_compare_exchange_weak`
* `atomic_and`
* `atomic_nand`
* `atomic_or`
* `atomic_xor`
* `atomic_max`
* `atomic_min`
* `atomic_umax`
* `atomic_umin`

However, none of those functions and macros actually depend on 8-bit
width and they are needed for all atomic widths (16-bit, 32-bit, 64-bit
etc.). Some targets might not support 8-bit atomics (i.e. BPF, if we
would enable atomic CAS for it).

This change fixes that by removing the `"8"` argument from annotations,
which results in accepting the whole variety of widths.

Fixes #106845
Fixes #106795

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2023-01-25 10:44:03 +08:00
Mads Marquart
660d985d12 Guarantee the memory layout of Cell 2023-01-24 20:59:39 +01:00
dimi
a2d1cb2c22 impl DispatchFromDyn for Cell and UnsafeCell 2023-01-24 12:06:12 +01:00
Chayim Refael Friedman
236f8231a6
sub_ptr() is equivalent to usize::try_from().unwrap_unchecked(), not usize::from().unwrap_unchecked().
`usize::from()` gives a `usize`, not `Result<usize>`, and `usize: From<isize>` is not implemented.
2023-01-23 14:42:32 +02:00
Yuki Okushi
8709c395a6
Rollup merge of #107109 - est31:thin_box_link, r=Mark-Simulacrum
ThinBox: Add intra-doc-links for Metadata
2023-01-23 19:30:00 +09:00
Lukas Bergdoll
5eff264533 Document missing unsafe blocks 2023-01-23 09:12:25 +01:00
Dylan DPC
28081a6aa6
Rollup merge of #106854 - steffahn:drop_linear_arc_rebased, r=Mark-Simulacrum
Add `Arc::into_inner` for safely discarding `Arc`s without calling the destructor on the inner type.

ACP: rust-lang/libs-team#162

Reviving #79665.

I want to get this merged this time; this does not contain changes (apart from very minor changes in comments/docs).

See #79665 for further description of the PR. The only “unresolved” points that led to that PR being closed, AFAICT, were

* The desire to also implement a `Rc::into_inner` function
  * however, this can very well also happen as a subsequent PR
* Possible need for further discussion on the naming “`into_inner`” (?)
  * `into_inner` seems fine to me; also, this PR introduces unstable API, and names can be changed later, too
* ~~I don't know if a tracking issue for the feature flag is supposed to be opened before or after this PR gets merged (if *before*, then I can add the issue number to the `#[unstable…]` attribute)~~ There is a [tracking issue](https://github.com/rust-lang/rust/issues/106894) now.

I say “unresolved” in quotation marks because from my point of view, if reviewers agree, the PR can be merged immediately and as-is :-)
2023-01-23 11:52:04 +05:30
bors
d3322e2773 Auto merge of #106981 - joboet:std_remove_box_syntax, r=thomcc
Do not use box syntax in `std`

See #94970 and #49733. About half of the `box` instances in `std` do not even need to allocate, the other half can simply be replaced with `Box::new`.

`@rustbot` label +T-libs
r? rust-lang/libs
2023-01-23 01:05:56 +00:00
Lenko Donchev
77133370ce Print why a test was ignored if it's the only test specified. 2023-01-22 18:56:13 -06:00
The 8472
6fcf1758fe simplify layout calculations in rawvec 2023-01-22 22:13:17 +01:00
Lukas Bergdoll
f297afa0c9 Flip scanning direction of stable sort
Memory pre-fetching prefers forward scanning vs backwards scanning, and the
code-gen is usually better. For the most sensitive types such as integers, these
are planned to be merged bidirectionally at once. So there is no benefit in
scanning backwards.

The largest perf gains are seen for full ascending and descending inputs, which
see 1.5x speedups. Random inputs benefit too, and some patterns can loose out,
but these losses are minimal.
2023-01-22 12:01:06 +01:00
Lukas Bergdoll
a3065a1a34 Unify insertion sort implementations
Avoid duplicate insertion sort implementations.
Optimize implementations.
2023-01-22 11:55:35 +01:00
Matthias Krüger
2f7a3a1f0a
Rollup merge of #107180 - nvzqz:rm-fmt-ref, r=joshtriplett
Remove unnecessary `&format!`

These were likely from before the `PartialEq<str>` impl for `&String`.
2023-01-22 11:43:09 +01:00
Matthias Krüger
17b9f2a7ed
Rollup merge of #107114 - Erk-:add-absolute-note-to-path-join, r=m-ou-se
Add note about absolute paths to Path::join

The note already exists on `PathBuf::push`, but I think it is good to have it on `Path::join` as well since it can cause issues if you are not careful with your input.
2023-01-22 11:43:06 +01:00
Michael Goulet
d1405c82b8
Rollup merge of #106144 - tgross35:patch-1, r=Mark-Simulacrum
Improve the documentation of `black_box`

There don't seem to be many great resources on how `black_box` should be used, so I added some information here
2023-01-21 23:20:59 -05:00
Nikolai Vazquez
734a91358b Remove unnecessary &format!
These were likely from before the `PartialEq<str>` impl for `&String`.
2023-01-21 22:06:42 -05:00
Peter Jaszkowiak
09f8885b3b debug assertions for slice::split_at_unchecked, str::get_unchecked 2023-01-21 12:50:03 -07:00
Frank Steffahn
33696fa9ca Add Arc::into_inner for safely discarding Arcs without calling the destructor on the inner type.
Mainly rebased and squashed from PR rust-lang/rust#79665,
furthermore includes minor changes in comments.
2023-01-22 01:43:25 +09:00
John Paul Adrian Glaubitz
8f70b5ccb7 library/std/sys_common: Define MIN_ALIGN for m68k-unknown-linux-gnu 2023-01-21 12:00:14 +00:00
Lukas Bergdoll
703ff60d9f Use NonNull in merge_sort
This is more clear about the intent of the pointer and avoids problems
if the allocation returns a null pointer.
2023-01-21 10:17:06 +01:00
Michael Goulet
68b390ae2a
Rollup merge of #104672 - Voultapher:unify-sort-modules, r=thomcc
Unify stable and unstable sort implementations in same core module

This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`.

This is in preparation of #100856 and #104116. It only moves code, it *doesn't* change any of the sort related logic. This unlocks the ability to share `insert_head`, `insert_tail`, `swap_if_less` `merge` and more.

Tagging ````@Mark-Simulacrum```` I hope this allows progress on #100856, by moving `merge_sort` here I hope future changes will be easier to review.
2023-01-20 21:33:21 -05:00
Valdemar Erk
d8f8adfe3d add example of joining with a absolute path 2023-01-20 12:03:43 +01:00
Valdemar Erk
ec3da87582 Add note about absolute paths to Path::join 2023-01-20 11:16:38 +01:00
est31
4127988317 ThinBox: Add intra-doc-links for Metadata 2023-01-20 08:07:45 +01:00
Matthias Krüger
66a9006759
Rollup merge of #107067 - tmiasko:custom-mir-storage-statements, r=oli-obk
Custom MIR: Support storage statements

r? `@oli-obk` `@JakobDegen`
2023-01-20 07:16:11 +01:00
Matthias Krüger
35d488f23d
Rollup merge of #107053 - devnexen:sigstringrepr_haiku, r=thomcc
signal update string representation for haiku.
2023-01-20 07:16:10 +01:00
Nilstrieb
6d0c91fda3 Add rustc_on_unimplemented on Sync for cell types
Suggest using a lock instead.
2023-01-19 21:09:25 +01:00
Nilstrieb
e1f630f23d Add OnceCell<T>: !Sync impl for diagnostics 2023-01-19 20:14:21 +01:00
bors
79335f1ac4 Auto merge of #107064 - GuillaumeGomez:rollup-pbgu6r3, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #105977 (Transform async `ResumeTy` in generator transform)
 - #106927 (make `CastError::NeedsDeref` create a `MachineApplicable` suggestion)
 - #106931 (document + UI test `E0208` and make its output more user-friendly)
 - #107027 (Remove extra removal from test path)
 - #107037 (Fix Dominators::rank_partial_cmp to match documentation)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-19 11:12:31 +00:00
Tomasz Miąsko
ca3d55e32d Custom MIR: Support storage statements 2023-01-19 11:53:33 +01:00
bors
705a96d39b Auto merge of #106989 - clubby789:is-zero-num, r=scottmcm
Implement `alloc::vec::IsZero` for `Option<$NUM>` types

Fixes #106911

Mirrors the `NonZero$NUM` implementations with an additional `assert_zero_valid`.
`None::<i32>` doesn't stricly satisfy `IsZero` but for the purpose of allocating we can produce more efficient codegen.
2023-01-19 08:04:26 +00:00
Arpad Borsos
96931a787a
Transform async ResumeTy in generator transform
- Eliminates all the `get_context` calls that async lowering created.
- Replace all `Local` `ResumeTy` types with `&mut Context<'_>`.

The `Local`s that have their types replaced are:
- The `resume` argument itself.
- The argument to `get_context`.
- The yielded value of a `yield`.

The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the
`get_context` function is being used to convert that back to a `&mut Context<'_>`.

Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection,
but rather directly use `&mut Context<'_>`, however that would currently
lead to higher-kinded lifetime errors.
See <https://github.com/rust-lang/rust/issues/105501>.

The async lowering step and the type / lifetime inference / checking are
still using the `ResumeTy` indirection for the time being, and that indirection
is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
2023-01-19 09:03:05 +01:00
Scott McMurray
3122db7d03 Implement SpecOptionPartialEq for cmp::Ordering 2023-01-18 19:19:28 -08:00
David Carlier
ae9e66bafb signal update string representation for haiku. 2023-01-18 23:06:59 +00:00
clubby789
50e9f2e6e8 Update IsZero documentation 2023-01-18 15:48:53 +00:00
clubby789
b94a29a25f Implement alloc::vec::IsZero for Option<$NUM> types 2023-01-18 15:15:15 +00:00
Dylan DPC
1ff4a1259d
Rollup merge of #106950 - the8472:fix-splice-miri, r=cuviper
Don't do pointer arithmetic on pointers to deallocated memory

vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed.

Fixes miri test failures.
Fixes https://github.com/rust-lang/miri/issues/2759
2023-01-18 15:55:38 +05:30
Dylan DPC
548ae602fc
Rollup merge of #106441 - mllken:abstract-socket-noref, r=joshtriplett
relax reference requirement on SocketAddrExt::from_abstract_name

Reference: https://github.com/rust-lang/rust/issues/85410#issuecomment-1369544671
2023-01-18 15:55:37 +05:30
Dylan DPC
d6ea99d2ed
Rollup merge of #103702 - WaffleLapkin:lift-sized-bounds-from-pointer-methods-where-applicable, r=m-ou-se
Lift `T: Sized` bounds from some `strict_provenance` pointer methods

This PR removes requirement for `T` (pointee type) to be `Sized` to call `pointer::{addr, expose_addr, with_addr, map_addr}`. These functions don't use `T`'s size, so there is no reason for them to require this. Updated public API:

cc ``@Gankra,`` #95228
r? libs-api
2023-01-18 15:55:36 +05:30
Matthias Krüger
788671c1c6
Rollup merge of #106997 - Sp00ph:introselect, r=scottmcm
Add heapsort fallback in `select_nth_unstable`

Addresses #102451 and #106933.

`slice::select_nth_unstable` uses a quick select implementation based on the same pattern defeating quicksort algorithm that `slice::sort_unstable` uses. `slice::sort_unstable` uses a recursion limit and falls back to heapsort if there were too many bad pivot choices, to ensure O(n log n) worst case running time (known as introsort). However, `slice::select_nth_unstable` does not have such a fallback strategy, which leads to it having a worst case running time of O(n²) instead. #102451 links to a playground which generates pathological inputs that show this quadratic behavior. On my machine, a randomly generated slice of length `1 << 19` takes ~200µs to calculate its median, whereas a pathological input of the same length takes over 2.5s. This PR adds an iteration limit to `select_nth_unstable`, falling back to heapsort, which ensures an O(n log n) worst case running time (introselect). With this change, there was no noticable slowdown for the random input, but the same pathological input now takes only ~1.2ms. In the future it might be worth implementing something like Median of Medians or Fast Deterministic Selection instead, which guarantee O(n) running time for all possible inputs. I've left this as a `FIXME` for now and only implemented the heapsort fallback to minimize the needed code changes.

I still think we should clarify in the `select_nth_unstable` docs that the worst case running time isn't currently O(n) (the original reason that #102451 was opened), but I think it's a lot better to be able to guarantee O(n log n) instead of O(n²) for the worst case.
2023-01-18 06:59:22 +01:00
Matthias Krüger
47ccca0c86
Rollup merge of #106992 - joboet:alloc_remove_box_syntax, r=thomcc
Remove unused `#![feature(box_syntax)]` in `alloc`
2023-01-18 06:59:21 +01:00
Markus Everling
ccba6c5151 Add vec_deque::IntoIter benchmarks 2023-01-18 00:33:05 +01:00
The 8472
47014b1bb9 Don't do pointer arithmetic on pointers to deallocated memory
vec::Splice can invalidate the slice::Iter inside vec::Drain.
So we replace them with dangling pointers which, unlike ones to
deallocated memory, are allowed.
2023-01-17 22:01:33 +01:00
Matthias Krüger
0ed2549802
Rollup merge of #106889 - scottmcm:windows-mut, r=cuviper
Mention the lack of `windows_mut` in `windows`

This is a common request, going back to at least 2015 (#23783), so mention in the docs that it can't be done and offer a workaround using <https://doc.rust-lang.org/std/cell/struct.Cell.html#method.as_slice_of_cells>.

(See also URLO threads like <https://internals.rust-lang.org/t/a-windows-mut-method-on-slice/16941/10?u=scottmcm>.)
2023-01-17 20:21:27 +01:00
Markus Everling
273c6c3913 Add heapsort fallback in select_nth_unstable 2023-01-17 19:38:37 +01:00
joboet
be9c363066
refactor[alloc]: remove unused box syntax feature 2023-01-17 18:55:44 +01:00
Dylan DPC
1b2d595c14
Rollup merge of #106922 - ChayimFriedman2:patch-5, r=workingjubilee
Avoid unsafe code in `to_ascii_[lower/upper]case()`
2023-01-17 20:33:04 +05:30
Dylan DPC
f91f369949
Rollup merge of #106148 - chenyukang:yukang/fix-105061-unused, r=lcnr
Fix unused_parens issue for higher ranked function pointers

fixes #105061

r? `@lcnr`
2023-01-17 20:33:03 +05:30
joboet
7f2cf19191
refactor[std]: do not use box syntax 2023-01-17 14:08:35 +01:00
onestacked
7355ab3fe3 Constify TypeId ordering impls 2023-01-16 21:26:03 +01:00
David Tolnay
25f0147db2
implement Hash for proc_macro::LineColumn 2023-01-16 11:41:19 -08:00
Chayim Refael Friedman
8dbc878a35
Avoid unsafe code in to_ascii_[lower/upper]case() 2023-01-16 01:15:06 +02:00
David Tolnay
fa2ff4d7e5
Rebuild BinaryHeap on unwind from retain 2023-01-15 13:20:00 -08:00
David Tolnay
0d3eaa848c
Add test showing broken behavior of BinaryHeap::retain 2023-01-15 13:12:28 -08:00
bors
9e75dddf60 Auto merge of #106393 - the8472:use-ptr-sub, r=scottmcm
Simplify manual ptr arithmetic in slice::Iter with ptr_sub

The old code was introduced in #61885, which predates the ptr_sub method and underlying intrinsic. The codegen test still passes.

r? `@scottmcm`
2023-01-15 18:39:40 +00:00
The 8472
9db0134018 replace manual ptr arithmetic with ptr_sub 2023-01-15 17:38:05 +01:00
bors
bbb36fe545 Auto merge of #105851 - dtolnay:peekmutleak, r=Mark-Simulacrum
Leak amplification for peek_mut() to ensure BinaryHeap's invariant is always met

In the libs-api team's discussion around #104210, some of the team had hesitations around exposing malformed BinaryHeaps of an element type whose Ord and Drop impls are trusted, and which does not contain interior mutability.

For example in the context of this kind of code:

```rust
use std::collections::BinaryHeap;
use std::ops::Range;
use std::slice;

fn main() {
    let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
    let cut_points = BinaryHeap::from(vec![4, 2, 7]);
    println!("{:?}", chop(slice, cut_points));
}

// This is a souped up slice::split_at_mut to split in arbitrary many places.
//
// usize's Ord impl is trusted, so 1 single bounds check guarantees all those
// output slices are non-overlapping and in-bounds
fn chop<T>(slice: &mut [T], mut cut_points: BinaryHeap<usize>) -> Vec<&mut [T]> {
    let mut vec = Vec::with_capacity(cut_points.len() + 1);
    let max = match cut_points.pop() {
        Some(max) => max,
        None => {
            vec.push(slice);
            return vec;
        }
    };

    assert!(max <= slice.len());

    let len = slice.len();
    let ptr: *mut T = slice.as_mut_ptr();
    let get_unchecked_mut = unsafe {
        |range: Range<usize>| &mut *slice::from_raw_parts_mut(ptr.add(range.start), range.len())
    };

    vec.push(get_unchecked_mut(max..len));
    let mut end = max;
    while let Some(start) = cut_points.pop() {
        vec.push(get_unchecked_mut(start..end));
        end = start;
    }
    vec.push(get_unchecked_mut(0..end));
    vec
}
```

```console
[['7', '8', '9'], ['4', '5', '6'], ['2', '3'], ['0', '1']]
```

In the current BinaryHeap API, `peek_mut()` is the only thing that makes the above function unsound.

```rust
let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
let mut cut_points = BinaryHeap::from(vec![4, 2, 7]);
{
    let mut max = cut_points.peek_mut().unwrap();
    *max = 0;
    std::mem::forget(max);
}
println!("{:?}", chop(slice, cut_points));
```

```console
[['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], [], ['2', '3'], ['0', '1']]
```

Or worse:

```rust
let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
let mut cut_points = BinaryHeap::from(vec![100, 100]);
{
    let mut max = cut_points.peek_mut().unwrap();
    *max = 0;
    std::mem::forget(max);
}
println!("{:?}", chop(slice, cut_points));
```

```console
[['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], [], ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\u{1}', '\0', '?', '翾', '?', '翾', '\0', '\0', '?', '翾', '?', '翾', '?', '啿', '?', '啿', '?', '啿', '?', '啿', '?', '啿', '?', '翾', '\0', '\0', '񤬐', '啿', '\u{5}', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\u{8}', '\0', '`@',` '\0', '\u{1}', '\0', '?', '翾', '?', '翾', '?', '翾', '
thread 'main' panicked at 'index out of bounds: the len is 33 but the index is 33', library/core/src/unicode/unicode_data.rs:319:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

---

This PR makes `peek_mut()` use leak amplification (https://doc.rust-lang.org/1.66.0/nomicon/leaking.html#drain) to preserve the heap's invariant even in the situation that `PeekMut` gets leaked.

I'll also follow up in the tracking issue of unstable `drain_sorted()` (#59278) and `retain()` (#71503).
2023-01-15 08:59:55 +00:00
Matthias Krüger
cdf462275a
Rollup merge of #106880 - tspiteri:borrowing-sub-typo, r=cuviper
doc: fix typo
2023-01-15 01:01:39 +01:00
Matthias Krüger
445e3841da
Rollup merge of #106867 - sunfishcode:sunfishcode/std-os-fd-stable-version, r=m-ou-se
Fix the stability attributes for `std::os::fd`.

As `@bjorn3` pointed out [here], I used the wrong stability attribute in #98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized.

[here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420
2023-01-15 01:01:38 +01:00
Scott McMurray
38917ee9e9 Mention the lack of windows_mut in windows 2023-01-14 15:31:32 -08:00
David Tolnay
23501703fb
Document guarantees about BinaryHeap invariant 2023-01-14 13:28:30 -08:00
David Tolnay
aedb756020
Leak amplification for peek_mut() to ensure BinaryHeap's invariant is always met 2023-01-14 13:28:22 -08:00
David Tolnay
4fe167f83a
Add test of leaking a binary_heap PeekMut 2023-01-14 13:28:14 -08:00
Trevor Spiteri
208b781bda doc: fix typo 2023-01-14 22:09:14 +01:00
Dan Gohman
287c65838c Fix the stability attributes for std::os::fd.
As @bjorn3 pointed out [here], I used the wrong stability attribute in #98368
when making `std::os::fd` public. I set it to Rust 1.63, which was when
io-safety was stabilized, but it should be Rust 1.66, which was when
`std::os::fd` was stabilized.

[here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420
2023-01-14 09:47:34 -08:00
Matthias Krüger
e0eb63a73c
Rollup merge of #106860 - anden3:doc-double-spaces, r=Dylan-DPC
Remove various double spaces in the libraries.

I was just pretty bothered by this when reading the source for a function, and was suggested to check if this happened elsewhere.
2023-01-14 18:45:29 +01:00
Matthias Krüger
43134714f5
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum
Stop probing for statx unless necessary

As is the current toy program:
fn main() -> std::io::Result<()> {
    use std::fs;

    let metadata = fs::metadata("foo.txt")?;

    assert!(!metadata.is_dir());
    Ok(())
}

... observed under strace will issue:
[snip]
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address) statx(AT_FDCWD, "foo.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0

While statx is not necessarily always present, checking for it can be delayed to the first error condition. Said condition may very well never happen, in which case the check got avoided altogether.

Note this is still suboptimal as there still will be programs issuing it, but bulk of the problem is removed.

Tested by forbidding the syscall for the binary and observing it correctly falls back to newfstatat.

While here tidy up the commentary, in particular by denoting some problems with the current approach.
2023-01-14 18:45:26 +01:00
Matthias Krüger
085d2f1f09
Rollup merge of #105526 - Xiretza:iter-from-generator-derive, r=scottmcm
libcore: make result of iter::from_generator Clone

`@rustbot` label +A-generators
2023-01-14 18:45:25 +01:00
André Vennberg
2fea03f5e6 Fix some missed double spaces. 2023-01-14 18:26:38 +01:00
André Vennberg
0b35f448f8 Remove various double spaces in source comments. 2023-01-14 17:22:04 +01:00
Ingvar Stepanyan
a41c5f9c38
Re-add #[allow(unused)] attr 2023-01-14 12:29:41 +00:00
Lukas Markeffsky
76e216f29b Use associated items of char instead of freestanding items in core::char 2023-01-14 11:58:41 +01:00
yukang
c67903ef21 fix issues in unused lint 2023-01-14 17:11:04 +08:00
Ibraheem Ahmed
ab20f8d5ba remove optimistic spinning from mpsc::SyncSender 2023-01-14 00:36:51 -05:00
Yuki Okushi
a05d06f7c5
Rollup merge of #106799 - scottmcm:remove-unused-generics, r=cuviper
Stop having unused lifetimes on some `impl`s

See <https://doc.rust-lang.org/nightly/std/cmp/trait.PartialOrd.html#impl-PartialOrd%3COsStr%3E-for-PathBuf>, where these lifetimes show up even though they're not needed:
![image](https://user-images.githubusercontent.com/18526288/212257802-da275167-38f9-4e2c-aafc-d44f0fc6a7c6.png)

With this PR, the unneeded lifetimes are no longer there:
![image](https://user-images.githubusercontent.com/18526288/212257938-0097c4bf-1247-4c91-8445-5bf0dde1b501.png)
2023-01-14 12:04:36 +09:00
Yuki Okushi
9b502a4765
Rollup merge of #106762 - WaffleLapkin:atomicptr+as_mut_ptr, r=m-ou-se
Add `AtomicPtr::as_mut_ptr`

See https://github.com/rust-lang/rust/issues/66893#issuecomment-720125447

r? thomcc
2023-01-14 12:04:35 +09:00
Yuki Okushi
feac18c0d6
Rollup merge of #106692 - eggyal:mv-binary_heap.rs-binary_heap/mod.rs, r=Mark-Simulacrum
mv binary_heap.rs binary_heap/mod.rs

I confess this request is somewhat selfish, as it's made in order to ease synchronisation with my [copse](https://crates.io/crates/copse) crate (see eggyal/copse#6 for explanation). I wholly understand that such grounds may be insufficient to justify merging this request—but no harm in asking, right?
2023-01-14 12:04:33 +09:00
Yuki Okushi
6d8ac8389e
Rollup merge of #105172 - alexs-sh:issue-98861-fix-next, r=scottmcm
Added error documentation for write_fmt

This continuation of work at rust-lang#98861
2023-01-14 12:04:32 +09:00
Yuki Okushi
6702f20ca7
Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcm
reword Option::as_ref and Option::map examples

The description for the examples of `Option::as_ref` and `Option::map` imply that the example is only doing type conversion, when it is actually finding the length of a string.

Changes the wording to imply that some operation is being run on the value contained in the `Option`

closes #104476
2023-01-14 12:04:31 +09:00
Mara Bos
a37b484222 Allow fmt::Arguments::as_str() to return more Some(_). 2023-01-13 22:42:11 +01:00
Matthias Krüger
720137b5da
Rollup merge of #106701 - ibraheemdev:sync-sender-spin, r=Amanieu
Fix `mpsc::SyncSender` spinning behavior

Resolves https://github.com/rust-lang/rust/issues/106668.
2023-01-13 19:16:44 +01:00
Scott McMurray
4949fb0419 Stop having unused lifetimes on some impls 2023-01-12 22:55:58 -08:00
Scott McMurray
fcbc12eae3 Implement signum with Ord 2023-01-12 22:39:25 -08:00
bors
279f1c9d8c Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obk
Const closures

cc https://github.com/rust-lang/rust/issues/106003
2023-01-13 05:04:48 +00:00
Yuki Okushi
7e5d477ac5
Rollup merge of #106740 - petar-dambovaliev:float-iterator-hint, r=Nilstrieb
Adding a hint on iterator type errors

Issue reference https://github.com/rust-lang/rust/issues/106728

- [x] add a case in the attribute
- [x] add a test

closes #106728
2023-01-13 05:47:23 +09:00
Yuki Okushi
3f21b812be
Rollup merge of #106446 - bzEq:fix-unwind-lsda, r=Amanieu
[LSDA] Take ttype_index into account when taking unwind action

If `cs_action != 0`, we should check the `ttype_index` field in action record. If `ttype_index == 0`, a clean up action is taken; otherwise catch action is taken.

This can fix unwind failure on AIX which uses LLVM's libunwind by default. IIUC, rust's LSDA is borrowed from c++ and I'm assuming itanium-cxx-abi https://itanium-cxx-abi.github.io/cxx-abi/exceptions.pdf should be followed, so the fix follows what libcxxabi does. See ec48682ce9/libcxxabi/src/cxa_personality.cpp (L152) for use of `ttype_index`.
2023-01-13 05:47:21 +09:00
Ingvar Stepanyan
6155b9a772
Avoid __cxa_thread_atexit_impl on Emscripten
- Fixes https://github.com/rust-lang/rust/issues/91628.
 - Fixes https://github.com/emscripten-core/emscripten/issues/15722.

See discussion in both issues.

The TL;DR is that weak linkage causes LLVM to produce broken Wasm, presumably due to pointer mismatch. The code is casting a void pointer to a function pointer with specific signature, but Wasm is very strict about function pointer compatibility, so the resulting code is invalid.

Ideally LLVM should catch this earlier in the process rather than emit invalid Wasm, but it currently doesn't and this is an easy and valid fix, given that Emcripten doesn't have `__cxa_thread_atexit_impl` these days anyway.

Unfortunately, I can't add a regression test as even after looking into this issue for a long time, I couldn't reproduce it with any minimal Rust example, only with extracted LLVM IR or on a large project involving Rust + C++.

r? @alexcrichton
2023-01-12 18:47:05 +00:00
Petar Dambovaliev
bdf990022a add note for float iterator 2023-01-12 15:29:53 +01:00
bors
606c390725 Auto merge of #106760 - compiler-errors:rollup-0bogyco, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #103236 (doc: rewrite doc for signed int::{carrying_add,borrowing_sub})
 - #103800 (Stabilize `::{core,std}::pin::pin!`)
 - #106097 (Migrate mir_build diagnostics 2 of 3)
 - #106170 (Move autoderef to `rustc_hir_analysis`)
 - #106323 (Stabilize f16c_target_feature)
 - #106360 (Tweak E0277 `&`-removal suggestions)
 - #106524 (Label `struct/enum constructor` instead of `fn item`, mention that it should be called on type mismatch)
 - #106739 (Remove `<dyn AstConv<'tcx>>::fun(c, ...)` calls in favour of `c.astconv().fun(...)`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-12 10:46:19 +00:00
Collin Baker
0a03d1c9ca Allow setting CFG_DISABLE_UNSTABLE_FEATURES to 0
Two locations check whether this build-time environment variable is
defined. Allowing it to be explicitly disabled with a "0" value is
useful, especially for integrating with external build systems.
2023-01-12 05:36:04 -05:00
Maybe Waffle
22b4c68895 Make // SAFETY comment part of the doctest, and not surrounding code 2023-01-12 07:28:43 +00:00
Maybe Waffle
f1a63bc2dd Remove unused mut from a doctest 2023-01-12 07:27:51 +00:00
Maybe Waffle
a513c84a5b Add AtomicPtr::as_mut_ptr 2023-01-12 07:27:36 +00:00
Michael Goulet
244b90edee
Rollup merge of #106323 - starkat99:stabilize-f16c_target_feature, r=petrochenkov
Stabilize f16c_target_feature

Resolves https://github.com/rust-lang/stdarch/issues/1234

Library PR for stabilizing corresponding intrinsics: https://github.com/rust-lang/stdarch/pull/1366

See also #44839 tracking issue for target_feature
2023-01-11 22:25:48 -08:00
Michael Goulet
2e17a5d406
Rollup merge of #103800 - danielhenrymantilla:stabilize-pin-macro, r=dtolnay
Stabilize `::{core,std}::pin::pin!`

As discussed [over here](https://github.com/rust-lang/rust/issues/93178#issuecomment-1295843548), it looks like a decent time to stabilize the `pin!` macro.

### Public API

```rust
// in module `core::pin`

/// API: `fn pin<T>($value: T) -> Pin<&'local mut T>`
pub macro pin($value:expr $(,)?) {
    …
}
```

  - Tracking issue: #93178

(now all this needs is an FCP by the proper team?)
2023-01-11 22:25:47 -08:00
Michael Goulet
e23b0fd318
Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-se
doc: rewrite doc for signed int::{carrying_add,borrowing_sub}

Reword the documentation for bigint helper methods, signed `int::{carrying_add,borrowing_sub}` (#85532).

This change is a follow-up to #101889, which was for the unsigned methods.
2023-01-11 22:25:46 -08:00
Matthias Krüger
db8301b7f8
Rollup merge of #106638 - RalfJung:realstd, r=thomcc
std tests: use __OsLocalKeyInner from realstd

This is basically the same as https://github.com/rust-lang/rust/pull/100201, but for __OsLocalKeyInner:

Some std tests are failing in Miri on Windows because [this static](a377893da2/library/std/src/sys/windows/thread_local_key.rs (L234-L239)) is getting duplicated, and Miri does not handle that properly -- Miri does not support this magic `.CRT$XLB` linker section, but instead just looks up this particular hard-coded static in the standard library. This PR lets the test suite use the std static instead of having its own copy.

Fixes https://github.com/rust-lang/miri/issues/2754
r? `@thomcc`
2023-01-12 06:52:37 +01:00
Ibraheem Ahmed
8917e99362 rework and document backoff behavior of sync::mpsc 2023-01-11 21:29:14 -05:00
Deadbeef
ca1eb4309e test use in libcore 2023-01-12 02:28:38 +00:00
Mara Bos
9e6785430b Make core::fmt::rt::v1::Argument::new const+inline. 2023-01-12 00:38:07 +01:00
mejrs
f92000816e Improve proc macro attribute diagnostics 2023-01-12 00:11:11 +01:00
Daniel Henry-Mantilla
48b7e2a5b9
Stabilize ::{core,std}::pin::pin! 2023-01-11 14:09:14 -08:00
Mara Bos
e83945150f Add new fn to core::fmt::rt::v1::Argument. 2023-01-11 21:53:24 +01:00
Mara Bos
bebf9fe063 Turn format arguments types into lang items. 2023-01-11 21:53:24 +01:00
Mateusz Guzik
b49aa8d53e Stop probing for statx unless necessary
As is the current toy program:
fn main() -> std::io::Result<()> {
    use std::fs;

    let metadata = fs::metadata("foo.txt")?;

    assert!(!metadata.is_dir());
    Ok(())
}

... observed under strace will issue:
[snip]
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address)
statx(AT_FDCWD, "foo.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0

While statx is not necessarily always present, checking for it can be
delayed to the first error condition. Said condition may very well never
happen, in which case the check got avoided altogether.

Note this is still suboptimal as there still will be programs issuing
it, but bulk of the problem is removed.

Tested by forbidding the syscall for the binary and observing it
correctly falls back to newfstatat.

While here tidy up the commentary, in particular by denoting some
problems with the current approach.
2023-01-11 17:10:08 +00:00
nils
9a820f7397
Rollup merge of #106664 - chenyukang:yukang/fix-106597-remove-lseek, r=cuviper
Remove unnecessary lseek syscall when using std::fs::read

Fixes #106597
r? ```@bjorn3```
2023-01-11 17:30:56 +01:00
nils
c962b07ed3
Rollup merge of #106570 - Xaeroxe:div-duration-tests, r=JohnTitor
add tests for div_duration_* functions

Per https://github.com/rust-lang/rust/issues/63139#issuecomment-817070719

this adds unit tests for the functions that will hopefully effectively demonstrate that `div_duration` is ready to be stabilized.
2023-01-11 17:30:54 +01:00
Albert Larsan
40ba0e84d5
Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
Yuki Okushi
feca61e5eb
Rollup merge of #106662 - Ezrashaw:specialize-bool-tostring, r=cuviper
specialize impl of `ToString` on `bool`

Fixes #106611

Specialize `bool`s `ToString` impl by copying it from `Display`. This is a significant optimization as we avoid lots of dynamic dispatch. AFAIK, this doesn't require a API Change Proposal as this doesn't regress existing code and can be undone without regressing code.
2023-01-11 14:18:56 +09:00
Yuki Okushi
397013dc44
Rollup merge of #106635 - RalfJung:std-test-nits, r=thomcc
std sync tests: better type name, clarifying comment

Just resolving some confusion that I encountered while reading these tests.

r? `@thomcc`
2023-01-11 14:18:54 +09:00
Ibraheem Ahmed
f8276c94ac add SyncSender::send_timeout test 2023-01-10 21:54:53 -05:00
Ibraheem Ahmed
2538c0c170 fix SyncSender spinning behavior 2023-01-10 21:39:02 -05:00
Alan Egerton
1a87ed9a45
mv binary_heap.rs binary_heap/mod.rs 2023-01-10 18:01:39 +00:00
yukang
f7bc68bb4e use with_capacity in read read_to_string 2023-01-11 00:19:27 +08:00
Ezra Shaw
203bbfa2f7
impl: specialize impl of ToString on bool 2023-01-10 15:34:21 +13:00
Yuki Okushi
002eccc752
Rollup merge of #105034 - HintringerFabian:improve_iterator_flatten_doc, r=cuviper
Add example for iterator_flatten

Adds an Example to iterator_flatten
Fixes #82687
2023-01-10 08:05:32 +09:00
Ralf Jung
ad79b2043f std tests: use __OsLocalKeyInner from realstd 2023-01-09 16:40:09 +01:00
Kai Luo
93ef4b3991 Add comment 2023-01-09 23:26:06 +08:00
Kai Luo
d4926eb8ab Move to intepret_cs_action 2023-01-09 23:18:06 +08:00
Kai Luo
8333e5cf5e Add comments 2023-01-09 23:09:18 +08:00
Ralf Jung
997101824b std test: better type name, clarifying comment 2023-01-09 16:08:26 +01:00
Kai Luo
04a697502f Also check ttype_index when using SJLJ 2023-01-09 23:02:53 +08:00
Caio
d1b7681e1e Remove unstable feature 2023-01-09 10:01:38 -03:00
Caio
fc8477798e Stabilize nonzero_min_max 2023-01-09 09:30:00 -03:00
Fabian Hintringer
c364d329dd
Relocate changes 2023-01-09 13:19:41 +01:00
John Millikin
92aa5f6b27 Disable linux_ext in wasm32 and fortanix rustdoc builds.
The `std::os::unix` module is stubbed out when building docs for these
target platforms. The introduction of Linux-specific extension traits
caused `std::os::net` to depend on sub-modules of `std::os::unix`,
which broke rustdoc for the `wasm32-unknown-unknown` target.

Adding an additional `#[cfg]` guard solves that rustdoc failure by
not declaring `linux_ext` on targets with a stubbed `std::os::unix`.
2023-01-09 14:07:05 +09:00
Michael Goulet
70f1566b2b
Rollup merge of #106584 - kpreid:vec-allocator, r=JohnTitor
Document that `Vec::from_raw_parts[_in]` must be given a pointer from the correct allocator.

Currently, the documentation of `Vec::from_raw_parts` and `Vec::from_raw_parts_in` says nothing about what allocator the pointer must come from. This PR adds that missing information explicitly.
2023-01-08 19:57:54 -08:00
Michael Goulet
db87e276c4
Rollup merge of #104163 - H4x5:once-repeat-with-debug, r=dtolnay
Don't derive Debug for `OnceWith` & `RepeatWith`

Closures don't impl Debug, so the derived impl is kinda useless. The behavior of not debug-printing closures is consistent with the rest of the iterator adapters/sources.
2023-01-08 19:57:52 -08:00
bors
a377893da2 Auto merge of #90291 - geeklint:loosen_weak_debug_bound, r=dtolnay
Loosen the bound on the Debug implementation of Weak.

Both `rc::Weak<T>` and `sync::Weak<T>` currently require `T: Debug` in their own `Debug` implementations, but they don't currently use it;  they only ever print a fixed string.

A general implementation of Debug for Weak that actually attempts to upgrade and rely on the contents is unlikely in the future because it may have unbounded recursion in the presence of reference cycles, which Weak is commonly used in.  (This was the justification for why the current implementation [was implemented the way it is](f0976e2cf3)).

When I brought it up [on the forum](https://internals.rust-lang.org/t/could-the-bound-on-weak-debug-be-relaxed/15504), it was suggested that, even if an implementation is specialized in the future that relies on the data stored within the Weak, it would likely rely on specialization anyway, and could therefore easily specialize on the Debug bound as well.
2023-01-08 22:40:38 +00:00
Yuki Okushi
14ce60333d
Rollup merge of #106562 - clubby789:vec-deque-example, r=Mark-Simulacrum
Clarify examples for `VecDeque::get/get_mut`

Closes #106114

``@rustbot`` label +A-docs
2023-01-08 17:01:48 +09:00
Yuki Okushi
ed77ffe166
Rollup merge of #103104 - SUPERCILEX:sep-ref, r=dtolnay
Stabilize `main_separator_str`

See reasoning here: https://github.com/rust-lang/rust/issues/94071#issuecomment-1279872605. Closes #94071.
2023-01-08 17:01:46 +09:00
bors
2afe58571e Auto merge of #104658 - thomcc:rand-update-and-usable-no_std, r=Mark-Simulacrum
Update `rand` in the stdlib tests, and remove the `getrandom` feature from it.

The main goal is actually removing `getrandom`, so that eventually we can allow running the stdlib test suite on tier3 targets which don't have `getrandom` support. Currently those targets can only run the subset of stdlib tests that exist in uitests, and (generally speaking), we prefer not to test libstd functionality in uitests, which came up recently in https://github.com/rust-lang/rust/pull/104095 and https://github.com/rust-lang/rust/pull/104185. Additionally, the fact that we can't update `rand`/`getrandom` means we're stuck with the old set of tier3 targets, so can't test new ones.

~~Anyway, I haven't checked that this actually does allow use on tier3 targets (I think it does not, as some work is needed in stdlib submodules) but it moves us slightly closer to this, and seems to allow at least finally updating our `rand` dep, which definitely improves the status quo.~~ Checked and works now.

For the most part, our tests and benchmarks are fine using hard-coded seeds. A couple tests seem to fail with this (stuff manipulating the environment expecting no collisions, for example), or become pointless (all inputs to a function become equivalent). In these cases I've done a (gross) dance (ab)using `RandomState` and `Location::caller()` for some extra "entropy".

Trying to share that code seems *way* more painful than it's worth given that the duplication is a 7-line function, even if the lines are quite gross. (Keeping in mind that sharing it would require adding `rand` as a non-dev dep to std, and exposing a type from it publicly, all of which sounds truly awful, even if done behind a perma-unstable feature).

See also some previous attempts:
- https://github.com/rust-lang/rust/pull/86963 (in particular https://github.com/rust-lang/rust/pull/86963#issuecomment-885438936 which explains why this is non-trivial)
- https://github.com/rust-lang/rust/pull/89131
- https://github.com/rust-lang/rust/pull/96626#issuecomment-1114562857 (I tried in that PR at the same time, but settled for just removing the usage of `thread_rng()` from the benchmarks, since that was the main goal).
- https://github.com/rust-lang/rust/pull/104185
- Probably more. It's very tempting of a thing to "just update".

r? `@Mark-Simulacrum`
2023-01-08 01:34:05 +00:00
Kevin Reid
288e89bf76 Document that Vec::from_raw_parts[_in] must be given a pointer from the correct allocator. 2023-01-07 15:56:36 -08:00
yukang
eae615dfdd Remove unnecessary lseek syscall when using std::fs::read 2023-01-08 05:02:04 +08:00
Trevor Gross
13e25b82f0 Improve the documentation of black_box 2023-01-07 15:44:38 -05:00
Matthias Krüger
3076f26988
Rollup merge of #106564 - Folyd:feat-repeatn, r=scottmcm
Change to immutable borrow when cloning element of RepeatN
2023-01-07 20:43:23 +01:00
Matthias Krüger
ee1992c695
Rollup merge of #106553 - Ezrashaw:fix-hashset-doctest, r=JohnTitor
docs: make `HashSet::retain` doctest more clear

Fixes #106535

Extremely simple fix suggested by ``@compiler-errors`` in the linked issue.
2023-01-07 20:43:22 +01:00
Matthias Krüger
d7519c3639
Rollup merge of #105128 - Sp00ph:vec_vec_deque_conversion, r=dtolnay
Add O(1) `Vec -> VecDeque` conversion guarantee

(See #105072)
2023-01-07 20:43:20 +01:00
Matthias Krüger
08653c8c57
Rollup merge of #104081 - joshlf:patch-6, r=dtolnay
PhantomData layout guarantees
2023-01-07 20:43:19 +01:00
Sky
eddb479ad3
Don't derive Debug for OnceWith & RepeatWith 2023-01-07 14:28:44 -05:00
Jacob Kiesel
9fd744b3e3 add tests for div_duration_* functions 2023-01-07 11:05:33 -07:00
Folyd
a139fd0627 Change to immutable borrow when cloning element of RepeatN 2023-01-07 23:50:07 +08:00
clubby789
fed349957d Clarify examples for VecDeque::get/get_mut 2023-01-07 14:38:21 +00:00
Ezra Shaw
43bec83266
docs: make HashSet::retain doctest more clear 2023-01-07 17:08:07 +13:00
Matthias Krüger
72d650f47a
Rollup merge of #106453 - coastalwhite:master, r=GuillaumeGomez
Improve include macro documentation

As outlined in #106118, the `include!` macro is a SEO problem when it comes to the Rust documentation. Beginners may see it as a replacement to `include` syntax in other languages. I feel like this documentation should quite explicitly link to the modules' documentation.

The primary goal of this PR is to address that issue by adding a warning to the documentation. While I was here, I also added some other parts. This included a `Uses` section and some (intra doc) links to other relevant topics.

I hope this can help beginners to Rust more quickly understand some multi-file project intricacies.

# References
- Syntax for the warning: 58accc6da3/tracing/src/lib.rs (L55)
2023-01-06 21:26:10 +01:00
Gijs Burghoorn
ae667be0f6 Remove HTML tags around warning 2023-01-06 13:20:58 +01:00
Gijs Burghoorn
c30f7c9980 Better phrasing for hygiene of include macro 2023-01-05 17:09:11 +01:00
Thom Chiovoloni
a4bf36e87b
Update rand in the stdlib tests, and remove the getrandom feature from it 2023-01-04 14:52:41 -08:00
Matthias Krüger
06b2df4706
Rollup merge of #106461 - notriddle:notriddle/window-searchstate-focus, r=GuillaumeGomez
docs: fix broken link "search bar"

Regression introduced by #84150
2023-01-04 23:39:52 +01:00
Matthias Krüger
5eb9698b4e
Rollup merge of #106398 - jyn514:fix-clippy, r=thomcc
Fix a few clippy lints in libtest

- Remove unnecessary references and dereferences
- Use `.contains` instead of `a <= x && x <= b`
- Use `mem::take` instead of `mem::replace` where possible

cc https://github.com/rust-lang/rust/pull/106394 :)
2023-01-04 23:39:49 +01:00
Michael Howell
854082c218 docs: fix broken link "search bar" 2023-01-04 12:47:24 -07:00
Gijs Burghoorn
eb2980c7f1 Tidy up whitespace 2023-01-04 16:18:34 +01:00
Gijs Burghoorn
0c43b42b0c Improve include macro documentation 2023-01-04 16:07:33 +01:00
bors
df756439df Auto merge of #106239 - LegionMammal978:thin-box-drop-guard, r=Amanieu
Deallocate ThinBox even if the value unwinds on drop

This makes it match the behavior of an ordinary `Box`.
2023-01-04 12:55:22 +00:00
Kai Luo
34534152f5 [LSDA] Take ttype_index into account when taking action
If cs_action != 0, we should check the ttype_index field in
action record. If ttype_index == 0, a clean up action is taken.
2023-01-04 18:00:09 +08:00
Matthias Krüger
d24b229072
Rollup merge of #106327 - gimbles:dbg, r=jyn514
Add tidy check for dbg

Fixes #106169
2023-01-04 07:28:55 +01:00
Matthias Krüger
70468af591
Rollup merge of #106200 - compiler-errors:suggest-impl-trait, r=estebank
Suggest `impl Fn*` and `impl Future` in `-> _` return suggestions

Follow-up to #106172, only the last commit is relevant. Can rebase once that PR is landed for easier review.

Suggests `impl Future` and `impl Fn{,Mut,Once}` in `-> _` return suggestions.

r? `@estebank`
2023-01-04 07:28:54 +01:00
mllken
ee59533167 relax reference requirement on from_abstract_name 2023-01-04 12:47:43 +07:00
Michael Goulet
f6b0f4707b
Rollup merge of #106045 - RalfJung:oom-nounwind-panic, r=Amanieu
default OOM handler: use non-unwinding panic, to match std handler

The OOM handler in std will by default abort. This adjusts the default in liballoc to do the same, using the `can_unwind` flag on the panic info to indicate a non-unwinding panic.

In practice this probably makes little difference since the liballoc default will only come into play in no-std situations where people write a custom panic handler, which most likely will not implement unwinding. But still, this seems more consistent.

Cc `@rust-lang/wg-allocators,` https://github.com/rust-lang/rust/issues/66741
2023-01-03 17:19:26 -08:00
Michael Goulet
a0390463fc Suggest more impl Trait on -> _ 2023-01-03 23:50:31 +00:00
Joshua Nelson
3534e0a393 Fix a few clippy lints in libtest
- Remove unnecessary references and dereferences
- Use `.contains` instead of `a <= x && x <= b`
- Use `mem::take` instead of `mem::replace` where possible
2023-01-03 18:55:03 +00:00