about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2024-03-22Rollup merge of #121881 - devnexen:bsd_acceptfilter, r=AmanieuMatthias Krüger-0/+83
std::net: adding acceptfilter feature for netbsd/freebsd. similar to linux's ext deferaccept, to filter incoming connections before accept.
2024-03-21Implement macro-based deref!() syntax for deref patternsMichael Goulet-0/+9
Stop using `box PAT` syntax for deref patterns, as it's misleading and also causes their semantics being tangled up.
2024-03-20Rollup merge of #122729 - m-ou-se:relax, r=AmanieuJacob Pratt-49/+63
Relax SeqCst ordering in standard library. Every single SeqCst in the standard library is unnecessary. In all cases, Relaxed or Release+Acquire was sufficient. As I [wrote](https://marabos.nl/atomics/memory-ordering.html#common-misconceptions) in my book on atomics: > [..] when reading code, SeqCst basically tells the reader: "this operation depends on the total order of every single SeqCst operation in the program," which is an incredibly far-reaching claim. The same code would likely be easier to review and verify if it used weaker memory ordering instead, if possible. For example, Release effectively tells the reader: "this relates to an acquire operation on the same variable," which involves far fewer considerations when forming an understanding of the code. > > It is advisable to see SeqCst as a warning sign. Seeing it in the wild often means that either something complicated is going on, or simply that the author did not take the time to analyze their memory ordering related assumptions, both of which are reasons for extra scrutiny. r? ````@Amanieu```` ````@joboet````
2024-03-20std::net: adding acceptfilter feature for netbsd/freebsd.David Carlier-0/+83
similar to linux's ext deferaccept, to filter incoming connections before accept.
2024-03-20SeqCst->Relaxed in condvar test.Mara Bos-2/+2
Relaxed is enough here. Synchronization is done by the mutex.
2024-03-20SeqCst->Relaxed in thread local test.Mara Bos-8/+11
Relaxed memory ordering is fine because spawn()/join() already provides all the synchronization we need.
2024-03-20SeqCst->Relaxed in std::net::test.Mara Bos-2/+2
Relaxed is enough to have fetch_add(1) return each value only once (until it wraps around).
2024-03-20Use less restricted memory ordering in xous::thread_local_key.Mara Bos-5/+5
SeqCst isn't necessary in any of these cases.
2024-03-20Auto merge of #122754 - Mark-Simulacrum:bootstrap-bump, r=albertlarsan68bors-8/+5
Bump to 1.78 bootstrap compiler https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-03-20step cfgsMark Rousskov-5/+2
2024-03-20Rollup merge of #122739 - Sky9x:insert-put, r=jhprattMatthias Krüger-2/+2
Add "put" as a confusable for insert on hash map/set Already a confusable on btree map/set. Java's `Map` calls the insert method `put`: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html#put(K,V)
2024-03-20Rollup merge of #122730 - ferrocene:hoverbear/qnx-ucred-cfgs, r=AmanieuMatthias Krüger-3/+6
Expose `ucred::peer_cred` on QNX targets to enable dist builds After following https://doc.rust-lang.org/rustc/platform-support/nto-qnx.html I attempted to run the following `x.py` command: ```bash export build_env=' CC_aarch64-unknown-nto-qnx710=qcc CFLAGS_aarch64-unknown-nto-qnx710=-Vgcc_ntoaarch64le_cxx CXX_aarch64-unknown-nto-qnx710=qcc AR_aarch64_unknown_nto_qnx710=ntoaarch64-ar CC_x86_64-pc-nto-qnx710=qcc CFLAGS_x86_64-pc-nto-qnx710=-Vgcc_ntox86_64_cxx CXX_x86_64-pc-nto-qnx710=qcc AR_x86_64_pc_nto_qnx710=ntox86_64-ar' env $build_env ./x.py --stage 2 dist rust-std --target aarch64-unknown-nto-qnx710,x86_64-pc-nto-qnx710,x86_64-unknown-linux-gnu ``` The result was the following error: ``` Compiling object v0.32.2 Compiling std_detect v0.1.5 (/home/ana/git/rust-lang/rust/library/stdarch/crates/std_detect) Compiling addr2line v0.21.0 error: function `peer_cred` is never used --> library/std/src/os/unix/net/ucred.rs:89:12 | 89 | pub fn peer_cred(socket: &UnixStream) -> io::Result<UCred> { | ^^^^^^^^^ | = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` error: could not compile `std` (lib) due to 1 previous error Build completed unsuccessfully in 0:06:25 ``` I contacted `@flba-eb` and `@gh-tr` over email and we confirmed that `peer_cred` here should be flagged on `nto` targets. This should enable the clean `x.py --stage 2 dist rust-std` command on these platforms.
2024-03-19branch 1.78: replace-version-placeholderMark Rousskov-3/+3
2024-03-20resolve clippy errorsonur-ozkan-4/+3
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-19Add "put" as a confusable for insert on hash map/setSky-2/+2
2024-03-19Expose ucred::peer_cred on QNX targets to enable dist buildsAna Hobden-3/+6
2024-03-19SeqCst->Relaxed for xous set_nonblocking.Mara Bos-1/+1
The SeqCst wasn't synchronizing with anything. Relaxed is enough.
2024-03-19SeqCst->{Release,Acquire} for xous DropLock.Mara Bos-3/+6
SeqCst is unnecessary. Release+Acquire is the right ordering for a mutex.
2024-03-19SeqCst->Relaxed in pal::windows::pipe.Mara Bos-4/+4
Relaxed is enough to ensure fetch_add(1) returns each integer exactly once.
2024-03-19SeqCst->{Release,Acquire} for wasm DropLock.Mara Bos-3/+6
SeqCst is unnecessary. Release+Acquire is the right ordering for a mutex.
2024-03-19SeqCst->{Release,Acquire} in sys_common::thread_local_key.Mara Bos-3/+3
SeqCst is unnecessary here.
2024-03-19Use less restricted memory ordering in thread_parking::pthread.Mara Bos-10/+12
SeqCst is unnecessary here.
2024-03-19SeqCst->{Release,Acquire} in xous mutex.Mara Bos-4/+7
No need for SeqCst. Release+Acquire is the right memory ordering for a mutex.
2024-03-19SeqCst->Relaxed for FIRST_PANIC.Mara Bos-1/+1
Relaxed is enough to make sure this `swap` results in `true` only once.
2024-03-19SeqCst->{Release,Acquire} for alloc error hook.Mara Bos-3/+3
SeqCst is unnecessary.
2024-03-18Support for visionOSAdam Gastineau-20/+389
2024-03-17Expand sys/os for UEFIAyush Singh-10/+81
- Implement current_exe() - Cache device_path_to_text protocol Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-03-16Rollup merge of #122583 - Zoxc:tls-non-mut, r=joboetChris Denton-8/+7
Use `UnsafeCell` for fast constant thread locals This uses `UnsafeCell` instead of `static mut` for fast constant thread locals. This changes the type of the TLS shims to return `&UnsafeCell<T>` instead of `*mut T` which means they are always non-null so LLVM can optimize away the check for `Some` in `LocalKey::with` if `T` has no destructor. LLVM is currently unable to do this optimization as we lose the fact that `__getit` always returns `Some` as it gets optimized to just returning the value of the TLS shim.
2024-03-16Rollup merge of #122390 - ChrisDenton:bindgen, r=Mark-SimulacrumChris Denton-213/+212
Bump windows-bindgen to 0.55.0 windows-bindgen is the crate used to generate std's Windows API bindings. Not many changes for us, it's mostly just simplifying the generate code (e.g. no more `-> ()`). The one substantial change is some structs now use `i8` byte arrays instead of `u8`. However, this only impacts one test.
2024-03-16Use `UnsafeCell` for fast constant thread localsJohn Kåre Alsaker-8/+7
2024-03-15Rollup merge of #122562 - Wilfred:break_keyword_docs, r=workingjubileeMatthias Krüger-1/+1
Mention labelled blocks in `break` docs `break` doesn't require a loop, so note this in the docs. This is covered in the linked sections of the rust reference, but this page implied that `break` is only for loops.
2024-03-15Mention labelled blocks in `break` docsWilfred Hughes-1/+1
`break` doesn't require a loop, so note this in the docs. This is covered in the linked sections of the rust reference, but this page implied that `break` is only for loops.
2024-03-15Rollup merge of #122512 - baitcode:2024-03-14-buffer-documentation-fix, ↵Guillaume Gomez-0/+2
r=Nilstrieb Cursor.rs documentation fix Reason: I've been learning Rust std library and got confused. Seek trait documentation clearly states that negative indexes will cause an error. And the code in the Cursor example uses negative index. I found myself trying to understand what am I missing until I've actually executed the code and got error. I decided to submit small fix to the documentation.
2024-03-14Rollup merge of #121650 - GrigorenkoPV:cap_setgid, r=AmanieuMatthias Krüger-3/+18
change std::process to drop supplementary groups based on CAP_SETGID A trivial rebase of #95982 Should fix #39186 (from what I can tell) Original description: > Fixes #88716 > > * Before this change, when a process was given a uid via `std::os::unix::process::CommandExt.uid`, there would be a `setgroups` call (when the process runs) to clear supplementary groups for the child **if the parent was root** (to remove potentially unwanted permissions). > * After this change, supplementary groups are cleared if we have permission to do so, that is, if we have the CAP_SETGID capability. > > This new behavior was agreed upon in #88716 but there was a bit of uncertainty from `@Amanieu` here: [#88716 (comment)](https://github.com/rust-lang/rust/issues/88716#issuecomment-973366600) > > > I agree with this change, but is it really necessary to ignore an EPERM from setgroups? If you have permissions to change UID then you should also have permissions to change groups. I would feel more comfortable if we documented set_uid as requiring both UID and GID changing permissions. > > The way I've currently written it, we ignore an EPERM as that's what #88716 originally suggested. I'm not at all an expert in any of this so I'd appreciate feedback on whether that was the right way to go.
2024-03-14Fix minor documentation issue. Code outside the test would fail. Seek ↵baitcode-0/+2
documentation clearly states that negative indexes will cause error. Just making the code in the example to return Result::Ok, instead of Result::Error.
2024-03-14Rollup merge of #119029 - dylni:avoid-closing-invalid-handles, r=ChrisDentonMatthias Krüger-21/+47
Avoid closing invalid handles Documentation for [`HandleOrInvalid`] has this note: > If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop. Documentation for [`HandleOrNull`] has this note: > If this holds a non-null handle, it will close the handle on drop. Currently, both will call `CloseHandle` on their invalid handles as a result of using `OwnedHandle` internally, contradicting the above paragraphs. This PR adds destructors that match the documentation. ```@rustbot``` label A-io O-windows T-libs [`HandleOrInvalid`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrInvalid.html [`HandleOrNull`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrNull.html
2024-03-14Auto merge of #114038 - Stargateur:108277, r=ChrisDentonbors-51/+35
unix time module now return result First try to fix #108277 without break anything. if anyone who read this know tips to be able to check compilation for different target I could use some help. So far I installed many target with rustup but `./x check --all-targets` doesn't seem to use them. TODO: - [x] better error - [ ] test, how ? `@rustbot` label -S-waiting-on-author +S-waiting-on-review
2024-03-13Provide `cabi_realloc` on `wasm32-wasip2` by defaultAlex Crichton-0/+67
This commit provides a component model intrinsic in the standard library by default on the `wasm32-wasip2` target. This intrinsic is not required by the component model itself but is quite common to use, for example it's needed if a wasm module receives a string or a list. The intention of this commit is to provide an overridable definition in the standard library through a weak definition of this function. That means that downstream crates can provide their own customized and more specific versions if they'd like, but the standard library's version should suffice for general-purpose use.
2024-03-13Get wasm32-wasip2 compiling with its custom pal implementationAlex Crichton-9/+3
The ordering of targets in `pal/mod.rs` did not end up using the wasip2 implementation, so after reordering that I've edited the implementation to compile correctly.
2024-03-13Rollup merge of #122386 - joboet:move_pal_once, r=jhprattMatthias Krüger-32/+19
Move `Once` implementations to `sys` Part of https://github.com/rust-lang/rust/issues/117276.
2024-03-12Specialize many implementations of `Read::read_buf_exact`Benoît du Garreau-18/+74
2024-03-12Convert [u8] to [i8] in testChris Denton-0/+1
2024-03-12Bump windows-bindgen to 0.55.0Chris Denton-183/+181
2024-03-12Bump windows-bindgen to 0.54.0Chris Denton-31/+31
2024-03-12std: move `Once` implementations to `sys`joboet-32/+19
2024-03-12Allow dead code in sys/palArthur Carcano-0/+6
The dead_code lint was previously eroneously missing this dead code. Since this lint bug has been fixed, the unused field need to be removed or marked as `#[allow(dead_code)]`. These structures API is common to all platforms so the code cannot be removed and is hence marked allow(dead_code).
2024-03-12Allow dead code in thread local dtorArthur Carcano-1/+1
The dead_code lint was previously eroneously missing this dead code. Since this lint bug has been fixed, the unused field need to be removed or marked as `#[allow(dead_code)]`. Given the nature of this code, I don't feel confident removing the field so it is only marked as allow(dead_code).
2024-03-12Use `min_exhaustive_patterns` in core & stdNadrieril-1/+10
2024-03-12std::rand: fix dragonflybsd after #121942.David Carlier-7/+13
2024-03-11Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviperJubilee-4/+4
std support for wasm32 panic=unwind Tracking issue: #118168 This adds std support for `-Cpanic=unwind` on wasm, and with it slightly more fleshed out rustc support. Now, the stable default is still panic=abort without exception-handling, but if you `-Zbuild-std` with `RUSTFLAGS=-Cpanic=unwind`, you get wasm exception-handling try/catch blocks in the binary: ```rust #[no_mangle] pub fn foo_bar(x: bool) -> *mut u8 { let s = Box::<str>::from("hello"); maybe_panic(x); Box::into_raw(s).cast() } #[inline(never)] #[no_mangle] fn maybe_panic(x: bool) { if x { panic!("AAAAA"); } } ``` ```wat ;; snip... (try $label$5 (do (call $maybe_panic (local.get $0) ) (br $label$1) ) (catch_all (global.set $__stack_pointer (local.get $1) ) (call $__rust_dealloc (local.get $2) (i32.const 5) (i32.const 1) ) (rethrow $label$5) ) ) ;; snip... ```