Commit graph

3150 commits

Author SHA1 Message Date
Ian Jackson
e78b5012f5 Provide NonZero_c_* integers
I'm pretty sure I am going want this for #73125 and it seems like an
omission that would be in any case good to remedy.

It's a shame we don't have competent token pasting and case mangling
for use in macro_rules!.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-02-17 20:48:22 +00:00
Ian Jackson
d6b9d9a1d6 std::src::os::raw: Refactor, introducing macro type_alias!
This file contained a lot of repetitive code.  This was about to get
considerably worse, with introduction of a slew of new aliases.

No functional change.  I've eyeballed the docs and they don't seem to
have changed either.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-02-17 20:36:59 +00:00
Guillaume Gomez
f46bd72e5f
Rollup merge of #82198 - SkiFire13:optimize-iter-is-sorted, r=sfackler
Use internal iteration in Iterator::is_sorted_by
2021-02-17 20:38:04 +01:00
Guillaume Gomez
8e6bc14f52
Rollup merge of #82196 - Manishearth:display-caveat, r=m-ou-se
Add caveat to Path::display() about lossiness

It's worth calling out that this API may do a lossy display.

r? ```@m-ou-se```
2021-02-17 20:38:03 +01:00
Guillaume Gomez
16481a2857
Rollup merge of #82169 - not-an-aardvark:assert-lazy-format-expressions, r=sfackler
Document that `assert!` format arguments are evaluated lazily

It can be useful to do some computation in `assert!` format arguments, in order to get better error messages. For example:

```rust
assert!(
    some_condition,
    "The state is invalid. Details: {}",
    expensive_call_to_get_debugging_info(),
);
```

It seems like `assert!` only evaluates the format arguments if the assertion fails, which is useful but doesn't appear to be documented anywhere. This PR documents the behavior and adds some tests.
2021-02-17 20:38:00 +01:00
Guillaume Gomez
253631d73f
Rollup merge of #82094 - gilescope:to_digit_speedup2, r=m-ou-se
To digit simplification

I found out the other day that all the ascii digits have the first four bits as one would hope them to. (Eg. char `2` ends `0b0010`). There are two bits to indicate it's in the digit range ( `0b0011_0000`). If it is a true digit then all the higher bits aside from these two will be 0 (as ascii is the lowest part of the unicode u32 spectrum). So XORing with `0b11_0000` should mean we either get the number 0-9 or alternativly we get a larger number in the u32 space. If we get something that's not 0-9 then it will be discarded as it will be greater than the radix.

The code seems so fast though that there's quite a lot of noise in the benchmarks so it's not that easy to prove conclusively that it's faster as well as less instructions.

The non-fast path I was toying with as well wondering if we could do this as then we'd only have one return and less instructions still:
```
           match self {
                'a'..='z' => self as u32 - 'a' as u32 + 10,
                'A'..='Z' => self as u32 - 'A' as u32 + 10,
                _ => { radix = 10; self as u32 ^ ASCII_DIGIT_MASK},
            }
```

Here's the [godbolt](https://godbolt.org/z/883c9n).

( H/T to ``@byteshadow`` for pointing out xor was what I needed)
2021-02-17 20:37:55 +01:00
Yonggang Luo
fa23ddf6e6 Expose force_quotes on Windows.
Quotes the arg and not quotes the arg have different effect on Windows when the program called
are msys2/cygwin program.
Refer to https://github.com/msys2/MSYS2-packages/issues/2176

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
2021-02-17 17:54:04 +00:00
Thom Chiovoloni
404da0bc90 Add link to tracking issue #82223 2021-02-17 09:04:03 -08:00
Thom Chiovoloni
2711b011e6 Rename Result::ok_or_err to Result::into_ok_or_err 2021-02-17 08:54:52 -08:00
Thom Chiovoloni
7d303661cd Fix doc link for slice::binary_search 2021-02-17 08:52:08 -08:00
Thom Chiovoloni
f688bee4ec Add a Result::ok_or_err method to extract a T from Result<T, T> 2021-02-17 08:51:58 -08:00
hyd-dev
43aed7441e
[libtest] Run the test synchronously when hitting thread limit 2021-02-17 21:38:25 +08:00
bjorn3
4fa9e08e3d Enable the tests on Arm Linux too 2021-02-17 10:01:39 +01:00
Giacomo Stevanato
61bb1836f8 Optimize Iterator::is_sorted_by by using Iterator::all for internal iteration 2021-02-16 21:49:56 +01:00
Manish Goregaokar
a98b22c837 Add caveat to Path::display() about lossiness 2021-02-16 11:45:46 -08:00
Peter Todd
3a03cbc9dd
[Minor] Update discriminant_value docs 2021-02-16 08:16:31 -05:00
bjorn3
dfdadad228 Ignore Atomic*::fetch_{min,max} tests on ARM 2021-02-16 09:45:27 +01:00
bors
f1c47c79fe Auto merge of #82058 - gilescope:to_digit_speedup, r=lcnr
no need to check assertion on fast path as will always hold.

V small change. Easy to review though!
2021-02-16 08:38:11 +00:00
Teddy Katz
cb653b100c Document that assert! format arguments are evaluated lazily
It can be useful to do some computation in `assert!` format arguments, in order to get better error messages. For example:

```rust
assert!(
    some_condition,
    "The state is invalid. Details: {}",
    expensive_call_to_get_debugging_info(),
);
```

It seems like `assert!` only evaluates the format arguments if the assertion fails, which is useful but doesn't appear to be documented anywhere. This PR documents the behavior and adds some tests.
2021-02-16 00:55:46 -05:00
Andrea Nall
67fcaaaa7a a few more diagnostic items 2021-02-16 02:32:21 +00:00
Andrea Nall
c6bb62810a requested/proposed changes 2021-02-15 22:59:47 +00:00
Lukas Kalbertodt
c675af82b4
Add internal collect_into_array[_unchecked] to remove duplicate code
This does not suggest adding such a function to the public API. This is
just for the purpose of avoiding duplicate code. Many array methods
already contained the same kind of code and there are still many array
related methods to come (e.g. `Iterator::{chunks, map_windows, next_n,
...}`) which all basically need this functionality. Writing custom
`unsafe` code for each of those seems not like a good idea.
2021-02-15 17:52:33 +01:00
Jonas Schievink
c87ef218f9
Rollup merge of #82120 - sfackler:arguments-as-str, r=dtolnay
Stabilize Arguments::as_str

Closes #74442
2021-02-15 16:07:08 +01:00
Jonas Schievink
2030a54f9d
Rollup merge of #82119 - m-ou-se:typo, r=dtolnay
Fix typo in link to CreateSymbolicLinkW documentation.
2021-02-15 16:07:06 +01:00
Jonas Schievink
b0bd056bc9
Rollup merge of #82118 - lukaslueg:env_decl, r=m-ou-se
Add missing env!-decl variant

Resolves #82117
2021-02-15 16:07:05 +01:00
Jonas Schievink
7842b5d2ec
Rollup merge of #82063 - NULLx76:fix-minor-typo, r=jonas-schievink
Fixed minor typo in catch_unwind docs

Changed "a an exception" to "an exception" inside of the `std::panic::catch_unwind` docs.
2021-02-15 16:06:58 +01:00
Jonas Schievink
c7ebc590da
Rollup merge of #82060 - taiki-e:typo, r=m-ou-se
Fix typos in BTreeSet::{first, last} docs

map -> set
2021-02-15 16:06:56 +01:00
Jonas Schievink
bd0e8a5df3
Rollup merge of #81975 - Amanieu:seal2, r=m-ou-se
Seal the CommandExt, OsStrExt and OsStringExt traits

A crater run (https://github.com/rust-lang/rust/pull/81213#issuecomment-767651811) has shown that this does not break any existing code.

This also unblocks #77728.

Based on #81213.

r? ````@m-ou-se````
cc ````@lygstate````
2021-02-15 16:06:54 +01:00
Simon Sapin
cac71bf809 Use local path for already-imported function
This module has `use super::*;` at the top.

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2021-02-15 14:27:52 +01:00
Simon Sapin
cf000f0408 Pointer metadata: add tracking issue number 2021-02-15 14:27:51 +01:00
Simon Sapin
5ade3fe32c Add a ThinBox library as a libcore test for pointer metadata APIs 2021-02-15 14:27:51 +01:00
Simon Sapin
21ceebf296 Fix intra-doc link to raw pointer method
CC https://github.com/rust-lang/rust/pull/80181
2021-02-15 14:27:50 +01:00
Simon Sapin
642486c2b2 Fix libcore unit tests in stage 0 2021-02-15 14:27:48 +01:00
Simon Sapin
3ea7f1504c More doc-comments for pointer metadata APIs 2021-02-15 14:27:34 +01:00
Simon Sapin
787f4de6ab Use new pointer metadata API inside libcore instead of manual transmutes 2021-02-15 14:27:34 +01:00
Simon Sapin
c0e3a1b096 Add to_raw_parts methods to *const, *mut, and NonNull
These are not named `into_` because they do not consume their receiver
since raw pointers are `Copy`.
2021-02-15 14:27:33 +01:00
Simon Sapin
937d580a25 Add ptr::from_raw_parts, ptr::from_raw_parts_mut, and NonNull::from_raw_parts
The use of module-level functions instead of associated functions
on `<*const T>` or `<*mut T>` follows the precedent of
`ptr::slice_from_raw_parts` and `ptr::slice_from_raw_parts_mut`.
2021-02-15 14:27:31 +01:00
Simon Sapin
9ab83b9338 Add size_of, align_of, and layout methods to DynMetadata 2021-02-15 14:27:17 +01:00
Simon Sapin
b1e15fa8a2 Parameterize DynMetadata over its dyn SomeTrait type 2021-02-15 14:27:16 +01:00
Simon Sapin
696b239f72 Add ptr::Pointee trait (for all types) and ptr::metadata function
RFC: https://github.com/rust-lang/rfcs/pull/2580
2021-02-15 14:27:12 +01:00
Stein Somers
342aa694f9 BTree: move more shared iterator code into navigate.rs 2021-02-15 10:56:22 +01:00
Squirrel
d2ba68b24e
Update methods.rs
Remove unused const
2021-02-15 07:39:15 +00:00
Squirrel
17e238d78e
Use wrapping sub
Co-authored-by: Mara <m-ou.se@m-ou.se>
2021-02-15 07:35:28 +00:00
Andrea Nall
5ef202520f add diagnostic items
Add diagnostic items to the following types:
  OsString (os_string_type)
  PathBuf (path_buf_type)
  Owned (to_owned_trait)

As well as the to_vec method on slice/[T]
2021-02-15 02:27:28 +00:00
Steven Fackler
4613b3764c Stabilize Arguments::as_str
Closes #74442
2021-02-14 17:48:51 -05:00
Alphyr
a357d86b7c Hide internals items in documentation
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-02-14 23:39:43 +01:00
Benoît du Garreau
546d062820 Apply suggestions
- Move `assert_failed` to core::panicking`
- Make `assert_failed` use an enum instead of a string
2021-02-14 23:39:42 +01:00
Benoît du Garreau
f138e260a0 Apply suggestion 2021-02-14 23:39:42 +01:00
Benoît du Garreau
52197d356c Fix UI tests and merge assert_eq and assert_ne internal functions 2021-02-14 23:39:31 +01:00
lukaslueg
3d7fcfff76
Update library/core/src/macros/mod.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-02-14 23:33:43 +01:00
Mara Bos
1aa965101c Fix typo in link to CreateSymbolicLinkW documentation. 2021-02-14 23:16:45 +01:00
Mara Bos
053769dd53 Use #[rustc_inherit_overflow_checks] instead of Add::add etc. 2021-02-14 23:06:36 +01:00
Benoît du Garreau
bbad2b2182 Improve assert_eq! and assert_ne!
It should improve compile times and reduce instruction cache use by moving the
panic formatting to a monomorphised function
2021-02-14 23:04:41 +01:00
Lukas Lueg
dee54244a6 Add missing env!-decl variant
Resolves #82117
2021-02-14 22:39:47 +01:00
Mara Bos
daa371d189 Only define rustc_diagnostic_item format_macro in not(test). 2021-02-14 20:03:13 +01:00
Giles Cope
33d8b04568
Move const def nearer usage. 2021-02-14 18:23:30 +00:00
Mara Bos
a428ab17ab Improve suggestion for panic!(format!(..)). 2021-02-14 18:52:47 +01:00
Giles Cope
845c14db05
Simpler way to convert to digit 2021-02-14 17:06:16 +00:00
Dylan DPC
4e888bf403
Rollup merge of #81919 - ssomers:btree_cleanup_comments, r=Mark-Simulacrum
BTreeMap: fix internal comments

Salvaged from #81372

r? `@Mark-Simulacrum`
2021-02-14 16:54:49 +01:00
bjorn3
d1a541e342 Add tests for Atomic*::fetch_{min,max} 2021-02-14 11:31:33 +01:00
bors
b86674e7cc Auto merge of #81956 - ssomers:btree_post_75200, r=Mark-Simulacrum
BTree: remove outdated traces of coercions

The introduction of `marker::ValMut` (#75200) meant iterators no longer see mutable keys but their code still pretends it does. And settle on the majority style `Some(unsafe {…})` over `unsafe { Some(…) }`.

r? `@Mark-Simulacrum`
2021-02-14 04:53:24 +00:00
bors
8e54a21139 Auto merge of #81238 - RalfJung:copy-intrinsics, r=m-ou-se
directly expose copy and copy_nonoverlapping intrinsics

This effectively un-does https://github.com/rust-lang/rust/pull/57997. That should help with `ptr::read` codegen in debug builds (and any other of these low-level functions that bottoms out at `copy`/`copy_nonoverlapping`), where the wrapper function will not get inlined. See the discussion in https://github.com/rust-lang/rust/pull/80290 and https://github.com/rust-lang/rust/issues/81163.

Cc `@bjorn3` `@therealprof`
2021-02-13 20:30:07 +00:00
Matthew Jasper
9bbd3e0f8e Remove ProjectionTy::from_ref_and_name 2021-02-13 19:29:55 +00:00
bors
3c10a880ec Auto merge of #81494 - cuviper:btree-node-init, r=Mark-Simulacrum
Initialize BTree nodes directly in the heap

We can avoid any stack-local nodes entirely by using `Box::new_uninit`, and since the nodes are mostly `MaybeUninit` fields, we only need a couple of actual writes before `assume_init`. This should help with the stack overflows in #81444, and may also improve performance in general.

r? `@Mark-Simulacrum`
cc `@ssomers`
2021-02-13 17:29:22 +00:00
Victor Roest
ee9709fae6
Fixed minor typo in catch_unwind docs
Changed 'a an exception' to 'an exception'
2021-02-13 16:59:06 +01:00
Taiki Endo
dd9db236cd Fix typos in BTreeSet::{first, last} docs 2021-02-13 22:49:46 +09:00
Giles Cope
b70428b9fb
no need to check assertion on fast path. 2021-02-13 12:25:56 +00:00
bors
3158857297 Auto merge of #81854 - the8472:specialize-clone-slice, r=Mark-Simulacrum
specialize slice::clone_from_slice() for T: Copy
2021-02-13 10:55:19 +00:00
Yuki Okushi
0ca5fd7ebc
Rollup merge of #82050 - hbina:fix/added-test-to-drain-empty-vec, r=dtolnay
Added tests to drain an empty vec

Discovered this kind of issue in an unrelated library.
The author copied the tests from here and AFAIK, there are no tests for this particular case.

https://github.com/LeonineKing1199/minivec/pull/19

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-02-13 16:36:52 +09:00
Yuki Okushi
2673026995
Rollup merge of #82041 - notriddle:shared-from-slice-docs, r=m-ou-se
Add docs for shared_from_slice From impls

The advantage of making these docs is mostly in pointing out that these
functions all make new allocations and copy/clone/move the source into them.

These docs are on the function, and not the `impl` block, to avoid showing
the "[+] show undocumented items" button.

CC #51430
2021-02-13 16:36:51 +09:00
Yuki Okushi
4cb381037e
Rollup merge of #81811 - schteve:fix_vec_retain_doc_test, r=m-ou-se
Fix doc test for Vec::retain(), now passes clippy::eval_order_dependence

Doc test for Vec::retain() works correctly but is flagged by clippy::eval_order_dependence. Fix avoids the issue by using an iterator instead of an index.
2021-02-13 16:36:40 +09:00
Hanif Bin Ariffin
fa9af6a9be Added tests to drain an empty vec
Discovered this kind of issue in an unrelated library.
The author copied the tests from here and AFAIK, there are no tests for this particular case.

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-02-13 11:18:36 +08:00
dylni
fe4fe19ddc Update new usage of assert_len 2021-02-12 22:03:39 -05:00
dylni
5d519eaa6e Rename Range::ensure_subset_of to slice::range 2021-02-12 22:01:04 -05:00
dylni
cb647f3e8e Fix possible soundness issue in ensure_subset_of 2021-02-12 22:01:04 -05:00
dylni
9d29793614 Improve design of assert_len 2021-02-12 22:01:04 -05:00
Dylan DPC
54013fe59e
Rollup merge of #82023 - MikailBag:boxed-docs-unallow, r=jyn514
Remove unnecessary lint allow attrs on example

It seems they are not needed anymore.
2021-02-12 22:53:37 +01:00
Dylan DPC
354f19cf24
Rollup merge of #81850 - the8472:env-rwlock, r=m-ou-se
use RWlock when accessing os::env

Multiple threads modifying the current process environment is fairly uncommon. Optimize for the more common read case.

r? ````@m-ou-se````
2021-02-12 22:53:33 +01:00
Dylan DPC
0cfba2fd09
Rollup merge of #81741 - sdroege:zip-trusted-random-access-specialization-panic-safety, r=KodrAus
Increment `self.index` before calling `Iterator::self.a.__iterator_ge…

…`t_unchecked` in `Zip` `TrustedRandomAccess` specialization

Otherwise if `Iterator::self.a.__iterator_get_unchecked` panics the
index would not have been incremented yet and another call to
`Iterator::next` would read from the same index again, which is not
allowed according to the API contract of `TrustedRandomAccess` for
`!Clone`.

Fixes https://github.com/rust-lang/rust/issues/81740
2021-02-12 22:53:32 +01:00
Dylan DPC
8280abc57b
Rollup merge of #81012 - VillSnow:stabilize_partition_point, r=matklad
Stabilize the partition_point feature

Stabilize the partition_point feature.
Tracking Issue: #73831
First PR: #73577
2021-02-12 22:53:28 +01:00
Michael Howell
7fafa4d0ca Add docs for shared_from_slice From impls
The advantage of making these docs is mostly in pointing out that these
functions all make new allocations and copy/clone/move the source into them.

These docs are on the function, and not the `impl` block, to avoid showing
the "[+] show undocumented items" button.

CC #51430
2021-02-12 14:02:23 -07:00
Stein Somers
5a58cf4943 Use raw ref macros as in #80886 2021-02-12 12:14:17 -08:00
Josh Stone
48e5866d11 Initialize BTree nodes directly in the heap 2021-02-12 12:14:17 -08:00
Giles Cope
daa55acdb0
Slightly more explicit 2021-02-12 13:42:42 +00:00
VillSnow
afdc8c7918 stabilize partition_point 2021-02-12 21:57:17 +09:00
VillSnow
de21cdf792 update documents 2021-02-12 21:57:17 +09:00
Yuki Okushi
0b6876cbe7
Rollup merge of #79983 - petar-dambovaliev:master, r=Dylan-DPC
fix indefinite article in cell.rs
2021-02-12 19:32:06 +09:00
Mikail Bagishov
f546633cf8
Remove unnecessary lint allow attrs on example 2021-02-12 12:46:02 +03:00
bors
a118ee2c13 Auto merge of #81486 - ssomers:btree_separate_drop, r=Mark-Simulacrum
BTreeMap: disentangle Drop implementation from IntoIter

No longer require every `BTreeMap` to dig up its last leaf edge before dying. This speeds up the `clone_` benchmarks by 25% for normal keys and values (far less for huge values).

r? `@Mark-Simulacrum`
2021-02-12 06:34:21 +00:00
bors
1efd804983 Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-se
Optimize Vec::retain

Use `copy_non_overlapping` instead of `swap` to reduce memory writes, like what we've done in #44355 and `String::retain`.
#48065 already tried to do this optimization but it is reverted in #67300 due to bad codegen of `DrainFilter::drop`.

This PR re-implement the drop-then-move approach. I did a [benchmark](https://gist.github.com/oxalica/3360eec9376f22533fcecff02798b698) on small-no-drop, small-need-drop, large-no-drop elements with different predicate functions. It turns out that the new implementation is >20% faster in average for almost all cases. Only 2/24 cases are slower by 3% and 5%. See the link above for more detail.

I think regression in may-panic cases is due to drop-guard preventing some optimization. If it's permitted to leak elements when predicate function of element's `drop` panic, the new implementation should be almost always faster than current one.
I'm not sure if we should leak on panic, since there is indeed an issue (#52267) complains about it before.
2021-02-11 04:40:57 +00:00
Dan Gohman
0060c91cfc Make WASI's hard_link behavior match other platforms.
Following #78026, `std::fs::hard_link` on most platforms does not follow
symlinks. Change the WASI implementation to also not follow symlinks.
2021-02-10 17:52:36 -08:00
Amanieu d'Antras
bfd1ccfb27 Seal the CommandExt, OsStrExt and OsStringExt traits 2021-02-10 21:30:30 +00:00
Stein Somers
f81358d578 BTree: remove outdated traces of coercions 2021-02-10 07:48:13 +01:00
Yuki Okushi
bf0c2d5382
Rollup merge of #81904 - jhpratt:const_int_fn-stabilization, r=jyn514
Bump stabilization version for const int methods

These methods missed the beta cutoff. See #80962 for details.

`@rustbot` modify labels to +A-const-fn, +A-intrinsics

r? `@m-ou-se`
2021-02-10 12:24:23 +09:00
Yuki Okushi
e2765f8cbd
Rollup merge of #81687 - WaffleLapkin:split_at_spare, r=KodrAus
Make Vec::split_at_spare_mut public

This PR introduces a new method to the public API, under
`vec_split_at_spare` feature gate:

```rust
impl<T, A: Allocator> impl Vec<T, A> {
    pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit<T>]);
}
```

The method returns 2 slices, one slice references the content of the vector,
and the other references the remaining spare capacity.

The method was previously implemented while adding `Vec::extend_from_within` in #79015,
and used to implement `Vec::spare_capacity_mut` (as the later is just a
subset of former one).

See also previous [discussion in `Vec::spare_capacity_mut` tracking issue](https://github.com/rust-lang/rust/issues/75017#issuecomment-770381335).

## Unresolved questions

- [ ] Should we consider changing the name? `split_at_spare_mut` doesn't seem like an intuitive name
- [ ] Should we deprecate `Vec::spare_capacity_mut`? Any usecase of `Vec::spare_capacity_mut` can be replaced with `Vec::split_at_spare_mut` (but not vise-versa)

r? `@KodrAus`
2021-02-10 12:24:22 +09:00
Yuki Okushi
a28f2afbeb
Rollup merge of #80438 - crlf0710:box_into_inner, r=m-ou-se
Add `Box::into_inner`.

This adds a `Box::into_inner` method to the `Box` type. <del>I actually suggest deprecating the compiler magic of `*b` if this gets stablized in the future.</del>

r? `@m-ou-se`
2021-02-10 12:24:19 +09:00
Yuki Okushi
bb06b13131
Rollup merge of #79849 - Digital-Chaos:sleep-zero, r=m-ou-se
Clarify docs regarding sleep of zero duration

Clarify that the behaviour of sleep() when given a duration of zero is actually platform specific.
2021-02-10 12:24:18 +09:00
Ashley Mannix
8ff7b75c01
update tracking issue for vec_split_at_spare 2021-02-10 09:50:59 +10:00
The8472
4fc181dd62 split guard into read and write types 2021-02-09 19:13:21 +01:00
Stein Somers
3045b75c6d BTreeMap: disentangle Drop implementation from IntoIter 2021-02-09 13:53:12 +01:00