summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2023-05-29Swap out CURRENT_RUSTC_VERSION to 1.71.0Mark Rousskov-6/+6
2023-05-27Rework handling of recursive panicsAmanieu d'Antras-53/+67
2023-05-26Rollup merge of #111940 - zirconium-n:io-read-doc-change, r=thomccMatthias Krüger-3/+4
Clarify safety concern of `io::Read::read` is only relevant in unsafe code We have this clarification note in other similar place like [Iterator::size_hint](https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.size_hint). The lack of clarification might lead to confusion to Rust beginners. [Relevant URLO post](https://users.rust-lang.org/t/can-read-overflow-a-buffer/94347).
2023-05-25Clarify safety concern of `io::Read::read` is only relevant in unsafe codeZiru Niu-3/+4
2023-05-23Rollup merge of #111609 - LegionMammal978:internal-unsafe, r=thomccDylan DPC-4/+7
Mark internal functions and traits unsafe to reflect preconditions No semantics are changed in this PR; I only mark some functions and and a trait `unsafe` which already had implicit preconditions. Although it seems somewhat redundant for `numfmt::Part::Copy` to contain a `&[u8]` instead of a `&str`, given that all of its current consumers ultimately expect valid UTF-8. Is the type also intended to work for byte-slice formatting in the future?
2023-05-19Auto merge of #109773 - beetrees:set-file-time-improvements, r=Amanieubors-28/+196
Add creation time support to `FileTimes` on apple and windows Adds support for setting file creation times on platforms which support changing it directly (currently only Apple and Windows). Based on top of #110093 (which was split from this PR). ACP: rust-lang/libs-team#199 (currently still in progress) Tracking issue: #98245 `@rustbot` label +T-libs-api -T-libs
2023-05-19Auto merge of #111590 - dtolnay:panictemporaries, r=bjorn3bors-2/+2
Shorten even more panic temporary lifetimes Followup to #104134. As pointed out by `@bjorn3` in https://github.com/rust-lang/rust/pull/104134#pullrequestreview-1425585948, there are other cases in the panic macros which would also benefit from dropping their non-Send temporaries as soon as possible, avoiding pointlessly holding them across an await point. For the tests added in this PR, here are the failures you get today on master without the macro changes in this PR: <details> <summary>tests/ui/macros/panic-temporaries-2018.rs</summary> ```console error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:52:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:52:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:53:18 | LL | require_send(panic_str()); | ^^^^^^^^^^^ future returned by `panic_str` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:40:36 | LL | f(panic!((NOT_SEND, "...").1)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:54:18 | LL | require_send(unreachable_display()); | ^^^^^^^^^^^^^^^^^^^^^ future returned by `unreachable_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:45:31 | LL | f(unreachable!(NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:54:18 | LL | require_send(unreachable_display()); | ^^^^^^^^^^^^^^^^^^^^^ future returned by `unreachable_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:45:31 | LL | f(unreachable!(NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: aborting due to 5 previous errors ``` </details> <details> <summary>tests/ui/macros/panic-temporaries.rs</summary> ```console error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries.rs:42:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries.rs:38:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries.rs:42:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries.rs:38:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: aborting due to 2 previous errors ``` </details> r? bjorn3
2023-05-18Auto merge of #111710 - Dylan-DPC:rollup-eutrx54, r=Dylan-DPCbors-0/+18
Rollup of 7 pull requests Successful merges: - #110884 (Support RISC-V unaligned-scalar-mem target feature) - #111160 (Update serde in workspace and non-synced dependencies) - #111168 (Specialize ToString implementation for fmt::Arguments) - #111527 (add examples of port 0 binding behavior) - #111561 (Include better context for "already exists" error in compiletest) - #111633 (Avoid `&format("...")` calls in error message code.) - #111679 (Remove libs message about ACPs from triagebot) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-05-18Rollup merge of #111527 - knickish:bind_port_0_documentation, r=Mark-SimulacrumDylan DPC-0/+18
add examples of port 0 binding behavior Was trying to find the method to specify the IP address but not the port, and there wasn't information easily accessible about it in the `TcpListener` or `SocketAddr`. Adding examples to `TcpListener` and `UdpSocket` for clarity.
2023-05-17Fix #107910, Shorten backtraces in ICEsyukang-5/+6
2023-05-16Auto merge of #111134 - GilShoshan94:remove-send-bound-on-error, r=dtolnaybors-3/+3
Remove unnecessary Send bound Hi, While working on a [PR on Tokio](https://github.com/tokio-rs/tokio/pull/5666), I took inspiration from the std channel mpsc and stumbled on a `Send` bound for a `Error` impl. Tokio's maintainer `@Darksonn` pointed out to me that `Error` used to required the `Send` bound long time ago (here https://github.com/rust-lang/rust/pull/23541). In the meantime, the `Send` bound `Error` got removed (see https://github.com/rust-lang/rust/pull/21312 and https://github.com/rust-lang/rust/pull/23799). So here a PR to removed this bound for `SendError<T>`, `TrySendError<T>` and `SendTimeoutError<T>`.
2023-05-15Mark internal functions and traits unsafeLegionMammal978-4/+7
2023-05-15Rollup merge of #110049 - SkiFire13:localkey-with-docs-fix, r=workingjubileeMatthias Krüger-2/+2
Don't claim `LocalKey::with` prevents a reference to be sent across threads The documentation for `LocalKey` claims that `with` yields a reference that cannot be sent across threads, but this is false since you can easily do that with scoped threads. What it actually prevents is the reference from outliving the current thread.
2023-05-15Add test for `FileTimes`beetrees-2/+52
2023-05-15Add creation time support to `FileTimes` on apple and windowsbeetrees-26/+144
2023-05-15Shorten lifetime of even more panic temporariesDavid Tolnay-2/+2
2023-05-15wanting => wantVagelis Prokopiou-2/+2
2023-05-14Auto merge of #108196 - sunfishcode:sunfishcode/windows-as-socket-impls, ↵bors-0/+72
r=dtolnay Implement `AsHandle`/`AsSocket` for `Arc`/`Rc`/`Box` on Windows Implement the Windows counterpart to #97437 and #107317: Implement `AsHandle` and `AsSocket` for `Arc<T>`, `Rc<T>`, and `Box<T>`.
2023-05-14Shorten lifetime of panic temporaries in panic_fmt caseDavid Tolnay-1/+3
2023-05-13add examples of port 0 binding behaviorkirk-0/+18
2023-05-12Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwcobors-6/+18
Uplift `clippy::{drop,forget}_{ref,copy}` lints This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints. Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted. ## `drop_ref` and `forget_ref` The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value. ### Example ```rust let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex // still locked operation_that_requires_mutex_to_be_unlocked(); ``` ### Explanation Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended. ## `drop_copy` and `forget_copy` The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait. ### Example ```rust let x: i32 = 42; // i32 implements Copy std::mem::forget(x) // A copy of x is passed to the function, leaving the // original unaffected ``` ### Explanation Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation. ----- Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-11Improve code around SGX waitqueueUrgau-3/+13
Followed up of d36e390d8176babedcf326581959958d447170cd See https://github.com/rust-lang/rust/pull/109732#issuecomment-1543574908 for more details. Co-authored-by: Jethro Beekman <jethro@fortanix.com>
2023-05-10Remove useless drop of copy typeUrgau-1/+1
2023-05-10Remove and fix useless drop of referenceUrgau-3/+5
2023-05-09Don't force include Windows goop when documentingChris Denton-59/+40
2023-05-09Auto merge of #110152 - ChrisDenton:windows-sys, r=thomccbors-3098/+7089
Start using `windows sys` for Windows FFI bindings in std Switch to using windows-sys for FFI. In order to avoid some currently contentious issues, this uses windows-bindgen to generate a smaller set of bindings instead of using the full crate. Unlike the windows-sys crate, the generated bindings uses `*mut c_void` for handle types instead of `isize`. This to sidestep opsem concerns about mixing pointer types and integers between languages. Note that `SOCKET` remains defined as an integer but instead of being a usize, it's changed to fit the [standard library definition](https://github.com/rust-lang/rust/blob/a41fc00eaf352541008965fec0dee811e44373b3/library/std/src/os/windows/raw.rs#L12-L16): ```rust #[cfg(target_pointer_width = "32")] pub type SOCKET = u32; #[cfg(target_pointer_width = "64")] pub type SOCKET = u64; ``` The generated bindings also customizes the `#[link]` imports. I hope to switch to using raw-dylib but I don't want to tie that too closely with the switch to windows-sys. --- Changes outside of the bindings are, for the most part, fairly minimal (e.g. some differences in `*mut` vs. `*const` or a few types differ). One issue is that our own bindings sometimes mix in higher level types, like `BorrowedHandle`. This is pretty adhoc though.
2023-05-08Rollup merge of #104070 - nbdd0121:unwind, r=AmanieuMichael Goulet-5/+11
Prevent aborting guard from aborting the process in a forced unwind Fix #101469
2023-05-08Rollup merge of #110638 - nikarh:vita, r=Mark-SimulacrumYuki Okushi-22/+233
STD support for PSVita This PR adds std support for `armv7-sony-vita-newlibeabihf` target. The work here is fairly similar to #95897, just for a different target platform. This depends on the following pull requests: rust-lang/backtrace-rs#523 rust-lang/libc#3209
2023-05-08Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, ↵bors-4/+5
r=Mark-Simulacrum enable `rust_2018_idioms` lint group for doctests With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests. Resolves #106086 Resolves #99144 Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-07PS Vita std supportNikolay Arhipov-22/+233
2023-05-07Prevent aborting guard from aborting the process in a forced unwindGary Guo-0/+3
2023-05-07Parse catch filter in personality functionGary Guo-5/+8
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-4/+5
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-06Rollup merge of #111139 - ↵Yuki Okushi-1/+5
fortanix:raoul/fix_mxcsr_configuration_dependent_timing, r=thomcc Fix MXCSR configuration dependent timing Dependent on the (potentially secret) data some vector instructions operate on, and the content in MXCSR, instruction retirement may be delayed by one cycle. This is a potential side channel. This PR fixes this vulnerability for the `x86_64-fortanix-unknown-sgx` platform by loading MXCSR with `0x1fbf` through an `xrstor` instruction when the enclave is entered and executing an `lfence` immediately after. Other changes of the MXCSR happen only when the enclave is about to be exited and no vector instructions will be executed before it will actually do so. Users of EDP who change the MXCSR and do wish to defend against this side channel, will need to implement the software mitigation described [here](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/mxcsr-configuration-dependent-timing.html). cc: `@jethrogb` `@monokles`
2023-05-06Rollup merge of #110830 - Freaky:freebsd-cpuset, r=thomccYuki Okushi-0/+19
Add FreeBSD cpuset support to `std::thread::available_concurrency` Use libc::cpuset_getaffinity to determine the CPUs available to the current process. The existing sysconf and sysctl paths are left as fallback.
2023-05-05Sort windows_sys.lst alphabeticallyChris Denton-614/+617
2023-05-05Use new bindingsChris Denton-53/+70
2023-05-05Generate windows-sys bindingsChris Denton-3045/+7016
2023-05-05Rollup merge of #103056 - beetrees:timespec-bug-fix, r=thomccDylan DPC-24/+35
Fix `checked_{add,sub}_duration` incorrectly returning `None` when `other` has more than `i64::MAX` seconds Use `checked_{add,sub}_unsigned` in `checked_{add,sub}_duration` so that the correct result is returned when adding/subtracting durations with more than `i64::MAX` seconds.
2023-05-05Rollup merge of #110946 - RalfJung:tls-realstd, r=m-ou-seYuki Okushi-17/+22
avoid duplicating TLS state between test std and realstd This basically re-lands https://github.com/rust-lang/rust/pull/100201 and https://github.com/rust-lang/rust/pull/106638, which got reverted by https://github.com/rust-lang/rust/pull/110861. This works around 2 Miri limitations: - Miri doesn't support the magic linker section that our Windows TLS support relies on, and instead knows where in std to find the symbol that stores the thread callback. - For macOS, Miri only supports at most one destructor to be registered per thread. The 2nd would not be very hard to fix (though the intended destructor order is unclear); the first would be a lot of work to fix. Neither of these is a problem for regular Rust code, but in the std test suite we have essentially 2 copies of the std code and then these both become issues. To avoid that we have the std test crate import the TLS code from the real std instead of having its own copy. r? ``````@m-ou-se``````
2023-05-04Rollup merge of #111009 - scottmcm:ascii-char, r=BurntSushiMatthias Krüger-0/+3
Add `ascii::Char` (ACP#179) ACP second: https://github.com/rust-lang/libs-team/issues/179#issuecomment-1527900570 New tracking issue: https://github.com/rust-lang/rust/issues/110998 For now this is an `enum` as `@kupiakos` [suggested](https://github.com/rust-lang/libs-team/issues/179#issuecomment-1527959724), with the variants under a different feature flag. There's lots more things that could be added here, and place for further doc updates, but this seems like a plausible starting point PR. I've gone through and put an `as_ascii` next to every `is_ascii`: on `u8`, `char`, `[u8]`, and `str`. As a demonstration, made a commit updating some formatting code to use this: https://github.com/scottmcm/rust/commit/ascii-char-in-fmt (I don't want to include that in this PR, though, because that brings in perf questions that don't exist if this is just adding new unstable APIs.)
2023-05-03Add the basic `ascii::Char` typeScott McMurray-0/+3
2023-05-03Rollup merge of #105695 - joboet:remove_generic_parker, r=m-ou-seManish Goregaokar-129/+17
Replace generic thread parker with explicit no-op parker With #98391 merged, all platforms supporting threads now have their own parking implementations. Therefore, the generic implementation can be removed. On the remaining platforms (really just WASM without atomics), parking is not supported, so calls to `thread::park` now return instantly, which is [allowed by their API](https://doc.rust-lang.org/nightly/std/thread/fn.park.html). This is a change in behaviour, as spurious wakeups do not currently occur since all platforms guard against them. It is invalid to depend on this, but I'm still going to tag this as libs-api for confirmation. ````@rustbot```` label +T-libs +T-libs-api +A-atomic r? rust-lang/libs
2023-05-03Rollup merge of #97594 - WaffleLapkin:array_tuple_conv, r=ChrisDentonManish Goregaokar-0/+20
Implement tuple<->array convertions via `From` This PR adds the following impls that convert between homogeneous tuples and arrays of the corresponding lengths: ```rust impl<T> From<[T; 1]> for (T,) { ... } impl<T> From<[T; 2]> for (T, T) { ... } /* ... */ impl<T> From<[T; 12]> for (T, T, T, T, T, T, T, T, T, T, T, T) { ... } impl<T> From<(T,)> for [T; 1] { ... } impl<T> From<(T, T)> for [T; 2] { ... } /* ... */ impl<T> From<(T, T, T, T, T, T, T, T, T, T, T, T)> for [T; 12] { ... } ``` IMO these are quite uncontroversial but note that they are, just like any other trait impls, insta-stable.
2023-05-03Mention array<->tuple convs in docsMaybe Waffle-0/+20
2023-05-03Fix MXCSR configuration dependent timingRaoul Strackx-1/+5
Some data-independent timing vector instructions may have subtle data-dependent timing due to MXCSR configuration; dependent on (potentially secret) data instruction retirement may be delayed by one cycle.
2023-05-03Remove unnecessary Send boundGil Shoshan-3/+3
2023-05-03Use `from_wide_to_user_path` in `read_link`Chris Denton-4/+7
2023-05-03Correctly convert an NT path to a Win32 pathChris Denton-12/+21
This can be done by simply changing the `\??\` prefix to `\\?\` and then attempting to convert to a user path. Currently it simply strips off the prefix which could lead to the wrong path being returned (e.g. if it's not a drive path or if the path contains trailing spaces, etc).
2023-05-02Rollup merge of #110895 - Ayush1325:thread-local-fix, r=thomccDylan DPC-1/+1
Remove `all` in target_thread_local cfg I think it was left there by mistake after the previous refactoring. I just came across it while rebasing to master.