Commit Graph

6634 Commits

Author SHA1 Message Date
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
The 8472
ca1a2a6457 wait for two short reads before uncapping the max read size
for disk IO:
1st short read = probably at end of file
2nd short read = confirming that it's indeed EOF
2024-09-21 18:50:29 +02:00
Matthias Krüger
f2290c23fc
Rollup merge of #129718 - lolbinarycat:remove_dir-docs, r=Noratrieb
add guarantee about remove_dir and remove_file error kinds

approved in ACP https://github.com/rust-lang/libs-team/issues/433
2024-09-21 07:22:47 +02:00
bors
da889684c8 Auto merge of #130631 - GuillaumeGomez:rollup-jpgy1iv, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #128209 (Remove macOS 10.10 dynamic linker bug workaround)
 - #130526 (Begin experimental support for pin reborrowing)
 - #130611 (Address diagnostics regression for `const_char_encode_utf8`.)
 - #130614 (Add arm64e-apple-tvos target)
 - #130617 (bail if there are too many non-region infer vars in the query response)
 - #130619 (Fix scraped examples height)
 - #130624 (Add `Vec::as_non_null`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-20 19:51:45 +00:00
nora
c72264157b
Remove double spaces 2024-09-20 19:55:28 +02:00
Guillaume Gomez
bf6389f077
Rollup merge of #128209 - beetrees:no-macos-10.10, r=jieyouxu
Remove macOS 10.10 dynamic linker bug workaround

Rust's current minimum macOS version is 10.12, so the hack can be removed. This PR also updates the `remove_dir_all` docs to reflect that all supported macOS versions are protected against TOCTOU race conditions (the fallback implementation was already removed in #127683).

try-job: dist-x86_64-apple
try-job: dist-aarch64-apple
try-job: dist-apple-various
try-job: aarch64-apple
try-job: x86_64-apple-1
2024-09-20 19:46:37 +02:00
bors
5ba6db1b64 Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errors
Disallow hidden references to mutable static

Closes #123060

Tracking:
- https://github.com/rust-lang/rust/issues/123758
2024-09-20 17:25:34 +00:00
GnomedDev
98e68e5040
[Clippy] Remove final std paths for diagnostic item 2024-09-20 10:39:31 +01:00
Matthias Krüger
553c20cc92
Rollup merge of #130554 - ShE3py:unsupported-exitcode, r=Noratrieb
`pal::unsupported::process::ExitCode`: use an `u8` instead of a `bool`

`ExitCode` should “represents the status code the current process can return to its parent under normal termination”, but is currently represented as a `bool` on unsupported platforms, making the `impl From<u8> for ExitCode` lossy.

Fixes #130532.

History: [IRLO thread](https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426) (`ExitCode` as a `main` return), #48618 (initial impl), #93445 (`From<u8>` impl).
2024-09-19 20:37:08 +02:00
Lieselotte
dc628c8ecb
pal::unsupported::process::ExitCode: use an u8 instead of a bool 2024-09-19 14:22:50 +02:00
GnomedDev
b2eebeeea9
[Clippy] Swap open_options to use diagnostic items instead of paths 2024-09-19 13:13:43 +01:00
GnomedDev
364e552940
[Clippy] Swap iter_over_hash_type to use diagnostic items instead of paths 2024-09-19 13:13:43 +01:00
GnomedDev
43b8e04d46
[Clippy] Swap non_octal_unix_permissions to use diagnostic item instead of path 2024-09-19 13:13:43 +01:00
GnomedDev
1890620b26
[Clippy] Swap instant_subtraction to use diagnostic item instead of path 2024-09-19 13:13:42 +01:00
GnomedDev
037b9784b6
[Clippy] Swap manual_main_separator_str to use diagnostic item instead of path 2024-09-19 13:13:20 +01:00
GnomedDev
afe7907914
[Clippy] Swap redundant_clone to use diagnostic items instead of paths 2024-09-19 13:13:20 +01:00
GnomedDev
5e4716888a
[Clippy] Swap option_as_ref_deref to use diagnostic items instead of paths 2024-09-19 13:13:19 +01:00
GnomedDev
a786be5d06
[Clippy] Swap map_entry to use diagnostic items instead of paths 2024-09-19 08:26:37 +01:00
Jubilee
4bd9de5512
Rollup merge of #130522 - GnomedDev:clippy-manual-retain-paths, r=compiler-errors
[Clippy] Swap `manual_retain` to use diagnostic items instead of paths

Part of https://github.com/rust-lang/rust-clippy/issues/5393, just a chore.
2024-09-18 14:32:28 -07:00
Jubilee
4d9ce4b4b3
Rollup merge of #130513 - shekhirin:fs-write-doc-comment, r=cuviper
Clarify docs for std::fs::File::write

This PR fixes the doc comment for `std::fs::File::write` method.
2024-09-18 14:32:27 -07:00
Jubilee
12b59e52bc
Rollup merge of #130476 - workingjubilee:more-lazy-methods-take-2, r=Amanieu
Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`

Tracking issue for `lazy_get`: https://github.com/rust-lang/rust/issues/129333
2024-09-18 14:32:26 -07:00
Jubilee
591ec6c9ce
Rollup merge of #129934 - ChrisDenton:remove-dir-all3, r=Amanieu
Win: Open dir for sync access in remove_dir_all

A small follow up to #129800.

We should explicitly open directories for synchronous access. We ultimately use `GetFileInformationByHandleEx` to read directories which should paper over any issues caused by using async directory reads (or else return an error) but it's better to do the right thing in the first place. Note though that `delete` does not read or write any data so it's not necessary there.
2024-09-18 14:32:25 -07:00
Jubilee
4722ad149e
Rollup merge of #97524 - ibraheemdev:thread-raw, r=ibraheemdev
Add `Thread::{into_raw, from_raw}`

Public API:
```rust
#![unstable(feature = "thread_raw", issue = "97523")]

impl Thread {
    pub fn into_raw(self) -> *const ();
    pub unsafe fn from_raw(ptr: *const ()) -> Thread;
}
```

ACP: https://github.com/rust-lang/libs-team/issues/200
2024-09-18 14:32:23 -07:00
Jubilee Young
f22797d3db library: Call it really_init_mut to avoid name collisions 2024-09-18 11:39:24 -07:00
Jubilee Young
d9cdb71497 library: Destabilize Lazy{Cell,Lock}::{force,deref}_mut 2024-09-18 11:39:21 -07:00
GnomedDev
a18564c198
[Clippy] Swap manual_retain to use diagnostic items instead of paths 2024-09-18 17:20:44 +01:00
Alexey Shekhirin
96a3b48197
Clarify docs for std::fs::File::write 2024-09-18 15:15:54 +01:00
Ibraheem Ahmed
0fa92b4159 add Thread::{into_raw, from_raw} 2024-09-17 18:50:06 -04:00
Chayim Refael Friedman
d0a2ca4867 Implement ACP 429: add Lazy{Cell,Lock}::get[_mut] and force_mut
In the implementation of `force_mut`, I chose performance over safety.
For `LazyLock` this isn't really a choice; the code has to be unsafe.
But for `LazyCell`, we can have a full-safe implementation, but it will
be a bit less performant, so I went with the unsafe approach.
2024-09-17 09:40:34 -07:00
Matthias Krüger
11fe22c3fb
Rollup merge of #128535 - mmvanheusden:master, r=workingjubilee
Format `std::env::consts` docstrings with markdown backticks

This clarifies possible outputs the constants might be.

**Before:**
--
<img src="https://github.com/user-attachments/assets/8ee8772a-7562-42a2-89be-f8772b76dbd5" width="500px">

**After:**
--
<img src="https://github.com/user-attachments/assets/4632e5e2-db3e-4372-b13e-006cc1701eb1" width="500px">
2024-09-17 17:28:31 +02:00
Matthias Krüger
558b302af7
Rollup merge of #130448 - alilleybrinker:master, r=workingjubilee
fix: Remove duplicate `LazyLock` example.

The top-level docs for `LazyLock` included two lines of code, each with an accompanying comment, that were identical and with nearly- identical comments. This looks like an oversight from a past edit which was perhaps trying to rewrite an existing example but ended up duplicating rather than replacing, though I haven't gone back through the Git history to check.

This commit removes what I personally think is the less-clear of the two examples.
2024-09-17 03:58:47 +02:00
bors
bde6bf2b07 Auto merge of #127633 - SamuelMarks:eq-exit-code, r=dtolnay
[library/std/src/process.rs] `PartialEq` for `ExitCode`

Converting a third-party CLI to a library so started passing around [`std::process::ExitCode`](https://doc.rust-lang.org/std/process/struct.ExitCode.html) in an `Either`. Then I realised the tests can't be modified to compare equality of `ExitCode`s.

This PR fixes this oversight.
2024-09-16 22:55:33 +00:00
Andrew Lilley Brinker
23e4e98d2c fix: Remove duplicate LazyLock example.
The top-level docs for `LazyLock` included two lines of code, each
with an accompanying comment, that were identical and with nearly-
identical comments. This looks like an oversight from a past edit
which was perhaps trying to rewrite an existing example but ended
up duplicating rather than replacing, though I haven't gone back
through the Git history to check.

This commit removes what I personally think is the less-clear of
the two examples.

Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com>
2024-09-16 14:21:05 -07:00
Matthias Krüger
f0fb411969
Rollup merge of #130339 - CAD97:unwind-choice, r=dtolnay
Add `core::panic::abort_unwind`

`abort_unwind` is like `catch_unwind` except that it aborts the process if it unwinds, using the `#[rustc_nounwind]` mechanism also used by `extern "C" fn` to abort unwinding. The docs attempt to make it clear when to (rarely) and when not to (usually) use the function.

Although usage of the function is discouraged, having it available will help to normalize the experience when abort_unwind shims are hit, as opposed to the current ecosystem where there exist multiple common patterns for converting unwinding into a process abort.

For further information and justification, see the linked ACP.

- Tracking issue: https://github.com/rust-lang/rust/issues/130338
- ACP: https://github.com/rust-lang/libs-team/issues/441
2024-09-15 20:55:13 +02:00
Matthias Krüger
011289c9d4
Rollup merge of #129195 - RalfJung:const-mut-refs, r=fee1-dead
Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const

This stabilizes `const_mut_refs` and `const_refs_to_cell`. That allows a bunch of new things in const contexts:
- Mentioning `&mut` types
- Creating `&mut` and `*mut` values
- Creating `&T` and `*const T` values where `T` contains interior mutability
- Dereferencing `&mut` and `*mut` values (both for reads and writes)

The same rules as at runtime apply: mutating immutable data is UB. This includes mutation through pointers derived from shared references; the following is diagnosed with a hard error:
```rust
#[allow(invalid_reference_casting)]
const _: () = {
    let mut val = 15;
    let ptr = &val as *const i32 as *mut i32;
    unsafe { *ptr = 16; }
};
```

The main limitation that is enforced is that the final value of a const (or non-`mut` static) may not contain `&mut` values nor interior mutable `&` values. This is necessary because the memory those references point to becomes *read-only* when the constant is done computing, so (interior) mutable references to such memory would be pretty dangerous. We take a multi-layered approach here to ensuring no mutable references escape the initializer expression:
- A static analysis rejects (interior) mutable references when the referee looks like it may outlive the current MIR body.
- To be extra sure, this static check is complemented by a "safety net" of dynamic checks. ("Dynamic" in the sense of "running during/after const-evaluation, e.g. at runtime of this code" -- in contrast to "static" which works entirely by looking at the MIR without evaluating it.)
  - After the final value is computed, we do a type-driven traversal of the entire value, and if we find any `&mut` or interior-mutable `&` we error out.
  - However, the type-driven traversal cannot traverse `union` or raw pointers, so there is a second dynamic check where if the final value of the const contains any pointer that was not derived from a shared reference, we complain. This is currently a future-compat lint, but will become an ICE in #128543. On the off-chance that it's actually possible to trigger this lint on stable, I'd prefer if we could make it an ICE before stabilizing const_mut_refs, but it's not a hard blocker. This part of the "safety net" is only active for mutable references since with shared references, it has false positives.

Altogether this should prevent people from leaking (interior) mutable references out of the const initializer.

While updating the tests I learned that surprisingly, this code gets rejected:
```rust
const _: Vec<i32> = {
    let mut x = Vec::<i32>::new(); //~ ERROR destructor of `Vec<i32>` cannot be evaluated at compile-time
    let r = &mut x;
    let y = x;
    y
};
```
The analysis that rejects destructors in `const` is very conservative when it sees an `&mut` being created to `x`, and then considers `x` to be always live. See [here](https://github.com/rust-lang/rust/issues/65394#issuecomment-541499219) for a longer explanation. `const_precise_live_drops` will solve this, so I consider this problem to be tracked by https://github.com/rust-lang/rust/issues/73255.

Cc `@rust-lang/wg-const-eval` `@rust-lang/lang`
Cc https://github.com/rust-lang/rust/issues/57349
Cc https://github.com/rust-lang/rust/issues/80384
2024-09-15 11:55:45 +02:00
Ralf Jung
3175cc2814 stabilize const_mut_refs 2024-09-15 09:51:32 +02:00
Stuart Cook
e02e6bf0e9
Rollup merge of #130042 - lolbinarycat:bufreaker_peek_eof, r=Amanieu
properly handle EOF in BufReader::peek

previously this would cause an infinite loop due to it being unable to read `n` bytes.
2024-09-15 12:14:55 +10:00
Christopher Durham
7e7ccb25b4
add std::panic::abort_unwind 2024-09-14 01:41:00 -04:00
Obei Sideg
3b0ce1bc33
Update tests for hidden references to mutable static 2024-09-13 14:10:56 +03:00
Félix Saparelli
0b2235d732
Stabilize entry_insert 2024-09-13 11:45:44 +12:00
bors
2e8db5e9e3 Auto merge of #130281 - matthiaskrgr:rollup-1b2ibs8, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #130101 (some const cleanup: remove unnecessary attributes, add const-hack indications)
 - #130208 (Introduce `'ra` lifetime name.)
 - #130263 (coverage: Simplify creation of sum counters)
 - #130273 (more eagerly discard constraints on overflow)
 - #130276 (Add test for nalgebra hang in coherence)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-12 18:27:55 +00:00
Matthias Krüger
4428d6f363
Rollup merge of #130101 - RalfJung:const-cleanup, r=fee1-dead
some const cleanup: remove unnecessary attributes, add const-hack indications

I learned that we use `FIXME(const-hack)` on top of the "const-hack" label. That seems much better since it marks the right place in the code and moves around with the code. So I went through the PRs with that label and added appropriate FIXMEs in the code. IMO this means we can then remove the label -- Cc ``@rust-lang/wg-const-eval.``

I also noticed some const stability attributes that don't do anything useful, and removed them.

r? ``@fee1-dead``
2024-09-12 19:03:41 +02:00
bors
8c0ec05f7d Auto merge of #129992 - alexcrichton:update-compiler-builtins, r=tgross35
Update compiler-builtins to 0.1.125

This commit updates the compiler-builtins crate from 0.1.123 to 0.1.125. The changes in this update are:

* https://github.com/rust-lang/compiler-builtins/pull/682
* https://github.com/rust-lang/compiler-builtins/pull/678
* https://github.com/rust-lang/compiler-builtins/pull/685
2024-09-12 15:28:40 +00:00
Stuart Cook
8e037ccec7
Rollup merge of #125060 - ChrisJefferson:pathbuf-doc, r=workingjubilee
Expand documentation of PathBuf, discussing lack of sanitization

Various methods in `PathBuf`, in particular `set_file_name` and `set_extension` accept strings which include path seperators (like `../../etc`). These methods just glue together strings, so you can end up with strange strings.

This isn't reasonable to change/fix at this point, and might not even be fixable, but I think should be documented. In particular, you probably shouldn't blindly build paths using strings given by possibly malicious users.
2024-09-12 20:37:14 +10:00
Jubilee Young
45c471b1f3 Fixup docs for PathBuf 2024-09-11 22:46:06 -07:00
Chris Jefferson
d6ef1b99e8 Expand PathBuf documentation
Mention that some methods do not sanitize their input fully
2024-09-11 22:33:12 -07:00
Jubilee
b4201d3f78
Rollup merge of #130248 - nyurik:fix-129895, r=workingjubilee
Limit `libc::link` usage to `nto70` target only, not NTO OS

It seems QNX 7.0 does not support `linkat` at all (most tests were failing). Limiting to QNX 7.0 only, while using `linkat` for the future versions seems like the right path forward (tested on 7.0).

Fixes #129895

CC: `@japaric` `@flba-eb` `@saethlin`
2024-09-11 15:53:25 -07:00
Jubilee
eb9a4f7ab8
Rollup merge of #130168 - juliusl:pr/fix-win-fs-change-time-links, r=ChrisDenton
maint: update docs for change_time ext and doc links

maint: update docs for change_time ext and doc links

Related: https://github.com/rust-lang/rust/issues/121478
r? tgross35
2024-09-11 15:53:23 -07:00
Jubilee
c4488c49de
Rollup merge of #130077 - madsmtm:watchos-arm-unwind, r=workingjubilee
Fix linking error when compiling for 32-bit watchOS

In https://github.com/rust-lang/rust/pull/124494 (or https://github.com/rust-lang/rust/pull/124748), I mistakenly conflated "not SjLj" to mean "ARM EHABI", which isn't true, 32-bit watchOS uses a third unwinding method called "DWARF CFI".

So this PR is effectively a revert of https://github.com/rust-lang/rust/pull/124494, with a few more comments explaining what's going on.

Fixes https://github.com/rust-lang/rust/issues/130071.

r? Mark-Simulacrum (since you reviewed the original)
2024-09-11 15:53:22 -07:00
Jubilee
312b597a7e
Rollup merge of #129835 - RalfJung:float-tests, r=workingjubilee
enable const-float-classify test, and test_next_up/down on 32bit x86

The  test_next_up/down tests have been disabled on all 32bit x86 targets, which goes too far -- they should definitely work on our (tier 1) i686 target, it is only without SSE that we might run into trouble due to https://github.com/rust-lang/rust/issues/114479. However, I cannot reproduce that trouble any more -- maybe that got fixed by https://github.com/rust-lang/rust/pull/123351?

The  const-float-classify test relied on const traits "because we can", and got disabled when const traits got removed. That's an unfortunate reduction in test coverage of our float functionality, so let's restore the test in a way that does not rely on const traits.

The const-float tests are actually testing runtime behavior as well, and I don't think that runtime behavior is covered anywhere else. Probably they shouldn't be called "const-float", but we don't have a `tests/ui/float` folder... should I create one and move them there? Are there any other ui tests that should be moved there?

I also removed some FIXME referring to not use x87 for Rust-to-Rust-calls -- that has happened in #123351 so this got fixed indeed. Does that mean we can simplify all that float code again? I am not sure how to test it. Is running the test suite with an i586 target enough?

Cc ```@tgross35``` ```@workingjubilee```
2024-09-11 15:53:21 -07:00