about summary refs log tree commit diff
path: root/library/std
AgeCommit message (Collapse)AuthorLines
2022-12-07Auto merge of #104799 - pcc:linkage-fn, r=tmiaskobors-1/+36
Support Option and similar enums as type of static variable with linkage attribute Compiler MCP: rust-lang/compiler-team#565
2022-12-06Don't set `STARTF_USESTDHANDLES` if none are setChris Denton-7/+15
2022-12-06Rollup merge of #105243 - RalfJung:no-op-let, r=Mark-SimulacrumMatthias Krüger-9/+3
remove no-op 'let _ = ' Also see the discussion at https://github.com/rust-lang/rust/pull/93563#discussion_r1034057555. I don't know why these `Drop` implementations exist to begin with, given that their body does literally nothing, but did not want to change that. (It might affect dropck.) Cc `````@ibraheemdev````` `````@Amanieu`````
2022-12-06Implement masking in FileType hashing on UnixArthur Carcano-1/+8
Commit 77005950f09d2f9ba54962bf5adc3f2bc3a7213f implemented masking of FileType to fix an issue[^1] in the semantic of FileType comparison. This commit introduces masking to Hash to maintain the invariant that x == y => hash(x) == hash(y). [^1]: https://github.com/rust-lang/rust/issues/104900
2022-12-06Make sentinel value configurableFlorian Bartels-8/+17
There are OSs that always return the lowest free value. The algorithm in `lazy_init` always avoids keys with the sentinel value. In affected OSs, this means that each call to `lazy_init` will always request two keys from the OS and returns/frees the first one (with sentinel value) immediately afterwards. By making the sentinel value configurable, affected OSs can use a different value than zero to prevent this performance issue.
2022-12-06Rollup merge of #105289 - Rageking8:fix-dupe-word-typos, r=cjgillotYuki Okushi-2/+2
Fix dupe word typos
2022-12-05Reimplement weak! using Option.Peter Collingbourne-1/+36
2022-12-05fix dupe word typosRageking8-2/+2
2022-12-04remove no-op 'let _ = 'Ralf Jung-9/+3
2022-12-03std update libc version and freebsd image build dependenciesDavid CARLIER-1/+1
2022-12-03Rollup merge of #105100 - jhpratt:fix-docs, r=JohnTitorYuki Okushi-2/+3
Add missing intra-doc link Trivial change. This makes the plain text into inline code and makes it a link. `@rustbot` label +A-docs
2022-12-02Auto merge of #104999 - saethlin:immediate-abort-inlining, r=thomccbors-2/+2
Adjust inlining attributes around panic_immediate_abort The goal of `panic_immediate_abort` is to permit the panic runtime and formatting code paths to be optimized away. But while poking through some disassembly of a small program compiled with that option, I found that was not the case. Enabling LTO did address that specific issue, but enabling LTO is a steep price to pay for this feature doing its job. This PR fixes that, by tweaking two things: * All the slice indexing functions that we `const_eval_select` on get `#[inline]`. `objdump -dC` told me that originally some `_ct` functions could end up in an executable. I won't pretend to understand what's going on there. * Normalize attributes across all `panic!` wrappers: use `inline(never) + cold` normally, and `inline` when `panic_immediate_abort` is enabled. But also, with LTO and `panic_immediate_abort` enabled, this patch knocks ~709 kB out of the `.text` segment of `librustc_driver.so`. That is slightly surprising to me, my best theory is that this shifts some inlining earlier in compilation, enabling some subsequent optimizations. The size improvement of `librustc_driver.so` with `panic_immediate_abort` due to this patch is greater with LTO than without LTO, which I suppose backs up this theory. I do not know how to test this. I would quite like to, because I think what this is solving was an accidental regression. This only works with `-Zbuild-std` which is a cargo flag, and thus can't be used in a rustc codegen test. r? `@thomcc` --- I do not seriously think anyone is going to use a compiler built with `panic_immediate_abort`, but I wanted a big complicated Rust program to try this out on, and the compiler is such.
2022-12-02Windows: make Command prefer non-verbatim pathsChris Denton-38/+62
When spawning Commands, the path we use can end up being queried using `env::current_exe` (or the equivalent in other languages). Not all applications handle these paths properly therefore we should have a stronger preference for non-verbatim paths when spawning processes.
2022-12-02std: cleanup timeouts in pthread condvarjoboet-66/+34
2022-12-02kmc-solid: Don't do `Box::from_raw(&*(x: Box<T>) as *const T as *mut T)`Tomoaki Kawada-18/+30
This pattern seems to be considered illegal by Miri.
2022-12-02Rollup merge of #105137 - yjhn:patch-1, r=Dylan-DPCMatthias Krüger-1/+1
Add tracking issue number for `file_create_new` feature It was missing a tracking issue, so I opened one (#105135).
2022-12-02Rollup merge of #104614 - Nilstrieb:type-ascribe!, r=TaKO8KiMatthias Krüger-0/+9
Add `type_ascribe!` macro as placeholder syntax for type ascription This makes it still possible to test the internal semantics of type ascription even once the `:`-syntax is removed from the parser. The macro now gets used in a bunch of UI tests that test the semantics and not syntax of type ascription. I might have forgotten a few tests but this should hopefully be most of them. The remaining ones will certainly be found once type ascription is removed from the parser altogether. Part of #101728
2022-12-01Add tracking issue for file_create_newAndrius Pukšta-1/+1
2022-12-01Gate macros behind `#[cfg(not(bootstrap))]`nils-0/+1
Co-authored-by: Takayuki Maeda <takoyaki0316@gmail.com>
2022-12-01kmc-solid: Address compiler warningsTomoaki Kawada-5/+4
Addresses the warn-by-default lints `unused_imports` and `unused_unsafe`.
2022-12-01kmc-solid: Add a stub implementation of `is_terminal`Tomoaki Kawada-0/+4
Copied from `unsupported/io.rs`. Fixes build failure.
2022-12-01kmc-solid: Use `expose_addr` and `from_exposed_addr` for pointer-integer castsTomoaki Kawada-2/+2
Pointer-integer casts are required for conversion between `EXINF` (ITRON task entry point parameter) and `*const ThreadInner`. Addresses the deny-level lint `fuzzy_provenance_casts`.
2022-12-01Auto merge of #104160 - Ayush1325:windows-args, r=m-ou-sebors-52/+62
Extract WStrUnits to sys_common::wstr This commit extracts WStrUnits from sys::windows::args to sys_common::wstr. This allows using the same structure for other targets which use wtf8 (example UEFI). This was originally a part of https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-30Add test for regression for FileType equalityArthur Carcano-0/+16
Cf: https://github.com/rust-lang/rust/issues/104900
2022-11-30Add missing intra-doc linkJacob Pratt-2/+3
2022-11-30Rollup merge of #104811 - haraldh:feat/wasm32_wasi_shutdown, r=joshtriplettMatthias Krüger-2/+8
feat: implement TcpStream shutdown for wasm32-wasi Signed-off-by: Harald Hoyer <harald@profian.com>
2022-11-29Add in the comment that solaris lacks also the 'linkat'Daniel Laügt-1/+1
2022-11-29Rollup merge of #105049 - mkroening:hermit-fixes, r=jyn514Matthias Krüger-4/+3
Hermit: Minor build fixes These changes are necessary to build for the hermit targets. CC: ``@stlankes``
2022-11-29Adjust inlining attributes around panic_immediate_abortBen Kimock-2/+2
2022-11-29hermit: Remove unused exportsMartin Kröning-3/+1
2022-11-29hermit: Fix fuzzy_provenance_castsMartin Kröning-1/+2
2022-11-28Add `as_mut_os_string` to `&mut PathBuf` and `as_mut_os_str` to `&mut Path`Andres Suarez-0/+46
Implements rust-lang/libs-team#140
2022-11-28Implement DerefMut for PathBufAndres Suarez-0/+14
2022-11-28Extract WStrUnits to sys_common::wstrAyush Singh-52/+62
This commit extracts WStrUnits from sys::windows::args to sys_common::wstr. This allows using the same structure for other targets which use wtf8 (example UEFI). This was originally a part of https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-11-28linkat() not available in the system headers of Solaris 10Daniel Laügt-1/+1
2022-11-26Remove redundant `all` in cfgChris Denton-6/+6
2022-11-25Implement masking in FileType comparison on UnixArthur Carcano-1/+10
Fixes: https://github.com/rust-lang/rust/issues/104900
2022-11-24Revert "Forbid inlining `thread_local!`'s `__getit` function on Windows"Thom Chiovoloni-16/+9
This reverts commit 3099dfdd9fc1a331eb9c53200b310fa1a06e1573.
2022-11-24feat: implement TcpStream shutdown for wasm32-wasiHarald Hoyer-2/+8
Signed-off-by: Harald Hoyer <harald@profian.com>
2022-11-22Rollup merge of #104647 - RalfJung:alloc-strict-provenance, r=thomccManish Goregaokar-4/+8
enable fuzzy_provenance_casts lint in liballoc and libstd r? ````@thomcc````
2022-11-23Rollup merge of #101368 - thomcc:wintls-noinline, r=ChrisDentonYuki Okushi-9/+16
Forbid inlining `thread_local!`'s `__getit` function on Windows Sadly, this will make things slower to avoid UB in an edge case, but it seems hard to avoid... and really whenever I look at this code I can't help but think we're asking for trouble. It's pretty dodgy for us to leave this as a normal function rather than `#[inline(never)]`, given that if it *does* get inlined into a dynamically linked component, it's extremely unsafe (you get some other thread local, or if you're lucky, crash). Given that it's pretty rare for people to use dylibs on Windows, the fact that we haven't gotten bug reports about it isn't really that convincing. Ideally we'd come up with some kind of compiler solution (that avoids paying for this cost when static linking, or *at least* for use within the same crate...), but it's not clear what that looks like. Oh, and because all this is only needed when we're implementing `thread_local!` with `#[thread_local]`, this patch adjusts the `cfg_attr` to be `all(windows, target_thread_local)` as well. r? ``@ChrisDenton`` See also #84933, which is about improving the situation.
2022-11-22disable strict-provenance-violating doctests in MiriRalf Jung-0/+2
2022-11-22Forbid inlining `thread_local!`'s `__getit` function on WindowsThom Chiovoloni-9/+16
2022-11-22rustdoc: Fix backoff doc to match implementationJonas Spinner-1/+1
2022-11-22Rollup merge of #103193 - krasimirgg:sysonce, r=AmanieuManish Goregaokar-0/+1
mark sys_common::once::generic::Once::new const-stable Attempt to address https://github.com/rust-lang/rust/issues/103191 by marking the impl const-stable. Picked the declaration from the callsite: https://github.com/rust-lang/rust/blob/21b246587c2687935bd6004ffa5dcc4f4dd6600d/library/std/src/sync/once.rs#L67 This is similar to https://github.com/rust-lang/rust/pull/98457. With this in, `python3 x.py build library/std --target x86_64-unknown-none` succeeds.
2022-11-22Rollup merge of #83608 - Kimundi:index_many, r=Mark-SimulacrumManish Goregaokar-0/+1
Add slice methods for indexing via an array of indices. Disclaimer: It's been a while since I contributed to the main Rust repo, apologies in advance if this is large enough already that it should've been an RFC. --- # Update: - Based on feedback, removed the `&[T]` variant of this API, and removed the requirements for the indices to be sorted. # Description This adds the following slice methods to `core`: ```rust impl<T> [T] { pub unsafe fn get_many_unchecked_mut<const N: usize>(&mut self, indices: [usize; N]) -> [&mut T; N]; pub fn get_many_mut<const N: usize>(&mut self, indices: [usize; N]) -> Option<[&mut T; N]>; } ``` This allows creating multiple mutable references to disjunct positions in a slice, which previously required writing some awkward code with `split_at_mut()` or `iter_mut()`. For the bound-checked variant, the indices are checked against each other and against the bounds of the slice, which requires `N * (N + 1) / 2` comparison operations. This has a proof-of-concept standalone implementation here: https://crates.io/crates/index_many Care has been taken that the implementation passes miri borrow checks, and generates straight-forward assembly (though this was only checked on x86_64). # Example ```rust let v = &mut [1, 2, 3, 4]; let [a, b] = v.get_many_mut([0, 2]).unwrap(); std::mem::swap(a, b); *v += 100; assert_eq!(v, &[3, 2, 101, 4]); ``` # Codegen Examples <details> <summary>Click to expand!</summary> Disclaimer: Taken from local tests with the standalone implementation. ## Unchecked Indexing: ```rust pub unsafe fn example_unchecked(slice: &mut [usize], indices: [usize; 3]) -> [&mut usize; 3] { slice.get_many_unchecked_mut(indices) } ``` ```nasm example_unchecked: mov rcx, qword, ptr, [r9] mov r8, qword, ptr, [r9, +, 8] mov r9, qword, ptr, [r9, +, 16] lea rcx, [rdx, +, 8*rcx] lea r8, [rdx, +, 8*r8] lea rdx, [rdx, +, 8*r9] mov qword, ptr, [rax], rcx mov qword, ptr, [rax, +, 8], r8 mov qword, ptr, [rax, +, 16], rdx ret ``` ## Checked Indexing (Option): ```rust pub unsafe fn example_option(slice: &mut [usize], indices: [usize; 3]) -> Option<[&mut usize; 3]> { slice.get_many_mut(indices) } ``` ```nasm mov r10, qword, ptr, [r9, +, 8] mov rcx, qword, ptr, [r9, +, 16] cmp rcx, r10 je .LBB0_7 mov r9, qword, ptr, [r9] cmp rcx, r9 je .LBB0_7 cmp rcx, r8 jae .LBB0_7 cmp r10, r9 je .LBB0_7 cmp r9, r8 jae .LBB0_7 cmp r10, r8 jae .LBB0_7 lea r8, [rdx, +, 8*r9] lea r9, [rdx, +, 8*r10] lea rcx, [rdx, +, 8*rcx] mov qword, ptr, [rax], r8 mov qword, ptr, [rax, +, 8], r9 mov qword, ptr, [rax, +, 16], rcx ret .LBB0_7: mov qword, ptr, [rax], 0 ret ``` ## Checked Indexing (Panic): ```rust pub fn example_panic(slice: &mut [usize], indices: [usize; 3]) -> [&mut usize; 3] { let len = slice.len(); match slice.get_many_mut(indices) { Some(s) => s, None => { let tmp = indices; index_many::sorted_bound_check_failed(&tmp, len) } } } ``` ```nasm example_panic: sub rsp, 56 mov rax, qword, ptr, [r9] mov r10, qword, ptr, [r9, +, 8] mov r9, qword, ptr, [r9, +, 16] cmp r9, r10 je .LBB0_6 cmp r9, rax je .LBB0_6 cmp r9, r8 jae .LBB0_6 cmp r10, rax je .LBB0_6 cmp rax, r8 jae .LBB0_6 cmp r10, r8 jae .LBB0_6 lea rax, [rdx, +, 8*rax] lea r8, [rdx, +, 8*r10] lea rdx, [rdx, +, 8*r9] mov qword, ptr, [rcx], rax mov qword, ptr, [rcx, +, 8], r8 mov qword, ptr, [rcx, +, 16], rdx mov rax, rcx add rsp, 56 ret .LBB0_6: mov qword, ptr, [rsp, +, 32], rax mov qword, ptr, [rsp, +, 40], r10 mov qword, ptr, [rsp, +, 48], r9 lea rcx, [rsp, +, 32] mov edx, 3 call index_many::bound_check_failed ud2 ``` </details> # Extensions There are multiple optional extensions to this. ## Indexing With Ranges This could easily be expanded to allow indexing with `[I; N]` where `I: SliceIndex<Self>`. I wanted to keep the initial implementation simple, so I didn't include it yet. ## Panicking Variant We could also add this method: ```rust impl<T> [T] { fn index_many_mut<const N: usize>(&mut self, indices: [usize; N]) -> [&mut T; N]; } ``` This would work similar to the regular index operator and panic with out-of-bound indices. The advantage would be that we could more easily ensure good codegen with a useful panic message, which is non-trivial with the `Option` variant. This is implemented in the standalone implementation, and used as basis for the codegen examples here and there.
2022-11-21dont attempt strict provenance in SGXRalf Jung-0/+1
2022-11-21reflow the stack size storyTshepang Mbambo-2/+4
2022-11-20enable fuzzy_provenance_casts lint in libstdRalf Jung-4/+7
2022-11-20Rollup merge of #104558 - thomcc:unalign-diriter, r=ChrisDentonMatthias Krüger-10/+23
Don't assume `FILE_ID_BOTH_DIR_INFO` will be aligned Fixes #104530. See that issue for info. r? `@ChrisDenton`