Commit graph

3314 commits

Author SHA1 Message Date
Ralf Jung 12608832c3 improve UnsafeCell docs 2021-02-21 17:24:19 +01:00
bors 3e826bb112 Auto merge of #82359 - JohnTitor:rollup-6puemik, r=JohnTitor
Rollup of 11 pull requests

Successful merges:

 - #81300 (BTree: share panicky test code & test panic during clear, clone)
 - #81706 (Document BinaryHeap unsafe functions)
 - #81833 (parallelize x.py test tidy)
 - #81966 (Add new `rustc` target for Arm64 machines that can target the iphonesimulator)
 - #82154 (Update RELEASES.md 1.50 to include methods stabilized in #79342)
 - #82177 (Do not delete bootstrap.exe on Windows during clean)
 - #82181 (Add check for ES5 in CI)
 - #82229 (Add [A-diagnostics] bug report template)
 - #82233 (try-back-block-type test: Use TryFromSliceError for From test)
 - #82302 (Remove unsafe impl Send for CompletedTest & TestResult)
 - #82349 (test: Print test name only once on timeout)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-21 12:23:45 +00:00
Ashley Mannix 60a9dcc4e3
update tracking issue for raw_os_nonzero 2021-02-21 19:43:42 +10:00
Yuki Okushi d7fb4de791
Rollup merge of #82349 - tmiasko:pretty-test-timeout, r=Mark-Simulacrum
test: Print test name only once on timeout

Pretty formatter when using multiple test threads displays test name twice on
timeout event. This implicitly suggest that those are two different events,
while in fact they are always printed together.

Print test name only once.

Before:

```
running 3 tests
test src/lib.rs - c (line 16) ... ok
test src/lib.rs - a (line 3) ... ok
test src/lib.rs - b (line 9) ... test src/lib.rs - b (line 9) has been running for over 60 seconds
test src/lib.rs - b (line 9) ... ok
```

After:

```
running 3 tests
test src/lib.rs - c (line 16) ... ok
test src/lib.rs - a (line 3) ... ok
test src/lib.rs - b (line 9) has been running for over 60 seconds
test src/lib.rs - b (line 9) ... ok
```
2021-02-21 15:26:50 +09:00
Yuki Okushi 01e1d2d5e8
Rollup merge of #82302 - tmiasko:test-unsafe-send, r=Mark-Simulacrum
Remove unsafe impl Send for CompletedTest & TestResult
2021-02-21 15:26:49 +09:00
Yuki Okushi 56ae3fb2f0
Rollup merge of #81706 - SkiFire13:document-binaryheap-unsafe, r=Mark-Simulacrum
Document BinaryHeap unsafe functions

`BinaryHeap` contains some private safe functions but that are actually unsafe to call. This PR marks them `unsafe` and documents all the `unsafe` function calls inside them.

While doing this I might also have found a bug: some "SAFETY" comments in `sift_down_range` and `sift_down_to_bottom` are valid only if you assume that `child` doesn't overflow. However it may overflow if `end > isize::MAX` which can be true for ZSTs (but I think only for them). I guess the easiest fix would be to skip any sifting if `mem::size_of::<T> == 0`.

Probably conflicts with #81127 but solving the eventual merge conflict should be pretty easy.
2021-02-21 15:26:40 +09:00
Yuki Okushi 3219a100fa
Rollup merge of #81300 - ssomers:btree_cleanup_leak_tests, r=Mark-Simulacrum
BTree: share panicky test code & test panic during clear, clone

Bases almost all tests of panic on the same, richer definition, and extends it to cloning to test panic during clone.

r? ```@Mark-Simulacrum```
2021-02-21 15:26:36 +09:00
bors ed58a2b03b Auto merge of #79100 - a1phyr:better_assert_eq, r=m-ou-se
Improve assert_eq! and assert_ne!

This PR improves `assert_eq!` and `assert_ne!` by moving the panicking code in an external function.

It does not change the fast path, but the move of the formatting in the cold path (the panic) may have a positive effect on in instruction cache use and with inlining.

Moreover, the use of trait objects instead of generic may improve compile times for `assert_eq!`-heavy code.

Godbolt link: ~~https://rust.godbolt.org/z/TYa9MT~~ \
Updated: https://rust.godbolt.org/z/bzE84x
2021-02-21 05:41:09 +00:00
Eric Huss 87ac39c800 Add a chapter on the test harness. 2021-02-20 16:12:11 -08:00
Tomasz Miąsko 88753cead8 test: Print test name only once on timeout
Pretty formatter when using multiple test threads displays test name twice on
timeout event. This implicitly suggest that those are two different events,
while in fact they are always printed together.

Print test name only once.

Before:

```
running 3 tests
test src/lib.rs - c (line 16) ... ok
test src/lib.rs - a (line 3) ... ok
test src/lib.rs - b (line 9) ... test src/lib.rs - b (line 9) has been running for over 60 seconds
test src/lib.rs - b (line 9) ... ok
```

After:

```
running 3 tests
test src/lib.rs - c (line 16) ... ok
test src/lib.rs - a (line 3) ... ok
test src/lib.rs - b (line 9) has been running for over 60 seconds
test src/lib.rs - b (line 9) ... ok
```
2021-02-21 00:00:00 +00:00
Joshua Nelson 3733275854 Update the bootstrap compiler
Note this does not change `core::derive` since it was merged after the
beta bump.
2021-02-20 17:19:30 -05:00
Giacomo Stevanato 3ec1a28418 Add FIXME for safety comments that are invalid when T is a ZST 2021-02-20 15:44:17 -05:00
Giacomo Stevanato 9b4e61255c Document BinaryHeap unsafe functions 2021-02-20 15:44:17 -05:00
Guillaume Gomez c26a8bbd6d
Rollup merge of #82244 - pickfire:patch-6, r=dtolnay
Keep consistency in example for Stdin StdinLock

Stdin uses handle whereas StdinLock uses stdin_lock, changed it to handle.
2021-02-20 20:37:01 +01:00
Guillaume Gomez d38f6e82a4
Rollup merge of #80595 - pthariensflame:patch-1, r=m-ou-se
`impl PartialEq<Punct> for char`; symmetry for #78636

Also fixes the "since" version of the original.

Pinging ``@dtolnay`` and ``@petrochenkov.``
2021-02-20 20:36:54 +01:00
bors da5f7f1093 Auto merge of #81427 - klensy:eat-digits, r=m-ou-se
simplify eat_digits

Simplify eat_digits by checking values in iterator, plus decrease function size, by returning unchecked slices.

https://godbolt.org/z/cxjav4
2021-02-20 07:31:43 +00:00
Alexander Ronald Altman 1839748772 impl PartialEq<Punct> for char; symmetry for #78636
Also fixes the "since" version of the original.
2021-02-19 17:28:19 -08:00
klensy ec09d7fc8b simplify eat_digits 2021-02-19 18:51:25 +03:00
Dan Gohman 1abcdfe449 x.py fmt 2021-02-19 07:31:01 -08:00
Dylan DPC 36a348bdc0
Rollup merge of #82274 - andersk:test-unwrap, r=Mark-Simulacrum
libtest: Fix unwrap panic on duplicate TestDesc

It is possible for different tests to collide to the same `TestDesc` when macros are involved. That is a bug, but it didn’t cause a panic until #81367. For now, change the code to ignore this problem.

Fixes #81852.

This will need to be applied to `beta` too.
2021-02-19 02:49:13 +01:00
Dylan DPC f8b61d852c
Rollup merge of #82093 - bjorn3:more_atomic_tests, r=kennytm
Add tests for Atomic*::fetch_{min,max}

This ensures that all atomic operations except for fences are tested. This has been useful to test my work on using atomic instructions for atomic operations in cg_clif instead of a global lock.
2021-02-19 02:49:07 +01:00
Dylan DPC c821063a53
Rollup merge of #81873 - mark-i-m:unlock, r=m-ou-se
Add Mutex::unlock

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

Discussion: https://github.com/rust-lang/rust/pull/79434#issuecomment-757135874

r? `@m-ou-se`
2021-02-19 02:49:06 +01:00
Tomasz Miąsko 2380090f49 Remove unsafe impl Send for CompletedTest & TestResult 2021-02-19 00:00:00 +00:00
Anders Kaseorg 1605af015c libtest: Fix unwrap panic on duplicate TestDesc.
It is possible for different tests to collide to the same TestDesc
when macros are involved.  That is a bug, but it didn’t cause a panic
until #81367.  For now, change the code to ignore this problem.

Fixes #81852.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2021-02-18 12:42:45 -08:00
mark e92e5fd787 add Mutex::unlock 2021-02-18 11:56:19 -06:00
Dylan DPC 66211f6657
Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726
Ensure valid TraitRefs are created for GATs

This fixes `ProjectionTy::trait_ref` to use the correct substs. Places that need all of the substs have been updated to not use `trait_ref`.

r? ````@jackh726````
2021-02-18 16:57:34 +01:00
Dylan DPC 55ab2e3879
Rollup merge of #81546 - hyd-dev:libtest-run-out-of-threads, r=Mark-Simulacrum
[libtest] Run the test synchronously when hitting thread limit

libtest currently panics if it hits the thread limit. This often results in spurious test failures (<code>thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }'</code> ... `error: test failed, to rerun pass '--lib'`). This PR makes it continue to run the test synchronously if it runs out of threads.

Closes #78165.

``@rustbot`` label: A-libtest T-libs
2021-02-18 16:57:33 +01:00
bors 25a2c13e9d Auto merge of #82249 - JohnTitor:rollup-3jbqija, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #82055 (Add diagnostics for specific cases for const/type mismatch err)
 - #82155 (Use !Sync std::lazy::OnceCell in usefulness checking)
 - #82202 (add specs for riscv32/riscv64 musl targets)
 - #82203 (Move some tests to more reasonable directories - 4)
 - #82211 (make `suggest_setup` help messages better)
 - #82212 (Remove redundant rustc_data_structures path component)
 - #82240 (remove useless ?s (clippy::needless_question_marks))
 - #82243 (Add more intra-doc links to std::io)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-18 07:22:30 +00:00
Yuki Okushi 21283dae9e
Rollup merge of #82243 - pickfire:patch-5, r=jyn514
Add more intra-doc links to std::io
2021-02-18 15:57:34 +09:00
bors d1462d8558 Auto merge of #81172 - SimonSapin:ptr-metadata, r=oli-obk
Implement RFC 2580: Pointer metadata & VTable

RFC: https://github.com/rust-lang/rfcs/pull/2580

~~Before merging this PR:~~

* [x] Wait for the end of the RFC’s [FCP to merge](https://github.com/rust-lang/rfcs/pull/2580#issuecomment-759145278).
* [x] Open a tracking issue: https://github.com/rust-lang/rust/issues/81513
* [x] Update `#[unstable]` attributes in the PR with the tracking issue number

----

This PR extends the language with a new lang item for the `Pointee` trait which is special-cased in trait resolution to implement it for all types. Even in generic contexts, parameters can be assumed to implement it without a corresponding bound.

For this I mostly imitated what the compiler was already doing for the `DiscriminantKind` trait. I’m very unfamiliar with compiler internals, so careful review is appreciated.

This PR also extends the standard library with new unstable APIs in `core::ptr` and `std::ptr`:

```rust
pub trait Pointee {
    /// One of `()`, `usize`, or `DynMetadata<dyn SomeTrait>`
    type Metadata: Copy + Send + Sync + Ord + Hash + Unpin;
}

pub trait Thin = Pointee<Metadata = ()>;

pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {}

pub const fn from_raw_parts<T: ?Sized>(*const (), <T as Pointee>::Metadata) -> *const T {}
pub const fn from_raw_parts_mut<T: ?Sized>(*mut (),<T as Pointee>::Metadata) -> *mut T {}

impl<T: ?Sized> NonNull<T> {
    pub const fn from_raw_parts(NonNull<()>, <T as Pointee>::Metadata) -> NonNull<T> {}

    /// Convenience for `(ptr.cast(), metadata(ptr))`
    pub const fn to_raw_parts(self) -> (NonNull<()>, <T as Pointee>::Metadata) {}
}

impl<T: ?Sized> *const T {
    pub const fn to_raw_parts(self) -> (*const (), <T as Pointee>::Metadata) {}
}

impl<T: ?Sized> *mut T {
    pub const fn to_raw_parts(self) -> (*mut (), <T as Pointee>::Metadata) {}
}

/// `<dyn SomeTrait as Pointee>::Metadata == DynMetadata<dyn SomeTrait>`
pub struct DynMetadata<Dyn: ?Sized> {
    // Private pointer to vtable
}

impl<Dyn: ?Sized> DynMetadata<Dyn> {
    pub fn size_of(self) -> usize {}
    pub fn align_of(self) -> usize {}
    pub fn layout(self) -> crate::alloc::Layout {}
}

unsafe impl<Dyn: ?Sized> Send for DynMetadata<Dyn> {}
unsafe impl<Dyn: ?Sized> Sync for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Debug for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Unpin for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Copy for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Clone for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Eq for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> PartialEq for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Ord for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> PartialOrd for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Hash for DynMetadata<Dyn> {}
```

API differences from the RFC, in areas noted as unresolved questions in the RFC:

* Module-level functions instead of associated `from_raw_parts` functions on `*const T` and `*mut T`, following the precedent of `null`, `slice_from_raw_parts`, etc.
* Added `to_raw_parts`
2021-02-18 04:22:16 +00:00
Ivan Tham 026be9dc26
Keep consistency in example for Stdin StdinLock
Stdin uses handle whereas StdinLock uses stdin_lock, changed it to handle.
2021-02-18 10:11:57 +08:00
Ivan Tham 250eeb4c3c
Add missing link from stdio doc 2021-02-18 09:58:15 +08:00
Dylan DPC 40e3af5a21
Rollup merge of #80572 - thomcc:ok_or_err, r=m-ou-se
Add a `Result::into_ok_or_err` method to extract a `T` from `Result<T, T>`

When updating code to handle the semi-recent deprecation of `compare_and_swap` in favor of `compare_exchange`, which returns `Result<T, T>`, I wanted this. I've also wanted it with code using `slice::binary_search` before.

The name (and perhaps the documentation) is the hardest part here, but this name seems consistent with the other Result methods, and equivalently memorable.
2021-02-17 23:51:13 +01:00
Dylan DPC db59950b6d
Rollup merge of #77728 - lygstate:master, r=Amanieu
Expose force_quotes on Windows.

On Windows, the arg quotes and not quotes have different effect
for the program it called, if the program called are msys2/cygwin program.
Refer to
https://github.com/msys2/MSYS2-packages/issues/2176

This also solve the issues comes from

https://internals.rust-lang.org/t/std-process-on-windows-is-escaping-raw-literals-which-causes-problems-with-chaining-commands/8163

Tracking issue:
https://github.com/rust-lang/rust/issues/82227
2021-02-17 23:51:12 +01:00
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
Josh Stone fc150d17b5 Expand FlattenCompat folds
The former `chain`+`chain`+`fold` implementation looked nice from a
functional-programming perspective, but it introduced unnecessary layers
of abstraction on every `flat_map`/`flatten` fold. It's straightforward
to just fold each part in turn, and this makes it look like a simplified
version of the existing `try_fold` implementation.

For the `iter::bench_flat_map*` benchmarks, I get a large improvement in
`bench_flat_map_chain_sum`, from 1,598,473 ns/iter to 499,889 ns/iter,
and the rest are unchanged.
2021-02-15 11:52:28 -08: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
Tomasz Miąsko dc3304c341 Turn may_have_side_effect into an associated constant
The `may_have_side_effect` is an implementation detail of `TrustedRandomAccess`
trait. It describes if obtaining an iterator element may have side effects. It
is currently implemented as an associated function.

Turn `may_have_side_effect` into an associated constant. This makes the
value immediately available to the optimizer.
2021-02-15 17:36:29 +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
Casey Rodarmor 66f4883308
[librustdoc] Reform lang string token splitting
Only split doctest lang strings on `,`, ` `, and `\t`. Additionally, to
preserve backwards compatibility with pandoc-style langstrings, strip a
surrounding `{}`, and remove leading `.`s from each token.

Prior to this change, doctest lang strings were split on all
non-alphanumeric characters except `-` or `_`, which limited future
extensions to doctest lang string tokens, for example using `=` for
key-value tokens.

This is a breaking change, although it is not expected to be disruptive,
because lang strings using separators other than `,` and ` ` are not
very common
2021-02-12 00:02:52 -08: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
Jacob Pratt c28f2a8bee
Stabilize str_split_once 2021-02-09 23:17:11 -05: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
Stein Somers cbbdb4439a BTreeMap: gather and decompose reusable tree fixing functions 2021-02-09 13:41:51 +01:00
Stein Somers f7edf5ce05 BTreeMap: fix internal comments 2021-02-09 13:19:37 +01:00
Stein Somers 3e1d602a6b BTreeMap: share panicky test code & test panic during clear, clone 2021-02-09 12:33:18 +01:00
Stein Somers 6d2247eac2 BTreeMap/BTreeSet: separate off code supporting tests 2021-02-09 11:21:42 +01:00
bors f4008fe949 Auto merge of #81905 - Dylan-DPC:rollup-mxpz1j7, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #72209 (Add checking for no_mangle to unsafe_code lint)
 - #80732 (Allow Trait inheritance with cycles on associated types take 2)
 - #81697 (Add "every" as a doc alias for "all".)
 - #81826 (Prefer match over combinators to make some Box methods inlineable)
 - #81834 (Resolve typedef in HashMap lldb pretty-printer only if possible)
 - #81841 ([rustbuild] Output rustdoc-json-types docs )
 - #81849 (Expand the docs for ops::ControlFlow a bit)
 - #81876 (parser: Fix panic in 'const impl' recovery)
 - #81882 (⬆️ rust-analyzer)
 - #81888 (Fix pretty printer macro_rules with semicolon.)
 - #81896 (Remove outdated comment in windows' mutex.rs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-09 05:57:18 +00:00
Charles Lew ce7de07866 Add Box::into_inner. 2021-02-09 10:28:50 +08:00
Dylan DPC d2e204d158
Rollup merge of #81896 - m-ou-se:oudated-comment, r=Mark-Simulacrum
Remove outdated comment in windows' mutex.rs

After https://github.com/rust-lang/rust/pull/81250, this `Mutex` no longer falls back to the `ReentrantMutex` implementation, so this comment is no longer relevant.
2021-02-09 02:40:06 +01:00
Dylan DPC a63085dc5e
Rollup merge of #81849 - scottmcm:control-flow-comments, r=Mark-Simulacrum
Expand the docs for ops::ControlFlow a bit

Since I was writing some examples for an RFC anyway.

And I almost made the mistake of reordering the variants, so added a note and a test about that.
2021-02-09 02:39:59 +01:00
Dylan DPC d19f37541c
Rollup merge of #81826 - tesuji:inline-box-zeros, r=Amanieu
Prefer match over combinators to make some Box methods inlineable

Hopefully this patch would make two snippets generated identical code: <https://rust.godbolt.org/z/fjrj4E>.
2021-02-09 02:39:53 +01:00
Dylan DPC 52bc54efff
Rollup merge of #81697 - xfix:every-doc-alias, r=Mark-Simulacrum
Add "every" as a doc alias for "all".

This matches [Array#every](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) in JavaScript.

Oddly enough, `core::iter::Iterator::all` appears twice. This appears to be a rustdoc bug which I decided to fill in as #81696.

![image](https://user-images.githubusercontent.com/1297598/106717890-94f43e80-6600-11eb-9428-2cd425823df9.png)
2021-02-09 02:39:51 +01:00
Jacob Pratt 1b32a7a4cf
Bump stabilization version for const int methods
These methods missed the beta cutoff
2021-02-08 19:26:01 -05:00
The8472 130fb243bd specialize slice::clone_from_slice() for T: Copy 2021-02-09 00:37:37 +01:00
bors a2704448c1 Auto merge of #81361 - ssomers:btree_drainy_refactor_7, r=Mark-Simulacrum
BTreeMap: lightly refactor the split_off implementation

r? `@Mark-Simulacrum`
2021-02-08 23:37:06 +00:00
The8472 44abad5b12 introduce StaticRWLock wrapper to make methods safe 2021-02-08 23:35:02 +01:00
The8472 2200cf10d8 avoid &mut on the read path since it now allows concurrent readers 2021-02-08 23:31:49 +01:00
Mara Bos 15de287cd5 Remove outdated comment. 2021-02-08 22:27:34 +01:00
Mara Bos 98aec1582b
Rollup merge of #81840 - ibraheemdev:patch-1, r=dtolnay
fix formatting of std::iter::Map
2021-02-08 19:28:22 +01:00
Mara Bos b102ea479d
Rollup merge of #81356 - ehuss:libtest-filters, r=m-ou-se
libtest: allow multiple filters

Libtest ignores any filters after the first. This changes it so that if multiple filters are passed, it will test against all of them.

This also affects compiletest to do the same.

Closes #30422
2021-02-08 19:28:13 +01:00
Giles Cope cadcf5ed99
Unify way to flip 6th bit. (Same assembly generated) 2021-02-08 12:21:36 +00:00
Lzu Tao 010e194d6e Specialize slice::fill for Copy type and u8/i8/bool 2021-02-08 11:32:18 +00:00
bors 0b96f60c07 Auto merge of #79245 - ssomers:btree_curb_ord_bound, r=dtolnay
BTree: remove Ord bound where it is absent elsewhere

Some btree methods don't really need an Ord bound and don't have one, while some methods that more obviously don't need it, do have one.

An example of the former is `iter`, even though it explicitly exposes the work of the Ord implementation (["sorted by key"](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.iter) - but I'm not suggesting it should have the Ord bound). An example of the latter is `new`, which doesn't involve any keys whatsoever.
2021-02-08 07:56:04 +00:00
bors 4940dd483a Auto merge of #80962 - jhpratt:const_int_fn-stabilization, r=dtolnay
Stabilize remaining integer methods as `const fn`

This pull request stabilizes the following methods as `const fn`:

- `i*::checked_div`
- `i*::checked_div_euclid`
- `i*::checked_rem`
- `i*::checked_rem_euclid`
- `i*::div_euclid`
- `i*::overflowing_div`
- `i*::overflowing_div_euclid`
- `i*::overflowing_rem`
- `i*::overflowing_rem_euclid`
- `i*::rem_euclid`
- `i*::wrapping_div`
- `i*::wrapping_div_euclid`
- `i*::wrapping_rem`
- `i*::wrapping_rem_euclid`
- `u*::checked_div`
- `u*::checked_div_euclid`
- `u*::checked_rem`
- `u*::checked_rem_euclid`
- `u*::div_euclid`
- `u*::overflowing_div`
- `u*::overflowing_div_euclid`
- `u*::overflowing_rem`
- `u*::overflowing_rem_euclid`
- `u*::rem_euclid`
- `u*::wrapping_div`
- `u*::wrapping_div_euclid`
- `u*::wrapping_rem`
- `u*::wrapping_rem_euclid`

These can all be implemented on the current stable (1.49). There are two unstable details: const likely/unlikely and unchecked division/remainder. Both of these are for optimizations, and are in no way required to make the methods function; there is no exposure of these details publicly. Per comments below, it seems best practice is to stabilize the intrinsics. As such, `intrinsics::unchecked_div` and `intrinsics::unchecked_rem` have been stabilized as `const` as part of this pull request as well. The methods themselves remain unstable.

I believe part of the reason these were not stabilized previously was the behavior around division by 0 and modulo 0. After testing on nightly, the diagnostic for something like `const _: i8 = 5i8 % 0i8;` is similar to that of `const _: i8 = 5i8.rem_euclid(0i8);` (assuming the appropriate feature flag is enabled). As such, I believe these methods are ready to be stabilized as `const fn`.

This pull request represents the final methods mentioned in #53718. As such, this PR closes #53718.

`@rustbot` modify labels to +A-const-fn, +T-libs
2021-02-08 05:05:55 +00:00
Ibraheem Ahmed 1dac9a1d78 fix formatting of std::iter::Map 2021-02-07 21:16:25 -05:00
bors 9778068cbc Auto merge of #79078 - petrochenkov:derattr, r=Aaron1011
expand/resolve: Turn `#[derive]` into a regular macro attribute

This PR turns `#[derive]` into a regular attribute macro declared in libcore and defined in `rustc_builtin_macros`, like it was previously done with other "active" attributes in https://github.com/rust-lang/rust/pull/62086, https://github.com/rust-lang/rust/pull/62735 and other PRs.
This PR is also a continuation of #65252, #69870 and other PRs linked from them, which layed the ground for converting `#[derive]` specifically.

`#[derive]` still asks `rustc_resolve` to resolve paths inside `derive(...)`, and `rustc_expand` gets those resolution results through some backdoor (which I'll try to address later), but otherwise `#[derive]` is treated as any other macro attributes, which simplifies the resolution-expansion infra pretty significantly.

The change has several observable effects on language and library.
Some of the language changes are **feature-gated** by [`feature(macro_attributes_in_derive_output)`](https://github.com/rust-lang/rust/issues/81119).

#### Library

- `derive` is now available through standard library as `{core,std}::prelude::v1::derive`.

#### Language

- `derive` now goes through name resolution, so it can now be renamed - `use derive as my_derive; #[my_derive(Debug)] struct S;`.
- `derive` now goes through name resolution, so this resolution can fail in corner cases. Crater found one such regression, where import `use foo as derive` goes into a cycle with `#[derive(Something)]`.
- **[feature-gated]** `#[derive]` is now expanded as any other attributes in left-to-right order. This allows to remove the restriction on other macro attributes following `#[derive]` (https://github.com/rust-lang/reference/issues/566). The following macro attributes become a part of the derive's input (this is not a change, non-macro attributes following `#[derive]` were treated in the same way previously).
- `#[derive]` is now expanded as any other attributes in left-to-right order. This means two derive attributes `#[derive(Foo)] #[derive(Bar)]` are now expanded separately rather than together. It doesn't generally make difference, except for esoteric cases. For example `#[derive(Foo)]` can now produce an import bringing `Bar` into scope, but previously both `Foo` and `Bar` were required to be resolved before expanding any of them.
- **[feature-gated]** `#[derive()]` (with empty list in parentheses) actually becomes useful. For historical reasons `#[derive]` *fully configures* its input, eagerly evaluating `cfg` everywhere in its target, for example on fields.
Expansion infra doesn't do that for other attributes, but now when macro attributes attributes are allowed to be written after `#[derive]`, it means that derive can *fully configure* items for them.
    ```rust
	#[derive()]
	#[my_attr]
	struct S {
		#[cfg(FALSE)] // this field in removed by `#[derive()]` and not observed by `#[my_attr]`
		field: u8
	}
    ```
- `#[derive]` on some non-item targets is now prohibited. This was accidentally allowed as noop in the past, but was warned about since early 2018 (#50092), despite that crater found a few such cases in unmaintained crates.
- Derive helper attributes used before their introduction are now reported with a deprecation lint. This change is long overdue (since macro modularization, https://github.com/rust-lang/rust/issues/52226#issuecomment-422605033), but it was hard to do without fixing expansion order for derives. The deprecation is tracked by #79202.
```rust
    #[trait_helper] // warning: derive helper attribute is used before it is introduced
    #[derive(Trait)]
    struct S {}
```

Crater analysis: https://github.com/rust-lang/rust/pull/79078#issuecomment-731436821
2021-02-07 19:36:10 +00:00
Vadim Petrochenkov dbdbd30bf2 expand/resolve: Turn #[derive] into a regular macro attribute 2021-02-07 20:08:45 +03:00
Guillaume Gomez f706216251
Rollup merge of #81742 - sdroege:exact-size-iterator-correctness, r=kennytm
Add a note about the correctness and the effect on unsafe code to the `ExactSizeIterator` docs

As it is a safe trait it does not provide any guarantee that the
returned length is correct and as such unsafe code must not rely on it.

That's why `TrustedLen` exists.

Fixes https://github.com/rust-lang/rust/issues/81739
2021-02-07 14:45:51 +01:00
Guillaume Gomez 6e1f7139c9
Rollup merge of #81526 - ojeda:btree-use-unwrap_unchecked, r=scottmcm
btree: use Option's unwrap_unchecked()

Now that https://github.com/rust-lang/rust/issues/81383 is available, start using it.
2021-02-07 14:45:46 +01:00
The8472 406fd3a277 silence dead code warnings on windows 2021-02-07 09:45:49 +01:00
The8472 55ca27faa7 use rwlock for accessing ENV 2021-02-07 09:12:21 +01:00
Scott McMurray 1b7309edd6 Expand the docs for ops::ControlFlow a bit
Since I was writing some examples for an RFC anyway.
2021-02-06 22:36:05 -08:00
bors 0961ae83b8 Auto merge of #81821 - nikic:update-wasm32, r=sanxiyn
Upgrade wasm32 image to Ubuntu 20.04

This switches the wasm32 image, which is used to test
wasm32-unknown-emscripten, to Ubuntu 20.04. While at it, enable
most of the excluded tests, as they seem to work fine with some
minor fixes.
2021-02-07 02:36:08 +00:00
Steve Heindel 0488afd967 Fix doc test for Vec::retain(), now passes clippy::eval_order_dependence 2021-02-06 21:20:28 -05:00
Giles Cope f30c51abe8
Pulling out constant. 2021-02-06 20:35:21 +00:00
Giles Cope f165f49d22
Slight perf improvement on char::to_ascii_lowercase 2021-02-06 19:56:43 +00:00
Jonas Schievink 747abb86db
Rollup merge of #81434 - ssomers:btree_drain_filter_doc_update, r=dtolnay
BTree: fix documentation of unstable public members

As rightfully requested in #62924 & #70530.
r? `@Mark-Simulacrum`
2021-02-06 17:01:43 +01:00
Lzu Tao fb4e734f99 Prefer match intead of combinators to make some Box function inlineable 2021-02-06 15:00:37 +00:00
Nikita Popov 55e237284f Upgrade wasm32 image to Ubuntu 20.04
This switches the wasm32 image, which is used to test
wasm32-unknown-emscripten to Ubuntu 20.04. While at it, enable
most of the excluded tests, as they seem to work fine with some
minor fixes.
2021-02-06 13:05:56 +01:00
Stein Somers 9066c736a2 BTreeMap: remove Ord bound where it is absent elsewhere 2021-02-06 09:04:50 +01:00
Stein Somers f0b8166870 BTreeMap: fix documentation of unstable public members 2021-02-06 00:33:50 +01:00
Mara Bos 78be1aa226
Rollup merge of #81610 - ssomers:btree_emphasize_ord_bound, r=dtolnay
BTreeMap: make Ord bound explicit, compile-test its absence

Most `BTreeMap` and `BTreeSet` members are subject to an `Ord` bound but a fair number of methods are not. To better convey and perhaps later tune the `Ord` bound, make it stand out in individual `where` clauses, instead of once far away at the beginning of an `impl` block. This PR does not introduce or remove any bounds.

Also adds compilation test cases checking that the bound doesn't creep in unintended on the historically unbounded methods.
2021-02-06 00:14:11 +01:00
Mara Bos 43b3adb4e2
Rollup merge of #81580 - rodrimati1992:patch-2, r=dtolnay
Document how `MaybeUninit<Struct>` can be initialized.
2021-02-06 00:14:09 +01:00
Mara Bos cc882fc3be
Rollup merge of #80011 - Stupremee:stabilize-peekable-next-if, r=dtolnay
Stabilize `peekable_next_if`

This PR stabilizes the `peekable_next_if` feature

Resolves #72480
2021-02-06 00:14:06 +01:00
David Tolnay ceda547c68
Bump peekable_next_if to rust 1.51.0 2021-02-05 14:25:21 -08:00
bors 5605b5d693 Auto merge of #81257 - pnkfelix:issue-80949-short-term-resolution-via-revert-of-pr-78373, r=matthewjasper
Revert 78373 ("dont leak return value after panic in drop")

Short term resolution for issue #80949.

Reopen #47949 after this lands.

(We plan to fine-tune PR #78373 to not run into this problem.)
2021-02-05 14:52:57 +00:00
Mara Bos e077dffaec
Rollup merge of #81767 - exrook:layout-error-stability, r=Mark-Simulacrum
Update LayoutError/LayoutErr stability attributes

`LayoutError` ended up not making it into 1.49.0, updating the stability attributes to reflect that.

I also pushed `LayoutErr` deprecation back a release to allow 2 releases before the deprecation comes into effect.

This change should be backported to beta.
2021-02-05 12:26:07 +01:00
Mara Bos ff3c85fd65
Rollup merge of #81730 - RustyYato:object-safe-allocator, r=Amanieu
Make `Allocator` object-safe

This allows rust-lang/wg-allocators#83: polymorphic allocators
2021-02-05 12:26:05 +01:00
Mara Bos ce1020fc55
Rollup merge of #81542 - RReverser:wasi-symlink, r=alexcrichton
Expose correct symlink API on WASI

As described in https://github.com/rust-lang/rust/issues/68574, the currently exposed API for symlinks is, in fact, a thin wrapper around the corresponding syscall, and not suitable for public usage.

The reason is that the 2nd param in the call is expected to be a handle of a "preopened directory" (a WASI concept for exposing dirs), and the only way to retrieve such handle right now is by tinkering with a private `__wasilibc_find_relpath` API, which is an implementation detail and definitely not something we want users to call directly.

Making matters worse, the semantics of this param aren't obvious from its name (`fd`), and easy to misinterpret, resulting in people trying to pass a handle of the target file itself (as in https://github.com/vitiral/path_abs/pull/50), which doesn't work as expected.

I did a [codesearch among open-source repos](https://sourcegraph.com/search?q=std%3A%3Aos%3A%3Awasi%3A%3Afs%3A%3Asymlink&patternType=literal), and the usage above is so far the only usage of this API at all, but we should fix it before more people start using it incorrectly.

While this is technically a breaking API change, I believe it's a justified one, as 1) it's OS-specific and 2) there was strictly no way to correctly use the previous form of the API, and if someone does use it, they're likely doing it wrong like in the example above.

The new API does not lead to the same confusion, as it mirrors `std::os::unix::fs::symlink` and `std::os::windows::fs::symlink_{file,dir}` variants by accepting source/target paths.

Fixes #68574.

r? ``@alexcrichton``
2021-02-05 12:26:00 +01:00
Felix S. Klock II a71a819480 Revert "Avoid leaking block expression values"
This reverts commit 4fef39113a.
2021-02-04 21:29:49 -05:00
Jacob Hughes 0c3a7d8b85 Update LayoutError/LayoutErr stability attributes 2021-02-04 19:02:57 -05:00
Mara Bos 6f014cd4db
Rollup merge of #81745 - Kixunil:stabilize_once_poison, r=m-ou-se
Stabilize poison API of Once, rename poisoned()

This stabilizes:

* `OnceState`
* `OnceState::is_poisoned()` (previously named `poisoned()`)
* `Once::call_once_force()`

`poisoned()` was renamed because the new name is more clear as a few
people agreed and nobody objected.

Closes #33577

Notes:

* I'm not entirely sure it's supposed to be 1.51, LMK if I did it wrong
* I failed to run tests locally, so we will have to leave it to bors or someone else can try
2021-02-04 21:10:44 +01:00
Mara Bos 113e27fcfc
Rollup merge of #81727 - m-ou-se:unstabilize-bits, r=Mark-Simulacrum
Revert stabilizing integer::BITS.

We agreed in the libs meeting just now to revert stablization, since the [breakage](https://github.com/rust-lang/rust/issues/81654) is significant throughout the ecosystem, through `lexical-core`.

cc https://github.com/rust-lang/rust/issues/76904

Fixes https://github.com/rust-lang/rust/issues/81654
2021-02-04 21:10:42 +01:00
Mara Bos e0ddc053f9
Rollup merge of #81711 - saethlin:ipaddr-inline, r=m-ou-se
add #[inline] to all the public IpAddr functions
2021-02-04 21:10:39 +01:00
Mara Bos 21e5827800
Rollup merge of #81710 - TyPR124:patch-2, r=m-ou-se
OsStr eq_ignore_ascii_case takes arg by value

Per a comment on #70516 this changes `eq_ignore_ascii_case` to take the generic parameter `S: AsRef<OsStr>` by value instead of by reference.

This is technically a breaking change to an unstable method. I think the only way it would break is if you called this method with an explicit type parameter, ie `my_os_str.eq_ignore_ascii_case::<str>("foo")` becomes `my_os_str.eq_ignore_ascii_case::<&str>("foo")`.

Besides that, I believe it is overall more flexible since it can now take an owned `OsString` for example.

If this change should be made in some other PR (like #80193) then please just close this.
2021-02-04 21:10:37 +01:00
Mara Bos 87b269ab66
Rollup merge of #81645 - m-ou-se:panic-lint, r=estebank,flip1995
Add lint for `panic!(123)` which is not accepted in Rust 2021.

This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021.

It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized
`std::panic::panic_any()` function as an alternative.

It renames the lint to `non_fmt_panic` to match the lint naming guidelines.

![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png)

This is part of #80162.

r? ```@estebank```
2021-02-04 21:10:36 +01:00
Mara Bos 5b0acfd049
Rollup merge of #79805 - m-ou-se:iterator-reduce, r=KodrAus
Rename Iterator::fold_first to reduce and stabilize it

This stabilizes `#![feature(iterator_fold_self)]`.

The name for this function (originally `fold_first`) was still an open question, but the discussion on [the tracking issue](https://github.com/rust-lang/rust/issues/68125) seems to have converged to `reduce`.
2021-02-04 21:10:33 +01:00
Martin Habovstiak f42e96149d Stabilize poison API of Once, rename poisoned()
This stabilizes:

* `OnceState`
* `OnceState::is_poisoned()` (previously named `poisoned()`)
* `Once::call_once_force()`

`poisoned()` was renamed because the new name is more clear as a few
people agreed and nobody objected.

Closes #33577
2021-02-04 15:20:14 +01:00
Mara Bos 24e0940169 Stabilize feature(iterator_fold_self): Iterator::reduce 2021-02-04 11:31:11 +01:00
Mara Bos 26af55f5c6 Improve documentation of Iterator::{fold, reduce}. 2021-02-04 11:30:42 +01:00
Mara Bos 5c056ed2f5 Rename Iterator::fold_first to reduce. 2021-02-04 11:30:42 +01:00
Sebastian Dröge f436630ac8 Add a note about the correctness and the effect on unsafe code to the ExactSizeIterator docs
As it is a safe trait it does not provide any guarantee that the
returned length is correct and as such unsafe code must not rely on it.

That's why `TrustedLen` exists.

Fixes https://github.com/rust-lang/rust/issues/81739
2021-02-04 11:31:31 +02:00
Sebastian Dröge 86a4b27475 Increment self.index before calling Iterator::self.a.__iterator_get_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-04 10:23:01 +02:00
RustyYato d06384ac29
make Allocator object-safe
add test to ensure object-safety
This allows for runtime polymorphic allocators
2021-02-03 20:46:16 -05:00