Commit Graph

12640 Commits

Author SHA1 Message Date
George Bateman
d995bd61e7
Enums in offset_of: update based on est31, scottmcm & llogiq review 2023-10-31 23:26:02 +00:00
bors
09ac6e4b6d Auto merge of #117459 - matthiaskrgr:rollup-t3osb3c, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #113241 (rustdoc: Document lack of object safety on affected traits)
 - #117388 (Turn const_caller_location from a query to a hook)
 - #117417 (Add a stable MIR visitor)
 - #117439 (prepopulate opaque ty storage before using it)
 - #117451 (Add support for pre-unix-epoch file dates on Apple platforms (#108277))

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-31 23:08:56 +00:00
Sebastian Thiel
a8ece1190b
Add support for pre-unix-epoch file dates on Apple platforms (#108277)
Time in UNIX system calls counts from the epoch, 1970-01-01. The timespec
struct used in various system calls represents this as a number of seconds and
a number of nanoseconds. Nanoseconds are required to be between 0 and
999_999_999, because the portion outside that range should be represented in
the seconds field; if nanoseconds were larger than 999_999_999, the seconds
field should go up instead.

Suppose you ask for the time 1969-12-31, what time is that? On UNIX systems
that support times before the epoch, that's seconds=-86400, one day before the
epoch. But now, suppose you ask for the time 1969-12-31 23:59:00.1. In other
words, a tenth of a second after one minute before the epoch.  On most UNIX
systems, that's represented as seconds=-60, nanoseconds=100_000_000. The macOS
bug is that it returns seconds=-59, nanoseconds=-900_000_000.

While that's in some sense an accurate description of the time (59.9 seconds
before the epoch), that violates the invariant of the timespec data structure:
nanoseconds must be between 0 and 999999999. This causes this assertion in the
Rust standard library.

So, on macOS, if we get a Timespec value with seconds less than or equal to
zero, and nanoseconds between -999_999_999 and -1 (inclusive), we can add
1_000_000_000 to the nanoseconds and subtract 1 from the seconds, and then
convert.  The resulting timespec value is still accepted by macOS, and when fed
back into the OS, produces the same results. (If you set a file's mtime with
that timestamp, then read it back, you get back the one with negative
nanoseconds again.)

Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2023-10-31 17:00:59 +01:00
Oli Scherer
4512f211ae Accept less invalid Rust in rustdoc 2023-10-31 13:58:03 +00:00
roblabla
4971e997e5 Fix switch_stdout_to on Windows7
The switch_stdout_to test was broken on Windows7, as the test
infrastructure would refuse to delete the temporary test folder because
the switch-stdout-output file we redirected the stdout to was still
opened.

To fix this issue, we make switch_stdout_to return the previous handle,
and add a new switch_stdout_to call at the end of the test to return the
stdio handles to their original state. The handle the second
switch_stdout_to returns will be automatically closed, which should
allow the temporary test folder to be deleted properly.
2023-10-31 09:50:07 +01:00
Bugen Zhao
c872ccc510
delegate box error provide
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
2023-10-31 16:35:59 +08:00
Josh Triplett
bcfc48db76 Stabilize file_set_times
Approved via FCP in https://github.com/rust-lang/rust/issues/98245 .
2023-10-31 14:34:02 +08:00
León Orell Valerian Liehr
5eb76fac7c
Rollup merge of #117205 - weiznich:multiple_notes_for_on_unimplemented, r=compiler-errors
Allows `#[diagnostic::on_unimplemented]` attributes to have multiple

notes

This commit extends the `#[diagnostic::on_unimplemented]` (and `#[rustc_on_unimplemented]`) attributes to allow multiple `note` options. This enables emitting multiple notes for custom error messages. For now I've opted to not change any of the existing usages of `#[rustc_on_unimplemented]` and just updated the relevant compile tests.

r? `@compiler-errors`

I'm happy to adjust any of the existing changed location to emit the old error message if that's desired.
2023-10-30 10:48:18 +01:00
León Orell Valerian Liehr
098bb3703c
Rollup merge of #117177 - Ayush1325:uefi-alloc-type, r=workingjubilee
Use ImageDataType for allocation type

Suggested at #100499

cc `@dvdhrm`
cc `@nicholasbishop`
2023-10-30 10:48:18 +01:00
Ayush Singh
441068b613
Use ImageDataType for allocation type
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2023-10-30 10:27:10 +05:30
bors
bcb5798dd8 Auto merge of #117332 - saethlin:panic-immediate-abort, r=workingjubilee
Increase the reach of panic_immediate_abort

I wanted to use/abuse this recently as part of another project, and I was surprised how many panic-related things were left in my binaries if I built a large crate with the feature enabled along with LTO. These changes get all the panic-related symbols that I could find out of my set of locally installed Rust utilities.
2023-10-30 00:03:47 +00:00
bors
608e9682f0 Auto merge of #117089 - wesleywiser:update_backtrace, r=Mark-Simulacrum
Update backtrace submodule

This pulls in a few notable changes (see the [complete list](99faef833f...e9da96eb45) for details):

- https://github.com/rust-lang/backtrace-rs/pull/508
- https://github.com/rust-lang/backtrace-rs/pull/566
- https://github.com/rust-lang/backtrace-rs/pull/569
  - Fixes #116403 by no longer using `dbghelp.dll` during backtrace capture.
2023-10-29 20:38:32 +00:00
Ben Kimock
2e7364a586 Increase the reach of panic_immediate_abort 2023-10-29 09:31:07 -04:00
Guillaume Gomez
72012402e1
Rollup merge of #117312 - RalfJung:memcpy-assumptions, r=Mark-Simulacrum
memcpy assumptions: link to source showing that GCC makes the same assumption

I finally stumbled upon a source showing that GCC also generates overlapping `memcpy`. So if we're linking major C compilers making such assumptions here, let's have both clang and GCC.
2023-10-29 12:35:01 +01:00
Guillaume Gomez
e9c7ebe2cd
Rollup merge of #115968 - git-bruh:master, r=workingjubilee
Don't use LFS64 symbols on musl

Supersedes #106246

~~Note to packagers: If your distro's musl package has already been updated, then you won't be able to build a newer version of rust until a new rust release is made with these changes merged (which can be used to bootstrap). I'm using a super hacky method to bypass this by creating a stub library with LFS64 symbols and building a patched rust, so the symbols satisfy the build requirements while the final compiler build has no references to LFS64 symbols, example: https://codeberg.org/kiss-community/repo/pulls/160/files~~ Doesn't seem to be necessary with new rustup nightly builds, likely due to updates to vendored crates

cc ```@alyssais```
2023-10-29 12:34:59 +01:00
git-bruh
7a504cc68a Don't use LFS64 symbols on musl
Simplify #[cfg] blocks

fmt

don't try to use the more appropriate direntry on musl
2023-10-29 03:29:27 +00:00
Jubilee
2dd37d402c
Rollup merge of #117316 - Coekjan:const-binary-heap-constructor, r=dtolnay
Mark constructor of `BinaryHeap` as const fn

#112353
2023-10-28 17:08:05 -07:00
Jubilee
61cd3d0174
Rollup merge of #117162 - c410-f3r:try, r=workingjubilee
Remove `cfg_match` from the prelude

Fixes #117057

cc #115585
2023-10-28 17:08:04 -07:00
bors
7cc36de72d Auto merge of #116240 - dtolnay:constdiscriminant, r=thomcc
Const stabilize mem::discriminant

Tracking issue: #69821.

This PR is a rebase of https://github.com/rust-lang/rust/pull/103893 to resolve conflicts in library/core/src/lib.rs (against #102470 and #110393).
2023-10-28 19:38:15 +00:00
coekjan
4dd7568a97
mark constructor of BinaryHeap as const fn 2023-10-28 21:30:43 +08:00
bors
7314873326 Auto merge of #117038 - saethlin:inline-range-methods, r=workingjubilee
Add #[inline] to some recalcitrant ops::range methods

Fixes https://github.com/rust-lang/rust/issues/116861
2023-10-28 13:21:00 +00:00
bors
3089c315b1 Auto merge of #116609 - eduardosm:bump-stdarch, r=workingjubilee
Bump stdarch submodule and remove special handling for LLVM intrinsics that are no longer needed

Bumps stdarch to pull https://github.com/rust-lang/stdarch/pull/1477, which reimplemented some functions with portable SIMD intrinsics instead of arch specific LLVM intrinsics.

Handling of those LLVM intrinsics is removed from cranelift codegen and miri.

cc `@RalfJung` `@bjorn3`
2023-10-28 11:26:34 +00:00
Ralf Jung
b329c69f6c memcpy assumptions: link to source showing that GCC makes the same assumption 2023-10-28 11:54:04 +02:00
Jubilee
d87b5e4727
Rollup merge of #116816 - ChrisDenton:api.rs, r=workingjubilee
Create `windows/api.rs` for safer FFI

FFI is inherently unsafe. For memory safety we need to assert that some contract is being upheld on both sides of the FFI, though of course we can only ever check our side. In Rust, `unsafe` blocks are used to assert safety and `// SAFETY` comments describing why it is safe. Currently in sys/windows we have a lot of this unsafety spread all over the place, with variations on the same unsafe patterns repeated. And because of the repitition and frequency, we're a bit lax with the safety comments.

This PR aims to fix this and to make FFI safety more auditable by creating an `api` module with the goal of centralising and consolidating this unsafety. It contains thin wrappers around the Windows API that make most functions safe to call or, if that's not possible, then at least safer. Note that its goal is *only* to address safety. It does not stray far from the Windows API and intentionally does not attempt to make higher lever wrappers around, for example, file handles. This is better left to the existing modules. The windows/api.rs file has a top level comment to help future contributors understand the intent of the module and the design decisions made.

I chose two functions as a first tentative step towards the above goal:

- [`GetLastError`](https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror) is trivially safe. There's no reason to wrap it in an `unsafe` block every time. So I simply created a safe `get_last_error` wrapper.
- [`SetFileInformationByHandle`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileinformationbyhandle) is more complex. It essentially takes a generic type but over a C API which necessitates some amount of ceremony. Rather than implementing similar unsafe patterns in multiple places, I provide a safe `set_file_information_by_handle` that takes a Rusty generic type and handles converting that to the form required by the C FFI.

r? libs
2023-10-28 01:07:36 -07:00
Matthias Krüger
f9d62a84f0
Rollup merge of #117281 - RalfJung:thread-safety, r=thomcc
std::thread : add SAFETY comment

I forgot to add this in https://github.com/rust-lang/rust/pull/117266.
2023-10-27 19:46:10 +02:00
Matthias Krüger
60b071fa8a
Rollup merge of #117270 - jhpratt:hide-print-internals, r=ChrisDenton
Hide internal methods from documentation

The two methods here are perma-unstable and only made public for technical reasons. There is no reason to show them in documentation.

`@rustbot` label +A-docs
2023-10-27 19:46:09 +02:00
Ralf Jung
ccb36a688d std:🧵 add SAFETY comment 2023-10-27 15:18:32 +02:00
Georg Semmler
160b1793b2
Allows #[diagnostic::on_unimplemented] attributes to have multiple
notes

This commit extends the `#[diagnostic::on_unimplemented]` (and
`#[rustc_on_unimplemented]`) attributes to allow multiple `note`
options. This enables emitting multiple notes for custom error messages.
For now I've opted to not change any of the existing usages of
`#[rustc_on_unimplemented]` and just updated the relevant compile tests.
2023-10-27 12:42:42 +02:00
bors
95f6a01e8f Auto merge of #117272 - matthiaskrgr:rollup-upg122z, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #114998 (feat(docs): add cargo-pgo to PGO documentation 📝)
 - #116868 (Tweak suggestion span for outer attr and point at item following invalid inner attr)
 - #117240 (Fix documentation typo in std::iter::Iterator::collect_into)
 - #117241 (Stash and cancel cycle errors for auto trait leakage in opaques)
 - #117262 (Create a new ConstantKind variant (ZeroSized) for StableMIR)
 - #117266 (replace transmute by raw pointer cast)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-27 10:19:35 +00:00
Matthias Krüger
2fdac630b4
Rollup merge of #117266 - RalfJung:cast-not-transmute, r=thomcc
replace transmute by raw pointer cast

Now that https://github.com/rust-lang/rust/issues/113257 is fixed we can finally do this. :)
2023-10-27 11:48:07 +02:00
Matthias Krüger
203292e489
Rollup merge of #117240 - trueNAHO:docs-std-iter-Iterator-collect-into-fix-typo, r=the8472
Fix documentation typo in std::iter::Iterator::collect_into
2023-10-27 11:48:06 +02:00
Jacob Pratt
72d5f4b1dc
Hide internal methods from documentation 2023-10-27 04:30:49 -04:00
bors
54e57e66ff Auto merge of #116205 - WaffleLapkin:stabilize_pointer_byte_offsets, r=dtolnay
Stabilize `[const_]pointer_byte_offsets`

Closes #96283
Awaiting FCP completion: https://github.com/rust-lang/rust/issues/96283#issuecomment-1735835331

r? libs-api
2023-10-27 08:24:54 +00:00
Ralf Jung
b3f7f4dff7 replace transmute by raw pointer cast 2023-10-27 08:02:16 +02:00
bors
707d8c3f1b Auto merge of #117260 - okaneco:ascii_branchless, r=thomcc
Refactor some `char`, `u8` ASCII functions to be branchless

Extract conditions in singular `matches!` with or-patterns to individual `matches!` statements which enables branchless code output. The following functions were changed:
- `is_ascii_alphanumeric`
- `is_ascii_hexdigit`
- `is_ascii_punctuation`

Added codegen tests

---

Continued from https://github.com/rust-lang/rust/pull/103024.
Based on the comment from `@scottmcm` https://github.com/rust-lang/rust/pull/103024#pullrequestreview-1248697206.

The unmodified `is_ascii_*` functions didn't seem to benefit from extracting the conditions.

I've never written a codegen test before, but I tried to check that no branches were emitted.
2023-10-27 04:06:40 +00:00
okaneco
465ffc9ca7 Refactor some char, u8 ascii functions to be branchless
Decompose singular `matches!` with or-patterns to individual `matches!`
statements to enable branchless code output. The following functions
were changed:
- `is_ascii_alphanumeric`
- `is_ascii_hexdigit`
- `is_ascii_punctuation`

Add codegen tests

Co-authored-by: George Bateman <george.bateman16@gmail.com>
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
2023-10-26 21:48:36 -04:00
Matthias Krüger
c0b1c1aedf
Rollup merge of #117243 - chfogelman:replace-not-swap-comment, r=thomcc
Explain implementation of mem::replace

This adds a comment to explain why `mem::replace` is not implemented in terms of `mem::swap` to prevent [naïfs like me](https://github.com/rust-lang/rust/pull/117189) from trying to "fix" it.
2023-10-26 22:26:12 +02:00
Carter Hunt Fogelman
94ecabfc4e Add comment to mem::replace to explain why it's not implemented via mem::swap 2023-10-26 11:10:04 -07:00
NAHO
4392230c08
Fix documentation typo in std::iter::Iterator::collect_into 2023-10-26 19:28:48 +02:00
bors
9ab0749ce3 Auto merge of #112875 - compiler-errors:negative-coherence-rework, r=lcnr
Rework negative coherence to properly consider impls that only partly overlap

This PR implements a modified negative coherence that handles impls that only have partial overlap.

It does this by:
1. taking both impl trait refs, instantiating them with infer vars
2. equating both trait refs
3. taking the equated trait ref (which represents the two impls' intersection), and resolving any vars
4. plugging all remaining infer vars with placeholder types

these placeholder-plugged trait refs can then be used normally with the new trait solver, since we no longer have to worry about the issue with infer vars in param-envs.

We use the **new trait solver** to reason correctly about unnormalized trait refs (due to deferred projection equality), since this avoid having to normalize anything under param-envs with infer vars in them.

This PR then additionally:
* removes the `FnPtr` knowable hack by implementing proper negative `FnPtr` trait bounds for rigid types.

---

An example:

Consider these two partially overlapping impls:

```
impl<T, U> PartialEq<&U> for &T where T: PartialEq<U> {}
impl<F> PartialEq<F> for F where F: FnPtr {}
```

Under the old algorithm, we would take one of these impls and replace it with infer vars, then try unifying it with the other impl under identity substitutions. This is not possible in either direction, since it either sets `T = U`, or tries to equate `F = &?0`.

Under the new algorithm, we try to unify `?0: PartialEq<?0>` with `&?1: PartialEq<&?2>`. This gives us `?0 = &?1 = &?2` and thus `?1 = ?2`. The intersection of these two trait refs therefore looks like: `&?1: PartialEq<&?1>`. After plugging this with placeholders, we get a trait ref that looks like `&!0: PartialEq<&!0>`, with the first impl having substs `?T = ?U = !0` and the second having substs `?F = &!0`[^1].

Then we can take the param-env from the first impl, and try to prove the negated where clause of the second.

We know that `&!0: !FnPtr` never holds, since it's a rigid type that is also not a fn ptr, we successfully detect that these impls may never overlap.

[^1]: For the purposes of this example, I just ignored lifetimes, since it doesn't really matter.
2023-10-26 10:57:21 +00:00
Maybe Waffle
e36224118f Stabilize [const_]pointer_byte_offsets 2023-10-25 22:35:12 +00:00
bors
ab5c841a1f Auto merge of #117180 - matthiaskrgr:rollup-rxhl6ep, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #117111 (Remove support for alias `-Z instrument-coverage`)
 - #117141 (Require target features to match exactly during inlining)
 - #117152 (Fix unwrap suggestion for async fn)
 - #117154 (implement C ABI lowering for CSKY)
 - #117159 (Work around the fact that `check_mod_type_wf` may spuriously return `ErrorGuaranteed`)
 - #117163 (compiletest: Display compilation errors in mir-opt tests)
 - #117173 (Make `Iterator` a lang item)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-25 19:29:58 +00:00
Lukas Bergdoll
e501add1f9 Avoid unnecessary comparison in partition_equal
The branchy Hoare partition `partition_equal` as part of `slice::sort_unstable`
has a bug that makes it perform a comparison of the last element twice.

Measuring inputs with a Zipfian distribution with characterizing exponent s ==
1.0, yields a ~0.05% reduction in the total number of comparisons performed.
2023-10-25 19:37:14 +02:00
Oli Scherer
268ec72839 Make Iterator a lang item 2023-10-25 16:18:57 +00:00
Joshua Liebow-Feeser
c278bc1f81
Update library/core/src/primitive_docs.rs
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
2023-10-25 08:26:07 -07:00
Oli Scherer
1be0033457 Fix some coroutine sentences that don't make sense anymore.
These happened during the `generator` -> `coroutine` rename.
2023-10-25 14:27:00 +00:00
Caio
0b96e479ca Remove cfg_match from the prelude 2023-10-25 09:42:56 -03:00
bors
eb03d40a9c Auto merge of #117102 - devnexen:dfbsd_stack_overflow_upd, r=thomcc
stack_overflow: get_stackp using MAP_STACK flag on dragonflybsd too.
2023-10-25 11:01:24 +00:00
bors
151256bd4b Auto merge of #117135 - matthiaskrgr:rollup-zdh18i6, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #116094 (Introduce `-C instrument-coverage=branch` to gate branch coverage)
 - #116396 (Migrate diagnostics in `rustc_hir_analysis/src/coherence/orphan.rs`)
 - #116714 (Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*`)
 - #116792 (Avoid unnecessary renumbering during borrowck)
 - #116841 (Suggest unwrap/expect for let binding type mismatch)
 - #116943 (Add target features for LoongArch)
 - #117010 (Add method to convert internal to stable constructs)
 - #117127 (Remove `#[allow(incomplete_features)]` from RPITIT/AFIT tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-24 19:32:19 +00:00
Matthias Krüger
845c414fae
Rollup merge of #116714 - WaffleLapkin:order-the-order, r=joshtriplett
Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*`

Fixes #116711

The main pain of this PR is to fix the buggy impl of `Ord` for `SocketAddrV6`, which ignored half of the fields (while `PartialEq` is derived):
4603f0b8af/library/core/src/net/socket_addr.rs (L99-L106)

4603f0b8af/library/core/src/net/socket_addr.rs (L676)

For me it looks like a simple copy-paste error made in https://github.com/rust-lang/rust/pull/72239 (copy from v4 impl) (cc `@hch12907),` as I don't see this behavior being mentioned anywhere on the PR and it also does not respect `cmp` trait "rules". I also do not see any reasons for those impls to _not_ be derived.

It's a shame we did not notice this for 28 versions/3 years. I guess this is a bug fix, but I'm not sure what the process here should be.

r? libs
2023-10-24 19:29:54 +02:00
bors
98b4a64a16 Auto merge of #117126 - matthiaskrgr:rollup-8huie8f, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #117081 (fix typos in comments)
 - #117091 (`OptWithInfcx` naming nits, trait bound simplifications)
 - #117092 (Add regression test for #117058)
 - #117093 (Update books)
 - #117105 (remove change-id assertion in bootstrap test)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-24 17:28:45 +00:00
Matthias Krüger
0aade2f0de
Rollup merge of #117081 - GoodDaisy:master, r=wesleywiser
fix typos in comments
2023-10-24 17:08:59 +02:00
bors
07a4b7e2a9 Auto merge of #116773 - dtolnay:validatestable, r=compiler-errors
Validate `feature` and `since` values inside `#[stable(…)]`

Previously the string passed to `#[unstable(feature = "...")]` would be validated as an identifier, but not `#[stable(feature = "...")]`. In the standard library there were `stable` attributes containing the empty string, and kebab-case string, neither of which should be allowed.

Pre-existing validation of `unstable`:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![unstable(feature = "kebab-case", issue = "none")]

#[unstable(feature = "kebab-case", issue = "none")]
pub struct Struct;
```

```console
error[E0546]: 'feature' is not an identifier
 --> src/lib.rs:5:1
  |
5 | #![unstable(feature = "kebab-case", issue = "none")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

For an `unstable` attribute, the need for an identifier is obvious because the downstream code needs to write a `#![feature(...)]` attribute containing that identifier. `#![feature(kebab-case)]` is not valid syntax and `#![feature(kebab_case)]` would not work if that is not the name of the feature.

Having a valid identifier even in `stable` is less essential but still useful because it allows for informative diagnostic about the stabilization of a feature. Compare:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![stable(feature = "kebab-case", since = "1.0.0")]

#[stable(feature = "kebab-case", since = "1.0.0")]
pub struct Struct;
```

```rust
// src/main.rs

#![feature(kebab_case)]

use repro::Struct;

fn main() {}
```

```console
error[E0635]: unknown feature `kebab_case`
 --> src/main.rs:3:12
  |
3 | #![feature(kebab_case)]
  |            ^^^^^^^^^^
```

vs the situation if we correctly use `feature = "snake_case"` and `#![feature(snake_case)]`, as enforced by this PR:

```console
warning: the feature `snake_case` has been stable since 1.0.0 and no longer requires an attribute to enable
 --> src/main.rs:3:12
  |
3 | #![feature(snake_case)]
  |            ^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default
```
2023-10-24 15:06:20 +00:00
bors
cee6db171d Auto merge of #116461 - ChrisDenton:sleep, r=thomcc
Windows: Support sub-millisecond sleep

Use `CreateWaitableTimerExW` with `CREATE_WAITABLE_TIMER_HIGH_RESOLUTION`. Does not work before Windows 10, version 1803 so in that case we fallback to using `Sleep`.

I've created a `WaitableTimer` type so it can one day be adapted to also support waiting to an absolute time (which has been talked about). Note though that it currently returns `Err(())` because we can't do anything with the errors other than fallback to the old `Sleep`. Feel free to tell me to do errors properly. It just didn't seem worth constructing an `io::Error` if we're never going to surface it to the user. And it *should* all be infallible anyway unless the OS is too old to support it.

Closes #43376
2023-10-24 11:14:15 +00:00
bors
6eb3e97d55 Auto merge of #116319 - BlackHoleFox:apple-rand-take-2, r=thomcc
Remove Apple RNG fallbacks and simplify implementation

Now that we have [higher Apple platform requirements](https://github.com/rust-lang/rust/pull/104385), the RNG code can be simplified a lot. Since `getentropy` still doesn't look to be usable outside macOS this implementation:
- Removes any macOS fallback paths and unconditionally links to `getentropy`
- Minimizes the implementation for everything else (iOS, watchOS, etc).

`CCRandomGenerateBytes` was added in iOS 8 which means that we can use it now. It and `SecRandomCopyBytes` have the exact same functionality, but the former has a simpler API and no longer requires libstd to link to `Security.framework` for one function. Its also available in all the other target's SDKs.

Why care about `getentropy` then though on macOS? Well, its still much more performant. Benchmarking shows it runs at ~2x the speed of `CCRandomGenerateBytes`, which makes sense since it directly pulls from the kernel vs going through its own generator etc.

Semi-related to a previous, but reverted, attempt at improving this logic in https://github.com/rust-lang/rust/pull/101011
2023-10-24 06:11:51 +00:00
bors
e918db897d Auto merge of #116238 - tamird:gettimeofday, r=thomcc
time: use clock_gettime on macos

Replace `gettimeofday` with `clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`gettimeofday` was first used in
cc367edd95
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca958d.

Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
cc367edd95
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca958d.

Note that this change was made for aarch64 in
5008a317ce which predated 10.12 becoming
the minimum supported version. The discussion took place in
https://github.com/rust-lang/rust/issues/91417 and in particular
https://github.com/rust-lang/rust/issues/91417#issuecomment-992151582
and
https://github.com/rust-lang/rust/issues/91417#issuecomment-1033048064
are relevant.
2023-10-24 04:15:39 +00:00
BlackHoleFox
090e9de570 Remove Apple RNG fallbacks and simplify implementation 2023-10-23 20:35:45 -05:00
Michael Goulet
66d7cfd3b5 Remove FnPtr hack from trait_ref_is_knowable 2023-10-23 23:35:27 +00:00
bors
f654229c27 Auto merge of #117103 - matthiaskrgr:rollup-96zuuom, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #107159 (rand use getrandom for freebsd (available since 12.x))
 - #116859 (Make `ty::print::Printer` take `&mut self` instead of `self`)
 - #117046 (return unfixed len if pat has reported error)
 - #117070 (rustdoc: wrap Type with Box instead of Generics)
 - #117074 (Remove smir from triage and add me to stablemir)
 - #117086 (Update .mailmap to promote my livename)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-23 22:18:45 +00:00
David Carlier
1d3d5aaa88 stack_overflow: get_stackp using MAP_STACK flag on dragonflybsd too. 2023-10-23 22:51:16 +01:00
Matthias Krüger
d287861309
Rollup merge of #107159 - devnexen:random_fbsd_update, r=workingjubilee
rand use getrandom for freebsd (available since 12.x)
2023-10-23 22:26:29 +02:00
bors
41aa06ecf9 Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkov
report `unused_import` for empty reexports even it is pub

Fixes #116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing #115993.)
2023-10-23 20:24:09 +00:00
David Tolnay
67ea7986c7
Fix invalid stability attribute features in standard library 2023-10-23 13:03:10 -07:00
Wesley Wiser
04fdcd3228 Update backtrace submodule 2023-10-23 15:11:37 -04:00
GoodDaisy
0d780b108b fix typos in comments 2023-10-23 20:52:14 +08:00
bors
aec4741d42 Auto merge of #116606 - ChrisDenton:empty, r=dtolnay
On Windows make `read_dir` error on the empty path

This makes Windows consistent with other platforms. Note that this should not be taken to imply any decision on #114149 has been taken. However it was felt that while there is a lack of libs-api consensus, we should be consistent across platforms in the meantime.

This is a change in behaviour for Windows so will also need an fcp before merging.

r? libs-api
2023-10-23 05:38:33 +00:00
bohan
482275b194 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Matthias Krüger
4d80740c1d
Rollup merge of #116989 - ChrisDenton:skip-unsupported, r=Mark-Simulacrum
Skip test if Unix sockets are unsupported

Fixes https://github.com/rust-lang/rust/pull/116683#issuecomment-1772314187

The test will be skipped if `AF_UNIX` is not supported. In that case [`WSASocketW` returns `WSAEAFNOSUPPORT`](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw#return-value).

It will never skip the test when run in CI but maybe this is me being too defensive since the error code is narrowly scoped to just the af family parameter being unsupported?

Also fixed a minor typo.

r? `@Mark-Simulacrum`
2023-10-22 09:15:42 +02:00
Ben Kimock
2820568c2d Add #[inline] to some recalcitrant ops::range methods 2023-10-22 00:29:45 -04:00
Gimbles
695beca219
Update boxed.rs 2023-10-21 23:41:32 +05:30
Matthias Krüger
90671a0d70
Rollup merge of #114521 - devnexen:std_fbsd_13_upd, r=cuviper
std: freebsd build update.

since freebsd 11 had been removed, minimum is now 12.
2023-10-21 10:08:15 +02:00
David Carlier
f4791420ab changes from feedback 2023-10-20 23:55:14 +01:00
Oli Scherer
3beadb5ebd Fix stage0 core tests 2023-10-20 21:14:02 +00:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Chris Denton
46f68ccb8b
Skip test if Unix sockets are unsupported 2023-10-20 18:10:34 +01:00
bors
7db4a89d49 Auto merge of #116966 - clarfonthey:atomic-docs-typo, r=workingjubilee
Fix typo in atomic docs

Maybe rustdoc or tidy should lint hanging backticks like this.
2023-10-20 14:56:08 +00:00
David CARLIER
9a963e8026 std: freebsd build update.
since freebsd 11 had been removed, minimum is now 12.
2023-10-20 14:59:13 +01:00
ltdk
b9c2d0e4ab Fix typo in atomic docs 2023-10-20 00:57:29 -04:00
bors
029d00c4a3 Auto merge of #116785 - nnethercote:spec-Bytes-read, r=the8472
Specialize `Bytes<R>::next` when `R` is a `BufReader`.

This reduces the runtime for a simple program using `Bytes::next` to iterate through a file from 220ms to 70ms on my Linux box.

r? `@the8472`
2023-10-20 04:01:07 +00:00
Nicholas Nethercote
181ce63183 Specialize Bytes<R>::next when R is a BufReader.
This reduces the runtime for a simple program using `Bytes::next` to
iterate through a file from 220ms to 70ms on my Linux box.
2023-10-20 08:52:56 +11:00
bors
3fbcfd2b6f Auto merge of #116132 - darthunix:connect_poll, r=cuviper
Make TCP connect handle EINTR correctly

According to the [POSIX](https://pubs.opengroup.org/onlinepubs/009695399/functions/connect.html) standard, if connect() is interrupted by a signal that is caught while blocked waiting to establish a connection, connect() shall fail and set errno to EINTR, but the connection request shall not be aborted, and the connection shall be established asynchronously. When the connection has been established asynchronously, select() and poll() shall indicate that the file descriptor for the socket is ready for writing.

The previous implementation differs from the recomendation: in a case of the EINTR we tried to reconnect in a loop and sometimes get EISCONN error (this problem was originally detected on MacOS).

1. More details about the problem in an [article](http://www.madore.org/~david/computers/connect-intr.html).
2. The original [issue](https://git.picodata.io/picodata/picodata/tarantool-module/-/issues/157).
2023-10-19 11:22:28 +00:00
bors
36b61e5aa5 Auto merge of #116923 - fmease:rollup-ev7q387, r=fmease
Rollup of 7 pull requests

Successful merges:

 - #116663 (Don't ICE when encountering unresolved regions in `fully_resolve`)
 - #116761 (Fix podman detection in CI scripts)
 - #116795 (Add `#[track_caller]` to `Option::unwrap_or_else`)
 - #116829 (Make `#[repr(Rust)]` incompatible with other (non-modifier) representation hints like `C` and `simd`)
 - #116883 (Change my name in mailmap)
 - #116908 (Tweak wording of type errors involving type params)
 - #116912 (Some renaming nits for `rustc_type_ir`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-19 03:52:32 +00:00
León Orell Valerian Liehr
80c9588549
Rollup merge of #116795 - DaniPopes:track-caller-option, r=cuviper
Add `#[track_caller]` to `Option::unwrap_or_else`

Same as #116317 but for `Option`.

Closes #115302
2023-10-19 04:34:46 +02:00
bors
020d00867a Auto merge of #114534 - niluxv:strict_prov_unwind, r=cuviper,workingjubilee
Strict provenance unwind

1. Turned many `usize`s in the personality/unwind code that are actually pointers into `*const u8`.
2. Rewrote `read_encoded_pointer` to conform to strict-provenance, along the lines as described by `@eddyb` [in zulip some time ago](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/strict.20provenance.20in.20dwarf.3A.3Aeh/near/276197290).

This should make supporting CHERI in the future easier (but they use a [slightly modified format in the callsite table](https://cheri-compiler-explorer.cl.cam.ac.uk/z/n6GhhW), which requires a CHERI specific modification to `find_eh_action`).
2023-10-19 01:56:45 +00:00
bors
89432aadcb Auto merge of #116402 - joboet:global_alloc_tls_unsoundness, r=thomcc,workingjubilee
Panic when the global allocator tries to register a TLS destructor

Using a `RefCell` avoids the undefined behaviour encountered in #116390 and reduces the amount of `unsafe` code in the codebase.
2023-10-19 00:03:42 +00:00
Joshua Liebow-Feeser
3fea7cc7da
Guarantee that char has the same size and alignment as u32 2023-10-18 09:14:31 -07:00
Ali MJ Al-Nasrawy
a536d58607
Rollup merge of #116856 - oli-obk:no_effects, r=compiler-errors
Disable effects in libcore again

r? `@fee1-dead`

This was accidentally allowed by https://github.com/rust-lang/rust/pull/114776 without feature gates
2023-10-18 14:24:51 +03:00
Ben Kimock
33b0e4be06 Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
Oli Scherer
bcdd3d7739 Disable effects in libcore again 2023-10-17 17:55:49 +00:00
bors
93e62a260f Auto merge of #115577 - RalfJung:atomic-load, r=Amanieu
document when atomic loads are guaranteed read-only

Based on this [discussion in Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Can.20.60Atomic*.3A.3Aload.60.20perform.20a.20write).

The values for x86 and x86_64 are complete guesswork on my side, and I have no clue what the values might be for other architectures. I hope we can get the right people to chime in to gather the required information. :)

I'll update Miri to respect these rules once we have more data.
2023-10-17 14:11:31 +00:00
bors
2e57d647b0 Auto merge of #116518 - vita-rust:vita, r=workingjubilee
Updated libc and doc for Vita target

Doc changes:

- Updated Vita target readme. The recommended approach to build artifacts for the platform now is [cargo-vita](https://crates.io/crates/cargo-vita) which wraps all the convoluted steps previously described in a yaml for `cargo-make`
- Updated maintainer list for Vita target. (`@ZetaNumbers` `@pheki` please agree to be added to the list, `@amg98` please let us know if you're still planning on actively maintaining target support)

Code changes:
- ~Updated libc for rust-lang/libc#3284 and rust-lang/libc#3366~ (Already merged in #116527)
- In dupfd changed the flag same as for esp target, there is no CLOEXEC on Vita
- Enabled `new_pair` since we've implemented `socketpair` in Vita newlib
2023-10-17 10:22:14 +00:00
Nikolay Arhipov
ba13e37e30 Updated libc and doc for Vita target 2023-10-17 10:44:39 +03:00
Ralf Jung
e494df436d remove 128bit atomics, they are anyway not exposed on those targets 2023-10-17 07:56:49 +02:00
bors
64338796ab Auto merge of #116820 - GuillaumeGomez:rollup-l54ri5q, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #116754 (coverage: Several small cleanups in `spans`)
 - #116798 (Improve display of parallel jobs in rustdoc-gui tester script)
 - #116800 (Fix implied outlives check for GAT in RPITIT)
 - #116805 (Make `rustc_onunimplemented` export path agnostic)
 - #116808 (Add myself to smir triage)
 - #116811 (Preserve unicode escapes in format string literals when pretty-printing AST)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-16 23:01:20 +00:00
Chris Denton
3733316c6b
Create windows/api.rs for safer FFI 2023-10-16 20:04:54 +01:00
Nilstrieb
414135d522 Make rustc_onunimplemented export path agnostic
This makes it so that all the matchers that match against paths use the
definition path instead of the export path. This removes all duplication
around `std`/`alloc`/`core`.

This is not necessarily optimal because we now depend on internal
implementation details like `core::ops::control_flow::ControlFlow`,
which is not very nice and probably not acceptable for a stable
`on_unimplemented`.

An alternative would be to just string-replace normalize away
`alloc`/`core` to `std` as a special case, keeping the export paths but
making it so that we're still fully standard library flavor agnostic.
2023-10-16 19:37:12 +02:00
Ralf Jung
6605116463 use target-arch based table 2023-10-16 19:29:16 +02:00
Arthur Carcano
0bcac8a7f2 Add invariant to Vec::pop that len < cap if pop successful
Fixes: https://github.com/rust-lang/rust/issues/114334
2023-10-16 18:49:25 +02:00
DaniPopes
0df670fb67
Add #[track_caller] to Option::unwrap_or_else 2023-10-16 15:17:15 +02:00