Commit graph

2133 commits

Author SHA1 Message Date
bjorn3
1ad44b23d1 Remove unused function 2021-09-16 14:58:36 +02:00
bjorn3
a8bb3bcd38 Use const {} for the THREAD_INFO thread local
This makes accesses to it cheaper
2021-09-16 14:55:15 +02:00
bjorn3
f78cd44602 Optimize ThreadInfo::with
The RefCell is now borrowed exactly once. In addition a code sequence
that contains an unwrap that is guaranteed to never panic at runtime is
replaced with get_or_insert_with, which makes the intended behavior
clearer and will not emit code to panic even without optimizations.
2021-09-16 14:48:33 +02:00
bjorn3
af7eededaa Remove an allocation from rt::init
Previously the thread name would first be heap allocated and then
re-allocated to add a nul terminator. Now it will be heap allocated only
once with nul terminator added form the start.
2021-09-16 14:41:09 +02:00
bjorn3
6f6bb16718 Merge sys_common::rt into rt 2021-09-16 14:32:32 +02:00
est31
372711906b Add IntoIterator intra doc link to various collections 2021-09-16 13:55:27 +02:00
tatami4
a452d02636
Fix typo in break docs 2021-09-16 14:51:14 +03:00
Mark Rousskov
db5ecd539c Avoid codegen for Result::into_ok in lang_start
Otherwise, we end up pulling in an extra module as part of codegen, and that
costs us a sizeable amount of work (both in LLVM and outside).
2021-09-15 21:35:10 -04:00
Gary Guo
11c0e58c74 Allow panic!("{}", computed_str) in const fn. 2021-09-15 21:56:43 +01:00
Josh Triplett
862d89e3b5 Add tracking issue for unix_chown 2021-09-15 13:09:54 -07:00
Michael Howell
cc7929b1bd docs(std): add docs for cof_from_cstr impls
CC #51430
2021-09-15 09:14:20 -07:00
Josh Triplett
4840f67fcb Add chown functions to std::os::unix::fs to change the owner and group of files
This is a straightforward wrapper that uses the existing helpers for C
string handling and errno handling.

Having this available is convenient for UNIX utility programs written in
Rust, and avoids having to call unsafe functions like `libc::chown`
directly and handle errors manually, in a program that may otherwise be
entirely safe code.

In addition, these functions provide a more Rustic interface by
accepting appropriate traits and using `None` rather than `-1`.
2021-09-14 19:10:05 -07:00
Guillaume Gomez
7965a9f143 Move fortanix module position in std::os reexports for alpha sort 2021-09-13 21:00:28 +02:00
Guillaume Gomez
1c4873c81f Remove usage of cfg_if in std/src/os/mod.rs 2021-09-13 21:00:28 +02:00
Guillaume Gomez
8d879aa0f2 Simplify std::os module reexports to fix rustdoc linking issues 2021-09-13 21:00:28 +02:00
Joshua Nelson
69fe39e8a8 Add primitive documentation to libcore
This works by doing two things:
- Adding links that are specific to the crate. Since not all primitive
  items are defined in `core` (due to lang_items), these need to use
  relative links and not intra-doc links.
- Duplicating `primitive_docs` in both core and std. This allows not needing CARGO_PKG_NAME to build the standard library. It also adds a tidy check to make sure they stay the same.
2021-09-12 02:23:08 +00:00
Manish Goregaokar
00553034db
Rollup merge of #88807 - jruderman:which_reverses, r=joshtriplett
Fix typo in docs for iterators
2021-09-10 08:23:26 -07:00
Manish Goregaokar
8368af060d
Rollup merge of #88667 - kraktus:patch-1, r=dtolnay
Tweak `write_fmt` doc.

Found this weird sentence while reading the docs.
2021-09-10 08:23:21 -07:00
Jesse Ruderman
81ff53fd3e
Fix typo in docs for iterators 2021-09-09 19:21:56 -07:00
Fabian Wolff
79adda930f Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
Mark Rousskov
b4e7649d6d Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
Jack Huey
b1c782f20b
Rollup merge of #88594 - steffahn:more_symbolic_doc_aliases, r=joshtriplett
More symbolic doc aliases

A bunch of small changes, mostly adding `#[doc(alias = "…")]` entries for symbolic `"…"`.

Also a small change in documentation of `const` keywords.
2021-09-08 12:24:17 -04:00
Ryan Levick
29a018def4
Rollup merge of #88647 - ChrisDenton:win-symlink-docs, r=joshtriplett
Document when to use Windows' `symlink_dir` vs. `symlink_file`

It was previously unclear why there are two functions and when they should be used.

Fixes: #88635
2021-09-06 12:38:54 +02:00
lovasoa
f63096e4f2
rust fmt 2021-09-05 22:56:15 +01:00
Frank Steffahn
5135d86920 Mention usage of const in raw pointer types at the top of the keyword's documentation page. 2021-09-05 19:14:55 +02:00
Frank Steffahn
2b69171dc2 Additional aliases for pointers 2021-09-05 19:14:44 +02:00
kraktus
bfb2b02d61
Tweak write_fmt doc.
Previous version wrongly used `but` while the two parts of the sentence are not contradicting but completing with each other.
2021-09-05 17:23:58 +02:00
bors
0961e688fd Auto merge of #88469 - patrick-gu:master, r=dtolnay
Add links in docs for some primitive types

This pull request adds additional links in existing documentation of some of the primitive types.

Where items are linked only once, I have used the `[link](destination)` format. For items in `std`, I have linked directly to the HTML, since although the primitives are in `core`, they are not displayed on `core` documentation. I was unsure of what length I should keep lines of documentation to, so I tried to keep them within reason.

Additionally, I have avoided excessively linking to keywords like `self` when they are not relevant to the documentation. I can add these links if it would be an improvement.

I hope this can improve Rust. Please let me know if there's anything I did wrong!
2021-09-05 01:56:25 +00:00
Chris Denton
2d95b5bce7
Document when to use Windows' symlink_dir vs. symlink_file
It was previously unclear which should be used when.
2021-09-04 19:22:34 +01:00
patrick-gu
911d0cbe80 Remove excessive linking 2021-09-03 17:09:37 -07:00
Mara Bos
00c8da145c Update primitive docs for rust 2021. 2021-09-03 12:49:37 +02:00
Ophir LOJKINE
aaa6de7905
Add a better error message for #39364
There is a known bug in the implementation of mpsc channels in rust.
This adds a clearer error message when the bug occurs, so that developers don't lose too much time looking for the origin of the bug.
See https://github.com/rust-lang/rust/issues/39364
2021-09-03 12:14:55 +02:00
bors
b834c4c1ba Auto merge of #88596 - m-ou-se:rollup-cidzt4v, r=m-ou-se
Rollup of 12 pull requests

Successful merges:

 - #88177 (Stabilize std::os::unix::fs::chroot)
 - #88505 (Use `unwrap_unchecked` where possible)
 - #88512 (Upgrade array_into_iter lint to include Deref-to-array types.)
 - #88532 (Remove single use variables)
 - #88543 (Improve closure dummy capture suggestion in macros.)
 - #88560 (`fmt::Formatter::pad`: don't call chars().count() more than one time)
 - #88565 (Add regression test for issue 83190)
 - #88567 (Remove redundant `Span` in `QueryJobInfo`)
 - #88573 (rustdoc: Don't panic on ambiguous inherent associated types)
 - #88582 (Implement #88581)
 - #88589 (Correct doc comments inside `use_expr_visitor.rs`)
 - #88592 (Fix ICE in const check)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-02 18:58:12 +00:00
Mara Bos
e50069ff4f
Rollup merge of #88177 - joshtriplett:stabilize-chroot, r=m-ou-se
Stabilize std::os::unix::fs::chroot

I've verified that this works as documented, and I've tested it in (a nightly
build of) production software as a replacement for an unsafe call to
`libc::chroot`. It's been available in nightly for a few releases. I think it's
ready to stabilize.

---

Tracking issue: https://github.com/rust-lang/rust/issues/84715
2021-09-02 19:10:12 +02:00
bors
1cf8fdd4f0 Auto merge of #87580 - ChrisDenton:win-arg-parse-2008, r=m-ou-se
Update Windows Argument Parsing

Fixes #44650

The Windows command line is passed to applications [as a single string](https://docs.microsoft.com/en-us/archive/blogs/larryosterman/the-windows-command-line-is-just-a-string) which the application then parses to get a list of arguments. The standard rules (as used by C/C++) for parsing the command line have slightly changed over the years, most recently in 2008 which added new escaping rules.

This PR implements the new rules as [described on MSDN](https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=msvc-160#parsing-c-command-line-arguments) and [further detailed here](https://daviddeley.com/autohotkey/parameters/parameters.htm#WIN). It has been tested against the behaviour of C++ by calling a C++ program that outputs its raw command line and the contents of `argv`. See [my repo](https://github.com/ChrisDenton/winarg/tree/std) if anyone wants to reproduce my work.

For an overview of how this PR changes argument parsing behavior and why we feel it is warranted see https://github.com/rust-lang/rust/pull/87580#issuecomment-893833893.

For some examples see: https://github.com/rust-lang/rust/pull/87580#issuecomment-894299249
2021-09-02 16:16:13 +00:00
Frank Steffahn
ab89c88faa Consistent placement of doc alias for primitives below the doc(primitive…) 2021-09-02 17:21:05 +02:00
bdbai
a8ac6d471e I/O safety for WinUWP 2021-09-02 18:18:00 +08:00
bors
cc9bb1522e Auto merge of #83342 - Count-Count:win-console-incomplete-utf8, r=m-ou-se
Allow writing of incomplete UTF-8 sequences to the Windows console via stdout/stderr

# Problem
Writes of just an incomplete UTF-8 byte sequence (e.g. `b"\xC3"` or `b"\xF0\x9F"`)  to stdout/stderr with a Windows console attached error with `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` even though further writes could complete the codepoint. This is currently a rare occurence since the [linewritershim](2c56ea38b0/library/std/src/io/buffered/linewritershim.rs) implementation flushes complete lines immediately and buffers up to 1024 bytes for incomplete lines. It can still happen as described in #83258.

The problem will become more pronounced once the developer can switch stdout/stderr from line-buffered to block-buffered or immediate when the changes in the "Switchable buffering for Stdout" pull request (#78515) get merged.

# Patch description
If there is at least one valid UTF-8 codepoint all valid UTF-8 is passed through to the extracted `write_valid_utf8_to_console()` fn. The new code only comes into play if `write()` is being passed a short byte slice comprising an incomplete UTF-8 codepoint. In this case up to three bytes are buffered in the `IncompleteUtf8` struct associated with `Stdout` / `Stderr`. The bytes are accepted one at a time. As soon as an error can be detected `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` is returned. Once a complete UTF-8 codepoint is received it is passed to the `write_valid_utf8_to_console()` and the buffer length is set to zero.

Calling `flush()` will neither error nor write anything if an incomplete codepoint is present in the buffer.

# Tests
Currently there are no Windows-specific tests for console writing code at all. Writing (regression) tests for this problem is a bit challenging since unit tests and UI tests don't run in a console and suddenly popping up another console window might be surprising to developers running the testsuite and it might not work at all in CI builds. To just test the new functionality in unit tests the code would need to be refactored. Some guidance on how to proceed would be appreciated.

# Public API changes
* `std::str::verifications::utf8_char_width()` would be exposed as `std::str::utf8_char_width()` behind the "str_internals" feature gate.

# Related issues
* Fixes #83258.
* PR #78515 will exacerbate the problem.

# Open questions
* Add tests?
* Squash into one commit with better commit message?
2021-09-02 03:31:17 +00:00
Mara Bos
d31352961c
Rollup merge of #88551 - inquisitivecrystal:unsafe_cell_raw_get, r=m-ou-se
Stabilize `UnsafeCell::raw_get()`

This PR stabilizes the associated function `UnsafeCell::raw_get()`. The FCP has [already completed](https://github.com/rust-lang/rust/issues/66358#issuecomment-899095068). While there was some discussion about the naming after the close of the FCP, it looks like people have agreed on this name. Still, it would probably be best if a `libs-api` member had a look at this and stated whether more discussion is needed.

While I was at it, I added some tests for `UnsafeCell`, because there were barely any.

Closes #66358.
2021-09-01 09:23:31 +02:00
Mara Bos
59588a9a56
Rollup merge of #88542 - tavianator:readdir_r-errno, r=jyn514
Use the return value of readdir_r() instead of errno

POSIX says:

> If successful, the readdir_r() function shall return zero; otherwise,
> an error number shall be returned to indicate the error.

But we were previously using errno instead of the return value.  This
led to issue #86649.
2021-09-01 09:23:29 +02:00
inquisitivecrystal
753dac16ab Stabilize UnsafeCell::raw_get() 2021-08-31 14:44:13 -07:00
Tavian Barnes
0e0c8aef87 Use the return value of readdir_r() instead of errno
POSIX says:

> If successful, the readdir_r() function shall return zero; otherwise,
> an error number shall be returned to indicate the error.

But we were previously using errno instead of the return value.  This
led to issue #86649.
2021-08-31 14:11:42 -04:00
Mara Bos
f5cf9678c2
Rollup merge of #88524 - soenkehahn:master, r=jyn514
Remove unnecessary `mut` from udp doctests

I don't think this `mut` is necessary, since both `recv_from` and `send_to` take `&self`.
2021-08-31 17:55:02 +02:00
Mara Bos
c5a34d802d
Rollup merge of #88495 - ibraheemdev:tcp-linger, r=joshtriplett
Add `TcpStream::set_linger` and `TcpStream::linger`

Adds methods for getting/setting the `SO_LINGER` option on TCP sockets. Behavior is consistent across Unix and Windows.

r? `@joshtriplett` (I noticed you've been reviewing net related PRs)
2021-08-31 17:54:58 +02:00
Ibraheem Ahmed
072e8c977a
disable tcp_linger feature in std
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-08-31 11:19:39 -04:00
Mara Bos
497267a961
Rollup merge of #88465 - marcospb19:master, r=joshtriplett
Adding examples to docs of `std::time` module

And adding missing link to `Duration` from `Instant`.
2021-08-31 10:41:24 +02:00
Mara Bos
cd20fbdf82
Rollup merge of #88394 - ChrisDenton:patch-1, r=joshtriplett
Document `std::env::current_exe` possible rename behaviour

It might not be obvious that the "path of the current running executable" may (or may not) imply "at the time it was loaded".

This came up recently in chat so I thought it might be worth documenting.
2021-08-31 10:41:17 +02:00
Sönke Hahn
4027629edc Remove unnecessary mut from udp doctests 2021-08-30 22:31:34 -06:00
ibraheemdev
dafc14794f clean up c::linger conversion 2021-08-30 14:00:21 -04:00
ibraheemdev
3b6777f1ab add TcpStream::set_linger and TcpStream::linger 2021-08-30 13:42:52 -04:00
João M. Bezerra
faf59853f9 Adding examples to docs of std::time module
And adding missing link to Duration from Instant
2021-08-29 23:59:35 -03:00
patrick-gu
5719d22125 Add links in docs for some primitive types 2021-08-29 13:48:21 -07:00
Guillaume Gomez
281dfac12f
Rollup merge of #88381 - rtzoeller:dfly_stack_t_ss_sp_void, r=dtolnay
Handle stack_t.ss_sp type change for DragonFlyBSD

stack_t.ss_sp is now c_void on DragonFlyBSD, like the rest of the BSDs.

Changed in 02922ef750.
2021-08-29 16:25:31 +02:00
bors
677b517e66 Auto merge of #87921 - kellerkindt:master, r=kennytm
Add Saturating type (based on Wrapping type)

Tracking #87920

### Unresolved Questions
<!--
Include any open questions that need to be answered before the feature can be
stabilised.
-->

 - [x] ~`impl Div for Saturating<T>` falls back on inner integer division - which seems alright?~
    - [x] add `saturating_div`? (to respect division by `-1`)
 - [x] There is no `::saturating_shl` and `::saturating_shr`. (How to) implement `Shl`, `ShlAssign`, `Shr` and `ShrAssign`?
   - [naively](3f7d2ce28f)
 - [x] ~`saturating_neg` is only implemented on [signed integer types](https://doc.rust-lang.org/std/?search=saturating_n)~
 - [x] Is the implementation copied over from the `Wrapping`-type correct for `Saturating`?
   - [x] `Saturating::rotate_left`
   - [x] `Saturating::rotate_right`
   - [x] `Not`
   - [x] `BitXorOr` and `BitXorOrAssign`
   - [x] `BitOr` and `BitOrAssign`
   - [x] `BitAnd` and `BitAndAssign`
   - [x] `Saturating::swap_bytes`
   - [x] `Saturating::reverse_bits`
2021-08-28 23:39:02 +00:00
Ryan Zoeller
0d1d9788e5 Handle stack_t.ss_sp type change for DragonFlyBSD
stack_t.ss_sp is now c_void on DragonFlyBSD, so the specialization is no longer needed.

Changed in 02922ef750.
2021-08-27 17:31:42 -05:00
Chris Denton
50da1eb1cd
Document std::env::current_exe rename behaviour
It might not be obvious that the "path of the current running executable" may (or may not) mean "at the time it was loaded".
2021-08-27 14:25:29 +01:00
bors
d5cd3205fd Auto merge of #88371 - Manishearth:rollup-pkkjsme, r=Manishearth
Rollup of 11 pull requests

Successful merges:

 - #87832 (Fix debugger stepping behavior with `match` expressions)
 - #88123 (Make spans for tuple patterns in E0023 more precise)
 - #88215 (Reland #83738: "rustdoc: Don't load all extern crates unconditionally")
 - #88216 (Don't stabilize creation of TryReserveError instances)
 - #88270 (Handle type ascription type ops in NLL HRTB diagnostics)
 - #88289 (Fixes for LLVM change 0f45c16f2caa7c035e5c3edd40af9e0d51ad6ba7)
 - #88320 (type_implements_trait consider obligation failure on overflow)
 - #88332 (Add argument types tait tests)
 - #88340 (Add `c_size_t` and `c_ssize_t` to `std::os::raw`.)
 - #88346 (Revert "Add type of a let tait test impl trait straight in let")
 - #88348 (Add field types tait tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-27 01:07:17 +00:00
piegames
ced597edb7 Add TcpListener::into_incoming and IntoIncoming
The `incoming` method is really useful, however for some use cases the borrow
this introduces is needlessly restricting. Thus, an owned variant is added.
2021-08-26 23:42:04 +02:00
Manish Goregaokar
e760740c03
Rollup merge of #88340 - thomcc:c_size_t, r=joshtriplett
Add `c_size_t` and `c_ssize_t` to `std::os::raw`.

Apparently these aren't guaranteed to be the same, and are merely "always the same in practice" (see https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/.60usize.60.20vs.20.60size_t.60).

This is a big footgun, but I suspect it can be alleviated if we expose this and start migrating people to it in advance of any platforms that ever have this as different.

I'll file a tracking issue after this gets some traction.
2021-08-26 12:38:13 -07:00
bors
ad02dc46ba Auto merge of #87194 - eddyb:const-value-mangling, r=michaelwoerister,oli-obk
rustc_symbol_mangling: support structural constants and &str in v0.

This PR should unblock #85530 (except for float `const` generics, which AFAIK should've never worked).
(cc `@tmiasko` could the https://github.com/rust-lang/rust/pull/85530#issuecomment-857855379 failures be retried with a quick crater "subset" run of this PR + changing the default to `v0`? Just to make sure I didn't miss anything other than the floats)

The encoding is the one suggested before in e.g. https://github.com/rust-lang/rust/issues/61486#issuecomment-878932102, tho this PR won't by itself finish #61486, before closing that we'd likely want to move to `@oli-obk's` "valtrees" (i.e. #83234 and other associated work).

<hr>

**EDITs**:
1. switched unit/tuple/braced-with-named-fields `<const-fields>` prefixes from `"u"`/`"T"`/`""` to `"U"`/`"T"`/`"S"` to avoid the ambiguity reported by `@tmiasko` in https://github.com/rust-lang/rust/pull/87194#issuecomment-884279921.

2. `rustc-demangle` PR: https://github.com/alexcrichton/rustc-demangle/pull/55

3. RFC amendment PR: https://github.com/rust-lang/rfcs/pull/3161
    * also removed the grammar changes included in that PR, from this description

4. added tests (temporarily using my fork of `rustc-demangle`)

<hr>

r? `@michaelwoerister`
2021-08-26 19:15:09 +00:00
Thom Chiovoloni
5b25de58d6 Reference tracking issue 2021-08-25 14:58:17 -07:00
Thom Chiovoloni
33c71ac87d Add c_size_t and c_ssize_t to std::os::raw. 2021-08-25 11:25:26 -07:00
Léo Lanteri Thauvin
3eee91b403
Rollup merge of #88299 - ijackson:bufwriter, r=Mark-Simulacrum
Stabilise BufWriter::into_parts

The FCP for this has already completed, in #80690.

This was just blocked on #85901 (which changed the name), which is now merged.  The original stabilisation MR was #84770 but that has a lot of noise in it, and I also accidentally deleted the branch while trying to tidy up.  So here is a new MR.  Sorry for the noise.

Closes #80690
2021-08-25 15:49:01 +02:00
Léo Lanteri Thauvin
82ecb0f412
Rollup merge of #88298 - ijackson:errorkind-reorder, r=dtolnay
Errorkind reorder

I was doing a bit more work in this area and the untidiness of these two orderings bothered me.

The commit messages have the detailed rationale.  For your convenience, I c&p them here:

```
    io::ErrorKind: rationalise ordering in main enum

    It is useful to keep some coherent structure to this ordering.  In
    particular, Other and Uncategorized should be next to each other, at
    the end.

    Also it seems to make sense to treat UnexpectedEof and OutOfMemory
    specially, since they are not like the other errors (despite
    OutOfMemory also being generatable by some OS errors).

    So:
     * Move Other to the end, just before Uncategorized
     * Move Unsupported to between Interrupted and UnexpectedEof
     * Add some comments documenting where to add things
```

```
    io::Error: alphabeticise the match in as_str()

    There was no rationale for the previous ordering.
```

r? kennytm   since that's who rust-highfive picked before, in #88294 which I accidentally closed.
2021-08-25 15:49:00 +02:00
Ian Jackson
db13636f03 Stabilise BufWriter::into_parts
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24 18:26:18 +01:00
Eduard-Mihai Burtescu
f8810ee171 Update rustc-demangle to 0.1.21. 2021-08-24 19:53:20 +03:00
Ian Jackson
7b5c0ecb3d Fix tidy
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24 17:45:53 +01:00
Ian Jackson
4c0203eb4b io::ErrorKind: rationalise ordering in main enum
It is useful to keep some coherent structure to this ordering.  In
particular, Other and Uncategorized should be next to each other, at
the end.

Also it seems to make sense to treat UnexpectedEof and OutOfMemory
specially, since they are not like the other errors (despite
OutOfMemory also being generatable by some OS errors).

So:
 * Move Other to the end, just before Uncategorized
 * Move Unsupported to between Interrupted and UnexpectedEof
 * Add some comments documenting where to add things

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24 16:53:58 +01:00
Ian Jackson
54df693dd7 io::Error: alphabeticise the match in as_str()
There was no rationale for the previous ordering.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24 16:51:58 +01:00
Frank Steffahn
04fa1d81dd Fix typo “a Rc” → “an Rc” 2021-08-24 02:23:16 +02:00
Mara Bos
5cf025f076
Rollup merge of #88230 - steffahn:a_an, r=oli-obk
Fix typos “a”→“an”

Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an.

While automation was used to find these, every change was checked manually.

Changes in submodules get separate PRs:
* https://github.com/rust-lang/stdarch/pull/1201
* https://github.com/rust-lang/cargo/pull/9821
* https://github.com/rust-lang/miri/pull/1874
* https://github.com/rust-lang/rls/pull/1746
* https://github.com/rust-analyzer/rust-analyzer/pull/9984
  _folks @ rust-analyzer are fast at merging…_
  * https://github.com/rust-analyzer/rust-analyzer/pull/9985
  * https://github.com/rust-analyzer/rust-analyzer/pull/9987
  * https://github.com/rust-analyzer/rust-analyzer/pull/9989

_For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._

<hr>

This has some overlap with #88226, but neither is a strict superset of the other.

If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23 20:45:49 +02:00
bors
33fdb797f5 Auto merge of #88220 - sunfishcode:sunfishcode/unix-listener-io-safety, r=joshtriplett
Implement `AsFd` etc. for `UnixListener`.

Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for
`UnixListener`. This is a follow-up to #87329.

r? `@joshtriplett`
2021-08-23 07:36:49 +00:00
bors
1c0485610e Auto merge of #87598 - ccqpein:master, r=yaahc
Add doctests for HashMap's into_values and into_keys methods

Fixes #87591
2021-08-23 05:06:29 +00:00
Dan Gohman
a0ce5f25fa Remove redundant conversions. 2021-08-22 16:51:30 -07:00
Frank Steffahn
2f9ddf3bc7 Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
Frank Steffahn
be9d2699ca Fix more “a”/“an” typos 2021-08-22 16:35:29 +02:00
Frank Steffahn
bf88b113ea Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
ccQpein
6eefee1077 Add doctests for 's into_values and into_keys methods 2021-08-22 09:21:00 -04:00
bors
2ad56d5c90 Auto merge of #85166 - mbhall88:file-prefix, r=dtolnay
add file_prefix method to std::path

This is an initial implementation of `std::path::Path::file_prefix`. It is effectively a "left" variant of the existing [`file_stem`](https://doc.rust-lang.org/std/path/struct.Path.html#method.file_stem) method. An illustration of the difference is

```rust
use std::path::Path;

let path = Path::new("foo.tar.gz");
assert_eq!(path.file_stem(), Some("foo.tar"));
assert_eq!(path.file_prefix(), Some("foo"));
```

In my own development, I generally find I almost always want the prefix, rather than the stem, so I thought it might be best to suggest it's addition to libstd.

Of course, as this is my first contribution, I expect there is probably more work that needs to be done. Additionally, if the libstd team feel this isn't appropriate then so be it.

There has been some [discussion about this on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/file_lstem/near/238076313) and a user there suggested I open a PR to see whether someone in the libstd team thinks it is worth pursuing.
2021-08-22 05:19:48 +00:00
Dan Gohman
be483ff4c1 Implement AsFd etc. for UnixListener.
Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for
`UnixListener`. This is a follow-up to #87329.
2021-08-21 19:42:30 -07:00
bors
a0035916e0 Auto merge of #83093 - the8472:smaller-instant-hammer, r=Amanieu
where available use AtomicU{64,128} instead of mutex for Instant backsliding protection

This decreases the overhead of backsliding protection on x86 systems with unreliable TSC, e.g. windows. And on aarch64 systems where 128bit atomics are available.

The following benchmarks were taken on x86_64 linux though by overriding `actually_monotonic()`, the numbers may look different on other platforms

```
# actually_monotonic() == true
test time::tests::instant_contention_01_threads                   ... bench:          44 ns/iter (+/- 0)
test time::tests::instant_contention_02_threads                   ... bench:          44 ns/iter (+/- 0)
test time::tests::instant_contention_04_threads                   ... bench:          44 ns/iter (+/- 0)
test time::tests::instant_contention_08_threads                   ... bench:          44 ns/iter (+/- 0)
test time::tests::instant_contention_16_threads                   ... bench:          44 ns/iter (+/- 0)

# 1x AtomicU64
test time::tests::instant_contention_01_threads                   ... bench:          65 ns/iter (+/- 0)
test time::tests::instant_contention_02_threads                   ... bench:         157 ns/iter (+/- 20)
test time::tests::instant_contention_04_threads                   ... bench:         281 ns/iter (+/- 53)
test time::tests::instant_contention_08_threads                   ... bench:         555 ns/iter (+/- 77)
test time::tests::instant_contention_16_threads                   ... bench:         883 ns/iter (+/- 107)

# mutex
test time::tests::instant_contention_01_threads                   ... bench:          60 ns/iter (+/- 2)
test time::tests::instant_contention_02_threads                   ... bench:         770 ns/iter (+/- 231)
test time::tests::instant_contention_04_threads                   ... bench:       1,347 ns/iter (+/- 45)
test time::tests::instant_contention_08_threads                   ... bench:       2,693 ns/iter (+/- 114)
test time::tests::instant_contention_16_threads                   ... bench:       5,244 ns/iter (+/- 487)
```

Since I don't have an arm machine with 128bit atomics I wasn't able to benchmark the AtomicU128 implementation.
2021-08-20 19:06:46 +00:00
The8472
cd82b4246e fix tests on wasm targets that have 32bit time_t and don't have threads 2021-08-20 20:34:23 +02:00
bors
521734787e Auto merge of #87329 - sunfishcode:sunfishcode/io-safety, r=joshtriplett
I/O safety.

Introduce `OwnedFd` and `BorrowedFd`, and the `AsFd` trait, and
implementations of `AsFd`, `From<OwnedFd>` and `From<T> for OwnedFd`
for relevant types, along with Windows counterparts for handles and
sockets.

Tracking issue: <https://github.com/rust-lang/rust/issues/87074>

RFC: <https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md>

Highlights:
 - The doc comments at the top of library/std/src/os/unix/io/mod.rs and library/std/src/os/windows/io/mod.rs
 - The new types and traits in library/std/src/os/unix/io/fd.rs and library/std/src/os/windows/io/handle.rs
 - The removal of the `RawHandle` struct the Windows impl, which had the same name as the `RawHandle` type alias, and its functionality is now folded into `Handle`.

Managing five levels of wrapping (File wraps sys::fs::File wraps sys::fs::FileDesc wraps OwnedFd wraps RawFd, etc.) made for a fair amount of churn and verbose as/into/from sequences in some places. I've managed to simplify some of them, but I'm open to ideas here.

r? `@joshtriplett`
2021-08-20 11:00:55 +00:00
bors
bcfd3f7e88 Auto merge of #86898 - the8472:path-cmp, r=dtolnay
Add fast path for Path::cmp that skips over long shared prefixes

```
# before
test path::tests::bench_path_cmp_fast_path_buf_sort               ... bench:      60,811 ns/iter (+/- 865)
test path::tests::bench_path_cmp_fast_path_long                   ... bench:       6,459 ns/iter (+/- 275)
test path::tests::bench_path_cmp_fast_path_short                  ... bench:       1,777 ns/iter (+/- 34)

# after
test path::tests::bench_path_cmp_fast_path_buf_sort               ... bench:      38,140 ns/iter (+/- 211)
test path::tests::bench_path_cmp_fast_path_long                   ... bench:       1,471 ns/iter (+/- 24)
test path::tests::bench_path_cmp_fast_path_short                  ... bench:       1,106 ns/iter (+/- 9)
```
2021-08-20 05:00:45 +00:00
Josh Triplett
40466672b5 Stabilize std::os::unix::fs::chroot 2021-08-19 20:22:39 -07:00
Dan Gohman
b4dfa198bf Fix doc test failures on Windows. 2021-08-19 16:15:29 -07:00
bors
6d64f7f695 Auto merge of #88165 - GuillaumeGomez:rollup-4o0v2ps, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #86123 (Preserve more spans in internal `rustc_queries!` macro)
 - #87874 (Add TcpStream type to TcpListener::incoming docs)
 - #88034 (rustc_privacy: Replace `HirId`s and `DefId`s with `LocalDefId`s where possible)
 - #88050 (Remove `HashStable` impls for `FileName` and `RealFileName`)
 - #88093 ([rustdoc] Wrap code blocks in `<code>` tag)
 - #88146 (Add tests for some `feature(const_evaluatable_checked)` incr comp issues)
 - #88153 (Update .mailmap)
 - #88159 (Use a trait instead of the now disallowed missing trait there)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-19 20:31:05 +00:00
Dan Gohman
e555003e6d Factor out a common RawFd/AsRawFd/etc for Unix and WASI. 2021-08-19 13:27:19 -07:00
Dan Gohman
0377a63352 Fix syntax for non-doc comments, and use crate:: instead of std::. 2021-08-19 12:23:04 -07:00
Dan Gohman
187ee5c824 Add I/O safety trait impls for process::Stdio and process::Child. 2021-08-19 12:02:41 -07:00
Dan Gohman
6f872880b4 Use the correct into_* on Windows to avoid dropping a stdio handle.
Use `into_raw_handle()` rather than `into_inner()` to completely consume a
`Handle` without dropping its contained handle.
2021-08-19 12:02:41 -07:00
Dan Gohman
9b99f8c454 Remove the #![feature(io_safety)] from lib.rs. 2021-08-19 12:02:40 -07:00
Dan Gohman
a7d9ab5835 Fix an unused import warning. 2021-08-19 12:02:40 -07:00
Dan Gohman
cada5fb336 Update PidFd for the new I/O safety APIs. 2021-08-19 12:02:40 -07:00
Dan Gohman
1ae1eeec25 Rename OptionFileHandle to HandleOrInvalid and make it just wrap an Option<OwnedHandle>
The name (and updated documentation) make the FFI-only usage clearer, and wrapping Option<OwnedHandle> avoids the need to write a separate Drop or Debug impl.

Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-08-19 12:02:40 -07:00
Dan Gohman
18a9f4628a Don't encourage migration until io_safety is stablized. 2021-08-19 12:02:40 -07:00
Dan Gohman
1dbd6d60f0 Factor out Unix and WASI fd code into a common module. 2021-08-19 12:02:40 -07:00
Dan Gohman
71dab738ac Synchronize minor differences between Unix and WASI implementations. 2021-08-19 12:02:40 -07:00
Dan Gohman
907f00be30 Add more comments about the INVALID_HANDLE_VALUE situation. 2021-08-19 12:02:40 -07:00
Dan Gohman
ab08639e59 Add comments about impls for File, TcpStream, ChildStdin, etc. 2021-08-19 12:02:40 -07:00