Commit Graph

2843 Commits

Author SHA1 Message Date
Matthias Krüger
313a668234
Rollup merge of #94635 - jhpratt:merge-deprecated-attrs, r=davidtwco
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-10 12:20:51 +01:00
Matthias Krüger
06944d9e49
Rollup merge of #94768 - 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-09 23:14:15 +01:00
Jacob Pratt
5636655d0f
New deprecated_suggestion feature, use in tests 2022-03-09 16:32:47 -05:00
Mara Bos
4d56c1563c Add documentation about lifetimes to thread::scope. 2022-03-09 15:20:00 +01:00
Raoul Strackx
491350ce75 Ignore close_read_wakes_up test on SGX platform 2022-03-09 12:28:16 +01:00
Dylan DPC
28d06bdec9
Rollup merge of #94756 - ChrisDenton:unreachable, r=yaahc
Use `unreachable!` for an unreachable code path

Closes #73212
2022-03-09 06:38:53 +01:00
bors
163c207fc2 Auto merge of #94750 - cuviper:dirent64_min, r=joshtriplett
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-09 02:17:58 +00:00
Chris Denton
57442beb18
Use unreachable! for an unreachable code path 2022-03-09 01:05:47 +00:00
Dylan DPC
5629026e90
Rollup merge of #94730 - msabansal:sabansal/b-atomic-mut-ptr, r=Dylan-DPC
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-08 22:44:01 +01:00
Dylan DPC
a67b6299b4
Rollup merge of #94724 - cuviper:rmdirall-cstr, r=Dylan-DPC
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-08 22:44:00 +01:00
Dylan DPC
ee8109d12d
Rollup merge of #94714 - ChrisDenton:win-close_read_wakes_up, r=Mark-Simulacrum
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-08 22:43:57 +01:00
Josh Stone
e8b9ba84be 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-08 13:36:01 -08:00
Matthias Krüger
a077e44c14
Rollup merge of #94712 - kckeiks:remove-rwlock-read-error-assumption, r=Mark-Simulacrum
promot debug_assert to assert

Fixes #94705
2022-03-08 11:04:55 +01:00
Matthias Krüger
aec535f805
Rollup merge of #94559 - m-ou-se:thread-scope-spawn-closure-without-arg, 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-08 11:04:51 +01:00
Sandeep Bansal
d8e75bc1b7 Reverted atomic-mut-ptr feature removal causing compilation break 2022-03-07 23:41:52 -08:00
Josh Stone
ef3e33bd16 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-07 18:51:53 -08:00
Chris Denton
24ec0f223d
Enable close_read_wakes_up on Windows 2022-03-07 22:35:17 +00:00
Mara Bos
a3d269e91c
Use f instead of || f().
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2022-03-07 22:14:02 +00:00
Fausto
776be7e73e promot debug_assert to assert 2022-03-07 15:48:35 -05:00
Eric Holk
7723506d13 Stabilize const_fn_fn_ptr_basics and const_fn_trait_bound 2022-03-07 08:47:15 -08:00
bors
2631aeef82 Auto merge of #94272 - tavianator:readdir-reclen-for-real, r=cuviper
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-07 04:48:23 +00:00
fee1-dead
8ea3f236dc
Rollup merge of #94649 - ChrisDenton:unix-absolute-fix, r=Dylan-DPC
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-06 22:35:31 +11:00
bors
c274e4969f Auto merge of #94648 - RalfJung:rollup-4iorcrd, r=RalfJung
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-05 19:53:45 +00:00
Chris Denton
0421af9a46
Use as_os_str to compare exact paths 2022-03-05 17:58:08 +00:00
Chris Denton
e8b7371a23
Unix path::absolute: Fix leading "." component
Testing leading `.` and `..` components were missing from the unix tests.
2022-03-05 17:57:12 +00:00
Ralf Jung
51b4ea2ba1 do not attempt to open cgroup files under Miri 2022-03-05 11:23:25 -05:00
Mara Bos
3b9e214c40 Small fixes in thread local code. 2022-03-05 11:39:03 +01:00
Mara Bos
c68c384b88 Update documentation in thread/local.rs. 2022-03-05 11:39:03 +01:00
Mara Bos
36c904594e Add debug asserts in thread local cell set methods. 2022-03-05 11:39:03 +01:00
Mara Bos
93c409d6e2 Add tracking issue number for local_key_cell_methods. 2022-03-05 11:39:03 +01:00
Mara Bos
88a693c4f4 Rename LocalKey's with_{ref,mut} to with_borrow{,_mut}. 2022-03-05 11:39:03 +01:00
Mara Bos
52ce11996b Implement RFC 3184 - thread local cell methods. 2022-03-05 11:39:03 +01:00
bors
86067bb461 Auto merge of #94546 - JmPotato:std-features-cleanup, r=m-ou-se
Clean up the std library's #![feature]s

Signed-off-by: JmPotato <ghzpotato@gmail.com>

This is part of https://github.com/rust-lang/rust/issues/87766.

r? `@m-ou-se`
2022-03-05 07:26:54 +00:00
Dylan DPC
3e1e9b4866
Rollup merge of #94446 - rusticstuff:remove_dir_all-illumos-fix, r=cuviper
UNIX `remove_dir_all()`: Try recursing first on the slow path

This only affects the _slow_ code path - if there is no `dirent.d_type` or if it is `DT_UNKNOWN`.

POSIX specifies that calling `unlink()` or `unlinkat(..., 0)` on a directory is allowed to succeed:
> The _path_ argument shall not name a directory unless the process has appropriate privileges and the implementation supports using _unlink()_ on directories.

This however can cause dangling inodes requiring an fsck e.g. on Illumos UFS, so we have to avoid that in the common case. We now just try to recurse into it first and unlink() if we can't open it as a directory.

The other two commits integrate the Macos x86-64 implementation reducing redundancy. Split into two commits for better reviewing.

Fixes #94335.
2022-03-05 04:46:37 +01:00
JmPotato
9b952b7d3a Clean up the std library's #![feature]s
Signed-off-by: JmPotato <ghzpotato@gmail.com>
2022-03-05 11:17:43 +08:00
bors
69f11fff33 Auto merge of #94628 - Dylan-DPC:rollup-v2slupe, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #94362 (Add well known values to `--check-cfg` implementation)
 - #94577 (only disable SIMD for doctests in Miri (not for the stdlib build itself))
 - #94595 (Fix invalid `unresolved imports` errors for a single-segment import)
 - #94596 (Delay bug in expr adjustment when check_expr is called multiple times)
 - #94618 (Don't round stack size up for created threads in Windows)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-05 00:15:54 +00:00
Dylan DPC
629e7aa718
Rollup merge of #94618 - lewisclark:remove-stack-size-rounding, r=yaahc
Don't round stack size up for created threads in Windows

Fixes #94454

Windows does the rounding itself, so there isn't a need to explicity do the rounding beforehand, as mentioned by ```@ChrisDenton``` in #94454

> The operating system rounds up the specified size to the nearest multiple of the system's allocation granularity (typically 64 KB). To retrieve the allocation granularity of the current system, use the [GetSystemInfo](https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsysteminfo) function.

https://docs.microsoft.com/en-us/windows/win32/procthread/thread-stack-size
2022-03-04 22:58:37 +01:00
bors
5a7e4c6b5a Auto merge of #94298 - Urgau:rustbuild-check-cfg, r=Mark-Simulacrum
Enable conditional compilation checking on the Rust codebase

This pull-request enable conditional compilation checking on every rust project build by the `bootstrap` tool.

To be more specific, this PR only enable well known names checking + extra names (bootstrap, parallel_compiler, ...).

r? `@Mark-Simulacrum`
2022-03-04 21:52:34 +00:00
Lewis Clark
6843dd5013 Don't round stack size up for created threads 2022-03-04 18:04:43 +00:00
Matthias Krüger
ee3a2c7a8c
Rollup merge of #94549 - m-ou-se:thread-is-finished, r=yaahc
Rename JoinHandle::is_running to is_finished.

This is renaming `is_running` to `is_finished` as discussed on the tracking issue here: https://github.com/rust-lang/rust/issues/90470#issuecomment-1050188499

Taking some of the docs suggestions from https://github.com/rust-lang/rust/pull/94033
2022-03-04 17:31:06 +01:00
Matthias Krüger
904c6ca95c
Rollup merge of #94236 - reez12g:add_track_caller_87707, r=yaahc
Add #[track_caller] to track callers when initializing poisoned Once

This PR is for this Issue.
https://github.com/rust-lang/rust/issues/87707

With this fix, we expect to be able to track the caller when poisoned Once is initialized.
2022-03-04 17:31:04 +01:00
Hans Kratz
735f60c34f Integrate macos x86-64 remove_dir_all() impl. Step 2: readd 2022-03-04 13:47:50 +01:00
Hans Kratz
41b4423cdf Integrate macos x86-64 remove_dir_all() impl. Step 1: remove 2022-03-04 13:47:36 +01:00
Hans Kratz
e427333071 remove_dir_all(): try recursing first instead of trying to unlink()
This only affects the `slow` code path, if there is no `dirent.d_type` or if
the type is `DT_UNKNOWN`.

POSIX specifies that calling `unlink()` or `unlinkat(..., 0)` on a directory can
succeed:
> "The _path_ argument shall not name a directory unless the process has
> appropriate privileges and the implementation supports using _unlink()_ on
> directories."
This however can cause orphaned directories requiring an fsck e.g. on Illumos
UFS, so we have to avoid that in the common case. We now just try to recurse
into it first and unlink() if we can't open it as a directory.
2022-03-04 13:33:35 +01:00
Mara Bos
9099353ea8
Use '_ for irrelevant lifetimes in Debug impl.
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2022-03-04 10:41:39 +00:00
Loïc BRANSTETT
a93c7abc69 Add #![allow(unexpected_cfgs)] in preparation of global --check-cfg 2022-03-04 11:34:51 +01:00
reez12g
bca67fe02f Add #[track_caller] to track callers when initializing poisoned Once 2022-03-03 22:41:27 -05:00
Dylan DPC
308efafc77
Rollup merge of #94572 - sunfishcode:sunfishcode/handle-or, r=joshtriplett
Use `HandleOrNull` and `HandleOrInvalid` in the Windows FFI bindings.

Use the new `HandleOrNull` and `HandleOrInvalid` types that were introduced
as part of [I/O safety] in a few functions in the Windows FFI bindings.

This factors out an `unsafe` block and two `unsafe` function calls in the
Windows implementation code.

And, it helps test `HandleOrNull` and `HandleOrInvalid`, and indeed, it
turned up a bug: `OwnedHandle` also needs to be `#[repr(transparent)]`,
as it's used inside of `HandleOrNull` and `HandleOrInvalid` which are also
`#[repr(transparent)]`.

r? ```@joshtriplett```

[I/O safety]: https://github.com/rust-lang/rust/issues/87074
2022-03-04 02:06:42 +01:00
Dylan DPC
cdfb39ef07
Rollup merge of #93965 - Mark-Simulacrum:owned-stdio, r=dtolnay
Make regular stdio lock() return 'static handles

This also deletes the unstable API surface area previously added to expose this
functionality on new methods rather than built into the current set.

Closes #86845 (tracking issue for unstable API needed without this)

r? ``````@dtolnay`````` to kick off T-libs-api FCP
2022-03-04 02:06:39 +01:00
Dylan DPC
4c70200476
Rollup merge of #88805 - krhancoc:master, r=dtolnay
Clarification of default socket flags

This PR outlines the decision to disable inheritance of socket objects when possible to child processes in the documentation.
2022-03-04 02:06:37 +01:00