Commit graph

5130 commits

Author SHA1 Message Date
Mara Bos
d31352961c
Rollup merge of #88551 - inquisitivecrystal:unsafe_cell_raw_get, r=m-ou-se
Stabilize `UnsafeCell::raw_get()`

This PR stabilizes the associated function `UnsafeCell::raw_get()`. The FCP has [already completed](https://github.com/rust-lang/rust/issues/66358#issuecomment-899095068). While there was some discussion about the naming after the close of the FCP, it looks like people have agreed on this name. Still, it would probably be best if a `libs-api` member had a look at this and stated whether more discussion is needed.

While I was at it, I added some tests for `UnsafeCell`, because there were barely any.

Closes #66358.
2021-09-01 09:23:31 +02:00
Mara Bos
f436b6d0a7
Rollup merge of #88548 - inquisitivecrystal:intersperse, r=m-ou-se
Stabilize `Iterator::intersperse()`

This PR stabilizes the methods `Iterator::intersperse()` and `Iterator::intersperse_with()`. The FCP has [already completed](https://github.com/rust-lang/rust/issues/79524#issuecomment-909663616).

Closes #79524.
2021-09-01 09:23:30 +02:00
Mara Bos
59588a9a56
Rollup merge of #88542 - tavianator:readdir_r-errno, r=jyn514
Use the return value of readdir_r() instead of errno

POSIX says:

> If successful, the readdir_r() function shall return zero; otherwise,
> an error number shall be returned to indicate the error.

But we were previously using errno instead of the return value.  This
led to issue #86649.
2021-09-01 09:23:29 +02:00
Mara Bos
5878780e64
Rollup merge of #88040 - nbdd0121:btreemap, r=m-ou-se
BTree: remove Ord bound from new

`K: Ord` bound is unnecessary on `BTree{Map,Set}::new` and their `Default` impl. No elements exist so there are nothing to compare anyway, so I don't think "future proof" would be a blocker here. This is analogous to `HashMap::new` not having a `K: Eq + Hash` bound.

#79245 originally does this and for some reason drops the change to `new` and `Default`. I can see why changes to other methods like `entry` or `symmetric_difference` need to be careful but I couldn't find out any reason not to do it on `new`.

Removing the bound also makes the stabilisation of `const fn new` not depending on const trait bounds.

cc `@steffahn` who suggests me to make this PR.

r? `@dtolnay`
2021-09-01 09:23:23 +02:00
inquisitivecrystal
227e004d3f Add a few tests for UnsafeCell 2021-08-31 16:32:01 -07:00
inquisitivecrystal
06dd4c03a0 Stabilize Iterator::intersperse() 2021-08-31 14:50:18 -07:00
inquisitivecrystal
753dac16ab Stabilize UnsafeCell::raw_get() 2021-08-31 14:44:13 -07:00
Tavian Barnes
0e0c8aef87 Use the return value of readdir_r() instead of errno
POSIX says:

> If successful, the readdir_r() function shall return zero; otherwise,
> an error number shall be returned to indicate the error.

But we were previously using errno instead of the return value.  This
led to issue #86649.
2021-08-31 14:11:42 -04:00
Mara Bos
f5cf9678c2
Rollup merge of #88524 - soenkehahn:master, r=jyn514
Remove unnecessary `mut` from udp doctests

I don't think this `mut` is necessary, since both `recv_from` and `send_to` take `&self`.
2021-08-31 17:55:02 +02:00
Mara Bos
c5a34d802d
Rollup merge of #88495 - ibraheemdev:tcp-linger, r=joshtriplett
Add `TcpStream::set_linger` and `TcpStream::linger`

Adds methods for getting/setting the `SO_LINGER` option on TCP sockets. Behavior is consistent across Unix and Windows.

r? `@joshtriplett` (I noticed you've been reviewing net related PRs)
2021-08-31 17:54:58 +02:00
Mara Bos
e7a247dba4
Rollup merge of #85017 - clarfonthey:carrying_widening, r=m-ou-se
Add carrying_add, borrowing_sub, widening_mul, carrying_mul methods to integers

This comes in part from my own attempts to make (crude) big integer implementations, and also due to the stalled discussion in [RFC 2417](https://github.com/rust-lang/rfcs/pull/2417). My understanding is that changes like these are best offered directly as code and then an RFC can be opened if there needs to be more discussion before stabilisation. Since all of these methods are unstable from the start, I figured I might as well offer them now.

I tried looking into intrinsics, messed around with a few different implementations, and ultimately concluded that these are "good enough" implementations for now to at least put up some code and maybe start bikeshedding on a proper API for these.

For the `carrying_add` and `borrowing_sub`, I tried looking into potential architecture-specific code and realised that even using the LLVM intrinsics for `addcarry` and `subborrow` on x86 specifically, I was getting exactly the same assembly as the naive implementation using `overflowing_add` and `overflowing_sub`, although the LLVM IR did differ because of the architecture-specific code. Longer-term I think that they would be best suited to specific intrinsics as that would make optimisations easier (instructions like add-carry tend to use implicit flags, and thus can only be optimised if they're done one-after-another, and thus it would make the most sense to have compact intrinsics that can be merged together easily).

For `widening_mul` and `carrying_mul`, for now at least, I simply cast to the larger type and perform arithmetic that way, since we currently have no intrinsic that would work better for 128-bit integers. In the future, I also think that some form of intrinsic would work best to cover that case, but for now at least, I think that they're "good enough" for now.

The main reasoning for offering these directly to the standard library even though they're relatively niche optimisations is to help ensure that the code generated for them is optimal. Plus, these operations alone aren't enough to create big integer implementations, although they could help simplify the code required to do so and make it a bit more accessible for the average implementor.

That said, I 100% understand if any or all of these methods are not desired simply because of how niche they are. Up to you. 🤷🏻
2021-08-31 17:54:52 +02:00
Ibraheem Ahmed
072e8c977a
disable tcp_linger feature in std
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-08-31 11:19:39 -04:00
Mara Bos
497267a961
Rollup merge of #88465 - marcospb19:master, r=joshtriplett
Adding examples to docs of `std::time` module

And adding missing link to `Duration` from `Instant`.
2021-08-31 10:41:24 +02:00
Mara Bos
cd20fbdf82
Rollup merge of #88394 - ChrisDenton:patch-1, r=joshtriplett
Document `std::env::current_exe` possible rename behaviour

It might not be obvious that the "path of the current running executable" may (or may not) imply "at the time it was loaded".

This came up recently in chat so I thought it might be worth documenting.
2021-08-31 10:41:17 +02:00
Sönke Hahn
4027629edc Remove unnecessary mut from udp doctests 2021-08-30 22:31:34 -06:00
ibraheemdev
dafc14794f clean up c::linger conversion 2021-08-30 14:00:21 -04:00
ibraheemdev
3b6777f1ab add TcpStream::set_linger and TcpStream::linger 2021-08-30 13:42:52 -04:00
João M. Bezerra
faf59853f9 Adding examples to docs of std::time module
And adding missing link to Duration from Instant
2021-08-29 23:59:35 -03:00
Guillaume Gomez
281dfac12f
Rollup merge of #88381 - rtzoeller:dfly_stack_t_ss_sp_void, r=dtolnay
Handle stack_t.ss_sp type change for DragonFlyBSD

stack_t.ss_sp is now c_void on DragonFlyBSD, like the rest of the BSDs.

Changed in 02922ef750.
2021-08-29 16:25:31 +02:00
bors
66acdee9f7 Auto merge of #88295 - alexcrichton:update-stdarch, r=kennytm
Update the stdarch submodule

This notably brings in a number of codegen updates to ensure that wasm
simd intrinsics generate the expected instruction with LLVM 13
2021-08-29 07:32:04 +00:00
bors
677b517e66 Auto merge of #87921 - kellerkindt:master, r=kennytm
Add Saturating type (based on Wrapping type)

Tracking #87920

### Unresolved Questions
<!--
Include any open questions that need to be answered before the feature can be
stabilised.
-->

 - [x] ~`impl Div for Saturating<T>` falls back on inner integer division - which seems alright?~
    - [x] add `saturating_div`? (to respect division by `-1`)
 - [x] There is no `::saturating_shl` and `::saturating_shr`. (How to) implement `Shl`, `ShlAssign`, `Shr` and `ShrAssign`?
   - [naively](3f7d2ce28f)
 - [x] ~`saturating_neg` is only implemented on [signed integer types](https://doc.rust-lang.org/std/?search=saturating_n)~
 - [x] Is the implementation copied over from the `Wrapping`-type correct for `Saturating`?
   - [x] `Saturating::rotate_left`
   - [x] `Saturating::rotate_right`
   - [x] `Not`
   - [x] `BitXorOr` and `BitXorOrAssign`
   - [x] `BitOr` and `BitOrAssign`
   - [x] `BitAnd` and `BitAndAssign`
   - [x] `Saturating::swap_bytes`
   - [x] `Saturating::reverse_bits`
2021-08-28 23:39:02 +00:00
Michael Watzko
ce636f25e5 Unimpl Shl{Assign} for signed Saturating types until the correct impl is clear 2021-08-28 13:39:09 +02:00
Michael Watzko
977ae5ac2c Fix mentions of wrapping operations 2021-08-28 13:29:19 +02:00
Michael Watzko
acf0a0c394 Use wrapping shift for unsigned types 2021-08-28 13:28:35 +02:00
12101111
4c9896f279
build llvm libunwind.a in rustbuild 2021-08-28 14:14:22 +08:00
Ryan Zoeller
0d1d9788e5 Handle stack_t.ss_sp type change for DragonFlyBSD
stack_t.ss_sp is now c_void on DragonFlyBSD, so the specialization is no longer needed.

Changed in 02922ef750.
2021-08-27 17:31:42 -05:00
Chris Denton
50da1eb1cd
Document std::env::current_exe rename behaviour
It might not be obvious that the "path of the current running executable" may (or may not) mean "at the time it was loaded".
2021-08-27 14:25:29 +01:00
bors
d5cd3205fd Auto merge of #88371 - Manishearth:rollup-pkkjsme, r=Manishearth
Rollup of 11 pull requests

Successful merges:

 - #87832 (Fix debugger stepping behavior with `match` expressions)
 - #88123 (Make spans for tuple patterns in E0023 more precise)
 - #88215 (Reland #83738: "rustdoc: Don't load all extern crates unconditionally")
 - #88216 (Don't stabilize creation of TryReserveError instances)
 - #88270 (Handle type ascription type ops in NLL HRTB diagnostics)
 - #88289 (Fixes for LLVM change 0f45c16f2caa7c035e5c3edd40af9e0d51ad6ba7)
 - #88320 (type_implements_trait consider obligation failure on overflow)
 - #88332 (Add argument types tait tests)
 - #88340 (Add `c_size_t` and `c_ssize_t` to `std::os::raw`.)
 - #88346 (Revert "Add type of a let tait test impl trait straight in let")
 - #88348 (Add field types tait tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-27 01:07:17 +00:00
ltdk
cc15047d50 Add carrying_add, borrowing_sub, widening_mul, carrying_mul methods to integers 2021-08-26 19:52:06 -04:00
Manish Goregaokar
e760740c03
Rollup merge of #88340 - thomcc:c_size_t, r=joshtriplett
Add `c_size_t` and `c_ssize_t` to `std::os::raw`.

Apparently these aren't guaranteed to be the same, and are merely "always the same in practice" (see https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/.60usize.60.20vs.20.60size_t.60).

This is a big footgun, but I suspect it can be alleviated if we expose this and start migrating people to it in advance of any platforms that ever have this as different.

I'll file a tracking issue after this gets some traction.
2021-08-26 12:38:13 -07:00
Manish Goregaokar
cf5e362fd5
Rollup merge of #88216 - kornelski:from_layout_err, r=kennytm
Don't stabilize creation of TryReserveError instances

#48043 + https://github.com/rust-lang/rust/pull/87993#issuecomment-903189016
2021-08-26 12:38:08 -07:00
bors
ad02dc46ba Auto merge of #87194 - eddyb:const-value-mangling, r=michaelwoerister,oli-obk
rustc_symbol_mangling: support structural constants and &str in v0.

This PR should unblock #85530 (except for float `const` generics, which AFAIK should've never worked).
(cc `@tmiasko` could the https://github.com/rust-lang/rust/pull/85530#issuecomment-857855379 failures be retried with a quick crater "subset" run of this PR + changing the default to `v0`? Just to make sure I didn't miss anything other than the floats)

The encoding is the one suggested before in e.g. https://github.com/rust-lang/rust/issues/61486#issuecomment-878932102, tho this PR won't by itself finish #61486, before closing that we'd likely want to move to `@oli-obk's` "valtrees" (i.e. #83234 and other associated work).

<hr>

**EDITs**:
1. switched unit/tuple/braced-with-named-fields `<const-fields>` prefixes from `"u"`/`"T"`/`""` to `"U"`/`"T"`/`"S"` to avoid the ambiguity reported by `@tmiasko` in https://github.com/rust-lang/rust/pull/87194#issuecomment-884279921.

2. `rustc-demangle` PR: https://github.com/alexcrichton/rustc-demangle/pull/55

3. RFC amendment PR: https://github.com/rust-lang/rfcs/pull/3161
    * also removed the grammar changes included in that PR, from this description

4. added tests (temporarily using my fork of `rustc-demangle`)

<hr>

r? `@michaelwoerister`
2021-08-26 19:15:09 +00:00
bors
76e755cf4a Auto merge of #88066 - LeSeulArtichaut:patterns-cleanups, r=nagisa
Use if-let guards in the codebase and various other pattern cleanups

Dogfooding if-let guards as experimentation for the feature.

Tracking issue #51114. Conflicts with #87937.
2021-08-26 05:23:35 +00:00
Thom Chiovoloni
5b25de58d6 Reference tracking issue 2021-08-25 14:58:17 -07:00
Thom Chiovoloni
33c71ac87d Add c_size_t and c_ssize_t to std::os::raw. 2021-08-25 11:25:26 -07:00
Léo Lanteri Thauvin
fde1b76b4b Use if-let guards in the codebase 2021-08-25 20:24:35 +02:00
Léo Lanteri Thauvin
3eee91b403
Rollup merge of #88299 - ijackson:bufwriter, r=Mark-Simulacrum
Stabilise BufWriter::into_parts

The FCP for this has already completed, in #80690.

This was just blocked on #85901 (which changed the name), which is now merged.  The original stabilisation MR was #84770 but that has a lot of noise in it, and I also accidentally deleted the branch while trying to tidy up.  So here is a new MR.  Sorry for the noise.

Closes #80690
2021-08-25 15:49:01 +02:00
Léo Lanteri Thauvin
82ecb0f412
Rollup merge of #88298 - ijackson:errorkind-reorder, r=dtolnay
Errorkind reorder

I was doing a bit more work in this area and the untidiness of these two orderings bothered me.

The commit messages have the detailed rationale.  For your convenience, I c&p them here:

```
    io::ErrorKind: rationalise ordering in main enum

    It is useful to keep some coherent structure to this ordering.  In
    particular, Other and Uncategorized should be next to each other, at
    the end.

    Also it seems to make sense to treat UnexpectedEof and OutOfMemory
    specially, since they are not like the other errors (despite
    OutOfMemory also being generatable by some OS errors).

    So:
     * Move Other to the end, just before Uncategorized
     * Move Unsupported to between Interrupted and UnexpectedEof
     * Add some comments documenting where to add things
```

```
    io::Error: alphabeticise the match in as_str()

    There was no rationale for the previous ordering.
```

r? kennytm   since that's who rust-highfive picked before, in #88294 which I accidentally closed.
2021-08-25 15:49:00 +02:00
Léo Lanteri Thauvin
0aabf4bb4b
Rollup merge of #88293 - est31:fix_grammar, r=Mark-Simulacrum
Fix grammar in alloc test
2021-08-25 15:48:59 +02:00
Léo Lanteri Thauvin
dc2c9746f8
Rollup merge of #88291 - mdsn:partition-in-blocks-safety, r=Mark-Simulacrum
Add SAFETY comments to core::slice::sort::partition_in_blocks

A few more SAFETY comments for #66219. There are still a few more in this module.

`@rustbot` label T-libs T-compiler C-cleanup
2021-08-25 15:48:58 +02:00
Léo Lanteri Thauvin
3375283763
Rollup merge of #88273 - jhpratt:update-iterator-docs, r=jyn514
Fix references to `ControlFlow` in docs

The `Iterator::for_each` method previously stated that it was not possible to use `break` and `continue` in it — this has been updated to acknowledge the stabilization of `ControlFlow`. Additionally, `ControlFlow` was referred to as `crate::ops::ControlFlow` which is not the correct path for an end user.

r? `@jyn514`
2021-08-25 15:48:55 +02:00
Léo Lanteri Thauvin
cc2a1271d4
Rollup merge of #88226 - steffahn:an_rc, r=michaelwoerister
Fix typo “a Rc” → “an Rc” (and a few more)

After stumbling about it in the dev-guide, I’ve devided to eliminate all mentions of “a Rc”, replacing it with “an Rc”. E.g.
```plain
$ rg "(^|[^'])\ba\b[^\w=:]*\bRc"
compiler/rustc_data_structures/src/owning_ref/mod.rs
1149:/// Typedef of a owning reference that uses a `Rc` as the owner.

library/std/src/ffi/os_str.rs
919:    /// Converts a [`OsString`] into a [`Rc`]`<OsStr>` without copying or allocating.

library/std/src/ffi/c_str.rs
961:    /// Converts a [`CString`] into a [`Rc`]`<CStr>` without copying or allocating.

src/doc/rustc-dev-guide/src/query.md
61:are cheaply cloneable; insert a `Rc` if necessary).

src/doc/book/src/ch15-06-reference-cycles.md
72:decreases the reference count of the `a` `Rc<List>` instance from 2 to 1 as

library/alloc/src/rc.rs
1746:    /// Converts a generic type `T` into a `Rc<T>`
```
_(the match in the book is a false positive)_
Since the dev-guide is a submodule, it’s getting a separate PR: rust-lang/rustc-dev-guide#1191

I’ve also gone ahead and done the same search for `RwLock` and hit a few cases in the `OwningRef` adaption. Then, I couldn’t keep the countless cases of “a owning …” or “a owner” unaddressed, which concludes this PR.

`@rustbot` label C-cleanup
2021-08-25 15:48:53 +02:00
Léo Lanteri Thauvin
b09c2547df
Rollup merge of #88223 - scottmcm:fix-alias, r=yaahc
Remove the `TryV2` alias

Post-bootstrap-update cleanup.

(No more `try_trait_transition` feature.)
2021-08-25 15:48:52 +02:00
Léo Lanteri Thauvin
214d8e3cd4
Rollup merge of #88156 - steffahn:arc_make_mut_and_weak, r=Mark-Simulacrum
Adjust / fix documentation of `Arc::make_mut`

Related discussion in the users forum:
[Whatʼs this alleged difference between Arc::make_mut and Rc::make_mut? – The Rust Programming Language Forum](https://users.rust-lang.org/t/what-s-this-alleged-difference-between-arc-make-mut-and-rc-make-mut/63747?u=steffahn)

Also includes a small formatting improvement in the documentation of `Rc::make_mut`.

This PR makes the two documentations in question complete analogs. The previously claimed point in which one “differs from the behavior of” the other turns out to be incorrect, AFAIK.

One remaining inaccuracy: `Weak` pointers aren’t disassociated from the allocation but only from the contained value, i.e. in case of outstanding `Weak` pointers there still is a new allocation created, just the call to `.clone()` is avoided, instead the value is moved from one allocation to the other.

`@rustbot` label T-libs-api, A-docs
2021-08-25 15:48:48 +02:00
Léo Lanteri Thauvin
ccefe27670
Rollup merge of #87944 - oconnor663:as_array_of_cells, r=scottmcm
add Cell::as_array_of_cells, similar to Cell::as_slice_of_cells

I'd like to propose adding `Cell::as_array_of_cells`, as a natural analog to `Cell::as_slice_of_cells`. I don't have a specific use case in mind, other than that supporting slices but not arrays feels like a gap. Do other folks agree with that intuition? Would this addition be substantial enough to need an RFC?

---

Previously, converting `&mut [T; N]` to `&[Cell<T>; N]` looks like this:

```rust
let array = &mut [1, 2, 3];
let cells: &[Cell<i32>; 3] = Cell::from_mut(&mut array[..])
    .as_slice_of_cells()
    .try_into()
    .unwrap();
```

With this new helper method, it looks like this:

```rust
let array = &mut [1, 2, 3];
let cells = Cell::from_mut(array).as_array_of_cells();
```
2021-08-25 15:48:47 +02:00
Mariano Casco
09e02a8919 Add SAFETY comments to core::slice::sort::partition_in_blocks 2021-08-24 16:47:26 -03:00
Frank Steffahn
90354c719a Make explanations of cross-references between make_mut and get_mut more accurate 2021-08-24 21:34:12 +02:00
Frank Steffahn
335bf7ca6b Clarifiy weak pointers being diassociated…
…noting the fact that `clone` is not called.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2021-08-24 21:17:20 +02:00
Ian Jackson
db13636f03 Stabilise BufWriter::into_parts
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24 18:26:18 +01:00
Eduard-Mihai Burtescu
f8810ee171 Update rustc-demangle to 0.1.21. 2021-08-24 19:53:20 +03:00