Commit Graph

17181 Commits

Author SHA1 Message Date
bors
f005c7437d Auto merge of #133561 - GuillaumeGomez:rollup-g4upmv4, r=GuillaumeGomez
Rollup of 12 pull requests

Successful merges:

 - #129409 (Expand std::os::unix::fs::chown() doc with a warning)
 - #133320 (Add release notes for Rust 1.83.0)
 - #133368 (Delay a bug when encountering an impl with unconstrained generics in `codegen_select`)
 - #133428 (Actually use placeholder regions for trait method late bound regions in `collect_return_position_impl_trait_in_trait_tys`)
 - #133512 (Add `as_array` and `as_mut_array` conversion methods to slices.)
 - #133519 (Check `xform_ret_ty` for WF in the new solver to improve method winnowing)
 - #133520 (Structurally resolve before applying projection in borrowck)
 - #133534 (extend group-forbid-always-trumps-cli test)
 - #133537 ([rustdoc] Fix new clippy lints)
 - #133543 ([AIX] create shim for lgammaf_r)
 - #133547 (rustc_span: Replace a `HashMap<_, ()>` with `HashSet`)
 - #133550 (print generated doc paths)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-28 03:36:03 +00:00
Guillaume Gomez
82d4eaeaff
Rollup merge of #133543 - mustartt:aix-lgammaf_r-shim, r=cuviper
[AIX] create shim for lgammaf_r

On AIX, we don't have 32bit floating point for re-entrant `lgammaf_r` but we do have the 64bit floating point re-entrant `lgamma_r` so we can use the 64bit version instead and truncate back to a 32bit float.

This solves the linker missing symbol for `.lgammaf_r` when testing and using these parts of the `std`.
2024-11-28 03:14:51 +01:00
Guillaume Gomez
b1c33f4f09
Rollup merge of #133512 - bjoernager:slice-as-array, r=Amanieu
Add `as_array` and `as_mut_array` conversion methods to slices.

Tracking issue: #133508

This PR unstably implements the `as_array` and `as_mut_array` converters to `[T]`, `*const [T]`, and `*mut [T]`.
2024-11-28 03:14:48 +01:00
Guillaume Gomez
10193a347a
Rollup merge of #129409 - grinapo:patch-1, r=Amanieu
Expand std::os::unix::fs::chown() doc with a warning

Include warning about losing setuid/gid when chowning, per POSIX.

It is about the underlying system call but it is rather useful to mention it in the help in case someone accidentally forgets (don't look at me :)).
2024-11-28 03:14:45 +01:00
Matthias Krüger
a8b690fada
Rollup merge of #133498 - GuillaumeGomez:missing-examples, r=joboet
Add missing code examples on `LocalKey`

r? ``@Amanieu``
2024-11-27 22:23:25 +01:00
Henry Jiang
527b6065ba
fmt 2024-11-27 12:02:02 -05:00
bors
39cb3386dd Auto merge of #133369 - Zalathar:profiler-builtins-no-core, r=jieyouxu
Allow injecting a profiler runtime into `#![no_core]` crates

An alternative to #133300, allowing `-Cinstrument-coverage` to be used with `-Zbuild-std`.

The incompatibility between `profiler_builtins` and `#![no_core]` crates appears to have been caused by profiler_builtins depending on core, and therefore conflicting with core (or minicore).

But that's a false dependency, because the profiler doesn't contain any actual Rust code. So we can just mark the profiler itself as `#![no_core]`, and remove the incompatibility error.

---

For context, the error was originally added by #79958.
2024-11-27 10:19:38 +00:00
Matthias Krüger
dcebc5eddd
Rollup merge of #133449 - joboet:io_const_error, r=tgross35
std: expose `const_io_error!` as `const_error!`

ACP: https://github.com/rust-lang/libs-team/issues/205
Tracking issue: https://github.com/rust-lang/rust/issues/133448

Probably best reviewed commit-by-commit, the first one does the API change, the second does the mass-rename.
2024-11-27 08:13:47 +01:00
Michael Goulet
8a2f57f0c4
Rollup merge of #133402 - compiler-errors:drop-and-destruct, r=lcnr
Constify `Drop` and `Destruct`

r? `@lcnr` or `@fee1-dead`
2024-11-26 20:35:38 -05:00
bors
dd2837ec5d Auto merge of #133505 - compiler-errors:rollup-xjp8hdi, r=compiler-errors
Rollup of 12 pull requests

Successful merges:

 - #133042 (btree: add `{Entry,VacantEntry}::insert_entry`)
 - #133070 (Lexer tweaks)
 - #133136 (Support ranges in `<[T]>::get_many_mut()`)
 - #133140 (Inline ExprPrecedence::order into Expr::precedence)
 - #133155 (Yet more `rustc_mir_dataflow` cleanups)
 - #133282 (Shorten the `MaybeUninit` `Debug` implementation)
 - #133326 (Remove the `DefinitelyInitializedPlaces` analysis.)
 - #133362 (No need to re-sort existential preds in relate impl)
 - #133367 (Simplify array length mismatch error reporting (to not try to turn consts into target usizes))
 - #133394 (Bail on more errors in dyn ty lowering)
 - #133410 (target check_consistency: ensure target feature string makes some basic sense)
 - #133435 (miri: disable test_downgrade_observe test on macOS)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-26 21:57:32 +00:00
Gabriel Bjørnager Jensen
4b8ca28a1e Add '<[T]>::as_array', '<[T]>::as_mut_array', '<*const [T]>::as_array', and '<*mut [T]>::as_mut_array' conversion methods; 2024-11-26 21:49:28 +01:00
joboet
c14d137bfc
std: update internal uses of io::const_error! 2024-11-26 18:38:24 +01:00
Michael Goulet
c4e2b0c605
Rollup merge of #133435 - RalfJung:test_downgrade_observe, r=tgross35
miri: disable test_downgrade_observe test on macOS

Due to https://github.com/rust-lang/rust/issues/121950, this test can fail on Miri. The test is also quite slow on Miri (taking more than 30s) due to the high iteration count (a total of 2000), so let's reduce that a little.

Fixes https://github.com/rust-lang/rust/issues/133421
2024-11-26 12:03:45 -05:00
Michael Goulet
3013cd83cc
Rollup merge of #133282 - tgross35:maybe-uninit-debug, r=Amanieu
Shorten the `MaybeUninit` `Debug` implementation

Currently the `Debug` implementation for `MaybeUninit` winds up being pretty verbose. This struct:

```rust
#[derive(Debug)]
pub struct Foo {
    pub a: u32,
    pub b: &'static str,
    pub c: MaybeUninit<u32>,
    pub d: MaybeUninit<String>,
}
```

Prints as:

    Foo {
        a: 0,
        b: "hello",
        c: core::mem::maybe_uninit::MaybeUninit<u32>,
        d: core::mem::maybe_uninit::MaybeUninit<alloc::string::String>,
    }

The goal is just to be a standin for content so the path prefix doesn't add any useful information. Change the implementation to trim `MaybeUninit`'s leading path, meaning the new result is now:

    Foo {
        a: 0,
        b: "hello",
        c: MaybeUninit<u32>,
        d: MaybeUninit<alloc::string::String>,
    }
2024-11-26 12:03:42 -05:00
Michael Goulet
42459a7971
Rollup merge of #133136 - ChayimFriedman2:get-many-mut, r=Amanieu
Support ranges in `<[T]>::get_many_mut()`

As per T-libs-api decision in #104642.

I implemented that with a separate trait and not within `SliceIndex`, because doing that via `SliceIndex` requires adding support for range types that are (almost) always overlapping e.g. `RangeFrom`, and also adding fake support code for `impl SliceIndex<str>`.

An inconvenience that I ran into was that slice indexing takes the index by value, but I only have it by reference. I could change slice indexing to take by ref, but this is pretty much the hottest code ever so I'm afraid to touch it. Instead I added a requirement for `Clone` (which all index types implement anyway) and cloned. This is an internal requirement the user won't see and the clone should always be optimized away.

I also implemented `Clone`, `PartialEq` and `Eq` for the error type, since I noticed it does not do that when writing the tests and other errors in std seem to implement them. I didn't implement `Copy` because maybe we will want to put something non-`Copy` there.
2024-11-26 12:03:40 -05:00
Michael Goulet
5915190fed
Rollup merge of #133042 - cuviper:btreemap-insert_entry, r=Amanieu
btree: add `{Entry,VacantEntry}::insert_entry`

This matches the recently-stabilized methods on `HashMap` entries. I've
reused tracking issue #65225 for now, but we may want to split it.
2024-11-26 12:03:39 -05:00
Guillaume Gomez
a06532e639
Rollup merge of #133464 - RalfJung:whitespace-panic, r=joboet
std:🧵 avoid leading whitespace in some panic messages

This:
```
        panic!(
            "use of std:🧵:current() is not possible after the thread's
         local data has been destroyed"
        )
```
will print a newline followed by a bunch of spaces, since the entire string literal is interpreted literally.

I think the intention was to print the message without the newline and the spaces, so let's add some `\` to make that happen.

r? ``@joboet``
2024-11-26 15:32:17 +01:00
Guillaume Gomez
ddb6904ee4
Rollup merge of #133419 - CromFr:add-path-strip_prefix-test-example, r=Amanieu
Added a doc test for std::path::strip_prefix

I was about 90% sure `Path::new("/test/haha/foo.txt").strip_prefix("/te")` would return an Err, but I couldn't find an example to confirm this behaviour.

This should be an easy merge :)
2024-11-26 15:32:13 +01:00
Guillaume Gomez
02c3e6d087 Add missing code examples on LocalKey 2024-11-26 15:29:47 +01:00
Ralf Jung
8bc8adb8dc std:🧵 avoid leading whitespace in some panic messages 2024-11-25 18:31:49 +01:00
Michael Goulet
bd44b632a8 Constify Drop and Destruct 2024-11-25 17:27:41 +00:00
joboet
d39afacbdf
std: expose const_io_error! as const_error!
ACP: rust-lang/libs-team#205
Tracking issue: #133448
2024-11-25 15:23:31 +01:00
bors
7db7489f9b Auto merge of #133247 - GuillaumeGomez:reduce-integer-display-impl, r=workingjubilee
Reduce integer `Display` implementation size

I was thinking about #128204 and how we could reduce the size of the code and just realized that we didn't need the `_fmt` method to be implemented on signed integers, which in turns allow to simplify greatly the macro call.

r? `@workingjubilee`
2024-11-25 11:03:41 +00:00
Chayim Refael Friedman
4a230bba74 Support ranges in <[T]>::get_many_mut()
I implemented that with a separate trait and not within `SliceIndex`, because doing that via `SliceIndex` requires adding support for range types that are (almost) always overlapping e.g. `RangeFrom`, and also adding fake support code for `impl SliceIndex<str>`.

An inconvenience that I ran into was that slice indexing takes the index by value, but I only have it by reference. I could change slice indexing to take by ref, but this is pretty much the hottest code ever so I'm afraid to touch it. Instead I added a requirement for `Clone` (which all index types implement anyway) and cloned. This is an internal requirement the user won't see and the clone should always be optimized away.

I also implemented `Clone`, `PartialEq` and `Eq` for the error type, since I noticed it does not do that when writing the tests and other errors in std seem to implement them. I didn't implement `Copy` because maybe we will want to put something non-`Copy` there.
2024-11-25 10:04:06 +02:00
Ralf Jung
c9b56b9694 miri: disable test_downgrade_observe test on macOS 2024-11-25 08:00:22 +01:00
Matthias Krüger
d2590e0ca3
Rollup merge of #132982 - suaviloquence:2-doc-changed-alloc-methods, r=Mark-Simulacrum
alloc: fix `Allocator` method names in `alloc` free function docs

It looks like these got renamed in 9274b37d99 but the docs never updated.

I couldn't find any history for `Allocator::realloc`.  The `grow` API is not 1:1 (e.g., it returns a result), so this may not be the correct change - let me know and I can change the method or even remove this entirely.
2024-11-25 07:01:41 +01:00
Matthias Krüger
813d3e7781
Rollup merge of #132533 - SUPERCILEX:patch-4, r=Mark-Simulacrum
Add BorrowedBuf::into_filled{,_mut} methods to allow returning buffer with original lifetime

See https://github.com/rust-lang/libs-team/issues/473 and tracking issue https://github.com/rust-lang/rust/issues/117693.
2024-11-25 07:01:40 +01:00
m
8542175b6f
fix Allocator method names in alloc free function docs 2024-11-24 16:38:29 -08:00
许杰友 Jieyou Xu (Joe)
1741b394da
Rollup merge of #133298 - n0toose:remove-dir-all-but-not-paths, r=Noratrieb
Mention that std::fs::remove_dir_all fails on files

This is explicitly mentioned for std::fs::remove_file.

It is more likely for a slightly lazy programmer to believe that removing a file would work and that they do not have to distinguish between directories (with contents) and files themself, because of the function's recursive nature and how it distinguishes between files and directories when removing them.

Follow-up for #133183.
2024-11-25 00:39:05 +08:00
许杰友 Jieyou Xu (Joe)
6bf9a2363d
Rollup merge of #133260 - compiler-errors:deref, r=fee1-dead
Constify the `Deref`/`DerefMut` traits, too

One more constification. Rebased on that one commit that makes it so we don't need to provide stability on const impls.

r? fee1-dead
2024-11-25 00:39:04 +08:00
许杰友 Jieyou Xu (Joe)
31b4023e24
Rollup merge of #132730 - joboet:after_main_sync, r=Noratrieb
std: allow after-main use of synchronization primitives

By creating an unnamed thread handle when the actual one has already been destroyed, synchronization primitives using thread parking can be used even outside the Rust runtime.

This also fixes an inefficiency in the queue-based `RwLock`: if `thread::current` was not initialized yet, it will create a new handle on every parking attempt without initializing `thread::current`. The private `current_or_unnamed` function introduced here fixes this.
2024-11-25 00:39:03 +08:00
Crom (Thibaut CHARLES)
f3ad32b769
Added a doc test for std::path::strip_prefix 2024-11-24 14:37:40 +01:00
Matthias Krüger
220251e181
Rollup merge of #133389 - eduardosm:stabilize-const_float_methods, r=RalfJung
Stabilize `const_float_methods`

Tracking issue: https://github.com/rust-lang/rust/issues/130843
Relnotes: #133383

Stabilized const API:

```rust
// in `core`
impl f32/f64 {
    pub const fn recip(self) -> Self;
    pub const fn to_degrees(self) -> Self;
    pub const fn to_radians(self) -> Self;
    pub const fn max(self, other: Self) -> Self;
    pub const fn min(self, other: Self) -> Self;
    pub const fn clamp(self, min: Self, max: Self) -> Self;
    pub const fn abs(self) -> Self;
    pub const fn signum(self) -> Self;
    pub const fn copysign(self, sign: Self) -> Self;
}
```

Closes https://github.com/rust-lang/rust/issues/130843

r? libs-api

cc `@RalfJung` -- I think the way const-stability attributes work have change a bit since the last time a wrote a const-stabilization PR, please make sure I got them right.
2024-11-24 11:08:20 +01:00
Matthias Krüger
3c52c9b483
Rollup merge of #133301 - GuillaumeGomez:add-example-wrapping-neg, r=workingjubilee
Add code example for `wrapping_neg` method for signed integers

With this example, we make it obvious that `wrapping_neg` works both ways (neg to pos and pos to neg).

r? `@workingjubilee`
2024-11-24 11:08:19 +01:00
bors
4e4c20d2ab Auto merge of #132611 - compiler-errors:async-prelude, r=ibraheemdev
Add `AsyncFn*` to the prelude in all editions

The general vibe is that we will most likely stabilize the `feature(async_closure)` *without* the `async Fn()` trait bound modifier.

Without `async Fn()` bound syntax, this necessitates users to spell the bound like `AsyncFn()`. Since `core::ops::AsyncFn` is not in the prelude, users will need to import these any time they actually want to use the trait. This seems annoying, so let's add these traits to the prelude unstably.

We're trying to work on the general vision of `async` trait bound modifier in general in: https://github.com/rust-lang/rfcs/pull/3710, however that RFC still needs more time for consensus to converge, and we've decided that the value that users get from calling the bound `async Fn()` is *not really* worth blocking landing async closures in general.
2024-11-24 04:53:16 +00:00
bors
124eb966e3 Auto merge of #132597 - lukas-code:btree-plug-leak, r=jhpratt
btree: don't leak value if destructor of key panics

This PR fixes a regression from https://github.com/rust-lang/rust/pull/84904.

The `BTreeMap` already attempts to handle panicking destructors of the key-value pairs by continuing to execute the remaining destructors after one destructor panicked. However, after #84904 the destructor of a value in a key-value pair gets skipped if the destructor of the key panics, only continuing with the next key-value pair. This PR reverts to the behavior before #84904 to also drop the corresponding value if the destructor of a key panics.

This avoids potential memory leaks and can fix the soundness of programs that rely on the destructors being executed (even though this should not be relied upon, because the std collections currently do not guarantee that the remaining elements are dropped after a panic in a destructor).

cc `@Amanieu` because you had opinions on panicking destructors
2024-11-24 02:08:58 +00:00
Zalathar
bba3567386 Make profiler_builtins #![no_core] instead of just #![no_std]
This crate doesn't contain any actual Rust code; it's just C/C++ code built and
packaged in a Rust-friendly way.
2024-11-24 11:35:32 +11:00
Zalathar
5967cf1a3a Remove unnecessary #![allow(unused_features)] 2024-11-24 11:35:32 +11:00
Zalathar
7d2d11b595 Sort and separate lint/feature attributes in profiler_builtins 2024-11-24 11:35:32 +11:00
Michael Goulet
04d1bdc377 Constify Deref and DerefMut 2024-11-24 00:19:47 +00:00
bors
15b663e684 Auto merge of #133379 - jieyouxu:rollup-00jxo71, r=jieyouxu
Rollup of 4 pull requests

Successful merges:

 - #133217 ([AIX] Add option -X32_64 to the "strip" command)
 - #133237 (Minimally constify `Add`)
 - #133355 (Add language tests for aggregate types)
 - #133374 (show abi_unsupported_vector_types lint in future breakage reports)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-23 20:45:19 +00:00
Eduardo Sánchez Muñoz
6f7dc38031 Stabilize const_float_methods 2024-11-23 18:42:44 +01:00
bors
826b673412 Auto merge of #133377 - jieyouxu:rollup-n536hzq, r=jieyouxu
Rollup of 6 pull requests

Successful merges:

 - #127483 (Allow disabling ASan instrumentation for globals)
 - #131505 (use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on Darwin)
 - #132949 (Add specific diagnostic for using macro_rules macro as attribute/derive)
 - #133286 (Re-delay a resolve `bug` related to `Self`-ctor in patterns)
 - #133332 (Mark `<[T; N]>::as_mut_slice` with the `const` specifier.)
 - #133366 (Remove unnecessary bool from `ExpectedFound::new`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-23 15:19:32 +00:00
Guillaume Gomez
0d4b52f772 Improve code by using unsigned_abs 2024-11-23 14:17:47 +01:00
许杰友 Jieyou Xu (Joe)
75b8f433e3
Rollup merge of #133237 - fee1-dead-contrib:constadd, r=compiler-errors
Minimally constify `Add`

* This PR removes the requirement for `impl const` to have a const stability attribute. cc ``@RalfJung`` I believe you mentioned that it would make much more sense to require `const_trait`s to have const stability instead. I agree with that sentiment but I don't think that is _required_ for a small scale experimentation like this PR. https://github.com/rust-lang/project-const-traits/issues/16 should definitely be prioritized in the future, but removing the impl check should be good for now as all callers need `const_trait_impl` enabled for any const impl to work.
* This PR is intentionally minimal as constifying other traits can become more complicated (`PartialEq`, for example, would run into requiring implementing it for `str` as that is used in matches, which runs into the implementation for slice equality which uses specialization)

Per the reasons above, anyone who is interested in making traits `const` in the standard library are **strongly encouraged** to reach out to us on the [Zulip channel](https://rust-lang.zulipchat.com/#narrow/channel/419616-t-compiler.2Fproject-const-traits) before proceeding with the work.

cc ``@rust-lang/project-const-traits``

I believe there is prior approval from libs that we can experiment, so

r? project-const-traits
2024-11-23 20:50:15 +08:00
许杰友 Jieyou Xu (Joe)
8036ff1302
Rollup merge of #133332 - bjoernager:const-array-as-mut-slice, r=jhpratt
Mark `<[T; N]>::as_mut_slice` with the `const` specifier.

Tracking issue: #133333

`<[T; N]>::as_mut_slice` can have the `const` specifier without any changes to the function body.
2024-11-23 20:19:54 +08:00
许杰友 Jieyou Xu (Joe)
f860f5bf90
Rollup merge of #131505 - madsmtm:darwin_user_temp_dir, r=dtolnay
use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on Darwin

Rebased version of https://github.com/rust-lang/rust/pull/100824, FCP has completed there. Motivation from https://github.com/rust-lang/rust/pull/100824#issuecomment-1262264127:

> This is a behavioral change in an edge case on Darwin platforms (macOS, iOS, ...).
>
> Specifically, this changes it so that iff `TMPDIR` is unset in the environment, then we use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` to query the user temporary directory (previously we just returned `"/tmp"`). If this fails (probably possible in a sandboxed program), only then do we fallback to `"/tmp"` (as before).
>
> The motivations here are two-fold:
>
> 1. This is better for security, and is in line with the [platform security recommendations](https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585-SW10), as it is unavailable to other users (although it is the same value as seen by all other processes run by the same user).
> 2. This is a more consistent fallback for when `getenv("TMPDIR")` is unavailable, as `$TMPDIR` is usually initialized to the `DARWIN_USER_TEMP_DIR`.
>
> It seems quite unlikely that anybody will break because of this, and I think it falls under the carve-out we have for platform specific behavior: https://doc.rust-lang.org/nightly/std/io/index.html#platform-specific-behavior.

Closes https://github.com/rust-lang/rust/issues/99608.
Closes https://github.com/rust-lang/rust/pull/100824.

``@rustbot`` label O-apple T-libs-api

r? Dylan-DPC
2024-11-23 20:19:52 +08:00
bors
ff1737bb00 Auto merge of #132994 - clubby789:cc-bisect, r=Kobzol
Update `cc` + bump bootstrap deps

https://github.com/rust-lang/rust/pull/132556#issuecomment-2471741435

note: The compiler/library/tools cc bumps have been tested with a try job, the bootstrap changes have not
2024-11-23 12:15:39 +00:00
bors
c49a687d63 Auto merge of #133360 - compiler-errors:rollup-a2o38tq, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #132090 (Stop being so bail-y in candidate assembly)
 - #132658 (Detect const in pattern with typo)
 - #132911 (Pretty print async fn sugar in opaques and trait bounds)
 - #133102 (aarch64 softfloat target: always pass floats in int registers)
 - #133159 (Don't allow `-Zunstable-options` to take a value )
 - #133208 (generate-copyright: Now generates a library file too.)
 - #133215 (Fix missing submodule in `./x vendor`)
 - #133264 (implement OsString::truncate)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-23 04:44:26 +00:00
Michael Goulet
7b3e593fb1
Rollup merge of #133264 - lolbinarycat:os-string-truncate, r=joboet
implement OsString::truncate

part of #133262
2024-11-22 21:07:41 -05:00