Commit graph

3305 commits

Author SHA1 Message Date
Peter Kehl d4763dac9e FloatToInit: Replacing round_unchecked_to --> to_int_unchecked
FloatToInit docs: Replacing round_unchecked_to with
to_int_unchecked. Bug #82709.
2021-03-02 12:38:22 -08:00
Ralf Jung dc685f6815 enable atomic_min/max tests in Miri 2021-03-02 19:58:55 +01:00
bors 795a934b51 Auto merge of #82043 - tmiasko:may-have-side-effect, r=kennytm
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-03-02 16:08:32 +00:00
Yuki Okushi bc5669eef8
Rollup merge of #80189 - jyn514:convert-primitives, r=poliorcetics
Convert primitives in the standard library to intra-doc links

Blocked on https://github.com/rust-lang/rust/pull/80181. I forgot that this needs to wait for the beta bump so the standard library can be documented with `doc --stage 0`.

Notably I didn't convert `core::slice` because it's like 50 links and I got scared 😨
2021-03-02 21:23:12 +09:00
Joshua Nelson cc62018e61 Rename rustdoc lints to be a tool lint instead of built-in.
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links`
- Ensure that the old lint names still work and give deprecation errors
- Register lints even when running doctests

  Otherwise, all `rustdoc::` lints would be ignored.

- Register all existing lints as removed

  This unfortunately doesn't work with `register_renamed` because tool
  lints have not yet been registered when rustc is running. For similar
  reasons, `check_backwards_compat` doesn't work either. Call
  `register_removed` directly instead.

- Fix fallout

  + Rustdoc lints for compiler/
  + Rustdoc lints for library/

Note that this does *not* suggest `rustdoc::broken_intra_doc_links` for
`rustdoc::intra_doc_link_resolution_failure`, since there was no time
when the latter was valid.
2021-03-01 19:29:15 -05:00
Guillaume Gomez 9a0ac7cb5f
Rollup merge of #82676 - dtolnay:powers, r=Mark-Simulacrum
Change twice used large const table to static

This table is used twice in core::num::dec2flt::algorithm::power_of_ten. According to the semantics of const, a separate huge definition of the table is inlined at both places.

5233edcf1c/library/core/src/num/dec2flt/algorithm.rs (L16-L22)

Theoretically this gets cleaned up by optimization passes, but in practice I am experiencing a miscompile from LTO on this code. Making the table a static, which would only be defined a single time and not require attention from LTO, eliminates the miscompile and seems semantically more appropriate anyway. A separate bug report on the LTO bug is forthcoming.

Original addition of `const` is from #27307.
2021-03-02 00:50:11 +01:00
Guillaume Gomez 5a82251e92
Rollup merge of #82598 - GuillaumeGomez:rustdoc-rustc-pass, r=jyn514
Check stability and feature attributes in rustdoc

Fixes #82588.

cc `@Nemo157` `@camelid`
r? `@jyn514`
2021-03-02 00:50:08 +01:00
Nikita Popov 41b81584e2 Build newly added InstrProfilingVersionVar.c file 2021-03-01 23:35:35 +01:00
Guillaume Gomez d20fd62d70 Add missing stability attributes in libstd 2021-03-01 20:28:37 +01:00
David Tolnay bd51dea693
Change twice used large const table to static
This table is used twice in core::num::dec2flt::algorithm::power_of_ten.
According to the semantics of const, a separate huge definition of the
table is inlined at both places.

    fn power_of_ten(e: i16) -> Fp {
        assert!(e >= table::MIN_E);
        let i = e - table::MIN_E;
        let sig = table::POWERS.0[i as usize];
        let exp = table::POWERS.1[i as usize];
        Fp { f: sig, e: exp }
    }

Theoretically this gets cleaned up by optimization passes, but in
practice I am experiencing a miscompile from LTO on this code. Making
the table a static, which would only be defined a single time and not
require attention from LTO, eliminates the miscompile and seems
semantically more appropriate anyway. A separate bug report on the LTO
bug is forthcoming.
2021-03-01 10:41:16 -08:00
Joshua Nelson 9a86a727c5
Rollup merge of #82645 - rkjnsn:patch-3, r=Mark-Simulacrum
Clarify that SyncOnceCell::set blocks.

Reading the discussion of this feature, I gained the mistaken impression that neither `set` nor `get` blocked, and thus calling `get` immediately after `set` was not guaranteed to succeed. It turns out that `set` *does* block, guaranteeing that the cell contains a value once `set` returns. This change updates the documentation to state that explicitly.

Happy to adjust the wording as desired.
2021-03-01 11:25:11 -05:00
Joshua Nelson efb9ee2df5
Rollup merge of #82578 - camsteffen:diag-items, r=oli-obk
Add some diagnostic items for Clippy
2021-03-01 11:25:07 -05:00
Joshua Nelson 57c568a918
Rollup merge of #81210 - ssomers:btree_fix_node_size_test, r=Mark-Simulacrum
BTreeMap: correct node size test case for choices of B

r? `@Mark-Simulacrum`
2021-03-01 11:24:58 -05:00
Cameron Steffen eada4d1c45 Add diagnostic items 2021-03-01 09:04:11 -06:00
bors d2731d8e93 Auto merge of #82654 - JohnTitor:rollup-nkcdkzp, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #82309 (Propagate RUSTDOCFLAGS in the environment when documenting)
 - #82403 (rustbuild: print out env vars on verbose rustc invocations)
 - #82507 (Rename the `tidy` binary to `rust-tidy`)
 - #82531 (Add GUI tests)
 - #82532 (Add `build.print_step_rusage` to config.toml)
 - #82543 (fix env var name in CI)
 - #82622 (Propagate `--test-args` for `x.py test src/tools/cargo`)
 - #82628 (Try to clarify GlobalAlloc::realloc documentation comment.)
 - #82630 (Fix a typo in the `find_anon_type` doc)
 - #82643 (Add more proc-macro attribute tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-01 08:22:06 +00:00
Yuki Okushi 1b9f420e1b
Rollup merge of #82628 - vakaras:realloc-doc, r=Mark-Simulacrum
Try to clarify GlobalAlloc::realloc documentation comment.

This PR tries to improve the documentation of [GlobalAlloc::realloc](https://doc.rust-lang.org/alloc/alloc/trait.GlobalAlloc.html#method.realloc) with two aspects:

1. Explicitly mention that `realloc` preserves the contents of the original memory block.
2. Explicitly mention which layout should be used to deallocate the reallocated block.
2021-03-01 15:07:38 +09:00
bors 05c300144c Auto merge of #82440 - ssomers:btree_fix_casts, r=Mark-Simulacrum
BTree: no longer define impossible casts

Casts to leaf to internal only make sense when the original has a chance of being the thing it's cast to.

r? `@Mark-Simulacrum`
2021-03-01 05:39:01 +00:00
bors 3b150b7a8f Auto merge of #81094 - ssomers:btree_drainy_refactor_3, r=Mark-Simulacrum
BTreeMap: split up range_search into two stages

`range_search` expects the caller to pass the same root twice and starts searching a node for both bounds of a range. It's not very clear that in the early iterations, it searches twice in the same node. This PR splits that search up in an initial `find_leaf_edges_spanning_range` that postpones aliasing until the last second, and a second phase for continuing the search for the range in the each subtree independently (`find_lower_bound_edge` & `find_upper_bound_edge`), which greatly helps for use in #81075. It also moves those functions over to the search module.

r? `@Mark-Simulacrum`
2021-03-01 02:48:29 +00:00
Erik Jensen 2616960be2
Clarify that SyncOnceCell::set blocks.
Reading the discussion of this feature, I gained the mistaken impression that neither `set` nor `get` blocked, and thus calling `get` immediately after `set` was not guaranteed to succeed. It turns out that `set` *does* block, guaranteeing that the cell contains a value once `set` returns. This change updates the documentation to state that explicitly.
2021-02-28 12:57:38 -08:00
Vytautas Astrauskas cdfff98394 Try to clarify GlobalAlloc::realloc documentation comment. 2021-02-28 14:30:26 +01:00
LinkTed 9e4e739209 unix: Non-mutable bufs in send_vectored_with_ancillary_to
Change the arguments of `send_vectored_with_ancillary` and
`send_vectored_with_ancillary_to` to take an non-mutable bufs.
2021-02-28 13:33:09 +01:00
bors 247337f409 Auto merge of #82350 - ehuss:test-chapter, r=jyn514
Add a chapter on the test harness.

There isn't really any online documentation on the test harness, so this adds a chapter to the rustc book which provides information on how the harness works and details on the command-line options.
2021-02-28 09:18:27 +00:00
bors 6e2801c44e Auto merge of #82594 - nagisa:nagisa/remove-rumprun, r=petrochenkov
Remove the x86_64-rumprun-netbsd target

Herein we remove the target from the compiler and the code from libstd intended to support the now-defunct rumprun project.

Closes #81514
2021-02-28 03:56:16 +00:00
Dylan DPC e38b3eb0b5
Rollup merge of #82596 - matklad:rwlock, r=sfackler
clarify RW lock's priority gotcha

In particular, the following program works on Linux, but deadlocks on
mac:

```rust
    use std::{
        sync::{Arc, RwLock},
        thread,
        time::Duration,
    };

    fn main() {
        let lock = Arc::new(RwLock::new(()));

        let r1 = thread::spawn({
            let lock = Arc::clone(&lock);
            move || {
                let _rg = lock.read();
                eprintln!("r1/1");
                sleep(1000);

                let _rg = lock.read();
                eprintln!("r1/2");

                sleep(5000);
            }
        });
        sleep(100);
        let w = thread::spawn({
            let lock = Arc::clone(&lock);
            move || {
                let _wg = lock.write();
                eprintln!("w");
            }
        });
        sleep(100);
        let r2 = thread::spawn({
            let lock = Arc::clone(&lock);
            move || {
                let _rg = lock.read();
                eprintln!("r2");
                sleep(2000);
            }
        });

        r1.join().unwrap();
        r2.join().unwrap();
        w.join().unwrap();
    }

    fn sleep(ms: u64) {
        std:🧵:sleep(Duration::from_millis(ms))
    }
```

Context: I was completely mystified by a my CI deadlocking on mac ([here](https://github.com/matklad/xshell/pull/7)), until ``@azdavis`` debugged the issue. See a stand-alone reproduciton here: https://github.com/matklad/xshell/pull/15
2021-02-27 21:56:24 +01:00
Dylan DPC b1113abacd
Rollup merge of #82561 - tspiteri:cube-root, r=Dylan-DPC
doc: cube root, not cubic root

Like we say square root, not quadratic root.
2021-02-27 21:56:21 +01:00
Dylan DPC ea43e5e21d
Rollup merge of #82395 - pickfire:see-more, r=GuillaumeGomez
Add missing "see its documentation for more" stdio

StdoutLock and StderrLock does not have example, it would be better
to leave "see its documentation for more" like iter docs.
2021-02-27 21:56:16 +01:00
Aleksey Kladov 261c952ba6
Update library/std/src/sync/rwlock.rs
Co-authored-by: Steven Fackler <sfackler@gmail.com>
2021-02-27 19:44:17 +03:00
Aleksey Kladov d94b4e81e4 clarify RW lock's priority gotcha
In particular, the following program works on Linux, but deadlocks on
mac:

    use std::{
        sync::{Arc, RwLock},
        thread,
        time::Duration,
    };

    fn main() {
        let lock = Arc::new(RwLock::new(()));

        let r1 = thread::spawn({
            let lock = Arc::clone(&lock);
            move || {
                let _rg = lock.read();
                eprintln!("r1/1");
                sleep(1000);

                let _rg = lock.read();
                eprintln!("r1/2");

                sleep(5000);
            }
        });
        sleep(100);
        let w = thread::spawn({
            let lock = Arc::clone(&lock);
            move || {
                let _wg = lock.write();
                eprintln!("w");
            }
        });
        sleep(100);
        let r2 = thread::spawn({
            let lock = Arc::clone(&lock);
            move || {
                let _rg = lock.read();
                eprintln!("r2");
                sleep(2000);
            }
        });

        r1.join().unwrap();
        r2.join().unwrap();
        w.join().unwrap();
    }

    fn sleep(ms: u64) {
        std:🧵:sleep(Duration::from_millis(ms))
    }
2021-02-27 19:21:50 +03:00
Simonas Kazlauskas a757fae245 Remove the x86_64-rumprun-netbsd target
Closes #81514
2021-02-27 17:55:22 +02:00
bors ec7f8d94df Auto merge of #81874 - tesuji:spec_slice_fill, r=matthewjasper
Specialize slice::fill with Copy type and u8/i8/bool

I don't expect rustperf could measure any perf improvements with this changes
since `slice::fill` is newly added.

Godbolt link for this change: <https://rust.godbolt.org/z/r3fzee>.

r? `@matthewjasper` since this patch added new specialization.
2021-02-27 14:54:31 +00:00
Folyd 3eb5bee242 Fix binary_search_by() overflow issue in ZST case 2021-02-27 22:11:44 +08:00
Dylan DPC b664e4bdb5
Rollup merge of #82473 - de-vri-es:android-x86-accept4, r=m-ou-se
Use libc::accept4 on Android instead of raw syscall.

This PR replaces the use of a raw `accept4` syscall with `libc::accept4`. This was originally added (by me) because `std` couldn't update to the latest `libc` with `accept4` support for android. By now, libc is already on 0.2.85, so the workaround can be removed.

`@rustbot` label +O-android +T-libs-impl
2021-02-27 02:34:31 +01:00
Dylan DPC d80033f048
Rollup merge of #82421 - sunfishcode:wasi-metadata-size, r=alexcrichton
Add a `size()` function to WASI's `MetadataExt`.

WASI's `filestat` type includes a size field, so expose it in
`MetadataExt` via a `size()` function, similar to the corresponding Unix
function.

r? ``````@alexcrichton``````
2021-02-27 02:34:28 +01:00
Dylan DPC f5b68a4444
Rollup merge of #82420 - sunfishcode:wasi-docs, r=alexcrichton
Enable API documentation for `std::os::wasi`.

This adds API documentation support for `std::os::wasi` modeled after
how `std::os::unix` works, so that WASI can be documented [here] along
with the other platforms.

[here]: https://doc.rust-lang.org/stable/std/os/index.html

Two changes of particular interest:

 - This changes the `AsRawFd` for `io::Stdin` for WASI to return
   `libc::STDIN_FILENO` instead of `sys::stdio::Stdin.as_raw_fd()` (and
   similar for `Stdout` and `Stderr`), which matches how the `unix`
   version works. `STDIN_FILENO` etc. may not always be explicitly
   reserved at the WASI level, but as long as we have Rust's `std` and
   `libc`, I think it's reasonable to guarantee that we'll always use
   `libc::STDIN_FILENO` for stdin.

 - This duplicates the `osstr2str` utility function, rather than
   trying to share it across all the configurations that need it.

r? ```@alexcrichton```
2021-02-27 02:34:27 +01:00
Waffle 2f04a793ae Revert Vec::spare_capacity_mut impl to prevent pointers invalidation 2021-02-27 00:27:34 +03:00
Trevor Spiteri dd502cb343 doc: cube root, not cubic root
Like we say square root, not quadratic root.
2021-02-26 19:03:44 +01:00
Guillaume Gomez 0db8349fff
Rollup merge of #81940 - jhpratt:stabilize-str_split_once, r=m-ou-se
Stabilize str_split_once

Closes #74773
2021-02-26 15:52:29 +01:00
Joshua Nelson 4d46735b8e Convert the rest of the standard library primitives to intra-doc links
Note that float methods in `core::intrinsics` weren't converted because
they are only defined in `std` (using language item hacks).
2021-02-25 20:32:49 -05:00
Joshua Nelson 9a75f4fed1 Convert primitives to use intra-doc links 2021-02-25 20:31:53 -05:00
bors d95d304861 Auto merge of #78429 - casey:doctest-attribute-splitting, r=jyn514
[librustdoc] Only split lang string on `,`, ` `, and `\t`

Split markdown lang strings into tokens on `,`.

The previous behavior was to split lang strings into tokens on any
character that wasn't a `_`, `_`, or alphanumeric.

This is a potentially breaking change, so please scrutinize! See discussion in #78344.

I noticed some test cases that made me wonder if there might have been some reason for the original behavior:

```
t("{.no_run .example}", false, true, Ignore::None, true, false, false, false, v(), None);
t("{.sh .should_panic}", true, false, Ignore::None, false, false, false, false, v(), None);
t("{.example .rust}", false, false, Ignore::None, true, false, false, false, v(), None);
t("{.test_harness .rust}", false, false, Ignore::None, true, true, false, false, v(), None);
```

It seemed pretty peculiar to specifically test lang strings in braces, with all the tokens prefixed by `.`.

I did some digging, and it looks like the test cases were added way back in [this commit from 2014](https://github.com/rust-lang/rust/commit/3fef7a74ca9a) by `@skade.`

It looks like they were added just to make sure that the splitting was permissive, and aren't testing that those strings in particular are accepted.

Closes https://github.com/rust-lang/rust/issues/78344.
2021-02-26 00:17:22 +00:00
Aaron Hill befa2dffda
Rollup merge of #82467 - ojeda:tidy-normalize-safety-comments, r=kennytm
library: Normalize safety-for-unsafe-block comments

Almost all safety comments are of the form `// SAFETY:`,
so normalize the rest and fix a few of them that should
have been a `/// # Safety` section instead.

Furthermore, make `tidy` only allow the uppercase form. While
currently `tidy` only checks `core`, it is a good idea to prevent
`core` from drifting to non-uppercase comments, so that later
we can start checking `alloc` etc. too.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-02-25 16:06:21 -05:00
Aaron Hill 503d50b94c
Rollup merge of #82464 - ehuss:unix-command-comment, r=kennytm
Update outdated comment in unix Command.

The big comment in the `Command` struct has been incorrect for some time (at least since #46789 which removed `envp`). Rather than try to remove the allocations, this PR just updates the comment to reflect reality. There is an explanation for the reasoning at https://github.com/rust-lang/rust/pull/31409#issuecomment-182122895, discussing the potential of being able to call `Command::exec` after `libc::fork`.  That can still be done in the future, but I think for now it would be good to just correct the comment.
2021-02-25 16:06:20 -05:00
Dylan DPC f891af9de5
Rollup merge of #82078 - lopopolo:char-u8-const-fn, r=m-ou-se
Make char and u8 methods const

char methods `len_utf8`, `len_utf16`, `to_ascii_lowercase`, `eq_ignore_ascii_case` can be made const.

`u8` methods `to_ascii_lowercase`, `to_ascii_uppercase` are required to be const as well.

`u8::eq_ignore_ascii_case` was additionally made const.

Rebase of https://github.com/rust-lang/rust/pull/79549 originally authored by ``@YenForYang.`` Changes from that PR:

- Squashed all commits from #79549.
- rebased to latest upstream master.
- Removed const attributes for `char::escape_unicode` and `char::escape_default`.
- Updated `since` attributes for `const` stabilization to 1.52.0.

cc ``@m-ou-se.``
2021-02-25 14:33:55 +01:00
Dylan DPC 4b9c213d6f
Rollup merge of #81167 - usbalbin:const_write, r=oli-obk
Make ptr::write const

~~The code in this PR as of right now is not much more than an experiment.~~

~~This should, if I am not mistaken, in theory compile and pass the tests once the bootstraping compiler is updated. Thus the PR is blocked on that which should happen some time after the February the 9th. Also we might want to wait for #79989 to avoid regressing performance due to using `mem::forget` over `intrinsics::forget`~~.
2021-02-25 14:33:51 +01:00
Dylan DPC 351d947e54
Rollup merge of #80553 - derekdreery:arc_error, r=m-ou-se
Add an impl of Error on `Arc<impl Error>`.

`Display` already exists so this should be a non-controversial change (famous last words).

Would have to be insta-stable.
2021-02-25 14:33:50 +01:00
Dylan DPC cb2b4ff714
Rollup merge of #80534 - LeSeulArtichaut:doc-include, r=jyn514
Use #[doc = include_str!()] in std

cc https://github.com/rust-lang/rust/issues/78835#issuecomment-742531894
r? `````@jyn514`````
2021-02-25 14:33:47 +01:00
Dylan DPC c9cf92226c
Rollup merge of #75807 - jyn514:num-intra-link, r=poliorcetics
Convert core/num/mod.rs to intra-doc links

Helps with #75080.
This can't convert the associated constants `MAX` and `MIN` until #74489 is merged.

r? `@poliorcetics`
2021-02-25 14:33:44 +01:00
bors 63bacf14cd Auto merge of #82162 - cuviper:flat-fold, r=Mark-Simulacrum
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-25 00:36:05 +00:00
Dan Gohman 7d5242a03a x.py fmt 2021-02-24 10:58:21 -08:00
Dan Gohman 94e75acf1f Mention "wasi" in the comment about "main modules". 2021-02-24 10:47:26 -08:00
Dan Gohman e66e263544 Make the main wasi module cfg(not(doc)). 2021-02-24 10:43:50 -08:00
Dan Gohman 0208fca342 Use super:: to refer to WASI-specific names.
This ensures that these names resolve to the right place even when
building the WASI support on other platforms for generating the
documentation.
2021-02-24 10:37:05 -08:00
Dan Gohman 9ce567efc2 Cast libc::STDIN_FILENO to RawFd.
WASI's `RawFd` is a `u32`, while `libc` uses `c_int`.
2021-02-24 10:35:40 -08:00
Maarten de Vries f291131f2e Bump minimum libc version to 0.2.85 for std. 2021-02-24 12:47:28 +01:00
Maarten de Vries 3ac62cafa3 Use libc::accept4 on Android instead of raw syscall. 2021-02-24 12:24:36 +01:00
Kevin Per a3db47ab6c Add suggestion for iterators in iterators 2021-02-24 07:07:53 +00:00
Miguel Ojeda eefec8abda library: Normalize safety-for-unsafe-block comments
Almost all safety comments are of the form `// SAFETY:`,
so normalize the rest and fix a few of them that should
have been a `/// # Safety` section instead.

Furthermore, make `tidy` only allow the uppercase form. While
currently `tidy` only checks `core`, it is a good idea to prevent
`core` from drifting to non-uppercase comments, so that later
we can start checking `alloc` etc. too.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-02-24 06:13:42 +01:00
Eric Huss 476c6c27e7 Update outdated comment in unix Command. 2021-02-23 20:19:15 -08:00
Albin Hedman 89c761058a
Constify ptr::write and the write[_unaligned] methods on *mut T
Constify intrinsics::forget
2021-02-23 18:00:01 +01:00
Ryan Lopopolo 1ed9dd4179
Make ascii_change_case_unchecked const
Rebases and makes changes required by the recent merge of #81837.
2021-02-23 07:20:13 -08:00
Ryan Lopopolo 7b41ad1c1f
Update since attributes for new const_ascii_methods_on_intrinsics to 1.52.0 2021-02-23 07:18:48 -08:00
Ryan Lopopolo 6a72491367
Remove const from iterator fns 2021-02-23 07:18:47 -08:00
YenForYang bcb1f068bc
Make char methods const
`escape_unicode`, `escape_default`, `len_utf8`, `len_utf16`, to_ascii_lowercase`, `eq_ignore_ascii_case`

`u8` methods `to_ascii_lowercase`, `to_ascii_uppercase` also must be made const

u8 methods made const

Update methods.rs

Update mod.rs

Update methods.rs

Fix `since` in rustc_const_stable to next stable

Fix `since` in rustc_const_stable to next stable

Update methods.rs

Update mod.rs
2021-02-23 07:18:45 -08:00
Dylan DPC 51511c75b5
Rollup merge of #82391 - RalfJung:miri-atomic-minmax, r=dtolnay
disable atomic_max/min tests in Miri

Disable some tests that currently [fail in Miri](https://travis-ci.com/github/RalfJung/miri-test-libstd/builds/217788631).
2021-02-23 16:10:30 +01:00
Dylan DPC 547b3adfe4
Rollup merge of #82113 - m-ou-se:panic-format-lint, r=estebank
Improve non_fmt_panic lint.

This change:
- fixes the span used by this lint in the case the panic argument is a single macro expansion (e.g. `panic!(a!())`);
- adds a suggestion for `panic!(format!(..))` to remove `format!()` instead of adding `"{}", ` or using `panic_any` like it does now; and
- fixes the incorrect suggestion to replace `panic![123]` by `panic_any(123]`.

Fixes #82109.
Fixes #82110.
Fixes #82111.

Example output:
```
warning: panic message is not a string literal
 --> src/main.rs:8:12
  |
8 |     panic!(format!("error: {}", "oh no"));
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(non_fmt_panic)]` on by default
  = note: this is no longer accepted in Rust 2021
  = note: the panic!() macro supports formatting, so there's no need for the format!() macro here
help: remove the `format!(..)` macro call
  |
8 |     panic!("error: {}", "oh no");
  |           --                  --

```

r? `@estebank`
2021-02-23 16:10:21 +01:00
LeSeulArtichaut a6eb836ff0 Use #[doc = include_str!()] in std 2021-02-23 15:54:55 +01:00
Joshua Nelson ea3118ca0d Fix link 2021-02-23 08:54:18 -05:00
Joshua Nelson 2179313dcf Convert core/num/mod.rs to intra-doc links 2021-02-23 08:54:16 -05:00
Dan Gohman 132ec261b0 Enable API documentation for std::os::wasi.
This adds API documentation support for `std::os::wasi` modeled after
how `std::os::unix` works, so that WASI can be documented [here] along
with the other platforms.

[here]: https://doc.rust-lang.org/stable/std/os/index.html

Two changes of particular interest:

 - This changes the `AsRawFd` for `io::Stdin` for WASI to return
   `libc::STDIN_FILENO` instead of `sys::stdio::Stdin.as_raw_fd()` (and
   similar for `Stdout` and `Stderr`), which matches how the `unix`
   version works. `STDIN_FILENO` etc. may not always be explicitly
   reserved at the WASI level, but as long as we have Rust's `std` and
   `libc`, I think it's reasonable to guarantee that we'll always use
   `libc::STDIN_FILENO` for stdin.

 - This duplicates the `osstr2str` utility function, rather than
   trying to share it across all the configurations that need it.
2021-02-23 05:40:08 -08:00
Stein Somers 986a183337 BTree: fix untrue safety 2021-02-23 11:44:10 +01:00
Stein Somers 794561c391 BTree: no longer define impossible casts 2021-02-23 11:39:03 +01:00
Stein Somers deebb63cc8 BTree: split off reusable components from range_search 2021-02-23 10:15:51 +01:00
bors cd64446196 Auto merge of #82076 - jyn514:update-bootstrap, r=Mark-Simulacrum
Update the bootstrap compiler

This updates the bootstrap compiler, notably leaving out a change to enable semicolon in macro expressions lint, because stdarch still depends on the old behavior.
2021-02-23 07:19:41 +00:00
bors a4e595db8f Auto merge of #82430 - Dylan-DPC:rollup-nu4kfyc, r=Dylan-DPC
Rollup of 12 pull requests

Successful merges:

 - #79423 (Enable smart punctuation)
 - #81154 (Improve design of `assert_len`)
 - #81235 (Improve suggestion for tuple struct pattern matching errors.)
 - #81769 (Suggest `return`ing tail expressions that match return type)
 - #81837 (Slight perf improvement on char::to_ascii_lowercase)
 - #81969 (Avoid `cfg_if` in `std::os`)
 - #81984 (Make WASI's `hard_link` behavior match other platforms.)
 - #82091 (use PlaceRef abstractions more consistently)
 - #82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice)
 - #82166 (add s390x-unknown-linux-musl target)
 - #82234 (Remove query parameters when skipping search results)
 - #82255 (Make `treat_err_as_bug` Option<NonZeroUsize>)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-23 04:31:32 +00:00
Dylan DPC b8d4354099
Rollup merge of #82128 - anall:feature/add_diagnostic_items, r=davidtwco
add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice

This is adding diagnostic items to be used by rust-lang/rust-clippy#6730, but my understanding is the clippy-side change does need to be done over there since I am adding a new clippy feature.

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-23 02:51:51 +01:00
Dylan DPC 7b9ef2fde4
Rollup merge of #81984 - sunfishcode:wasi-link, r=alexcrichton
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.

r? ```@alexcrichton```
2021-02-23 02:51:49 +01:00
Dylan DPC c3de8ab908
Rollup merge of #81969 - jonas-schievink:no-cfg-if, r=Mark-Simulacrum
Avoid `cfg_if` in `std::os`

rust-analyzer cannot currently load the `cfg_if` crate, which means that rust-analyzer is unable to see `std::os::{unix, windows, linux}` here. This works around that by avoiding `cfg_if`; the `#[cfg]` expressions are simple enough to reasonably write by hand.

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6038
2021-02-23 02:51:48 +01:00
Dylan DPC 4af965e732
Rollup merge of #81837 - gilescope:to_ascii_speedups, r=dtolnay
Slight perf improvement on char::to_ascii_lowercase

`char::to_ascii_lowercase()` was checking if it was ascii and then if it was in the right range. Instead propose to check once (I think removing a compare and a shift in the process: [godbolt](https://godbolt.org/z/e5Tora) ).

before:
```
        test char::methods::bench_to_ascii_lowercase                    ... bench:      11,196 ns/iter (+/- 632)
        test char::methods::bench_to_ascii_uppercase                    ... bench:      11,656 ns/iter (+/- 671)
```
after:
```
         test char::methods::bench_to_ascii_lowercase                    ... bench:       9,612 ns/iter (+/- 979)
         test char::methods::bench_to_ascii_uppercase                    ... bench:       8,241 ns/iter (+/- 701)
```

(calling u8::to_ascii_lowercase and letting that flip the 5th bit is also an option, but it's more instructions. I'm thinking for things around ascii and char we want to be as efficient as possible.)
2021-02-23 02:51:47 +01:00
Dylan DPC 72e6d51583
Rollup merge of #81154 - dylni:improve-design-of-assert-len, r=KodrAus
Improve design of `assert_len`

It was discussed in the [tracking issue](https://github.com/rust-lang/rust/issues/76393#issuecomment-761765448) that `assert_len`'s name and usage are confusing. This PR improves them based on a suggestion by ``@scottmcm`` in that issue.

I also improved the documentation to make it clearer when you might want to use this method.

Old example:

```rust
let range = range.assert_len(slice.len());
```

New example:

```rust
let range = range.ensure_subset_of(..slice.len());
```

Fixes #81157
2021-02-23 02:51:43 +01:00
bors b02a6193b3 Auto merge of #81937 - ssomers:btree_drainy_refactor_9b, r=Mark-Simulacrum
BTree: move more shared iterator code into navigate.rs

The functions in navigate.rs only exist to support iterators, and these look easier on my eyes if there is a shared `struct` with the recurring pair of handles.

r? `@Mark-Simulacrum`
2021-02-23 00:30:37 +00:00
Dan Gohman e8dcc02dc5 Add a size() function to WASI's MetadataExt.
WASI's `filestat` type includes a size field, so expose it in
`MetadataExt` via a `size()` function, similar to the corresponding Unix
function.
2021-02-22 14:42:59 -08:00
Jonas Schievink 7bc501687b Avoid cfg_if in std::os 2021-02-22 19:56:20 +01:00
bors a15f484b91 Auto merge of #81362 - ssomers:btree_drainy_refactor_8, r=Mark-Simulacrum
BTreeMap: gather and decompose reusable tree fixing functions

This is kind of pushing it as a standalone refactor, probably only useful for #81075 (or similar).
r? `@Mark-Simulacrum`
2021-02-22 17:56:43 +00:00
Richard Dodd 0d6640a5b0 Add impl Error for Arc 2021-02-22 12:49:42 +00:00
Ivan Tham bff4e937ab Add missing "see its documentation for more" stdio
StdoutLock and StderrLock does not have example, it would be better
to leave "see its documentation for more" like iter docs.
2021-02-22 18:48:32 +08:00
Yuki Okushi 7958166300
Rollup merge of #82372 - RalfJung:unsafe-cell, r=KodrAus
improve UnsafeCell docs

Sometimes [questions like this come up](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/UnsafeCells.20as.20raw.20pointers) because the UnsafeCell docs say "it's the only legal way to obtain aliasable data that is considered mutable". That is not entirely correct, since raw pointers also provide that option. So I propose we focus the docs on the interaction of `UnsafeCell` and *shared references* specifically, which is really where they are needed.
2021-02-22 18:26:11 +09:00
Yuki Okushi a5f6668920
Rollup merge of #82228 - ijackson:nonzero-cint, r=KodrAus
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.

<strike>Because the raw C types are in `std`, not `core`, to achieve this we
must export the relevant macros from `core` so that `std` can use
them.  That's done with a new `num_internals` perma-unstable feature.

The macros need to take more parameters for the module to get the
types from and feature attributes to use.

I have eyeballed the docs output for core, to check that my changes to
these macros have made no difference to the core docs output.</strike>
2021-02-22 18:26:06 +09:00
Yuki Okushi 3cf201fb81
Rollup merge of #82098 - LukasKalbertodt:add-collect-into-array, r=dtolnay
Add internal `collect_into_array[_unchecked]` to remove duplicate code

Unlike the similar PRs  #69985, #75644 and #79659, this PR only adds private functions and does not propose any new public API. The change 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, ...}`, `[T; N]::{cloned, copied, ...}`, ...) which all basically need this functionality. Writing custom `unsafe` code for each of those doesn't seem like a good idea. I added two functions in this PR (and not just the `unsafe` version) because I already know that I need the `Option`-returning version for `Iterator::map_windows`.

This is closely related to https://github.com/rust-lang/rust/issues/81615. I think that all options listed in that issue can be implemented using the function added in this PR. The only instance where `collect_array_into` might not be general enough is when the caller want to handle incomplete arrays manually. Currently, if `iter` yields fewer than `N` items, `None` is returned and the already yielded items are dropped. But as this is just a private function, it can be made more general in future PRs.

And while this was not the goal, this seems to lead to better assembly for `array::map`: https://rust.godbolt.org/z/75qKTa (CC ``@JulianKnodt)``

Let me know what you think :)

CC ``@matklad`` ``@bstrie``
2021-02-22 18:26:04 +09:00
Ralf Jung dd9ab160a1 disable atomic_max/min tests in Miri 2021-02-22 10:06:51 +01:00
bors e952db8fd0 Auto merge of #81732 - m-ou-se:inherit-overflow-checks, r=Mark-Simulacrum
Use `#[rustc_inherit_overflow_checks]` instead of Add::add etc.

See https://github.com/rust-lang/rust/issues/81721
2021-02-22 04:07:05 +00:00
Stein Somers d9daedd433 BTreeMap: correct tests for alternative choices of B 2021-02-21 19:06:46 +01:00
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