about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2022-02-09Bump compiler-builtins to 0.1.69Amanieu d'Antras-1/+1
2022-02-09Stabilize cfg_target_has_atomicAmanieu d'Antras-1/+1
Closes #32976
2022-02-09Rollup merge of #93445 - yaahc:exitcode-constructor, r=dtolnayYuki Okushi-0/+29
Add From<u8> for ExitCode This should cover a mostly cross-platform subset of supported exit codes. We decided to stick with `u8` initially since its the common subset between all platforms that we support (excluding wasm which I think only works with `true` or `false`). Posix is supposed to take i32s, but in practice many unix platforms mask out all but the low 8 bits or in some cases the 8-15th bits. Windows takes a u32 instead of an i32. Bourne-compatible shells also report signals as exitcode 128 + `signal_no`, so there's some ambiguity there when returning exit codes > 127, but it is possible to disambiguate them on the other side so we decided against restricting the possible codes further than to `u8`. ## Related - Detailed analysis of exit code support on various platforms: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426 - https://github.com/rust-lang/rust/issues/48711 - https://github.com/rust-lang/rust/issues/43301 - https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization
2022-02-08Rollup merge of #93206 - ChrisDenton:ntopenfile, r=nagisaMatthias Krüger-7/+18
Use `NtCreateFile` instead of `NtOpenFile` to open a file Generally the internal `Nt*` functions should be avoided but when we do need to use one we should stick to the most commonly used for the job. To that end, this PR replaces `NtOpenFile` with `NtCreateFile`. NOTE: The initial version of this comment hypothesised that this may help with some recent false positives from malware scanners. This hypothesis proved wrong. Sorry for the distraction.
2022-02-08Fix `absolute` issuesChris Denton-4/+5
2022-02-08`std::path::absolute`Chris Denton-4/+208
2022-02-07fix exclusive range errorJane Lusby-1/+1
2022-02-07Auto merge of #87869 - thomcc:skinny-io-error, r=yaahcbors-269/+837
Make io::Error use 64 bits on targets with 64 bit pointers. I've wanted this for a long time, but didn't see a good way to do it without having extra allocation. When looking at it yesterday, it was more clear what to do for some reason. This approach avoids any additional allocations, and reduces the size by half (8 bytes, down from 16). AFAICT it doesn't come additional runtime cost, and the compiler seems to do a better job with code using it. Additionally, this `io::Error` has a niche (still), so `io::Result<()>` is *also* 64 bits (8 bytes, down from 16), and `io::Result<usize>` (used for lots of io trait functions) is 2x64 bits (16 bytes, down from 24 — this means on x86_64 it can use the nice rax/rdx 2-reg struct return). More generally, it shaves a whole 64 bit integer register off of the size of basically any `io::Result<()>`. (For clarity: Improving `io::Result` (rather than io::Error) was most of the motivation for this) On 32 bit (or other non-64bit) targets we still use something equivalent the old repr — I don't think think there's improving it, since one of the fields it stores is a `i32`, so we can't get below that, and it's already about as close as we can get to it. --- ### Isn't Pointer Tagging Dodgy? The details of the layout, and why its implemented the way it is, are explained in the header comment of library/std/src/io/error/repr_bitpacked.rs. There's probably more details than there need to be, but I didn't trim it down that much, since there's a lot of stuff I did deliberately, that might have not seemed that way. There's actually only one variant holding a pointer which gets tagged. This one is the (holder for the) user-provided error. I believe the scheme used to tag it is not UB, and that it preserves pointer provenance (even though often pointer tagging does not) because the tagging operation is just `core::ptr::add`, and untagging is `core::ptr::sub`. The result of both operations lands inside the original allocation, so it would follow the safety contract of `core::ptr::{add,sub}`. The other pointer this had to encode is not tagged — or rather, the tagged repr is equivalent to untagged (it's tagged with 0b00, and has >=4b alignment, so we can reuse the bottom bits). And the other variants we encode are just integers, which (which can be untagged using bitwise operations without worry — they're integers). CC `@RalfJung` for the stuff in repr_bitpacked.rs, as my comments are informed by a lot of the UCG work, but it's possible I missed something or got it wrong (even if the implementation is okay, there are parts of the header comment that says things like "We can't do $x" which could be false). --- ### Why So Many Changes? The repr change was mostly internal, but changed one widely used API: I had to switch how `io::Error::new_const` works. This required switching `io::Error::new_const` to take the full message data (including the kind) as a `&'static`, rather than just the string. This would have been really tedious, but I made a macro that made it much simpler, but it was a wide change since `io::Error::new_const` is used everywhere. This included changing files for a lot of targets I don't have easy access to (SGX? Haiku? Windows? Who has heard of these things), so I expect there to be spottiness in CI initially, unless luck is on my side. Anyway this large only tangentially-related change is all in the first commit (although that commit also pulls the previous repr out into its own file), whereas the packing stuff is all in commit 2. --- P.S. I haven't looked at all of this since writing it, and will do a pass over it again later, sorry for any obvious typos or w/e. I also definitely repeat myself in comments and such. (It probably could use more tests too. I did some basic testing, and made it so we `debug_assert!` in cases the decode isn't what we encoded, but I don't know the degree which I can assume libstd's testing of IO would exercise this. That is: it wouldn't be surprising to me if libstds IO testing were minimal, especially around error cases, although I have no idea).
2022-02-06Add From<u8> for ExitCodeJane Lusby-0/+29
This should cover a mostly cross-platform subset of supported exit codes.
2022-02-06rewrite from_bytes_with_nul to match code style in from_vec_with_nulInteon-7/+8
Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com>
2022-02-06Fix hashing for windows paths containing a CurDir componentThe 8472-9/+52
* the logic only checked for / but not for \ * verbatim paths shouldn't skip items at all since they don't get normalized * the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false * tests lacked windows coverage for these cases That lead to equal paths not having equal hashes and to unnecessary collisions.
2022-02-06keyword_docs: document use of `in` with `pub` keywordMuhammad Falak R Wani-0/+14
Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
2022-02-04Add more tests for io::Error packing, and fix some comments that weren't ↵Thom Chiovoloni-16/+101
quite accurate anymore
2022-02-04Update documentation somewhatThom Chiovoloni-12/+26
2022-02-04Use wrapping pointer arithmetic in the bitpacked io::ErrorThom Chiovoloni-8/+15
2022-02-04Elaborate some in the documentation and respond to some review commentsThom Chiovoloni-8/+19
2022-02-04Update library/std/src/io/error/repr_bitpacked.rsThom Chiovoloni-1/+1
Co-authored-by: the8472 <the8472@users.noreply.github.com>
2022-02-04Fix comment typos noticed by code review.Thom Chiovoloni-2/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-02-04Address address comments, improve comments slightlyThom Chiovoloni-5/+20
2022-02-04Optimize io::error::Repr layout on 64 bit targets.Thom Chiovoloni-4/+364
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-269/+345
2022-02-04x.py fmtDan Gohman-4/+4
2022-02-04Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`.Dan Gohman-25/+62
Also, rename `BorrowedHandle::borrow_raw_handle` and `BorrowedSocket::borrow_raw_socket` to `BorrowedHandle::borrow_raw` and `BorrowedSocket::borrow_raw`. This is just a minor rename to reduce redundancy in the user code calling these functions, and to eliminate an inessential difference between `BorrowedFd` code and `BorrowedHandle`/`BorrowedSocket` code. While here, add a simple test exercising `BorrowedFd::borrow_raw_fd`.
2022-02-04Rollup merge of #93495 - solid-rs:fix-kmc-solid-rtc-month, r=yaahcMatthias Krüger-1/+1
kmc-solid: Fix off-by-one error in `SystemTime::now` Fixes a miscalculation of `SystemTime` on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. Unlike the identically-named libc counterpart `tm::tm_mon`, `SOLID_RTC_TIME::tm_mon` contains a 1-based month number.
2022-02-04Rollup merge of #93555 - ChrisDenton:fs-try-exists-doc, r=Mark-SimulacrumMatthias Krüger-2/+6
Link `try_exists` docs to `Path::exists` Links to the existing `Path::exists` method from both `std::Path::try_exists` and `std::fs:try_exists`. Tracking issue for `path_try_exists`: #83186
2022-02-04Stabilize pin_static_ref.Mara Bos-1/+0
2022-02-03Move `{core,std}::stream::Stream` to `{core,std}::async_iter::AsyncIterator`.Charles Lew-3/+3
2022-02-03Auto merge of #93146 - workingjubilee:use-std-simd, r=Mark-Simulacrumbors-2/+20
pub use std::simd::StdFloat; Syncs portable-simd up to commit rust-lang/portable-simd@03f6fbb21e6050da2a05b3ce8f480c020b384916, Diff: https://github.com/rust-lang/portable-simd/compare/533f0fc81ab9ba097779fcd27c8f9ea12261fef5...03f6fbb21e6050da2a05b3ce8f480c020b384916 This sync requires a little bit more legwork because it also introduces a trait into `std::simd`, so that it is no longer simply a reexport of `core::simd`. Out of simple-minded consistency and to allow more options, I replicated the pattern for the way `core::simd` is integrated in the first place, however this is not necessary if it doesn't acquire any interdependencies inside `std`: it could be a simple crate reexport. I just don't know yet if that will happen or not. To summarize other misc changes: - Shifts no longer panic, now wrap on too-large shifts (like `Simd` integers usually do!) - mask16x32 will now be many i16s, not many i32s... 🙃 - `#[must_use]` is spread around generously - Adjusts division, float min/max, and `Mask::{from,to}_array` internally to be faster - Adds the much-requested `Simd::cast::<U>` function (equivalent to `simd.to_array().map(|lane| lane as U)`)
2022-02-02Remove the documentation comment for `OwnedSocket::from_raw_socket`.Dan Gohman-7/+0
This function is documented in more detail in the `FromRawSocket` trait.
2022-02-02Auto merge of #93101 - Mark-Simulacrum:library-backtrace, r=yaahcbors-65/+129
Support configuring whether to capture backtraces at runtime Tracking issue: https://github.com/rust-lang/rust/issues/93346 This adds a new API to the `std::panic` module which configures whether and how the default panic hook will emit a backtrace when a panic occurs. After discussion with `@yaahc` on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/backtrace.20lib.20vs.2E.20panic), this PR chooses to avoid adjusting or seeking to provide a similar API for the (currently unstable) std::backtrace API. It seems likely that the users of that API may wish to expose more specific settings rather than just a global one (e.g., emulating the `env_logger`, `tracing` per-module configuration) to avoid the cost of capture in hot code. The API added here could plausibly be copied and/or re-exported directly from std::backtrace relatively easily, but I don't think that's the right call as of now. ```rust mod panic { #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum BacktraceStyle { Short, Full, Off, } fn set_backtrace_style(BacktraceStyle); fn get_backtrace_style() -> Option<BacktraceStyle>; } ``` Several unresolved questions: * Do we need to move to a thread-local or otherwise more customizable strategy for whether to capture backtraces? See [this comment](https://github.com/rust-lang/rust/pull/79085#issuecomment-727845826) for some potential use cases for this. * Proposed answer: no, leave this for third-party hooks. * Bikeshed on naming of all the options, as usual. * Should BacktraceStyle be moved into `std::backtrace`? * It's already somewhat annoying to import and/or re-type the `std::panic::` prefix necessary to use these APIs, probably adding a second module to the mix isn't worth it. Note that PR #79085 proposed a much simpler API, but particularly in light of the desire to fully replace setting environment variables via `env::set_var` to control the backtrace API, a more complete API seems preferable. This PR likely subsumes that one.
2022-02-02Configure panic hook backtrace behaviorMark Rousskov-65/+129
2022-02-02Rollup merge of #93531 - TheColdVoid:patch-1, r=m-ou-seMatthias Krüger-1/+1
Fix incorrect panic message in example The panic message when calling the `connect()` should probably be a message about connection failure, not a message about binding address failure.
2022-02-02Rollup merge of #93493 - GKFX:char-docs-2, r=scottmcmMatthias Krüger-5/+54
Document valid values of the char type As discussed at #93392, the current documentation on what constitutes a valid char isn't very detailed and is partly on the MAX constant rather than the type itself. This PR expands on that information, stating the actual numerical range, giving examples of what won't work, and also mentions how a `char` might be a valid USV but still not be a defined character (terminology checked against [Unicode 14.0, table 2-3](https://www.unicode.org/versions/Unicode14.0.0/ch02.pdf#M9.61673.TableTitle.Table.22.Types.of.Code.Points)).
2022-02-01x.py fmtDan Gohman-2/+2
2022-02-01Use `From`/`Into` rather than the traits they replaced.Dan Gohman-15/+21
2022-02-01Fix errors.Dan Gohman-3/+3
2022-02-01Fix unresolved doc links.Dan Gohman-0/+6
2022-02-01Fix two copy+pastos.Dan Gohman-2/+2
2022-02-01Add missing `pub` keywords.Dan Gohman-2/+2
2022-02-01Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`.Dan Gohman-63/+101
This change weakens the descriptions of the `{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that they *do* express ownership relations to say that they are *typically used* in ways that express ownership relations. This needed needed since, for example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of the ownership relationships. This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`, adds the requirement that raw handles be not opened with the `FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle` comment into the main `FromRawHandle::from_raw_handle` comment. And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement `FromRawHandle`, since they are intended for limited use in FFI situations, and not for generic use, and they have constraints that are stronger than the those of `FromRawHandle`. [`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html
2022-02-01Fix annotation of code blocksGeorge Bateman-2/+3
2022-02-01Auto merge of #93442 - yaahc:Termination-abstraction, r=Mark-Simulacrumbors-9/+24
Change Termination::report return type to ExitCode Related to https://github.com/rust-lang/rust/issues/43301 The goal of this change is to minimize the forward compatibility risks in stabilizing Termination. By using the opaque type `ExitCode` instead of an `i32` we leave room for us to evolve the API over time to provide what cross-platform consistency we can / minimize footguns when working with exit codes, where as stabilizing on `i32` would limit what changes we could make in the future in how we represent and construct exit codes.
2022-02-01Link `try_exists` docs to `Path::exists`Chris Denton-2/+6
2022-02-01Rollup merge of #93436 - dcsommer:master, r=Mark-SimulacrumMatthias Krüger-1/+1
Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff: ``` $ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l 2 ``` And after: ``` $ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l 1 ``` Fixes #93310 See also https://github.com/rust-lang/compiler-builtins/issues/449 and https://github.com/rust-lang/compiler-builtins/pull/450
2022-02-01Rollup merge of #92584 - lcnr:query-stable-lint, r=estebankMatthias Krüger-0/+20
add rustc lint, warning when iterating over hashmaps 2 first introduced in #89558 and reverted in #90380 due to its perf impact r? ``@estebank``
2022-02-01add a rustc::query_stability lintlcnr-0/+20
2022-01-31Rollup merge of #93504 - solid-rs:fix-kmc-solid-stack-size, r=nagisaEric Huss-1/+2
kmc-solid: Increase the default stack size This PR increases the default minimum stack size on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets to 64KiB (Arm) and 128KiB (AArch64). This value was chosen as a middle ground between supporting a relatively complex program (e.g., an application using a full-fledged off-the-shelf web server framework) with no additional configuration and minimizing resource consumption for the embedded platform that doesn't support lazily-allocated pages nor over-commitment (i.e., wasted stack spaces are wasted physical memory). If the need arises, the users can always set the `RUST_MIN_STACK` environmental variable to override the default stack size or use the platform API directly.
2022-01-31Rollup merge of #93090 - jyn514:errorkind-asstr, r=dtolnayEric Huss-1/+17
`impl Display for io::ErrorKind` This avoids having to convert from `ErrorKind` to `Error` just to print the error message.
2022-02-01Fix incorrect panic message in exampleTheVoid-1/+1
2022-01-31(#93493) Add items from code reviewGeorge Bateman-15/+35