Commit graph

813 commits

Author SHA1 Message Date
bors
8ca930aa26 Auto merge of #79229 - sdroege:slice-fill-memset, r=dtolnay
Add "memset" as doc alias to slice::fill()

Similar to 53f969dfd1 and should make it easier for people coming from C to find this function.
2020-11-22 04:27:03 +00:00
Dylan DPC
6cd02a85f1
Rollup merge of #77844 - RalfJung:zst-box, r=nikomatsakis
clarify rules for ZST Boxes

LLVM's rules around `getelementptr inbounds` with offset 0 are a bit annoying, and as a consequence we have no choice but say that a `Box<()>` pointing to previously allocated memory that has since been freed is UB. Clarify the docs to reflect this.

This is based on conversations on the LLVM mailing list.
* Here's my initial mail: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130452.html
* The first email of the March part of that thread: https://lists.llvm.org/pipermail/llvm-dev/2019-March/130831.html
* First email of the April part: https://lists.llvm.org/pipermail/llvm-dev/2019-April/131693.html

The conclusion for me at least was that `getelementptr inbounds` with offset 0 is *not* the identity function, but can sometimes return `poison` even when the input is a regular pointer -- specifically, it returns `poison` when this pointer points into something that LLVM "knows has been deallocated", i.e., a former LLVM-managed allocation. It is however the identity function on pointers obtained by casting integers.

Note that there [are formal proposals](https://people.mpi-sws.org/~jung/twinsem/twinsem.pdf) for LLVM semantics where `getelementptr inbounds` with offset 0 isn't quite the identity function but never returns `poison` (it affects the provenance of the pointer but in a way that doesn't matter if this pointer is never used for memory accesses), and indeed this is likely necessary to consistently describe LLVM semantics. But with the informal LLVM LangRef that we have right now, and with LLVM devs insisting otherwise, it seems unwise to rely on this.
2020-11-21 19:44:07 +01:00
bors
29a74e6285 Auto merge of #79222 - yoshuawuyts:slice-fill-with, r=m-ou-se
Add `core::slice::fill_with`

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

As suggested by `@m-ou-se` in https://github.com/rust-lang/rust/issues/70758#issuecomment-726838099 this implements `slice::fill_with` as a counterpart to `slice::fill`. This mirrors `Vec::resize` and `Vec::resize_with`. Thanks!

r? `@m-ou-se`
2020-11-21 08:15:16 +00:00
Sebastian Dröge
7a3b331587 Add "memset" as doc alias to slice::fill() 2020-11-20 15:19:47 +02:00
Yoshua Wuyts
a64d0d4774 Add core::slice::fill_with 2020-11-20 14:12:54 +01:00
Ralf Jung
a7677f7714 reference NonNull::dangling 2020-11-20 11:09:49 +01:00
bors
74285eb3a8 Auto merge of #78088 - fusion-engineering-forks:panic-fmt-lint, r=estebank
Add lint for panic!("{}")

This adds a lint that warns about `panic!("{}")`.

`panic!(msg)` invocations with a single argument use their argument as panic payload literally, without using it as a format string. The same holds for `assert!(expr, msg)`.

This lints checks if `msg` is a string literal (after expansion), and warns in case it contained braces. It suggests to insert `"{}", ` to use the message literally, or to add arguments to use it as a format string.

![image](https://user-images.githubusercontent.com/783247/96643867-79eb1080-1328-11eb-8d4e-a5586837c70a.png)

This lint is also a good starting point for adding warnings about `panic!(not_a_string)` later, once [`panic_any()`](https://github.com/rust-lang/rust/pull/74622) becomes a stable alternative.
2020-11-20 03:40:20 +00:00
Dylan DPC
5adc00fbb8
Rollup merge of #79217 - yoshuawuyts:copy_from_slice-alias, r=Mark-Simulacrum
Add the "memcpy" doc alias to slice::copy_from_slice

[RFC1419](https://github.com/rust-lang/rfcs/pull/1419) describes `slice::copy_from_slice` as a "safe memcpy". This enables people searching for `memcpy` to find the `slice::copy_from_slice` method. Thanks!

## Screenshots

This is currently the output when searching for "memcpy" -- `copy_from_slice` is safe, and should be part of this list.

![Screenshot_2020-11-19 Results for memcpy - Rust](https://user-images.githubusercontent.com/2467194/99722964-c9e8fe80-2ab1-11eb-82a5-4afe703a0eea.png)
2020-11-19 23:58:50 +01:00
Dylan DPC
169e2212d9
Rollup merge of #79194 - est31:array_into_iter_slice, r=scottmcm
Make as{_mut,}_slice on array::IntoIter public

The functions are useful in cases where you want to move data out of the IntoIter in bulk, by transmute_copy'ing the slice and then forgetting the IntoIter.

In the compiler, this is useful for providing a sped up IntoIter implementation. One can alternatively provide a separate allocate_array function but one can avoid duplicating some logic by passing everything through the generic iterator using interface.

As per suggestion in https://github.com/rust-lang/rust/pull/78569/files#r526506964
2020-11-19 23:58:45 +01:00
Dylan DPC
c2a277c11d
Rollup merge of #79123 - CDirkx:128-bits, r=Mark-Simulacrum
Add u128 and i128 integer tests

Add the missing integer tests for u128 and i128 for completeness with the other integer types.
2020-11-19 23:58:35 +01:00
Dylan DPC
138e96d222
Rollup merge of #79119 - jamesmunns:patch-1, r=Mark-Simulacrum
Clarify availability of atomic operations

This was noticed while we were updating the embedded rust book: https://github.com/rust-embedded/book/pull/273/files

These targets do natively have atomic load/stores, but do not support CAS operations.
2020-11-19 23:58:33 +01:00
Yoshua Wuyts
53f969dfd1 Add the "memcpy" doc alias to slice::copy_from_slice 2020-11-19 21:52:08 +01:00
est31
de08df26d3 Make as{_mut,}_slice on array::IntoIter public 2020-11-19 08:28:49 +01:00
Aaron Hill
5d26145dee
Remove semicolon from internal err macro
This macro is used in expression position (a match arm), and only
compiles because of #33953

Regardless of what happens with that issue, this makes the
usage of the macro less confusing at the call site.
2020-11-18 23:10:35 -05:00
Mara Bos
126d88bd12
Rollup merge of #79114 - andjo403:nonzero_leading_trailing_zeros, r=m-ou-se
add trailing_zeros and leading_zeros to non zero types

as a way towards being able to use the optimized intrinsics ctlz_nonzero and cttz_nonzero from stable.

have not crated any tracking issue if this is not a solution that is wanted
2020-11-18 15:46:31 +01:00
Andreas Jonson
9bbc4c16d3 add trailing_zeros and leading_zeros to non zero types 2020-11-17 19:54:29 +01:00
James Munns
69477f50d8
Clarify availability of atomic operations
This was noticed while we were updating the embedded rust book: https://github.com/rust-embedded/book/pull/273/files

These targets do natively have atomic load/stores, but do not support CAS operations.
2020-11-17 01:38:53 +01:00
Mara Bos
c0a9bf9336
Rollup merge of #78769 - est31:remove_lifetimes, r=KodrAus
Remove unneeded lifetimes in array/mod.rs
2020-11-16 17:26:29 +01:00
Mara Bos
5bbf75da78
Rollup merge of #77691 - exrook:rename-layouterr, r=KodrAus
Rename/Deprecate LayoutErr in favor of LayoutError

Implements rust-lang/wg-allocators#73.

This patch renames LayoutErr to LayoutError, and uses a type alias to support users using the old name.

The new name will be instantly stable in release 1.49 (current nightly), the type alias will become deprecated in release 1.51 (so that when the current nightly is 1.51, 1.49 will be stable).

This is the only error type in `std` that ends in `Err` rather than `Error`, if this PR lands all stdlib error types will end in `Error` 🥰
2020-11-16 17:26:17 +01:00
Mara Bos
de0aa6169f
Rollup merge of #76339 - CDirkx:structural-match-range, r=Mark-Simulacrum
Test structural matching for all range types

As of #70166 all range types (`core::ops::Range` etc.) can be structurally matched upon, and by extension used in const generics. In reference to the fact that this is a publicly observable property of these types, and thus falls under the Rust stability guarantees of the standard library, a regression test was added in #70283.

This regression test was implemented by me by testing for the ability to use the range types within const generics, but that is not the actual property the std guarantees now (const generics is still unstable). This PR addresses that situation by adding extra tests for the range types that directly test whether they can be structurally matched upon.

Note: also adds the otherwise unrelated test `test_range_to_inclusive` for completeness with the other range unit tests
2020-11-16 17:26:13 +01:00
pubfnbar
c03dfa6671 Implement Index[Mut] for arrays
Adds implementations of `Index` and `IndexMut` for arrays that simply forward to the slice indexing implementation.
2020-11-16 09:05:15 -05:00
Christiaan Dirkx
6554086526 Add u128 and i128 integer tests 2020-11-14 20:27:08 +01:00
Jonas Schievink
62f0a78056
Rollup merge of #78216 - workingjubilee:duration-zero, r=m-ou-se
Duration::zero() -> Duration::ZERO

In review for #72790, whether or not a constant or a function should be favored for `#![feature(duration_zero)]` was seen as an open question. In https://github.com/rust-lang/rust/issues/73544#issuecomment-691701670 an invitation was opened to either stabilize the methods or propose a switch to the constant value, supplemented with reasoning. Followup comments suggested community preference leans towards the const ZERO, which would be reason enough.

ZERO also "makes sense" beside existing associated consts for Duration. It is ever so slightly awkward to have a series of constants specifying 1 of various units but leave 0 as a method, especially when they are side-by-side in code. It seems unintuitive for the one non-dynamic value (that isn't from Default) to be not-a-const, which could hurt discoverability of the associated constants overall. Elsewhere in `std`, methods for obtaining a constant value were even deprecated, as seen with [std::u32::min_value](https://doc.rust-lang.org/std/primitive.u32.html#method.min_value).

Most importantly, ZERO costs less to use. A match supports a const pattern, but const fn can only be used if evaluated through a const context such as an inline `const { const_fn() }` or a `const NAME: T = const_fn()` declaration elsewhere. Likewise, while https://github.com/rust-lang/rust/issues/73544#issuecomment-691949373 notes `Duration::zero()` can optimize to a constant value, "can" is not "will". Only const contexts have a strong promise of such. Even without that in mind, the comment in question still leans in favor of the constant for simplicity. As it costs less for a developer to use, may cost less to optimize, and seems to have more of a community consensus for it, the associated const seems best.

r? ```@LukasKalbertodt```
2020-11-11 20:58:52 +01:00
Jonas Schievink
42fae6bb65
Rollup merge of #78910 - tmiasko:intrinsics-link, r=jyn514
Fix links to stabilized versions of some intrinsics
2020-11-10 14:45:34 +01:00
cyqsimon
bf982a52f6 Bad grammar 2020-11-09 23:52:33 +08:00
cyqsimon
2633e93aa0 Clarified description of write! macro 2020-11-09 23:00:31 +08:00
Dylan DPC
d69ee57f97
Rollup merge of #77640 - ethanboxx:int_error_matching_attempt_2, r=KodrAus
Refactor IntErrorKind to avoid "underflow" terminology

This PR is a continuation of #76455

# Changes

- `Overflow` renamed to `PosOverflow` and `Underflow` renamed to `NegOverflow` after discussion in #76455
- Changed some of the parsing code to return `InvalidDigit` rather than `Empty` for strings "+" and "-". https://users.rust-lang.org/t/misleading-error-in-str-parse-for-int-types/49178
- Carry the problem `char` with the `InvalidDigit` variant.
- Necessary changes were made to the compiler as it depends on `int_error_matching`.
- Redid tests to match on specific errors.

r? ```@KodrAus```
2020-11-09 01:13:25 +01:00
Tomasz Miąsko
f1739575ef Fix links to stabilized versions of some intrinsics 2020-11-09 00:00:00 +00:00
Mara Bos
96975e515a
Rollup merge of #78852 - camelid:intra-doc-bonanza, r=jyn514
Convert a bunch of intra-doc links

An intra-doc link bonanza!

This was accomplished using a bunch of trial-and-error with sed.
2020-11-08 13:36:28 +01:00
Mara Bos
3541280753
Rollup merge of #78788 - jhpratt:isize-impl-fix, r=m-ou-se
Correct unsigned equivalent of isize to be usize

See [#74913 (comment)](https://github.com/rust-lang/rust/issues/74913#issuecomment-722334456) for why this matters. Apparently it hasn't been used anywhere else, though CI will tell for sure.
2020-11-08 13:36:18 +01:00
Mara Bos
2967e58be3
Rollup merge of #78728 - a1phyr:const_cell_into_inner, r=dtolnay
Constantify `UnsafeCell::into_inner` and related

Tracking issue: #78729

This PR constantifies:
- `UnsafeCell::into_inner`
- `Cell::into_inner`
- `RefCell::into_inner`
- `Atomic*::into_inner`

r? `````@dtolnay`````
2020-11-08 13:36:14 +01:00
Mara Bos
bdeace9f4e
Rollup merge of #76227 - CDirkx:const-poll, r=KodrAus
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](https://github.com/rust-lang/rust/pull/76198).

Possible because of the recent stabilization of const control flow.

Part of #76225.
2020-11-08 13:35:58 +01:00
Mara Bos
1f034f77bc
Rollup merge of #76097 - pickfire:stabilize-spin-loop, r=KodrAus
Stabilize hint::spin_loop

Partially fix #55002, deprecate in another release

r? ``````@KodrAus``````
2020-11-08 13:35:54 +01:00
Camelid
8258cf285f Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
Christiaan Dirkx
6728240f36 Test structural matching for all range types
Adds structural match tests for all range types.

Note: also adds the otherwise unrelated test `test_range_to_inclusive` for completeness
2020-11-07 01:31:44 +01:00
Yuki Okushi
8f70cad032
Rollup merge of #78730 - kornelski:not-inverse, r=Dylan-DPC
Expand explanation of reverse_bits

Original documentation only rephrased the function name
2020-11-07 01:02:20 +09:00
Ivan Tham
e8b5be5dff Stabilize hint::spin_loop
Partially fix #55002, deprecate in another release

Co-authored-by: Ashley Mannix <kodraus@hey.com>

Update stable version for stabilize_spin_loop

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Use better example for spinlock

As suggested by KodrAus

Remove renamed_spin_loop already available in master

Fix spin loop example
2020-11-06 23:41:55 +08:00
bors
f92b931045 Auto merge of #77856 - GuillaumeGomez:automatic-links-lint, r=jyn514,ollie27
Add non_autolinks lint

Part of #77501.

r? `@jyn514`
2020-11-06 04:17:41 +00:00
Jacob Pratt
8078474b0a
Correct unsigned equivalent of isize to be usize 2020-11-05 16:52:32 -05:00
Guillaume Gomez
99200f760b Fix even more URLs 2020-11-05 20:11:29 +01:00
est31
5058cad41e Remove unneeded lifetimes in array/mod.rs 2020-11-05 11:49:27 +01:00
Mara Bos
f383e4f1d9
Rollup merge of #78757 - camelid:crate-link-text, r=jyn514
Improve and clean up some intra-doc links
2020-11-05 10:30:02 +01:00
Mara Bos
86e6afafe1
Rollup merge of #78738 - sasurau4:test/move-range-test-to-library-core, r=jyn514
Move range in ui test to ops test in library/core

Helps with #76268

r? ````@matklad````
2020-11-05 10:29:56 +01:00
Mara Bos
29fad213b2
Rollup merge of #78735 - danielhenrymantilla:simplify-unsafecell-getmut, r=RalfJung
Simplify the implementation of `get_mut` (no unsafe)

Quick PR to reduce one use of `unsafe` pointed out in the previous PR

r? ````@RalfJung````
2020-11-05 10:29:54 +01:00
Mara Bos
43e1b58bcc
Rollup merge of #78716 - est31:array_traits, r=Dylan-DPC
Array trait impl comment/doc fixes

Two small doc/comment fixes regarding trait implementations on arrays.
2020-11-05 10:29:46 +01:00
Guillaume Gomez
9d114506c6 Rename lint to non_autolinks 2020-11-05 10:22:08 +01:00
Guillaume Gomez
60caf51b0d Rename automatic_links to url_improvements 2020-11-05 10:22:08 +01:00
Guillaume Gomez
55b4d21e25 Fix automatic_links warnings 2020-11-05 10:22:08 +01:00
chansuke
f9b139f9c4 Add mod nan for test 2020-11-05 12:57:18 +09:00
Camelid
3084a55d54 Don't use crate in link text
`crate::` -> `core::`

It looks weird to have `crate::` in the link text and we use the actual
crate name everywhere else.

If anyone is curious, I used this Vim command to update all the links:

    %s/\(\s\)\[`crate::\(.*\)`\]/\1[`core::\2`](crate::\2)/g
2020-11-04 18:44:40 -08:00