about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-02-11Auto merge of #90271 - adamgemmell:dev/feat-detect-stabilise, r=Amanieubors-3/+4
Stabilise `is_aarch64_feature_detected!` under `simd_aarch64` feature Initial implementation, looking for feedback on the approach here. https://github.com/rust-lang/rust/issues/86941 One point I noticed was that I haven't seen different "since" versions for the same feature - does this mean that other features can't be added to to the `simd_aarch64` feature once this is in stable? If so it might need a more specific name. r? `@Amanieu`
2022-02-11Add missing platform-specific information on current_dir and set_current_dirGuillaume Gomez-0/+10
2022-02-10Implement `AsFd` for `&T` and `&mut T`.Dan Gohman-1/+49
Add implementations of `AsFd` for `&T` and `&mut T`, so that users can write code like this: ```rust pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> { ``` with `fd: F` rather than `fd: &F`. And similar for `AsHandle` and `AsSocket` on Windows. Also, adjust the `fchown` example to pass the file by reference. The code can work either way now, but passing by reference is more likely to be what users will want to do. This is an alternative to #93869, and is a simpler way to achieve the same goals: users don't need to pass borrowed-`BorrowedFd` arguments, and it prevents a pitfall in the case where users write `fd: F` instead of `fd: &F`.
2022-02-10Move `is_aarch64_feature_detected!` to `simd_aarch64` feature and stabiliseAdam Gemmell-3/+4
2022-02-10Rename to `InvalidFilename`Yuki Okushi-9/+8
2022-02-10Fix description of FilenameInvalidJosh Triplett-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-02-10Map `ERROR_INVALID_NAME` to `FilenameInvalid`Yuki Okushi-1/+2
2022-02-10Rename `FilenameTooLong` to `FilenameInvalid`Yuki Okushi-4/+4
2022-02-10windows: Map `ERROR_INVALID_NAME` as `InvalidInput`Yuki Okushi-1/+1
2022-02-10Rollup merge of #93843 - solid-rs:fix-kmc-solid-condvar, r=m-ou-seMatthias Krüger-4/+9
kmc-solid: Fix wait queue manipulation errors in the `Condvar` implementation This PR fixes a number of bugs in the `Condvar` wait queue implementation used by the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. These bugs can occur when there are multiple threads waiting on the same `Condvar` and sometimes manifest as an `unwrap` failure.
2022-02-10kmc-solid: Use the filesystem thread-safety wrapperTomoaki Kawada-1/+20
Neither the SOLID filesystem API nor built-in filesystems guarantee thread safety by default. Although this may suffice in general embedded- system use cases, and in fact the API can be used from multiple threads without any problems in many cases, this has been a source of unsoundness in `std::sys::solid::fs`. This commit updates the `std` code to leverage the filesystem thread- safety wrapper to enforce thread safety. This is done by prefixing all paths passed to the filesystem API with `\TS`. (Note that relative paths aren't supported in this platform.)
2022-02-10kmc-solid: Wait queue should be sorted in the descending order of task ↵Tomoaki Kawada-1/+1
priorities In ITRON, lower priority values mean higher priorities.
2022-02-10kmc-solid: Fix wait queue manipulation errors in the `Condvar` implementationTomoaki Kawada-3/+8
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