Commit graph

4926 commits

Author SHA1 Message Date
Yuki Okushi
6412bf98ea
Rollup merge of #87848 - godmar:@godmar/thread-join-documentation-fix, r=joshtriplett
removed references to parent/child from std::thread documentation

- also clarifies how thread.join and detaching of threads works
- the previous prose implied that there is a relationship between a
spawning thread and the thread being spawned, and that "child" threads
couldn't outlive their "parents" unless detached, which is incorrect.
2021-08-11 04:18:38 +09:00
Yuki Okushi
bdc92f10e7
Rollup merge of #87636 - Kixiron:unzip-option, r=scottmcm
Added the `Option::unzip()` method

* Adds the `Option::unzip()` method to turn an `Option<(T, U)>` into `(Option<T>, Option<U>)` under the `unzip_option` feature
* Adds tests for both `Option::unzip()` and `Option::zip()`, I noticed that `.zip()` didn't have any
* Adds `#[inline]` to a few of `Option`'s methods that were missing it
2021-08-11 04:18:34 +09:00
Yuki Okushi
3b41447a02
Rollup merge of #86840 - usbalbin:const_from, r=oli-obk
Constify implementations of `(Try)From` for int types

I believe this to be one of the (many?) things blocking const (Range) iterators.

~~If this is to be merged maybe that should wait until `#![feature(const_trait_impl)]` no longer needs `#![allow(incomplete_features)]`?~~ - Done
2021-08-11 04:18:33 +09:00
Chase Wilson
ab2c5902ca
Added tracking issue to unstable attribute 2021-08-09 10:24:03 -05:00
Chase Wilson
9d8081e8b6
Enabled unzip_option feature for core tests & unzip docs 2021-08-09 10:24:02 -05:00
Chase Wilson
eea3520a8f
Added some basic tests for Option::unzip() and Option::zip() (I noticed that zip had no tests) 2021-08-09 10:24:00 -05:00
Chase Wilson
bc4ce79764
Added the Option::unzip() method 2021-08-09 10:23:46 -05:00
bors
eaf6f46359 Auto merge of #87820 - elichai:patch-2, r=kennytm
Replace read_to_string with read_line in Stdin example

The current example results in infinitely reading from stdin, which can confuse newcomers trying to read from stdin.
(`@razmag` encountered this while learning the language from the docs)
2021-08-09 08:19:19 +00:00
bors
ad981d58e1 Auto merge of #86879 - YohDeadfall:stabilize-vec-shrink-to, r=dtolnay
Stabilize Vec<T>::shrink_to

This PR stabilizes `shrink_to` feature and closes the corresponding issue. The second point was addressed already, and no `panic!` should occur.

Closes #56431.
2021-08-08 19:37:02 +00:00
David Tolnay
8ec5060cdd
Bump shrink_to stabilization to Rust 1.56 2021-08-08 11:36:53 -07:00
bors
4e886d6876 Auto merge of #87827 - eddyb:wrapperless-mem-replace, r=m-ou-se
Avoid using the `copy_nonoverlapping` wrapper through `mem::replace`.

This is a much simpler way to achieve the pre-#86003 behavior of `mem::replace` not needing dynamically-sized `memcpy`s (at least before inlining), than re-doing #81238 (which needs #86699 or something similar).

I didn't notice it until recently, but `ptr::write` already explicitly avoided using the wrapper, while `ptr::read` just called the wrapper (and was the reason for us observing any behavior change from #86003 in Rust-GPU).

<hr/>

The codegen test I've added fails without the change to `core::ptr::read` like this (ignore the `v0` mangling, I was using a worktree with it turned on by default, for this):
```llvm
       13: ; core::intrinsics::copy_nonoverlapping::<u8>
       14: ; Function Attrs: inlinehint nonlazybind uwtable
       15: define internal void `@_RINvNtCscK5tvALCJol_4core10intrinsics19copy_nonoverlappinghECsaS4X3EinRE8_25mem_replace_direct_memcpy(i8*` %src, i8* %dst, i64 %count) unnamed_addr #0 {
       16: start:
       17:  %0 = mul i64 %count, 1
       18:  call void `@llvm.memcpy.p0i8.p0i8.i64(i8*` align 1 %dst, i8* align 1 %src, i64 %0, i1 false)
not:17      !~~~~~~~~~~~~~~~~~~~~~                                                                     error: no match expected
       19:  ret void
       20: }
```
With the `core::ptr::read` change, `core::intrinsics::copy_nonoverlapping` doesn't get instantiated and the test passes.

<hr/>

r? `@m-ou-se` cc `@nagisa` (codegen test) `@oli-obk` / `@RalfJung` (miri diagnostic changes)
2021-08-08 13:11:09 +00:00
Eduard-Mihai Burtescu
a1d014bdbc Avoid using the copy_nonoverlapping wrapper through mem::replace. 2021-08-08 13:59:36 +03:00
bors
e8c25f2663 Auto merge of #87836 - tsoutsman:master, r=petrochenkov
Change proc_macro::Diagnostics docs

With Rust 1.54 attributes can invoke function-like macros. This allows functions generated by macros to have non-generic documentation. This pull request changes the documentation of `proc_macro::Diagnostics` to be more specific and include a link to the level.
## Example
Before:
```markdown
Adds a new child diagnostic message to `self` with the level
identified by this method’s name with the given `message`.
```
After:
```markdown
Adds a new child diagnostic message to self with the [`Level::Error`]
level, and the given `message`.
```
2021-08-08 10:23:17 +00:00
Klim Tsoutsman
26bf0ef0b5
Merge branch 'rust-lang:master' into master 2021-08-08 13:17:23 +10:00
bors
835dce569d Auto merge of #86744 - ijackson:sink-default, r=dtolnay
impl Default, Copy, Clone for std::io::Sink and Empty

The omission of `Sink: Default` is causing me a slight inconvenience in a test harness.  There seems little reason for this and `Empty` not to be `Clone` and `Copy` too.

I have made all three of these insta-stable, because:

AIUI `Copy` can only be derived, and I was not able to find any examples of how to unstably derive it.  I think it is probably not possible.

I hunted through the git history for precedent and found

> 79b8ad84c8
> Implement `Copy` for `IoSlice`
> https://github.com/rust-lang/rust/pull/69403

which was also insta-stable.
2021-08-08 01:52:32 +00:00
Albin Hedman
c8bf5ed628
Add test for int to float 2021-08-07 19:03:34 +02:00
Albin Hedman
09928a9a20
Add tests 2021-08-07 19:03:33 +02:00
Albin Hedman
eefd790d3b
impl const From<num> for num 2021-08-07 19:03:08 +02:00
Yuki Okushi
c159806cf0
Rollup merge of #87842 - steffahn:hidden_broken_intra_doc, r=dtolnay
Fix intra doc link in hidden doc of Iterator::__iterator_get_unchecked

Recently, I edited the import list of the `core::iter::traits::iterator` module (in #85874). This results in a broken intra doc link in a hidden documentation with the effect that `RUSTDOCFLAGS='--document-private-items --document-hidden-items' x doc library/std` fails. (This can be worked around by adding `-Arustdoc::broken-intra-doc-links`; still, it’s a broken link so let’s fix it.)

``@rustbot`` label C-cleanup, T-libs
2021-08-08 01:13:45 +09:00
Yuki Okushi
349290047f
Rollup merge of #87838 - jetomit:add-readdir-note, r=dtolnay
Document that fs::read_dir skips . and ..

Hi,

I think this is worth noting in the docs since it differs from POSIX `readdir`. I didn’t put it under platform-specific notes because it seems to be consistent across platforms, and changing this behavior in the future could cause pretty nasty bugs.

Thanks!
2021-08-08 01:13:44 +09:00
Godmar Back
2a56a4fe54 removed references to parent/child from std::thread documentation
- also clarifies how thread.join and detaching of threads works
- the previous prose implied that there is a relationship between a
spawning thread and the thread being spawned, and that "child" threads
couldn't outlive their parents unless detached, which is incorrect.
2021-08-07 11:33:18 -04:00
Klim Tsoutsman
75e80358d2
Change proc_macro::Diagnostics docs
Add links

Fit 100-character limit
2021-08-07 23:54:34 +10:00
bors
508b328c39 Auto merge of #87810 - devnexen:haiku_os_simpl, r=Mark-Simulacrum
current_exe haiku code path simplification all of these part of libc
2021-08-07 12:44:09 +00:00
Frank Steffahn
5c30df5954 Fix intra doc link in hidden doc of Iterator::__iterator_get_unchecked 2021-08-07 13:42:15 +02:00
Timotej Lazar
c32e4ba60a
Document that fs::read_dir skips . and .. 2021-08-07 10:14:41 +02:00
bors
996ff2e0a0 Auto merge of #87408 - kornelski:try_reserve_error, r=yaahc
Hide allocator details from TryReserveError

I think there's [no need for TryReserveError to carry detailed information](https://github.com/rust-lang/rust/issues/48043#issuecomment-825139280), but I wouldn't want that issue to delay stabilization of the `try_reserve` feature.

So I'm proposing to stabilize `try_reserve` with a `TryReserveError` as an opaque structure, and if needed, expose error details later.

This PR moves the `enum` to an unstable inner `TryReserveErrorKind` that lives under a separate feature flag. `TryReserveErrorKind` could possibly be left as an implementation detail forever, and the `TryReserveError` get methods such as `allocation_size() -> Option<usize>` or `layout() -> Option<Layout>` instead, or the details could be dropped completely to make try-reserve errors just a unit struct, and thus smaller and cheaper.
2021-08-07 01:26:15 +00:00
bors
db3cb435c1 Auto merge of #87774 - camelid:process-typo, r=jyn514
Fix typo

Add missing "by".
2021-08-06 22:42:25 +00:00
Elichai Turkel
4763ef2bd3
Replace read_to_string with read_line in Stdin example 2021-08-06 20:27:09 +03:00
Yuki Okushi
dba6cb76c2
Rollup merge of #87809 - InnovativeInventor:pointer-typo, r=dtolnay
Fix typo in the ptr documentation

Spotted a minor typo in the docs ;). Pointers are cool!
2021-08-07 01:46:36 +09:00
Yuki Okushi
c5202b3779
Rollup merge of #87787 - hyd-dev:c-unwind, r=RalfJung
Use `C-unwind` ABI for `__rust_start_panic` in `panic_abort`

The function originally has `C` ABI but is called using `C-unwind` ABI in `std`:
d4ad1cfc63/library/std/src/panicking.rs (L49-L54)
Which might be [problematic](https://github.com/rust-lang/miri/pull/1745#discussion_r596096876) and triggers this [Miri error](https://github.com/rust-lang/rust/issues/87778#issuecomment-893306222):
```
error: Undefined Behavior: calling a function with ABI C using caller ABI C-unwind
   --> /home/hyd-dev/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/panicking.rs:672:9
    |
672 |         __rust_start_panic(obj)
    |         ^^^^^^^^^^^^^^^^^^^^^^^ calling a function with ABI C using caller ABI C-unwind
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
```
Changing the ABI of the function to `C-unwind` fixes the error above.
2021-08-07 01:46:35 +09:00
bors
4c29cc8fd0 Auto merge of #87777 - the8472:fix-mir-max-rss, r=oli-obk,joshtriplett
Use zeroed allocations in the mir interpreter instead eagerly touching the memory

#86255 introduced a 30% regression in [page faults](https://perf.rust-lang.org/compare.html?start=64ae15ddd3f3cca7036ab2b2f3a6b130b62af4da&end=39e20f1ae5f13451eb35247808d6a2527cb7d060&stat=faults
) and a 3% regression in [max-rss](https://perf.rust-lang.org/index.html?start=2021-07-01&end=&absolute=false&stat=max-rss) in the ctfe-stress benchmarks.
That's most likely happened because it separated allocation from initialization of the vec which defeats the zero-optimization.

Currently there's no allocation API that is fallible, zeroing and returns a slice, so this PR introduces one and then uses that to solve the problem. In principle `vec.resize(len, 0)` could be optimized to use `alloc::grow_zeroed` where appropriate but that would require new specializations and new plumbing in `RawVec`.
2021-08-06 12:11:30 +00:00
David Carlier
5501eba645 current_exe haiku code path simplification all of these part of libc 2021-08-06 10:11:49 +01:00
bors
1f94abcda6 Auto merge of #87808 - JohnTitor:rollup-qqp79xs, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #87561 (thread set_name haiku implementation.)
 - #87715 (Add long error explanation for E0625)
 - #87727 (explicit_generic_args_with_impl_trait: fix min expected number of generics)
 - #87742 (Validate FFI-safety warnings on naked functions)
 - #87756 (Add back -Zno-profiler-runtime)
 - #87759 (Re-use std::sealed::Sealed in os/linux/process.)
 - #87760 (Promote `aarch64-apple-ios-sim` to Tier 2)
 - #87770 (permit drop impls with generic constants in where clauses)
 - #87780 (alloc: Use intra doc links for the reserve function)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-06 05:02:35 +00:00
Max Fan
89a8ba46b8 Fix typo in the ptr documentation 2021-08-05 22:50:56 -04:00
Yuki Okushi
b98c388352
Rollup merge of #87780 - est31:intra_doc_links, r=jyn514
alloc: Use intra doc links for the reserve function

The sentence exists to highlight the existence of a
performance footgun of repeated calls of the
reserve_exact function.
2021-08-06 11:21:36 +09:00
Yuki Okushi
13f9a4c309
Rollup merge of #87759 - m-ou-se:linux-process-sealed, r=jyn514
Re-use std::sealed::Sealed in os/linux/process.

This uses `std::sealed::Sealed` in `std::os::linux::process` instead of defining new `Sealed` traits there.
2021-08-06 11:21:33 +09:00
Yuki Okushi
4b068dd657
Rollup merge of #87561 - devnexen:haiku_thread_build_fix, r=yaahc
thread set_name haiku implementation.
2021-08-06 11:21:28 +09:00
bors
7129033b42 Auto merge of #87462 - ibraheemdev:tidy-file-length-ignore-comment, r=Mark-Simulacrum
Ignore comments in tidy-filelength

Ref https://github.com/rust-lang/rust/issues/60302#issuecomment-652402127
2021-08-06 02:07:01 +00:00
The8472
1c21373b50 add Box::try_new_uninit_slice for symmetry 2021-08-05 21:21:52 +02:00
The8472
6ed2d870fc remove cfg gate on use RawVec since it is now also used in fallible code 2021-08-05 19:45:02 +02:00
Mara Bos
cdf83c030a Make rustfmt happy. 2021-08-05 12:55:35 +02:00
Mara Bos
1b318a2b49 Remove unnecessary #[unstable] from internal macro.
After this change, all library #![feature]s enabled in core are for
const fns.
2021-08-05 12:55:35 +02:00
Mara Bos
9decf6365d Remove unused langauge #![feature]s from core. 2021-08-05 12:55:35 +02:00
Mara Bos
37d402eadd Remove unused library #![feature]s from core. 2021-08-05 12:55:35 +02:00
Mara Bos
25d0c58e0a Sort and categorize lint and feature attributes in core. 2021-08-05 12:55:33 +02:00
hyd-dev
7520ea9046
Use C-unwind ABI for __rust_start_panic in panic_abort 2021-08-05 18:01:17 +08:00
est31
1db8737f65 alloc: Use intra doc links for the reserve function
The sentence exists to highlight the existence of a
performance footgun of repeated calls of the
reserve_exact function.
2021-08-05 04:23:54 +02:00
The8472
de91157389 add Box::try_new_zeroed_slice()
Currently there is no API that allows fallible zero-allocation of a Vec.
Vec.try_reserve is not appropriate for this job since it doesn't know
whether it should zero or arbitrary uninitialized memory is fine.

Since Box currently holds most of the zeroing/uninit/slice allocation APIs
it's the best place to add yet another entry into this feature matrix.
2021-08-05 00:23:19 +02:00
bors
25b7648496 Auto merge of #86155 - alexcrichton:abort-on-unwind, r=nikomatsakis
rustc: Fill out remaining parts of C-unwind ABI

This commit intends to fill out some of the remaining pieces of the
C-unwind ABI. This has a number of other changes with it though to move
this design space forward a bit. Notably contained within here is:

* On `panic=unwind`, the `extern "C"` ABI is now considered as "may
  unwind". This fixes a longstanding soundness issue where if you
  `panic!()` in an `extern "C"` function defined in Rust that's actually
  UB because the LLVM representation for the function has the `nounwind`
  attribute, but then you unwind.

* Whether or not a function unwinds now mainly considers the ABI of the
  function instead of first checking the panic strategy. This fixes a
  miscompile of `extern "C-unwind"` with `panic=abort` because that ABI
  can still unwind.

* The aborting stub for non-unwinding ABIs with `panic=unwind` has been
  reimplemented. Previously this was done as a small tweak during MIR
  generation, but this has been moved to a separate and dedicated MIR
  pass. This new pass will, for appropriate functions and function
  calls, insert a `cleanup` landing pad for any function call that may
  unwind within a function that is itself not allowed to unwind. Note
  that this subtly changes some behavior from before where previously on
  an unwind which was caught-to-abort it would run active destructors in
  the function, and now it simply immediately aborts the process.

* The `#[unwind]` attribute has been removed and all users in tests and
  such are now using `C-unwind` and `#![feature(c_unwind)]`.

I think this is largely the last piece of the RFC to implement.
Unfortunately I believe this is still not stabilizable as-is because
activating the feature gate changes the behavior of the existing `extern
"C"` ABI in a way that has no replacement. My thinking for how to enable
this is that we add support for the `C-unwind` ABI on stable Rust first,
and then after it hits stable we change the behavior of the `C` ABI.
That way anyone straddling stable/beta/nightly can switch to `C-unwind`
safely.
2021-08-04 21:09:53 +00:00
Noah Lev
42a417e49a
Fix typo 2021-08-04 14:04:58 -07:00