Commit Graph

15502 Commits

Author SHA1 Message Date
Chris Denton
2043de12a3
Narrow the scope of the ReadFile unsafe block 2024-07-17 05:53:20 +00:00
Chris Denton
a33abbba98
forbid(unsafe_op_in_unsafe_fn) in sys/os_str 2024-07-17 05:52:38 +00:00
Chris Denton
10b845cbc8
Add unsafe blocks in unsafe Thread::new 2024-07-16 20:48:39 +00:00
Chris Denton
55c84e39cc
Remove slice_to_end 2024-07-16 20:24:57 +00:00
Chris Denton
5922234654
allow(unsafe_op_in_unsafe_fn) on some functions
These need to get their safety story straight
2024-07-15 14:16:17 +00:00
Chris Denton
37295e6268
Some Windows functions are safe 2024-07-15 14:16:17 +00:00
Chris Denton
d1a3c1daeb
Deny more windows unsafe_op_in_unsafe_fn 2024-07-15 14:16:11 +00:00
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
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
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
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
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
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
Matthias Krüger
dba010d7fa
Rollup merge of #127704 - workingjubilee:fixup-better-than, r=ChrisDenton
Fix minor typos in std::process doc on Win argv
2024-07-14 10:05:21 +02:00
bors
8a63c84af5 Auto merge of #127706 - workingjubilee:rollup-d07ij30, r=workingjubilee
Rollup of 6 pull requests

Successful merges:

 - #122300 (Add FileCheck annotations to mir-opt/dest-prop tests)
 - #127434 (use "bootstrap" instead of "rustbuild" in comments and docs)
 - #127477 (Clear `inner_attr_ranges` regularly.)
 - #127558 (More attribute cleanups)
 - #127659 (Use ManuallyDrop in BufWriter::into_parts)
 - #127671 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 8))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-14 05:41:24 +00:00
Jubilee
2d8493bb5f
Rollup merge of #127659 - saethlin:manually-drop-bufwriter, r=joboet
Use ManuallyDrop in BufWriter::into_parts

The fact that `mem::forget` takes by value means that it interacts very poorly with Stacked Borrows; generally users think of calling it as a no-op, but in Stacked Borrows, the field retagging tends to cause surprise tag invalidation.
2024-07-13 20:19:47 -07:00
Jubilee
285d45d299
Rollup merge of #127446 - zachs18:miri-stdlib-leaks-core-alloc, r=Mark-Simulacrum
Remove memory leaks in doctests in `core`, `alloc`, and `std`

cc `@RalfJung`  https://github.com/rust-lang/rust/issues/126067 https://github.com/rust-lang/miri/issues/3670

Should be no actual *documentation* changes[^1], all added/modified lines in the doctests are hidden with `#`,

This PR splits the existing memory leaks in doctests in `core`, `alloc`, and `std` into two general categories:

1. "Non-focused" memory leaks that are incidental to the thing being documented, and/or are easy to remove, i.e. they are only there because preventing the leak would make the doctest less clear and/or concise.
    - These doctests simply have a comment like `# // Prevent leaks for Miri.` above the added line that removes the memory leak.
    - [^2]Some of these would perhaps be better as part of the public documentation part of the doctest, to clarify that a memory leak can happen if it is not otherwise mentioned explicitly in the documentation  (specifically the ones in `(A)Rc::increment_strong_count(_in)`).
2. "Focused" memory leaks that are intentional and documented, and/or are possibly fragile to remove.
    - These doctests have a `# // FIXME` comment above the line that removes the memory leak, with a note that once `-Zmiri-disable-leak-check` can be applied at test granularity, these tests should be "un-unleakified" and have `-Zmiri-disable-leak-check` enabled.
    - Some of these are possibly fragile (e.g. unleaking the result of `Vec::leak`) and thus should definitely not be made part of the documentation.

This should be all of the leaks currently in `core` and `alloc`. I only found one leak in `std`, and it was in the first category (excluding the modules `@RalfJung` mentioned in https://github.com/rust-lang/rust/issues/126067 , and reducing the number of iterations of [one test](https://github.com/rust-lang/rust/blob/master/library/std/src/sync/once_lock.rs#L49-L94) from 1000 to 10)

[^1]: assuming [^2] is not added
[^2]: backlink
2024-07-13 20:18:23 -07:00
Jubilee
5c56577948
Rollup merge of #127370 - ChrisDenton:win-sys, r=Mark-Simulacrum
Windows: Add experimental support for linking std-required system DLLs using raw-dylib

For Windows, this allows std to define system imports without needing the user to have import libraries. It's intended for this to become the default.

For now it's an experimental feature so it can be tested using build-std.
2024-07-13 20:18:23 -07:00