Commit Graph

17130 Commits

Author SHA1 Message Date
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
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
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
许杰友 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
bors
743003b1a6 Auto merge of #132329 - compiler-errors:fn-and-destruct, r=lcnr
Implement `~const Destruct` effect goal in the new solver

This also fixed a subtle bug/limitation of the `NeedsConstDrop` check. Specifically, the "`Qualif`" API basically treats const drops as totally structural, even though dropping something that has an explicit `Drop` implementation cannot be structurally decomposed. For example:

```rust
#![feature(const_trait_impl)]

#[const_trait] trait Foo {
    fn foo();
}

struct Conditional<T: Foo>(T);

impl Foo for () {
    fn foo() {
        println!("uh oh");
    }
}

impl<T> const Drop for Conditional<T> where T: ~const Foo {
    fn drop(&mut self) {
        T::foo();
    }
}

const FOO: () = {
    let _ = Conditional(());
    //~^ This should error.
};

fn main() {}
```

In this example, when checking if the `Conditional(())` rvalue is const-drop, since `Conditional` has a const destructor, we would previously recurse into the `()` value and determine it has nothing to drop, which means that it is considered to *not* need a const drop -- even though dropping `Conditional(())` would mean evaluating the destructor which relies on that `T: const Foo` bound to hold!

This could be fixed alternatively by banning any const conditions on `const Drop` impls, but that really sucks -- that means that basically no *interesting* const drop impls could be written. We have the capability to totally and intuitively support the right behavior, which I've implemented here.
2024-11-23 02:03:50 +00:00
Michael Goulet
af0d566e76 Deduplicate checking drop terminator 2024-11-22 16:54:41 +00:00
Michael Goulet
2088260852 Gate const drop behind const_destruct feature, and fix const_precise_live_drops post-drop-elaboration check 2024-11-22 16:54:40 +00:00
bors
a47555110c Auto merge of #133339 - jieyouxu:rollup-gav0nvr, r=jieyouxu
Rollup of 8 pull requests

Successful merges:

 - #133238 (re-export `is_loongarch_feature_detected`)
 - #133288 (Support `each_ref` and `each_mut` in `[T; N]` in constant expressions.)
 - #133311 (Miri subtree update)
 - #133313 (Use arc4random of libc for RTEMS target)
 - #133319 (Simplify `fulfill_implication`)
 - #133323 (Bail in effects in old solver if self ty is ty var)
 - #133330 (library: update comment around close())
 - #133337 (Fix typo in `std:🧵:Scope::spawn` documentation.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-22 16:27:07 +00:00
许杰友 Jieyou Xu (Joe)
874cf85674
Rollup merge of #133337 - ColinFinck:thread-scoped-fix-typo, r=joboet
Fix typo in `std:🧵:Scope::spawn` documentation.

Just a simple fix for a typo that caught my attention.
2024-11-22 20:32:38 +08:00
许杰友 Jieyou Xu (Joe)
bbc4cbe3e2
Rollup merge of #133330 - RalfJung:close, r=the8472
library: update comment around close()

r? `@the8472`
2024-11-22 20:32:38 +08:00
许杰友 Jieyou Xu (Joe)
b8453c9023
Rollup merge of #133313 - thesummer:fix-arc4random, r=cuviper
Use arc4random of libc for RTEMS target

Switch to the `arc4random` from libc. It is available since libc 0.2.162
2024-11-22 20:32:36 +08:00
许杰友 Jieyou Xu (Joe)
2e93a759a3
Rollup merge of #133288 - bjoernager:const-array-each-ref, r=jhpratt
Support `each_ref` and `each_mut` in `[T; N]` in constant expressions.

Tracking issue: #133289

The methods `<[T; N]>::each_ref` and `<[T; N]>::each_mut` can easily be reimplemented to allow marking them with the `const` specifier.

This specific implementation takes a different approach than the original as to avoid using iterators (which are illegal in constant expressions).
2024-11-22 20:32:35 +08:00
许杰友 Jieyou Xu (Joe)
9eb67bb25c
Rollup merge of #133238 - heiher:loong-stdarch-rexport, r=Amanieu
re-export `is_loongarch_feature_detected`

r? ``@Amanieu``
2024-11-22 20:32:34 +08:00
bors
f1e0752404 Auto merge of #130867 - michirakara:steps_between, r=dtolnay
distinguish overflow and unimplemented in Step::steps_between
2024-11-22 10:54:22 +00:00
Colin Finck
d0384f3ba5
Fix typo in std:🧵:Scope::spawn documentation. 2024-11-22 11:51:38 +01:00
Gabriel Bjørnager Jensen
c85a742cb1 Mark '<[T; N]>::as_mut_slice' as 'const'; 2024-11-22 09:49:30 +01:00
Ralf Jung
729d3aa0fe library: update comment around close() 2024-11-22 08:43:51 +01:00
Mads Marquart
f98d9dd334 Don't try to use confstr in Miri 2024-11-22 07:59:51 +01:00
bors
2cf7908998 Auto merge of #129238 - umgefahren:stabilize-ipv6-unique-local, r=dtolnay
Stabilize `Ipv6Addr::is_unique_local` and `Ipv6Addr::is_unicast_link_local`

Make `Ipv6Addr::is_unique_local` and `Ipv6Addr::is_unicast_link_local` stable (+const).

Newly stable API:

```rust
impl Ipv6Addr {
	// Newly stable under `ipv6_is_unique_local`
	const fn is_unique_local(&self) -> bool;

	// Newly stable under `ipv6_is_unique_local`
	const fn is_unicast_link_local(&self) -> bool;
}
```

These stabilise a subset of the following tracking issue:
- #27709

I have looked and could not find any issues with `is_unique_local` and `is_unicast_link_local`. There is a well received comment calling for stabilisation of the latter function.

Both functions are well defined and consistent with implementations in other languages:
- [Go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/net/netip/netip.go;l=518)
- [Python](e9d1bf353c/Lib/ipaddress.py (L2319-L2321))
- [Ruby (unique local)](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html#private-3F-source)
- [Ruby (unicast link local)](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html#link_local-3F-source)

cc implementor `@little-dude`
(I can't find the original PR for `is_unqiue_local`)

r? libs-api
`@rustbot` label +T-libs-api +needs-fcp
2024-11-22 06:38:39 +00:00
michirakara
de741d2093
distinguish overflow and unimplemented in Step::steps_between 2024-11-21 15:49:55 -08:00
Jan Sommer
a4a06b305d Use arc4random of libc for RTEMS target
Is available since libc 0.2.162
2024-11-21 23:10:19 +01:00
Gabriel Bjørnager Jensen
7c799c3e0d Mark and implement 'each_ref' and 'each_mut' in '[T; N]' as const; 2024-11-21 12:27:18 +01:00
Deadbeef
514ef180fd constify Add 2024-11-21 18:56:49 +08:00
Matthias Krüger
61878ec254
Rollup merge of #131736 - hoodmane:emscripten-wasm-bigint, r=workingjubilee
Emscripten: link with -sWASM_BIGINT

When linking an executable without dynamic linking, this is a pure improvement. It significantly reduces code size and avoids a lot of buggy behaviors. It is supported in all browsers for many years and in all maintained versions of Node.

It does change the ABI, so people who are dynamically linking with a library or executable that uses the old ABI may need to turn it off. It can be disabled if needed by passing `-Clink-arg -sWASM_BIGINT=0` to `rustc`. But few people will want to turn it off.

Note this includes a libc bump to 0.2.162!
2024-11-21 07:56:11 +01:00
binarycat
7e79f91390 implement OsString::truncate 2024-11-20 15:16:05 -06:00
Matthias Krüger
fbed195b4d
Rollup merge of #133226 - compiler-errors:opt-in-pointer-like, r=lcnr
Make `PointerLike` opt-in instead of built-in

The `PointerLike` trait currently is a built-in trait that computes the layout of the type. This is a bit problematic, because types implement this trait automatically. Since this can be broken due to semver-compatible changes to a type's layout, this is undesirable. Also, calling `layout_of` in the trait system also causes cycles.

This PR makes the trait implemented via regular impls, and adds additional validation on top to make sure that those impls are valid. This could eventually be `derive()`d for custom smart pointers, and we can trust *that* as a semver promise rather than risking library authors accidentally breaking it.

On the other hand, we may never expose `PointerLike`, but at least now the implementation doesn't invoke `layout_of` which could cause ICEs or cause cycles.

Right now for a `PointerLike` impl to be valid, it must be an ADT that is `repr(transparent)` and the non-1zst field needs to implement `PointerLike`. There are also some primitive impls for `&T`/ `&mut T`/`*const T`/`*mut T`/`Box<T>`.
2024-11-20 20:10:13 +01:00
Matthias Krüger
71d3c7790f
Rollup merge of #130800 - bjoernager:const-mut-cursor, r=joshtriplett
Mark `get_mut` and `set_position` in `std::io::Cursor` as const.

Relevant tracking issue: #130801

The methods `get_mut` and `set_position` can trivially be marked as const due to #57349 being stabilised.
2024-11-20 20:10:12 +01:00
Matthias Krüger
0576cc987b
Rollup merge of #129838 - Ayush1325:uefi-process-args, r=joboet
uefi: process: Add args support

- Wrap all args with quotes.
- Escape ^ and " inside quotes using ^.
- Doing reverse of arg parsing: d571ae851d/library/std/src/sys/pal/uefi/args.rs (L81)

 r​? joboet
2024-11-20 20:10:11 +01:00
Michael Goulet
228068bc6e Make PointerLike opt-in as a trait 2024-11-20 16:36:12 +00:00
George Bateman
5777c73438 Stabilize const_pin_2 2024-11-20 07:54:12 -05:00
WANG Rui
37224817d7 re-export is_loongarch_feature_detected 2024-11-20 18:38:22 +08:00
Jacob Pratt
25dc4d0394
Rollup merge of #132732 - gavincrawford:as_ptr_attribute, r=Urgau
Use attributes for `dangling_pointers_from_temporaries` lint

Checking for dangling pointers by function name isn't ideal, and leaves out certain pointer-returning methods that don't follow the `as_ptr` naming convention. Using an attribute for this lint cleans things up and allows more thorough coverage of other methods, such as `UnsafeCell::get()`.
2024-11-20 01:54:24 -05:00
Matthias Krüger
d5dca43df6
Rollup merge of #133183 - n0toose:improve-remove-dir-docs, r=joboet
Mention std::fs::remove_dir_all in std::fs::remove_dir
2024-11-19 22:24:45 +01:00
Matthias Krüger
6c127f3ffd
Rollup merge of #125405 - m-ou-se:thread-add-spawn-hook, r=WaffleLapkin
Add std:🧵:add_spawn_hook.

Implementation of https://github.com/rust-lang/rfcs/pull/3642
2024-11-19 22:24:44 +01:00
Matthias Krüger
001f98ad80
Rollup merge of #123947 - zopsicle:vec_deque-Iter-as_slices, r=Amanieu
Add vec_deque::Iter::as_slices and friends

Add the following methods, that work similarly to VecDeque::as_slices:

 - alloc::collections::vec_deque::Iter::as_slices
 - alloc::collections::vec_deque::IterMut::into_slices
 - alloc::collections::vec_deque::IterMut::as_slices
 - alloc::collections::vec_deque::IterMut::as_mut_slices

Obtaining slices from a VecDeque iterator was not previously possible.
2024-11-19 22:24:43 +01:00
Mara Bos
691796be03 Update doc comments for spawn hook. 2024-11-19 18:55:52 +01:00
Mara Bos
b96f023dbd Address review comments.
Co-authored-by: waffle <waffle.lapkin@gmail.com>
2024-11-19 18:55:52 +01:00
Mara Bos
38b9a448c9 Fix tracking issue. 2024-11-19 18:54:21 +01:00
Mara Bos
24fec0d896 Add tracking issue. 2024-11-19 18:54:21 +01:00
Mara Bos
5a80b48fe1 Use Send + Sync for spawn hooks. 2024-11-19 18:54:20 +01:00
Mara Bos
f2bf9e198e Add thread Builder::no_hooks(). 2024-11-19 18:54:20 +01:00
Mara Bos
947354fbec Update thread spawn hooks.
1. Make the effect thread local.
2. Don't return a io::Result from hooks.
2024-11-19 18:54:20 +01:00
Mara Bos
ef9055f3ee Use add_spawn_hook for libtest's output capturing. 2024-11-19 18:54:20 +01:00
Mara Bos
7ac4c04731 Add std:🧵:add_spawn_hook. 2024-11-19 18:54:20 +01:00