Commit Graph

260593 Commits

Author SHA1 Message Date
Jubilee 476d399782
Rollup merge of #127750 - ChrisDenton:safe-unsafe-unsafe, r=workingjubilee
Make os/windows and pal/windows default to `#![deny(unsafe_op_in_unsafe_fn)]`

This is to prevent regressions in modules that currently pass. I did also fix up a few trivial places where the module contained only one or two simple wrappers. In more complex cases we should try to ensure the `unsafe` blocks are appropriately scoped and have any appropriate safety comments.

This does not fix the windows bits of #127747 but it should help prevent regressions until that is done and also make it more obvious specifically which modules need attention.
2024-07-15 02:28:44 -07:00
Jubilee 99c5302d9f
Rollup merge of #127744 - workingjubilee:deny-unsafe-op-in-std, r=jhpratt
std: `#![deny(unsafe_op_in_unsafe_fn)]` in platform-independent code

This applies the `unsafe_op_in_unsafe_fn` lint in all places in std that _do not have platform-specific cfg in their code_. For all such places, the lint remains allowed, because they need further work to address the relevant concerns. This list includes:

- `std::backtrace_rs` (internal-only)
- `std::sys` (internal-only)
- `std::os`

Notably this eliminates all "unwrapped" unsafe operations in `std::io` and `std::sync`, which will make them much more auditable in the future. Such has *also* been left for future work. While I made a few safety comments along the way on interfaces I have grown sufficiently familiar with, in most cases I had no context, nor particular confidence the unsafety was correct.

In the cases where I was able to determine the unsafety was correct without having prior context, it was obviously redundant. For example, an unsafe function calling another unsafe function that has the exact same contract, forwarding its caller's requirements just as it forwards its actual call.
2024-07-15 02:28:44 -07:00
Jubilee 64495b5f94
Rollup merge of #127712 - ChrisDenton:raw-types, r=workingjubilee
Windows: Remove some unnecessary type aliases

Back in the olden days, C did not have fixed-width types so these type aliases were at least potentially useful. Nowadays, and especially in Rust, we don't need the aliases and they don't help with anything. Notably the windows bindings we use also don't bother with the aliases. And even when we have used aliases they're often only used once then forgotten about.

The only one that gives me pause is `DWORD` because it's used a fair bit. But it's still used inconsistently and we implicitly assume it's a `u32` anyway (e.g. `as` casting from an `i32`).
2024-07-15 02:28:43 -07:00
Chris Denton 7e16d5fb61
Move safety comment outside unsafe block 2024-07-15 07:30:11 +00:00
Chris Denton 3411a025d5
Make os/windows default to deny unsafe in unsafe 2024-07-15 07:17:39 +00:00
Chris Denton 2402e84e78
Make pal/windows default to deny unsafe in unsafe 2024-07-15 07:00:40 +00:00
Chris Denton 816d90ae5f
Fix Windows 7 2024-07-15 06:14:53 +00:00
bors 0da95bd869 Auto merge of #127719 - devnexen:math_log_fix_solill, r=Amanieu
std: removes logarithms family function edge cases handling for solaris.

Issue had been fixed over time with solaris, 11.x behaves correctly
 (and we support it as minimum), illumos works correctly too.
2024-07-15 05:43:22 +00:00
Chris Denton ffe8fc276e
Don't re-export `c_int` from `c` 2024-07-15 05:01:23 +00:00
Chris Denton 8a1ce3dfcc
Make normalization regex less exact 2024-07-15 05:01:22 +00:00
Chris Denton e2b062c9b5
Remove DWORD 2024-07-15 05:01:22 +00:00
Chris Denton d8d7c5c3b9
Remove ULONG 2024-07-15 05:01:22 +00:00
Chris Denton 21f69b5b82
Remove PSRWLOCK 2024-07-15 05:01:22 +00:00
Chris Denton 84dd7e4959
Remove LPVOID 2024-07-15 05:01:21 +00:00
Chris Denton 351f1f36f6
Remove LPSECURITY_ATTRIBUTES 2024-07-15 05:01:21 +00:00
Chris Denton 1b7cf3a3f2
Remove LPOVERLAPPED 2024-07-15 05:01:21 +00:00
Chris Denton 8052fb8f3c
Remove LPCVOID 2024-07-15 05:01:21 +00:00
Chris Denton 286c3270b4
Remove SIZE_T 2024-07-15 05:01:20 +00:00
Chris Denton 5b700a76cf
Remove CHAR
As with USHORT, keep using C types for BSD socket APIs.
2024-07-15 05:01:20 +00:00
Chris Denton f2cc94361c
Remove USHORT
We stick to C types in for socket and address as these are at least nominally BSD-ish and they're used outside of pal/windows in general *nix code
2024-07-15 05:01:20 +00:00
Chris Denton e70cc28831
Remove LPWSTR 2024-07-15 05:01:20 +00:00
Chris Denton b107cfa73c
Remove UINT 2024-07-15 05:01:19 +00:00
Chris Denton 65da4af0be
Remove LONG 2024-07-15 05:01:19 +00:00
Chris Denton 91ba4ebcfd
Remove LARGE_INTEGER 2024-07-15 05:01:19 +00:00
Chris Denton 1d1cae1ba5
Remove NonZeroDWORD 2024-07-15 05:01:18 +00:00
bors 594702ebb5 Auto merge of #127732 - GrigorenkoPV:teeos-safe-sys-init, r=Amanieu
sys::init is not unsafe on teeos

88fa119c77/library/std/src/sys/pal/teeos/mod.rs (L40-L42)

r​? `@petrochenkov`
2024-07-15 03:19:47 +00:00
Jubilee Young e32460276c std: Unsafe-wrap std::sync 2024-07-14 17:59:37 -07:00
Jubilee Young 64fb2366da std: Unsafe-wrap in Wtf8 impl 2024-07-14 17:44:13 -07:00
Jubilee Young df353a0cc3 std: Unsafe-wrap std::io 2024-07-14 17:17:55 -07:00
Jubilee Young 83a0fe5396 std: Directly call unsafe {un,}setenv in env 2024-07-14 17:08:44 -07:00
Jubilee Young ce35265105 std: Unsafe-wrap OSStr{,ing}::from_encoded_bytes_unchecked 2024-07-14 16:59:12 -07:00
Jubilee Young 87d850dff0 std: Unsafe-wrap HashMap::get_many_unchecked_mut 2024-07-14 16:49:16 -07:00
Jubilee Young 4572ed6389 std: deny(unsafe_op_in_unsafe_fn) but allow sites
This provides a list of locations to hunt down issues in.
2024-07-14 16:44:01 -07:00
bors 8b72d7a9d7 Auto merge of #127718 - cjgillot:find_field, r=compiler-errors
find_field does not need to be a query.

The current implementation is quadratic in the number of nested fields.

r? `@davidtwco` as you reviewed https://github.com/rust-lang/rust/pull/115367
Fixes https://github.com/rust-lang/rust/issues/121755
2024-07-14 23:35:45 +00:00
David Carlier d939351c31
std: removes logarithms family function edge cases handling for solaris.
Issue had been fixed over time with solaris, 11.x behaves correctly
 (and we support it as minimum), illumos works correctly too.
2024-07-14 23:20:46 +01:00
bors d9284afea9 Auto merge of #127726 - RalfJung:miri-sync, r=RalfJung
Miri subtree update

r? `@ghost`
2024-07-14 21:14:02 +00:00
bors f8e4ac0760 Auto merge of #127728 - matthiaskrgr:rollup-ercdbjd, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #127273 (Fix `DebugParser`.)
 - #127587 (Report usage of lib features in ast validation)
 - #127592 (doc: Suggest `str::repeat` over `iter::repeat().take().collect()`)
 - #127630 (Remove lang feature for type ascription (since it's a lib feature now))
 - #127711 (Add regression test for a gce + effects ICE)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-14 18:50:26 +00:00
Pavel Grigorenko bbf303ed14 sys::init is not unsafe on teeos 2024-07-14 21:43:20 +03:00
Matthias Krüger f19cb0b294
Rollup merge of #127711 - BoxyUwU:add_effects_test, r=fee1-dead
Add regression test for a gce + effects ICE

Fixes #125770

I'm not *exactly* sure why this stopped ICEing, I assume its something to do with the fact that there used to be a generic parameter on `Add` for the host generic and we have mismatched args here, which #125608 made no longer later cause issues. But now the desugaring is also different so? 🤷‍♀️

r? `@fee1-dead`
2024-07-14 20:25:00 +02:00
Matthias Krüger 79000d2a8f
Rollup merge of #127630 - compiler-errors:type-ascription, r=chenyukang
Remove lang feature for type ascription (since it's a lib feature now)

It's not necessary since it's a library feature now, via the type ascription macro. We can't (and shouldn't) register it as a removed feature since I think that would give "this feature has been removed" errors even for people using the macro (well, I'm pretty sure, though I didn't check).

r? `@Nilstrieb`
2024-07-14 20:24:59 +02:00
Matthias Krüger 77d25b9f9c
Rollup merge of #127592 - tesuji:patch-1, r=Mark-Simulacrum
doc: Suggest `str::repeat` over `iter::repeat().take().collect()`

r? libs
2024-07-14 20:24:59 +02:00
Matthias Krüger 5d1f9e21cf
Rollup merge of #127587 - compiler-errors:all-features-at-once, r=Nilstrieb
Report usage of lib features in ast validation

No idea why it was split between ast validation for lang features and a later pass for lang features.

r? `@Nilstrieb`
2024-07-14 20:24:58 +02:00
Matthias Krüger febe4423c1
Rollup merge of #127273 - nnethercote:fix-DebugParser, r=workingjubilee
Fix `DebugParser`.

I tried using this and it didn't work at all. `prev_token` is never eof, so the accumulator is always false, which means the `then_some` always returns `None`, which means `scan` always returns `None`, and `tokens` always ends up an empty vec. I'm not sure how this code was supposed to work.

(An aside: I find `Iterator::scan` to be a pretty wretched function, that produces code which is very hard to understand. Probably why this is just one of two uses of it in the entire compiler.)

This commit changes it to a simpler imperative style that produces a valid `tokens` vec.

r? `@workingjubilee`
2024-07-14 20:24:58 +02:00
bors e90f04731a Auto merge of #3745 - joboet:os_unfair_lock, r=RalfJung
Implement the `os_unfair_lock` functions on macOS

These are needed for rust-lang/rust#122408. See the documentation [here](https://developer.apple.com/documentation/os/synchronization?language=objc) and the implementation [here](a00a4cc36d/src/os/lock.c (L645)).
2024-07-14 17:36:18 +00:00
joboet 32221c3a10
implement the `os_unfair_lock` functions on macOS 2024-07-14 19:15:06 +02:00
bors 5f993496b5 Auto merge of #3750 - RalfJung:dangling-intermediate-ref, r=RalfJung
add test for intermediate reference in '&(*x).0 as *const i32'
2024-07-14 16:45:52 +00:00
Ralf Jung 9a23878ea7 add test for intermediate reference in '&(*x).0 as *const i32' 2024-07-14 18:43:15 +02:00
bors 09682988f2 Auto merge of #125935 - madsmtm:merge-os-apple, r=workingjubilee
Merge Apple `std::os` extensions modules into `std::os::darwin`

The functionality available on Apple platforms are very similar, and were (basically) duplicated for each platform.

This PR rectifies that by merging the code into one module.

Ultimately, I've done this to fix `./x build library --target=aarch64-apple-tvos,aarch64-apple-watchos,aarch64-apple-visionos`, as that currently fails because of dead code warnings.

Publically exposing these to tvOS/watchOS/visionOS targets is considered in https://github.com/rust-lang/rust/pull/123723, but that seems to be dragging out, and in any case I think it makes sense to do the refactor separately from stabilization.

r? libs

Fixes https://github.com/rust-lang/rust/issues/121640 and https://github.com/rust-lang/rust/issues/124825.
2024-07-14 16:28:07 +00:00
Mads Marquart 306d5788a6 Merge Apple `std::os` extensions modules into `std::os::darwin`
The functionality available on Apple platforms are very similar, and
were duplicated for each platform.

Additionally, this fixes a warning when compiling the standard library
for tvOS, watchOS and visionOS by marking the corresponding code as
dead code.
2024-07-14 15:31:54 +02:00
Camille GILLOT b494d98b18 find_field does not need to be a query. 2024-07-14 13:25:25 +00:00