about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-03-10Rollup merge of #94790 - RalfJung:portable-simd-miri, r=Dylan-DPCDylan DPC-2/+0
enable portable-simd doctests in Miri With https://github.com/rust-lang/miri/pull/2013 we shouldn't need to disable these tests any more. :)
2022-03-10Rollup merge of #93950 - T-O-R-U-S:use-modern-formatting-for-format!-macros, ↵Dylan DPC-293/+285
r=Mark-Simulacrum Use modern formatting for format! macros This updates the standard library's documentation to use the new format_args syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored). `eprintln!("{}", e)` becomes `eprintln!("{e}")`, but `eprintln!("{}", e.kind())` remains untouched.
2022-03-10Rollup merge of #94644 - m-ou-se:scoped-threads-drop-soundness, r=joshtriplettMatthias Krüger-12/+52
Fix soundness issue in scoped threads. This was discovered in https://github.com/rust-lang/rust/pull/94559#discussion_r820116323 The `scope()` function returns when all threads are finished, but I accidentally considered a thread 'finished' before dropping their panic payload or ignored return value. So if a thread returned (or panics with) something that in its `Drop` implementation still uses borrowed stuff, it goes wrong. https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=2a1f19ac4676cdabe43e24e536ff9358
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-293/+285
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-03-10Rollup merge of #94635 - jhpratt:merge-deprecated-attrs, r=davidtwcoMatthias Krüger-0/+1
Merge `#[deprecated]` and `#[rustc_deprecated]` The first commit makes "reason" an alias for "note" in `#[rustc_deprecated]`, while still prohibiting it in `#[deprecated]`. The second commit changes "suggestion" to not just be a feature of `#[rustc_deprecated]`. This is placed behind the new `deprecated_suggestion` feature. This needs a tracking issue; let me know if this PR will be approved and I can create one. The third commit is what permits `#[deprecated]` to be used when `#![feature(staged_api)]` is enabled. This isn't yet used in stdlib (only tests), as it would require duplicating all deprecation attributes until a bootstrap occurs. I intend to submit a follow-up PR that replaces all uses and removes the remaining `#[rustc_deprecated]` code after the next bootstrap. `@rustbot` label +T-libs-api +C-feature-request +A-attributes +S-waiting-on-review
2022-03-09enable portable-simd doctests in MiriRalf Jung-2/+0
2022-03-09Rollup merge of #94768 - ↵Matthias Krüger-0/+1
fortanix:raoul/fix_close_read_wakes_up_test_sgx_platform, r=dtolnay Ignore `close_read_wakes_up` test on SGX platform PR #94714 enabled the `close_read_wakes_up` test for all platforms. This is incorrect. This test should be ignored at least for the SGX platform. cc: ``@mzohreva`` ``@jethrogb``
2022-03-09New `deprecated_suggestion` feature, use in testsJacob Pratt-0/+1
2022-03-09Add documentation about lifetimes to thread::scope.Mara Bos-0/+18
2022-03-09Ignore `close_read_wakes_up` test on SGX platformRaoul Strackx-0/+1
2022-03-09add as_raw() method to L4Re's Socket mockBenjamin Lamowski-0/+5
Minimally comply with with #87329 to avoid breaking tests on L4Re.
2022-03-09put L4Re specifics into their own platformBenjamin Lamowski-2/+760
The initial stdlib modifications for L4Re just used the linux specifics directly because they were reasonably close to L4Re's behavior. However, this breaks when Linux-specific code relies on code that is only available for the linux target, such as in #81825. Put L4Re into its own platform to avoid such breakage in the future. This uses the Linux-specific code as a starting point, which seems to be in line with other OSes with a unix-y interface such as Fuchsia.
2022-03-09adapt L4Re network interface mock to #87329Benjamin Lamowski-9/+34
Copy the relevant trait implementations from the Unix default.
2022-03-09L4Re does not support sanitizing standard streamsBenjamin Lamowski-0/+1
L4Re provides limited POSIX support which includes support for standard I/O streams, and a limited implementation of the standard file handling API. However, because as a capability based OS it strives to only make a local view available to each application, there are currently no standardized special files like /dev/null that could serve to sanitize closed standard FDs. For now, skip any attempts to sanitize standard streams until a more complete POSIX runtime is available.
2022-03-09drop unused libc imports on L4ReBenjamin Lamowski-1/+4
As a capability-based microkernel OS, L4Re only has incomplete support for POSIX APIs, in particular it does not implement UIDs and GIDs.
2022-03-09fix return value of LookupHost::port()Sebastian Humenda-1/+1
[Benjamin Lamowski: Reworded commit message after split commit.]
2022-03-09fix return values in L4Re networking stubSebastian Humenda-4/+4
[Benjamin Lamowski: Reworded commit message after split commit.]
2022-03-09Add soundness test for dropping scoped thread results before joining.Mara Bos-1/+24
2022-03-09Remove outdated comment.Mara Bos-2/+0
2022-03-09Properly abort when thread result panics on drop.Mara Bos-24/+26
2022-03-09Fix soundness issue in scoped threads.Mara Bos-0/+17
2022-03-09Rollup merge of #94756 - ChrisDenton:unreachable, r=yaahcDylan DPC-1/+7
Use `unreachable!` for an unreachable code path Closes #73212
2022-03-09Auto merge of #94750 - cuviper:dirent64_min, r=joshtriplettbors-10/+47
unix: reduce the size of DirEntry On platforms where we call `readdir` instead of `readdir_r`, we store the name as an allocated `CString` for variable length. There's no point carrying around a full `dirent64` with its fixed-length `d_name` too.
2022-03-08docsRalf Jung-3/+4
2022-03-09Use `unreachable!` for an unreachable code pathChris Denton-1/+7
2022-03-08Rollup merge of #94730 - msabansal:sabansal/b-atomic-mut-ptr, r=Dylan-DPCDylan DPC-0/+1
Reverted atomic_mut_ptr feature removal causing compilation break Fixes a regression introduced as part of https://github.com/rust-lang/rust/pull/94546 Std no longer compiles on nightly while using the following commnd: export RUSTFLAGS='-C target-feature=+atomics,+bulk-memory' cargo build --target wasm32-unknown-unknown -Z build-std=panic_abort,std I can help add tests to avoid future breaks but i couldn't understand the test framework
2022-03-08Rollup merge of #94724 - cuviper:rmdirall-cstr, r=Dylan-DPCDylan DPC-10/+9
unix: Avoid name conversions in `remove_dir_all_recursive` Each recursive call was creating an `OsString` for a `&Path`, only for it to be turned into a `CString` right away. Instead we can directly pass `.name_cstr()`, saving two allocations each time.
2022-03-08Rollup merge of #94714 - ChrisDenton:win-close_read_wakes_up, r=Mark-SimulacrumDylan DPC-1/+0
Enable `close_read_wakes_up` test on Windows I wonder if we could/should try enabling this again? It was closed by #38867 due to #31657. I've tried running this test (along with other tests) on my machine a number of times and haven't seen this fail yet, Caveat: the worst that can happen is this succeeds initially but then causes random hangs in CI. This is not a great failure mode and would be a reason not to do this. If this does work out, closes #39006 r? `@Mark-Simulacrum`
2022-03-08unix: reduce the size of DirEntryJosh Stone-10/+47
On platforms where we call `readdir` instead of `readdir_r`, we store the name as an allocated `CString` for variable length. There's no point carrying around a full `dirent64` with its fixed-length `d_name` too.
2022-03-08remove_dir_all: use fallback implementation on MiriRalf Jung-3/+3
2022-03-08Rollup merge of #94712 - kckeiks:remove-rwlock-read-error-assumption, ↵Matthias Krüger-3/+3
r=Mark-Simulacrum promot debug_assert to assert Fixes #94705
2022-03-08Rollup merge of #94559 - m-ou-se:thread-scope-spawn-closure-without-arg, ↵Matthias Krüger-21/+23
r=Mark-Simulacrum Remove argument from closure in thread::Scope::spawn. This implements ```@danielhenrymantilla's``` [suggestion](https://github.com/rust-lang/rust/issues/93203#issuecomment-1040798286) for improving the scoped threads interface. Summary: The `Scope` type gets an extra lifetime argument, which represents basically its own lifetime that will be used in `&'scope Scope<'scope, 'env>`: ```diff - pub struct Scope<'env> { .. }; + pub struct Scope<'scope, 'env: 'scope> { .. } pub fn scope<'env, F, T>(f: F) -> T where - F: FnOnce(&Scope<'env>) -> T; + F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> T; ``` This simplifies the `spawn` function, which now no longer passes an argument to the closure you give it, and now uses the `'scope` lifetime for everything: ```diff - pub fn spawn<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> + pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> where - F: FnOnce(&Scope<'env>) -> T + Send + 'env, + F: FnOnce() -> T + Send + 'scope, - T: Send + 'env; + T: Send + 'scope; ``` The only difference the user will notice, is that their closure now takes no arguments anymore, even when spawning threads from spawned threads: ```diff thread::scope(|s| { - s.spawn(|_| { + s.spawn(|| { ... }); - s.spawn(|s| { + s.spawn(|| { ... - s.spawn(|_| ...); + s.spawn(|| ...); }); }); ``` <details><summary>And, as a bonus, errors get <em>slightly</em> better because now any lifetime issues point to the outermost <code>s</code> (since there is only one <code>s</code>), rather than the innermost <code>s</code>, making it clear that the lifetime lasts for the entire <code>thread::scope</code>. </summary> ```diff error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function --> src/main.rs:9:21 | - 7 | s.spawn(|s| { - | - has type `&Scope<'1>` + 6 | thread::scope(|s| { + | - lifetime `'1` appears in the type of `s` 9 | s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped | ^^ - `a` is borrowed here | | | may outlive borrowed value `a` | note: function requires argument type to outlive `'1` --> src/main.rs:9:13 | 9 | s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword | 9 | s.spawn(move || println!("{:?}", a)); // might run after `a` is dropped | ++++ " ``` </details> The downside is that the signature of `scope` and `Scope` gets slightly more complex, but in most cases the user wouldn't need to write those, as they just use the argument provided by `thread::scope` without having to name its type. Another downside is that this does not work nicely in Rust 2015 and Rust 2018, since in those editions, `s` would be captured by reference and not by copy. In those editions, the user would need to use `move ||` to capture `s` by copy. (Which is what the compiler suggests in the error.)
2022-03-08Fix for issue #93283Miguel Perez-1/+9
2022-03-07Reverted atomic-mut-ptr feature removal causing compilation breakSandeep Bansal-0/+1
2022-03-07unix: Avoid name conversions in `remove_dir_all_recursive`Josh Stone-10/+9
Each recursive call was creating an `OsString` for a `&Path`, only for it to be turned into a `CString` right away. Instead we can directly pass `.name_cstr()`, saving two allocations each time.
2022-03-07Enable `close_read_wakes_up` on WindowsChris Denton-1/+0
2022-03-07Use `f` instead of `|| f()`.Mara Bos-1/+1
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2022-03-07promot debug_assert to assertFausto-3/+3
2022-03-07Stabilize const_fn_fn_ptr_basics and const_fn_trait_boundEric Holk-2/+2
2022-03-07Auto merge of #94272 - tavianator:readdir-reclen-for-real, r=cuviperbors-5/+9
fs: Don't dereference a pointer to a too-small allocation ptr::addr_of!((*ptr).field) still requires ptr to point to an appropriate allocation for its type. Since the pointer returned by readdir() can be smaller than sizeof(struct dirent), we need to entirely avoid dereferencing it as that type. Link: https://github.com/rust-lang/miri/pull/1981#issuecomment-1048278492 Link: https://github.com/rust-lang/rust/pull/93459#discussion_r795089971
2022-03-06Rollup merge of #94649 - ChrisDenton:unix-absolute-fix, r=Dylan-DPCfee1-dead-8/+17
Unix path::absolute: Fix leading "." component Testing leading `.` and `..` components were missing from the unix tests. This PR adds them and fixes the leading `.` case. It also fixes the test cases so that they do an exact comparison. This problem reported by ``@axetroy``
2022-03-05Auto merge of #94648 - RalfJung:rollup-4iorcrd, r=RalfJungbors-0/+5
Rollup of 4 pull requests Successful merges: - #94630 (Update note about tier 2 docs.) - #94633 (Suggest removing a semicolon after derive attributes) - #94642 (Fix source code pages scroll) - #94645 (do not attempt to open cgroup files under Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-03-05Use as_os_str to compare exact pathsChris Denton-3/+6
2022-03-05Relax tests for Windows dos device namesChris Denton-4/+1
Windows 11 no longer turn paths ending with dos device names into device paths. E.g. `C:\path\to\COM1.txt` used to get turned into `\\.\COM1`. Whereas now the path is left as is.
2022-03-05Use `as_os_str` to compare exact pathsChris Denton-7/+10
2022-03-05Unix `path::absolute`: Fix leading "." componentChris Denton-1/+7
Testing leading `.` and `..` components were missing from the unix tests.
2022-03-05do not attempt to open cgroup files under MiriRalf Jung-0/+5
2022-03-05Small fixes in thread local code.Mara Bos-2/+2
2022-03-05Update documentation in thread/local.rs.Mara Bos-6/+26
2022-03-05Add debug asserts in thread local cell set methods.Mara Bos-0/+4