about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2021-09-15Avoid codegen for Result::into_ok in lang_startMark Rousskov-3/+3
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-15Allow `panic!("{}", computed_str)` in const fn.Gary Guo-1/+7
2021-09-15Add tracking issue for unix_chownJosh Triplett-3/+3
2021-09-15docs(std): add docs for cof_from_cstr implsMichael Howell-0/+3
CC #51430
2021-09-14Add chown functions to std::os::unix::fs to change the owner and group of filesJosh Triplett-0/+87
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-13Move fortanix module position in std::os reexports for alpha sortGuillaume Gomez-20/+34
2021-09-13Remove usage of cfg_if in std/src/os/mod.rsGuillaume Gomez-31/+71
2021-09-13Simplify std::os module reexports to fix rustdoc linking issuesGuillaume Gomez-109/+74
2021-09-12Add primitive documentation to libcoreJoshua Nelson-21/+25
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-10Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlockFabian Wolff-4/+3
2021-09-10Rollup merge of #88807 - jruderman:which_reverses, r=joshtriplettManish Goregaokar-1/+1
Fix typo in docs for iterators
2021-09-10Rollup merge of #88667 - kraktus:patch-1, r=dtolnayManish Goregaokar-1/+1
Tweak `write_fmt` doc. Found this weird sentence while reading the docs.
2021-09-09Fix typo in docs for iteratorsJesse Ruderman-1/+1
2021-09-09Run fmtRyan Hancock-1/+1
2021-09-09Clarification of default socket flags used by RustRyan Hancock-0/+4
2021-09-09Fix Windows compilation errors.Dan Gohman-11/+6
2021-09-09Fix another Windows compilation error.Dan Gohman-1/+1
2021-09-09Fix more Windows compilation errors.Dan Gohman-20/+22
2021-09-09Fix assertion failures in `OwnedHandle` with `windows_subsystem`.Dan Gohman-40/+72
As discussed in #88576, raw handle values in Windows can be null, such as in `windows_subsystem` mode, or when consoles are detached from a process. So, don't use `NonNull` to hold them, don't assert that they're not null, and remove `OwnedHandle`'s `repr(transparent)`. Introduce a new `HandleOrNull` type, similar to `HandleOrInvalid`, to cover the FFI use case.
2021-09-09Fix Windows compilation errors.Dan Gohman-5/+13
2021-09-09Add a `try_clone()` function to `OwnedFd`.Dan Gohman-76/+115
As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code.
2021-09-09Ignore automatically derived impls of `Clone` and `Debug` in dead code analysisFabian Wolff-4/+0
2021-09-08Bump stage0 compiler to 1.56Mark Rousskov-7/+3
2021-09-08Rollup merge of #88594 - steffahn:more_symbolic_doc_aliases, r=joshtriplettJack Huey-3/+6
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-06Rollup merge of #88647 - ChrisDenton:win-symlink-docs, r=joshtriplettRyan Levick-2/+20
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-05rust fmtlovasoa-1/+5
2021-09-05Mention usage of `const` in raw pointer types at the top of the keyword's ↵Frank Steffahn-1/+1
documentation page.
2021-09-05Additional aliases for pointersFrank Steffahn-0/+3
2021-09-05Tweak `write_fmt` doc.kraktus-1/+1
Previous version wrongly used `but` while the two parts of the sentence are not contradicting but completing with each other.
2021-09-05Auto merge of #88469 - patrick-gu:master, r=dtolnaybors-14/+20
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-04linux/aarch64 Now() should be actually_monotonic()Ali Saidi-0/+15
While issues have been seen on arm64 platforms the Arm architecture requires that the counter monotonically increases and that it must provide a uniform view of system time (e.g. it must not be possible for a core to receive a message from another core with a time stamp and observe time going backwards (ARM DDI 0487G.b D11.1.2). While there have been a few 64bit SoCs that have bugs (#49281, #56940) which cause time to not monotonically increase, these have been fixed in the Linux kernel and we shouldn't penalize all Arm SoCs for those who refuse to update their kernels: SUN50I_ERRATUM_UNKNOWN1 - Allwinner A64 / Pine A64 - fixed in 5.1 FSL_ERRATUM_A008585 - Freescale LS2080A/LS1043A - fixed in 4.10 HISILICON_ERRATUM_161010101 - Hisilicon 1610 - fixed in 4.11 ARM64_ERRATUM_858921 - Cortex A73 - fixed in 4.12 255a3f3e183 std: Force `Instant::now()` to be monotonic added a mutex to work around this problem and a small test program using glommio shows the majority of time spent acquiring and releasing this Mutex. 3914a7b0da8 tries to improve this, but actually makes it worse on big systems as for 128b atomics a ldxp/stxp pair (and successful loop) is required which is expensive as a lock and because of how the load/store-exclusives scale on large Arm systems is both unfair to threads and tends to go backwards in performance.
2021-09-04Use the 64b inner:monotonize() implementation not the 128b one for aarch64Ali Saidi-2/+2
aarch64 prior to v8.4 (FEAT_LSE2) doesn't have an instruction that guarantees untorn 128b reads except for completing a 128b load/store exclusive pair (ldxp/stxp) or compare-and-swap (casp) successfully. The requirement to complete a 128b read+write atomic is actually more expensive and more unfair than the previous implementation of monotonize() which used a Mutex on aarch64, especially at large core counts. For aarch64 switch to the 64b atomic implementation which is about 13x faster for a benchmark that involves many calls to Instant::now().
2021-09-04Document when to use Windows' `symlink_dir` vs. `symlink_file`Chris Denton-2/+20
It was previously unclear which should be used when.
2021-09-03Remove excessive linkingpatrick-gu-22/+19
2021-09-03simplify `impl Termination for Result<Infallible, E>`Ibraheem Ahmed-2/+1
Co-authored-by: Konrad Borowski <konrad@borowski.pw>
2021-09-03Update primitive docs for rust 2021.Mara Bos-7/+11
2021-09-03Add a better error message for #39364Ophir LOJKINE-1/+1
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-02implement `Termination` for `Result<Infallible, E>`ibraheemdev-0/+10
2021-09-02Auto merge of #88596 - m-ou-se:rollup-cidzt4v, r=m-ou-sebors-2/+1
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-02Rollup merge of #88177 - joshtriplett:stabilize-chroot, r=m-ou-seMara Bos-2/+1
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-02Auto merge of #87580 - ChrisDenton:win-arg-parse-2008, r=m-ou-sebors-123/+201
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-02Consistent placement of doc alias for primitives below the `doc(primitive…)`Frank Steffahn-2/+2
2021-09-02I/O safety for WinUWPbdbai-4/+5
2021-09-02Auto merge of #83342 - Count-Count:win-console-incomplete-utf8, r=m-ou-sebors-14/+90
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](https://github.com/rust-lang/rust/blob/2c56ea38b045624dc8b42ec948fc169eaff1206a/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-01Rollup merge of #88551 - inquisitivecrystal:unsafe_cell_raw_get, r=m-ou-seMara Bos-1/+0
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-01Rollup merge of #88542 - tavianator:readdir_r-errno, r=jyn514Mara Bos-2/+3
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-31Stabilize `UnsafeCell::raw_get()`inquisitivecrystal-1/+0
2021-08-31Use the return value of readdir_r() instead of errnoTavian Barnes-2/+3
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-31Rollup merge of #88524 - soenkehahn:master, r=jyn514Mara Bos-1/+1
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-31Rollup merge of #88495 - ibraheemdev:tcp-linger, r=joshtriplettMara Bos-1/+165
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)