Commit graph

3896 commits

Author SHA1 Message Date
Yuki Okushi
5b7c98676f
Rollup merge of #84248 - calebsander:refactor/vec-functions, r=Amanieu
Remove duplicated fn(Box<[T]>) -> Vec<T>

`<[T]>::into_vec()` does the same thing as `Vec::from::<Box<[T]>>()`, so they can be implemented in terms of each other. This was the previous implementation of `Vec::from()`, but was changed in #78461. I'm not sure what the rationale was for that change, but it seems preferable to maintain a single implementation.
2021-04-24 03:44:04 +09:00
Yuki Okushi
dcb4083ed9
Rollup merge of #80805 - camelid:iter-by_ref-example, r=steveklabnik
Improve `Iterator::by_ref` example

I split the example into two: one that fails to compile, and one that
works. I also made them identical except for the addition of `by_ref`
so we don't confuse readers with random differences.

cc `@steveklabnik,` who is the one that added the previous version of this example
2021-04-24 03:44:02 +09:00
Adrien Morison
21b3b27fe4 Mention FusedIterator case in Iterator::fuse doc
Using `fuse` on an iterator that incorrectly implements
`FusedIterator` does not fuse the iterator. This commit adds a
note about this in the documentation of this method to increase
awareness about this potential issue (esp. when relying on fuse
in unsafe code).
2021-04-23 19:13:27 +01:00
bors
cb81dc535c Auto merge of #82585 - TrolledWoods:master, r=dtolnay
Added CharIndices::offset function

The CharIndices iterator has a field internally called front_offset, that I think would be very useful to have access to.

You can already do something like ``char_indices.next().map(|(offset, _)| offset)``, but that is wordy, in addition to not handling the case where the iterator has ended, where you'd want the offset to be equal to the length.

I'm very new to the open source world and the rust repository, so I'm sorry if I missed a step or did something weird.
2021-04-23 02:48:13 +00:00
bors
f4a8cf0a00 Auto merge of #78681 - m-ou-se:binary-heap-retain, r=Amanieu
Improve rebuilding behaviour of BinaryHeap::retain.

This changes `BinaryHeap::retain` such that it doesn't always fully rebuild the heap, but only rebuilds the parts for which that's necessary.

This makes use of the fact that retain gives out `&T`s and not `&mut T`s.

Retaining every element or removing only elements at the end results in no rebuilding at all. Retaining most elements results in only reordering the elements that got moved (those after the first removed element), using the same logic as was already used for `append`.

cc `@KodrAus` `@sfackler` - We briefly discussed this possibility in the meeting last week while we talked about stabilization of this function (#71503).
2021-04-23 00:07:19 +00:00
Christiaan Dirkx
dc110af7fc Explicitly implement !Send and !Sync for sys::{Args, Env} 2021-04-23 00:15:35 +02:00
Michael Howell
60ff298070 Document From implementations for Waker and RawWaker 2021-04-22 14:16:33 -07:00
Michael Howell
c247055032 Get rid of "[+] show undocumented items" toggle on numeric From impls
On most From implementations, the docstring is attached to the
function. This is also how people have been [recommended] to do it.

Screenshots:

* [before](https://user-images.githubusercontent.com/1593513/115767662-323c5480-a35e-11eb-9918-98aba83e9183.png)
* [after](https://user-images.githubusercontent.com/1593513/115767675-35374500-a35e-11eb-964f-c28eeb6c807a.png)

[recommended]: https://github.com/rust-lang/rust/issues/51430#issuecomment-398322434
2021-04-22 11:51:05 -07:00
bors
5f1aeb52c2 Auto merge of #84440 - Dylan-DPC:rollup-0xjb8oi, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #84343 (Remove `ScopeTree::closure_tree`)
 - #84376 (Uses flex to fix formatting of h1 at any width)
 - #84377 (Followup to #83944)
 - #84396 (Update LLVM submodule)
 - #84402 (Move `sys_common::rwlock::StaticRWLock` etc. to `sys::unix::rwlock`)
 - #84404 (Check for intrinsics before coercing to a function pointer)
 - #84413 (Remove `sys::args::Args::inner_debug` and use `Debug` instead)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-04-22 18:17:23 +00:00
Dylan DPC
d1f5fc6017
Rollup merge of #84413 - CDirkx:args_inner_debug, r=m-ou-se
Remove `sys::args::Args::inner_debug` and use `Debug` instead

This removes the method `sys::args::Args::inner_debug` on all platforms and implements `Debug` for `Args` instead.

I believe this creates a more natural API for the different platforms under `sys`: export a type `Args: Debug + Iterator + ...` vs. `Args: Iterator + ...` and with a method `inner_debug`.
2021-04-22 18:14:43 +02:00
Dylan DPC
aac5125da4
Rollup merge of #84402 - CDirkx:rwlock, r=dtolnay
Move `sys_common::rwlock::StaticRWLock` etc. to `sys::unix::rwlock`

This moves `sys_common::rwlock::StaticRwLock`, `RWLockReadGuard` and `RWLockWriteGuard` to `sys::unix::rwlock`. They are already `#[cfg(unix)]` and don't need to be in `sys_common`.
2021-04-22 18:14:41 +02:00
Christiaan Dirkx
7171fec13f Remove Once from init 2021-04-22 18:00:18 +02:00
Christiaan Dirkx
e1b1081d2f Document that init and cleanup are not guaranteed to run 2021-04-22 18:00:18 +02:00
Christiaan Dirkx
8aeea227da Apply suggestions from review 2021-04-22 18:00:17 +02:00
Christiaan Dirkx
11445c10ab Move most init to sys::init 2021-04-22 18:00:12 +02:00
bors
ccf171242b Auto merge of #77704 - AnthonyMikh:slice_index_with_ops_bound_pair, r=m-ou-se
Implement indexing slices with pairs of core::ops::Bound<usize>

Closes #49976.

I am not sure about code duplication between `check_range` and `into_maybe_range`. Should be former implemented in terms of the latter? Also this PR doesn't address code duplication between `impl SliceIndex for Range*`.
2021-04-22 15:36:27 +00:00
Mara Bos
f5d72ab69b Add better test for BinaryHeap::retain. 2021-04-22 14:24:30 +02:00
Mara Bos
62226eecb6 Improve BinaryHeap::retain.
It now doesn't fully rebuild the heap, but only the parts that are
necessary.
2021-04-22 14:24:30 +02:00
Christiaan Dirkx
1a6de8450e Remove sys::args::Args::inner_debug and use Debug instead 2021-04-22 11:04:29 +02:00
Christiaan Dirkx
cf470197ad Move all cleanup to sys::cleanup 2021-04-22 10:44:44 +02:00
Christiaan Dirkx
5b30662741 Rework at_exit to cleanup 2021-04-22 10:34:48 +02:00
Christiaan Dirkx
9cabbd0afc Move sys_common::poison to sync::poison 2021-04-22 10:27:21 +02:00
Caleb Sander
f505d619c4 Remove duplicated fn(Box<[T]>) -> Vec<T> 2021-04-21 23:32:10 -04:00
Mara Bos
268d29d75d
Rollup merge of #84406 - m-ou-se:drop-delete-alias, r=dtolnay
Remove `delete` alias from `mem::drop`.

See https://github.com/rust-lang/rust/pull/81988#issuecomment-824168459 and https://github.com/rust-lang/rust/pull/81988#issuecomment-824213843
2021-04-21 23:06:24 +02:00
Mara Bos
49a5c80a3b
Rollup merge of #84390 - m-ou-se:make-debug-non-exhaustive-without-fields-a-little-bit-less-verbose, r=kennytm
Format `Struct { .. }` on one line even with `{:#?}`.

The result of `debug_struct("A").finish_non_exhaustive()` before this change:
```
A {
    ..
}
```
And after this change:
```
A { .. }
```

If there's any fields, the result stays unchanged:
```
A {
    field: value,
    ..
}
2021-04-21 23:06:21 +02:00
Mara Bos
d341851f94
Rollup merge of #84301 - r00ster91:patch-1, r=kennytm
Document that `index` and `index_mut` can panic

I thought this was noteworthy and I think a bit more explicitness does no harm.
2021-04-21 23:06:16 +02:00
Mara Bos
47886ead1f
Rollup merge of #84251 - RalfJung:non-zero-const-since, r=kennytm
fix 'const-stable since' for NonZeroU*::new_unchecked

For the unsigned `NonZero` types, `new_unchecked` was const-stable from the start with https://github.com/rust-lang/rust/pull/50808. Fix the docs to accurately reflect that.

I think this `since` is also incorrect:
```rust
            #[stable(feature = "from_nonzero", since = "1.31.0")]
            impl From<$Ty> for $Int {
```
The signed nonzero types were only stabilized in 1.34, so that `From` impl certainly didn't exist before. But I had enough of digging through git histories after I figured out when `new_unchecked` became const-stable...^^
2021-04-21 23:06:15 +02:00
Mara Bos
31b83802a4
Rollup merge of #84212 - CDirkx:void, r=m-ou-se
Replace `Void` in `sys` with never type

This PR replaces several occurrences in `sys` of the type `enum Void {}` with the Rust never type (`!`).
The name `Void` is unfortunate because in other languages (C etc.) it refers to a unit type, not an uninhabited type.

Note that the previous stabilization of the never type was reverted, however all uses here are implementation details and not publicly visible.
2021-04-21 23:06:14 +02:00
Mara Bos
3897ad1128
Rollup merge of #84119 - CDirkx:vxworks, r=m-ou-se
Move `sys::vxworks` code to `sys::unix`

Follow-up to #77666, `sys::vxworks` is almost identical to `sys::unix`, the only differences are the `rand`, `thread_local_dtor`, and `process` implementation. Since `vxworks` is `target_family = unix` anyway, there is no reason for the code not to live inside of `sys::unix` like all the other unix-OSes.

e41f378f82/compiler/rustc_target/src/spec/vxworks_base.rs (L12)

``@rustbot`` label: +T-libs-impl
2021-04-21 23:06:12 +02:00
Mara Bos
a7a7737114
Rollup merge of #84013 - CDirkx:fmt, r=m-ou-se
Replace all `fmt.pad` with `debug_struct`

This replaces any occurrence of:
- `f.pad("X")` with `f.debug_struct("X").finish()`
- `f.pad("X { .. }")` with `f.debug_struct("X").finish_non_exhaustive()`

This is in line with existing formatting code such as
1255053067/library/std/src/sync/mpsc/mod.rs (L1470-L1475)
2021-04-21 23:06:11 +02:00
Mara Bos
6763a40eff
Bump slice_index_with_ops_bound_pair to 1.53.0 2021-04-21 22:40:19 +02:00
Mara Bos
f1f3069a98 Remove delete alias from mem::drop. 2021-04-21 21:54:39 +02:00
Christiaan Dirkx
eb9b0f6ab7 Move sys_common::rwlock::StaticRWLock etc. to sys::unix::rwlock 2021-04-21 17:53:00 +02:00
Christiaan Dirkx
aa46f08abd Apply suggestions from code review 2021-04-21 16:06:32 +02:00
Christiaan Dirkx
fccc75cf82 Fix alloc::test::test_show 2021-04-21 15:45:41 +02:00
Christiaan Dirkx
fdae75738b Change the Debug impl of Any and UnsafeCell to use finish_non_exhaustive 2021-04-21 14:51:04 +02:00
Christiaan Dirkx
1fb3256fcb Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
Mara Bos
82dc73b1ae Format Struct { .. } on one line even with {:#?}. 2021-04-21 13:50:56 +02:00
Christiaan Dirkx
d45e1314f3 Change uses of never type 2021-04-20 20:53:07 +02:00
Christiaan Dirkx
389fef3b30 Replace Void with never type 2021-04-20 20:53:07 +02:00
Dylan DPC
9f03385499
Rollup merge of #84337 - matklad:insert_or_insert, r=jyn514
Clarify the difference between insert and get_or_insert

Took me a while to realize that the two are actually different.
2021-04-20 11:08:27 +02:00
Dylan DPC
761243572e
Rollup merge of #84291 - RalfJung:thread-local-const-init, r=alexcrichton
fix aliasing violations in thread_local_const_init

Fixes https://github.com/rust-lang/rust/pull/83416#discussion_r615364774

r? `@alexcrichton` `@sfackler`
2021-04-19 22:00:09 +02:00
Dylan DPC
fb78dc05e4
Rollup merge of #84256 - tspiteri:pretty-minus-zero, r=workingjubilee
doc: use U+2212 for minus sign in floating-point -0.0 remarks

Also remove plus sign in `-0.0 == +0.0` to make it a valid expression.
2021-04-19 22:00:08 +02:00
Aleksey Kladov
de16951dad Clarify the difference between insert and get_or_insert 2021-04-19 18:17:45 +03:00
bors
41f0e13bc5 Auto merge of #84294 - WaffleLapkin:patch-2, r=jonas-schievink
Slightly change wording in doc comment and fix typo in vec/mod.rs

Suggested by `@pickfire` in https://github.com/rust-lang/rust/pull/82760
2021-04-19 11:55:52 +00:00
Christiaan Dirkx
9bd9cbb28e Fix vxworks compilation errors 2021-04-19 13:29:35 +02:00
Christiaan Dirkx
12120409d5 Move sys::vxworks code to sys::unix 2021-04-19 13:29:22 +02:00
Trevor Spiteri
4c6477026d
Update library/std/src/primitive_docs.rs
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2021-04-19 02:58:38 +02:00
bors
5a4ab26459 Auto merge of #78880 - CDirkx:not_supported, r=joshtriplett
Add `Unsupported` to `std::io::ErrorKind`

I noticed a significant portion of the uses of `ErrorKind::Other` in std is for unsupported operations.
The notion that a specific operation is not available on a target (and will thus never succeed) seems semantically distinct enough from just "an unspecified error occurred", which is why I am proposing to add the variant `Unsupported` to `std::io::ErrorKind`.

**Implementation**:

The following variant will be added to `std::io::ErrorKind`:

```rust
/// This operation is unsupported on this platform.
Unsupported
```
`std::io::ErrorKind::Unsupported` is an error returned when a given operation is not supported on a platform, and will thus never succeed; there is no way for the software to recover. It will be used instead of `Other` where appropriate, e.g. on wasm for file and network operations.

`decode_error_kind` will be updated  to decode operating system errors to `Unsupported`:
- Unix and VxWorks: `libc::ENOSYS`
- Windows: `c::ERROR_CALL_NOT_IMPLEMENTED`
- WASI: `wasi::ERRNO_NOSYS`

**Stability**:
This changes the kind of error returned by some functions on some platforms, which I think is not covered by the stability guarantees of the std? User code could depend on this behavior, expecting `ErrorKind::Other`, however the docs already mention:

> Errors that are `Other` now may move to a different or a new `ErrorKind` variant in the future. It is not recommended to match an error against `Other` and to expect any additional characteristics, e.g., a specific `Error::raw_os_error` return value.

The most recent variant added to `ErrorKind` was `UnexpectedEof` in `1.6.0` (almost 5 years ago), but `ErrorKind` is marked as `#[non_exhaustive]` and the docs warn about exhaustively matching on it, so adding a new variant per se should not be a breaking change.

The variant `Unsupported` itself could be marked as `#[unstable]`, however, because this PR also immediately uses this new variant and changes the errors returned by functions I'm inclined to agree with the others in this thread that the variant should be insta-stabilized.
2021-04-18 20:03:54 +00:00
Ralf Jung
fbfaab2cb7 separate feature flag for unsizing casts in const fn 2021-04-18 19:11:29 +02:00
Ralf Jung
fdad6ab3a3 move 'trait bounds on const fn' to separate feature gate 2021-04-18 18:36:41 +02:00
r00ster
c86ffe9e89
Say that it "may panic" 2021-04-18 18:16:10 +02:00
r00ster
df01b3a67b
Document that index and index_mut can panic 2021-04-18 15:51:16 +02:00
Waffle Lapkin
3ecaf57b29
Slightly change wording and fix typo in vec/mod.rs 2021-04-18 12:32:10 +03:00
Ralf Jung
7a5418dae1 fix aliasing violations in thread_local_const_init 2021-04-18 10:55:09 +02:00
CDirkx
b42e52f2cc Bump to 1.53.0
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-04-18 09:29:24 +02:00
Christiaan Dirkx
0895a693bd Fix test metadata_access_times to also check for Unsupported 2021-04-18 09:29:24 +02:00
Christiaan Dirkx
af0dec2795 Rename NotSupported to Unsupported 2021-04-18 09:29:23 +02:00
Christiaan Dirkx
1b5f117c47 Use NotSupported in more places 2021-04-18 09:29:23 +02:00
CDirkx
86592b9939 Bump since to 1.52.0 2021-04-18 09:29:22 +02:00
Christiaan Dirkx
9f589b023f Update decode_error_kind to decode os errors to NotSupported 2021-04-18 09:29:22 +02:00
Christiaan Dirkx
4a15bd8eaf Add and insta-stabilize std::io::ErrorKind::NotSupported 2021-04-18 09:29:22 +02:00
bors
d7c3386414 Auto merge of #84207 - SimonSapin:deprecate-core-raw, r=dtolnay
Deprecate the core::raw / std::raw module

It only contains the `TraitObject` struct which exposes components of wide pointer. Pointer metadata APIs are designed to replace this: https://github.com/rust-lang/rust/issues/81513
2021-04-18 07:23:54 +00:00
bors
83ca4b7e60 Auto merge of #84061 - AngelicosPhosphoros:issue-75598-add-inline-always-arithmetic, r=nagisa
Add some #[inline(always)] to arithmetic methods of integers

I tried to add it only to methods which return results of intrinsics and don't have any branching.
Branching could made performance of debug builds (`-Copt-level=0`) worse.
Main goal of changes is allowing wider optimizations in `-Copt-level=1`.

Closes: https://github.com/rust-lang/rust/issues/75598

r? `@nagisa`
2021-04-17 23:31:10 +00:00
Scott McMurray
1864970430 Add the try_trait_v2 library basics
No compiler changes as part of this -- just new unstable traits and impls thereof.

The goal here is to add the things that aren't going to break anything, to keep the feature implementation simpler in the next PR.
2021-04-17 11:58:18 -07:00
Josh Triplett
9aa4d068a1 Add documentation to help people find Ipv4Addr::UNSPECIFIED
People looking for `INADDR_ANY` don't always find
`Ipv4Addr::UNSPECIFIED`; add some documentation and an alias to help.
2021-04-16 13:18:04 -07:00
Trevor Spiteri
18955203d3 doc: use U+2212 for minus sign in floating-point -0.0 remarks
Also remove plus sign in `-0.0 == +0.0` to make it a valid expression.
2021-04-16 21:48:41 +02:00
Ralf Jung
9aa6c1e0c9 fix 'const-stable since' for NonZeroU*::new_unchecked 2021-04-16 20:35:14 +02:00
Josh Stone
c020367b82 Document the edition behavior for array.into_iter() 2021-04-16 11:12:01 -07:00
Josh Stone
3dab4e22d4 Skip into_iter() for arrays before 2021 2021-04-16 11:12:01 -07:00
Lukas Kalbertodt
35b1590223 Adjust docs and tests for new IntoIterator impl for arrays 2021-04-16 11:12:01 -07:00
Lukas Kalbertodt
32aaea9c8f Add IntoIterator impl for [T; N] (arrays by value) 2021-04-16 11:12:01 -07:00
bors
0cc00c48d2 Auto merge of #83416 - alexcrichton:const-thread-local, r=sfackler
std: Add a variant of thread locals with const init

This commit adds a variant of the `thread_local!` macro as a new
`thread_local_const_init!` macro which requires that the initialization
expression is constant (e.g. could be stuck into a `const` if so
desired). This form of thread local allows for a more efficient
implementation of `LocalKey::with` both if the value has a destructor
and if it doesn't. If the value doesn't have a destructor then `with`
should desugar to exactly as-if you use `#[thread_local]` given
sufficient inlining.

The purpose of this new form of thread locals is to precisely be
equivalent to `#[thread_local]` on platforms where possible for values
which fit the bill (those without destructors). This should help close
the gap in performance between `thread_local!`, which is safe, relative
to `#[thread_local]`, which is not easy to use in a portable fashion.
2021-04-16 16:36:46 +00:00
Alex Crichton
c6eea222a9 std: Add a variant of thread locals with const init
This commit adds a variant of the `thread_local!` macro as a new
`thread_local_const_init!` macro which requires that the initialization
expression is constant (e.g. could be stuck into a `const` if so
desired). This form of thread local allows for a more efficient
implementation of `LocalKey::with` both if the value has a destructor
and if it doesn't. If the value doesn't have a destructor then `with`
should desugar to exactly as-if you use `#[thread_local]` given
sufficient inlining.

The purpose of this new form of thread locals is to precisely be
equivalent to `#[thread_local]` on platforms where possible for values
which fit the bill (those without destructors). This should help close
the gap in performance between `thread_local!`, which is safe, relative
to `#[thread_local]`, which is not easy to use in a portable fashion.
2021-04-16 09:21:38 -07:00
Dylan DPC
a5ec5cf72a
Rollup merge of #84145 - vojtechkral:vecdeque-binary-search, r=m-ou-se
Address comments for vecdeque_binary_search #78021
2021-04-16 14:08:32 +02:00
bors
5e7bebad1d Auto merge of #84220 - gpluscb:weak_doc, r=jyn514
Correct outdated documentation for rc::Weak

This was overlooked in ~~#50357~~ #51901
2021-04-16 02:31:15 +00:00
Vojtech Kral
44be1c2aa0 VecDeque: Improve doc comments in binary search fns
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-04-15 23:23:46 +02:00
Vojtech Kral
e68680d30d VecDeque: Add partition_point() #78021 2021-04-15 23:23:23 +02:00
Vojtech Kral
bccbf9db1c VecDeque: binary_search_by(): return right away if hit found at back.first() #78021 2021-04-15 23:23:22 +02:00
Simon Sapin
4d683c0292 Allow use of deprecated std::raw in a test for that feature 2021-04-15 19:16:18 +02:00
bors
2962e7c008 Auto merge of #84209 - pickfire:patch-3, r=jyn514
Merge same condition branch in vec spec_extend

Follow up of https://github.com/rust-lang/rust/pull/83726#discussion_r613438246
2021-04-15 15:18:16 +00:00
MarRue
288bd49528 Correct outdated rc::Weak::default documentation 2021-04-15 14:54:39 +02:00
bors
f1ca558db1 Auto merge of #84088 - m-ou-se:stabilize-option-insert, r=m-ou-se
Stabilize option_insert.

FCP finished here: https://github.com/rust-lang/rust/issues/78271#issuecomment-817201319
2021-04-15 12:37:19 +00:00
bors
043d916076 Auto merge of #84198 - mlodato517:patch-1, r=jyn514
Fix small typo in Drop documentation
2021-04-15 04:08:33 +00:00
Ivan Tham
eeac70c567
Merge same condition branch in vec spec_extend 2021-04-15 11:58:02 +08:00
David Tolnay
e9bd80f961
Requires deprecated *and* deprecated_in_future, depending on what stage is building 2021-04-14 19:28:39 -07:00
David Tolnay
28efb22745
s/deprecated_in_future/deprecated/ 2021-04-14 18:44:22 -07:00
Simon Sapin
b80a96c286 Deprecate the core::raw / std::raw module
It only contains the `TraitObject` struct which exposes components
of wide pointer. Pointer metadata APIs are designed to replace this:
https://github.com/rust-lang/rust/issues/81513
2021-04-15 02:32:33 +02:00
Dylan DPC
d783f399e5
Rollup merge of #84177 - ehuss:join_paths-err, r=kennytm
Fix join_paths error display.

On unix, the error from `join_paths` looked like this:

```
path segment contains separator `58`
```

This PR changes it to look like this:

```
path segment contains separator `:`
```
2021-04-15 01:27:53 +02:00
Dylan DPC
80ee7cbb37
Rollup merge of #82492 - CDirkx:sys_common_alloc, r=m-ou-se
Move `std::sys_common::alloc` to new module `std::sys::common`

6b56603e35/library/std/src/sys_common/mod.rs (L7-L13)

It was my impression that the goal for `std::sys` has changed from extracting it into a separate crate to making std work with features. However the fact remains that there is a lot of interdependence between `sys` and `sys_common`, this is because `sys_common` contains two types of code:

- abstractions over the different platform implementations in `std::sys` (for example [`std::sys_common::mutex`](https://github.com/rust-lang/rust/blob/master/library/std/src/sys_common/mutex.rs))
- code shared between platforms (for example [`std::sys_common::alloc`](https://github.com/rust-lang/rust/blob/master/library/std/src/sys_common/alloc.rs))

This PR attempts to address this by adding a new module `common` to `std::sys` which will contain code shared between platforms, `alloc.rs` in this case but more can be moved over in the future.
2021-04-15 01:27:52 +02:00
Mark Lodato
46d2a96fac
Fix small typo in Drop documentation 2021-04-14 16:05:56 -04:00
bors
7537b20626 Auto merge of #83948 - ABouttefeux:lint-nullprt-deref, r=RalfJung
add lint deref_nullptr detecting when a null ptr is dereferenced

fixes #83856
changelog: add lint that detect code like
```rust
unsafe {
      &*core::ptr::null::<i32>()
 };
unsafe {
     addr_of!(std::ptr::null::<i32>())
};
let x: i32 = unsafe {*core::ptr::null()};
let x: i32 = unsafe {*core::ptr::null_mut()};
unsafe {*(0 as *const i32)};
unsafe {*(core::ptr::null() as *const i32)};
```
```
warning: Dereferencing a null pointer causes undefined behavior
 --> src\main.rs:5:26
  |
5 |     let x: i32 = unsafe {*core::ptr::null()};
  |                          ^^^^^^^^^^^^^^^^^^
  |                          |
  |                          a null pointer is dereferenced
  |                          this code causes undefined behavior when executed
  |
  = note: `#[warn(deref_nullptr)]` on by default
```

Limitation:
It does not detect code like
```rust
const ZERO: usize = 0;
unsafe {*(ZERO as *const i32)};
```
or code where `0` is not directly a literal
2021-04-14 18:04:22 +00:00
Christiaan Dirkx
cac0dd63b3 Update documentation 2021-04-14 14:03:00 +02:00
Christiaan Dirkx
905d23b65c Move std::sys_common::alloc to std::sys::common 2021-04-14 13:24:10 +02:00
Eric Huss
a8fbe2f22f Fix join_paths error display. 2021-04-13 14:20:49 -07:00
Cameron Steffen
b319031808 Remove slice diagnostic item 2021-04-13 15:41:13 -05:00
bors
5c1304205b Auto merge of #84135 - rust-lang:GuillaumeGomez-patch-1, r=kennytm
Improve code example for length comparison

Small fix/improvement: it's much safer to check that you're under the length of an array rather than chacking that you're equal to it. It's even more true in case you update the length of the array while iterating.
2021-04-13 14:03:49 +00:00
AnthonyMikh
7efba4f982 Implement indexing slices with pairs of ops::Bound<usize> 2021-04-13 09:57:24 -04:00
Dylan DPC
cf67c9bbf7
Rollup merge of #84121 - workingjubilee:stabilize-btree-retain, r=dtolnay
Stabilize BTree{Map,Set}::retain

Closes #79025.
FCP concluded here: https://github.com/rust-lang/rust/issues/79025#issuecomment-817201302

This is an approved feature on BTree{Map,Set} to mirror a functionality in Hash{Map,Set}, which has had some adequate testing since its introduction in https://github.com/rust-lang/rust/pull/79026 and doesn't seem to have caused any problems since.
2021-04-13 11:10:42 +02:00
Dylan DPC
3d6a364e33
Rollup merge of #84084 - m-ou-se:stabilize-zero, r=scottmcm
Stabilize duration_zero.

FCP here: https://github.com/rust-lang/rust/issues/73544#issuecomment-817201305
2021-04-13 11:10:40 +02:00