Commit Graph

13428 Commits

Author SHA1 Message Date
Michael Goulet
6628bba060 Remove crashes and fix tests 2024-10-01 13:55:46 -04:00
Michael Goulet
e3a0da1863 Remove unnamed field feature 2024-10-01 13:55:46 -04:00
bors
8dd5cd0bc1 Auto merge of #126839 - obeis:mpmc, r=Amanieu
Add multi-producer, multi-consumer channel (mpmc)

Closes #125712

Tracking issue: #126840

r? m-ou-se
2024-10-01 13:35:16 +00:00
bors
21aa500bb0 Auto merge of #129972 - eholk:stabilize-expr_2021, r=compiler-errors,traviscross
Stabilize expr_2021 fragment specifier in all editions

This is part of the `expr`/`expr_2021` fragment specifier for Edition 2024 (#123742). The RFC says we can support expr_2021 in as many editions as is practical, and there's nothing particularly hard about supporting it all the way back to 2015.

In editions 2021 and earlier, `expr` and `expr_2021` are synonyms. Their behavior diverges starting in Edition 2024. This is checked by the `expr_2021_inline_const.rs` test.

cc `@vincenzopalazzo` `@rust-lang/wg-macros` `@traviscross`
2024-10-01 08:12:49 +00:00
Eric Holk
c7cd55f7c5 Stabilize expr_2021 fragment in all editions
Co-authored-by: Michael Goulet <michael@errs.io>
Co-authored-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-10-01 07:51:58 +00:00
bors
07f08ffb2d Auto merge of #131076 - lukas-code:doc-stab2, r=notriddle
rustdoc: rewrite stability inheritance as a doc pass

Since doc inlining can almost arbitrarily change the module hierarchy, we can't just use the HIR ancestors of an item to compute its effective stability. This PR moves the stability inheritance that I implemented in https://github.com/rust-lang/rust/pull/130798 into a new doc pass `propagate-stability` that runs after doc inlining and uses the post-inlining ancestors of an item to correctly compute its effective stability.

fixes https://github.com/rust-lang/rust/issues/131020

r? `@notriddle`
2024-10-01 04:30:33 +00:00
bors
f79ef02e4b Auto merge of #130587 - coolreader18:field-variant-doclink-disambig, r=notriddle,jyn514
Add `field@` and `variant@` doc-link disambiguators

I'm not sure if this is big enough to need an fcp or not, but this is something I found missing when trying to refer to a field in macro-generated docs, not knowing if a method might be defined as well. Obviously, there are definitely other uses.

In the case where it's not disambiguated, methods (and I suppose other associated items in the value namespace) still take priority, which `@jyn514` said was an oversight but I think is probably the desired behavior 99% of the time anyway - shadowing a field with an accessor method is a very common pattern. If fields and methods with the same name started conflicting, it would be a breaking change. Though, to quote them:

> jyn: maybe you can break this only if both [the method and the field] are public
> jyn: rustc has some future-incompat warning level
> jyn: that gets through -A warnings and --cap-lints from cargo

That'd be out of scope of this PR, though.

Fixes #80283
2024-10-01 01:45:35 +00:00
Trevor Gross
a0637597b4
Rollup merge of #130966 - RalfJung:ptr-metadata-const-stable, r=scottmcm
make ptr metadata functions callable from stable const fn

So far this was done with a bunch of `rustc_allow_const_fn_unstable`. But those should be the exception, not the norm. If we are confident we can expose the ptr metadata APIs *indirectly* in stable const fn, we should just mark them as `rustc_const_stable`. And we better be confident we can do that since it's already been done a while ago. ;)

In particular this marks two intrinsics as const-stable: `aggregate_raw_ptr`, `ptr_metadata`. This should be uncontroversial, they are trivial to implement in the interpreter.
Cc `@rust-lang/wg-const-eval` `@rust-lang/lang`
2024-09-30 19:18:51 -04:00
Trevor Gross
acaa6cee07
Rollup merge of #130877 - taiki-e:riscv-atomic, r=Amanieu
rustc_target: Add RISC-V atomic-related features

This adds the following three target features to unstable riscv_target_feature.

- `zaamo` (Zaamo Extension 1.0.0): Atomic Memory Operations (`amo*.{w,d}{,.aq,.rl,.aqrl}`)
  ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L229-L231), [available since LLVM 19](8be079cddd))
- `zabha` (Zabha Extension 1.0.0): Byte and Halfword Atomic Memory Operations (`amo*.{b,h}{,.aq,.rl,.aqrl}`)
  ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L238-L240), [available since LLVM 19](6b7444964a))
- `zalrsc` (Zalrsc Extension 1.0.0): Load-Reserved/Store-Conditional Instructions (`lr.{w,d}{,.aq,.rl,.aqrl}` and `sc.{w,d}{,.aq,.rl,.aqrl}`)
  ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L261-L263), [available since LLVM 19](8be079cddd))

(Zacas Extension is not included here because it is still marked as experimental in LLVM 19 70e7d26e56 and will become non-experimental in LLVM 20 614aeda93b)

`a` implies `zaamo` and `zalrsc`, and `zabha` implies `zaamo`:

- After Zaamo and Zalrsc Extensions are frozen, riscv-isa-manual says "The A extension comprises instructions provided by the Zaamo and Zalrsc extensions" (e87412e621), and [`a` implies `zaamo` and `zalrsc` in GCC](08693e29ec/gcc/config/riscv/arch-canonicalize (L44)). However, in LLVM, [`a` does not define them as implying `zaamo` and `zalrsc`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L206).
- Zabha and Zaamo are in a similar situation, [riscv-isa-manual](https://github.com/riscv/riscv-isa-manual/blob/main/src/zabha.adoc) says "The Zabha extension depends upon the Zaamo standard extension", and [`zabha` implies `zaamo` in GCC](08693e29ec/gcc/config/riscv/arch-canonicalize (L45-L46)), but [does not in LLVM (but enabling `zabha` without `zaamo` or `a` is not allowed)](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/TargetParser/RISCVISAInfo.cpp#L776-L778).

r? `@Amanieu`

`@rustbot` label +O-riscv +A-target-feature
2024-09-30 19:18:49 -04:00
Lukas Markeffsky
cd31b3acb3 rustdoc: rewrite stability inheritance as a pass 2024-09-30 21:58:18 +00:00
Ralf Jung
7650307c0e add test ensuring we cannot call const-stable unstable functions 2024-09-30 20:58:37 +02:00
Obei Sideg
041e76b7cd
Add multi-producer, multi-consumer channel (mpmc) 2024-09-30 20:43:51 +03:00
Matthias Krüger
5df1123b39
Rollup merge of #131038 - onkoe:fix/adt_const_params_leak_118179, r=compiler-errors
Fix `adt_const_params` leaking `{type error}` in error msg

Fixes the confusing diagnostic described in #118179. (users would see `{type error}` in some situations, which is pretty weird)

`adt_const_params` tracking issue: #95174
2024-09-30 18:25:14 +02:00
Matthias Krüger
dc1ccc5264
Rollup merge of #131035 - dingxiangfei2009:tweak-if-let-rescope-lint, r=jieyouxu
Preserve brackets around if-lets and skip while-lets

r? `@jieyouxu`

Tracked by #124085

Fresh out of #129466, we have discovered 9 crates that the lint did not successfully migrate because the span of `if let` includes the surrounding brackets `(..)` like the following, which surprised me a bit.

```rust
if (if let .. { .. } else { .. }) {
// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// the span somehow includes the surrounding brackets
}
```

There is one crate that failed the migration because some suggestion spans cross the macro expansion boundaries. Surely there is no way to patch them with `match` rewrite. To handle this case, we will instead require all spans to be tested for admissibility as suggestion spans.

Besides, there are 4 false negative cases discovered with desugared-`while let`. We don't need to lint them, because the `else` branch surely contains exactly one statement because the drop order is not changed whatsoever in this case.

```rust
while let Some(value) = droppy().get() {
..
}
// is desugared into
loop {
    if let Some(value) = droppy().get() {
        ..
    } else {
        break;
        // here can be nothing observable in this block
    }
}
```

I believe this is the one and only false positive that I have found. I think we have finally nailed all the corner cases this time.
2024-09-30 18:25:14 +02:00
Ding Xiang Fei
ed5443fcdf
apply suggestions 2024-09-30 22:21:45 +08:00
Matthias Krüger
90fdb11f51
Rollup merge of #131057 - Urgau:cfg-erronous-unsafe, r=jieyouxu
Reject leading unsafe in `cfg!(...)` and `--check-cfg`

This PR reject leading unsafe in `cfg!(...)` and `--check-cfg`.

Fixes (after-backport) https://github.com/rust-lang/rust/issues/131055
r? `@jieyouxu`
2024-09-30 14:33:46 +02:00
Matthias Krüger
fd2785f67a
Rollup merge of #130895 - RalfJung:asm-tests, r=nnethercote
make type-check-4 asm tests about non-const expressions

These tests recently got changed in https://github.com/rust-lang/rust/pull/129759. I asked the PR author to make the tests read from a `static mut` (rather than just making them "pass"), but I now think that was a mistake: previously the tests failed because the const was not a valid const expression, after the PR they failed because the const failed to evaluate.

So this PR restores the tests to "fail because the const is not a valid const expression". That can be done in a target-independent way so I unified the x86 and aarch64 tests into one.

Cc `@oli-obk` as the original [author](0d88631059) of these tests -- not sure if you still remember what they were intended to test.
2024-09-30 14:33:46 +02:00
Ralf Jung
ac2e318034 make type-check-4 asm tests about non-const expressions 2024-09-30 13:47:36 +02:00
Urgau
9cb540a13c Reject leading unsafe in cfg!(...) and --check-cfg. 2024-09-30 12:15:08 +02:00
Barrett Ray
c5598d6a9e fix(hir_analysis/wfcheck): don't leak {type error}
avoid `{type error}` being leaked in user-facing messages,
particularly when using the `adt_const_params` feature
2024-09-29 23:40:43 -05:00
bors
4e91cedaed Auto merge of #129499 - fee1-dead-contrib:supereffects, r=compiler-errors
properly elaborate effects implied bounds for super traits

Summary: This PR makes it so that we elaborate `<T as Tr>::Fx: EffectsCompat<somebool>` into `<T as SuperTr>::Fx: EffectsCompat<somebool>` when we know that `trait Tr: ~const SuperTr`.

Some discussion at https://github.com/rust-lang/project-const-traits/issues/2.

r? project-const-traits
`@rust-lang/project-const-traits:` how do we feel about this approach?
2024-09-30 00:30:09 +00:00
bors
0d6e130196 Auto merge of #131002 - steffahn:rustdoc-long-names-fix, r=notriddle
In redesigned rustdoc toolbar: Adjust spacings and sizing to improve behavior with over-long names

Fixes #130993.

Some additional adjustments also fix more issues I’ve noticed such as:

* on small screens, opening search made the 3 bottons move down very slightly (because the row with the crate picker got larger, enlarging the whole grid), this is fixed with a `min-height: 60px` on the toolbar
* with long names in the “breadcrumps” area, wrapping was very broken
  * ![Screenshot_20240929_031831](https://github.com/user-attachments/assets/6f46bbb7-004b-4606-bf17-8a6f3289a8f7)
  * fixed:
  * ![Screenshot_20240929_035312](https://github.com/user-attachments/assets/4e2f8dd2-043e-4279-b588-0a72c7533f8e)
* the left grid area has a minimal width (105px); like before, that leaves about enough space for crate names becoming as short as “all cra…”;
    to save even more space, there’s support for a little bit of extra squeezing of the buttons
  * ![Screenshot_20240929_034511](https://github.com/user-attachments/assets/7c6788ee-8ec1-4a38-b341-8d67704f5575)
  * ![Screenshot_20240929_034525](https://github.com/user-attachments/assets/e141756d-37a9-4205-bc4d-235ddd1c0609)
  * ![Screenshot_20240929_034535](https://github.com/user-attachments/assets/526447f3-48b6-47aa-8a60-e5b0d4d055f0)

I’m really not super good with HTML or CSS stuff at all; there seem to be many magical numbers already, I’ve just used `px` values until things look right, I hope that’s okay 🤷‍♂️

r? `@GuillaumeGomez`

cc `@notriddle`
2024-09-29 22:04:32 +00:00
Ding Xiang Fei
6d1a25ad7e
preserve brackets around if-lets and skip while-lets 2024-09-30 04:21:10 +08:00
Matthias Krüger
a0ae32d6a2
Rollup merge of #130990 - RalfJung:mir-const-normalize, r=compiler-errors
try to get rid of mir::Const::normalize

It was easy to make this compile, let's see if anything breaks...

r? `@compiler-errors`
2024-09-29 20:17:37 +02:00
Michael Howell
c27b54ac4a rustdoc-gui: fix test cases 2024-09-29 10:02:06 -07:00
bors
42ff2eedb0 Auto merge of #131022 - matthiaskrgr:rollup-g9y1v11, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #130931 (Rename `standalone` doctest attribute into `standalone_crate`)
 - #131000 (Weekly `cargo update`)
 - #131011 (cleanup: don't `.into()` identical types)
 - #131013 (cleanup: don't manually `unwrap_or_default()`)
 - #131014 (cleanup: don't clone types that are Copy)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-29 15:52:51 +00:00
Matthias Krüger
3097951023
Rollup merge of #130931 - GuillaumeGomez:standalone-crate, r=notriddle
Rename `standalone` doctest attribute into `standalone_crate`

Following [zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/Renaming.20code.20block.20.22standalone.22.20attribute.3F) and poll results.

r? `@notriddle`
2024-09-29 16:51:55 +02:00
bors
d194948e50 Auto merge of #130975 - matthiaskrgr:nice_ice_shall_suffice, r=jieyouxu
crashes: more tests

r? `@jieyouxu`
2024-09-29 13:09:08 +00:00
Guillaume Gomez
6f5f21adfc Rename doctest attribute standalone-crate into standalone_crate for coherency 2024-09-29 13:01:41 +02:00
Matthias Krüger
6d3aee2ab6 crashes: more tests 2024-09-29 11:58:09 +02:00
bors
329e7b4d4e Auto merge of #130983 - GuillaumeGomez:wait-for-false, r=notriddle
Update `browser-ui-test` version and make use of `wait-for*-false` commands

I added `wait-for*-false` commands, making possible these changes.

r? `@notriddle`
2024-09-29 08:22:20 +00:00
Ralf Jung
7eedb6846c adjust test 2024-09-29 08:49:37 +02:00
bors
1d9162bced Auto merge of #129687 - Urgau:rfc3127-sysroot-2, r=jieyouxu
Implement RFC3137 trim-paths sysroot changes - take 2

This PR is a continuation of https://github.com/rust-lang/rust/pull/118149. Nothing really changed, except for https://github.com/rust-lang/rust/pull/129408 which I was able to trigger locally.

Original description:

> Implement parts of #111540
>
> Right now, backtraces into sysroot always shows /rustc/$hash in diagnostics, e.g.
>
> ```
> thread 'main' panicked at 'hello world', map-panic.rs:2:50
> stack backtrace:
>    0: std::panicking::begin_panic
>              at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:616:12
>    1: map_panic::main::{{closure}}
>              at ./map-panic.rs:2:50
>    2: core::option::Option<T>::map
>              at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/option.rs:929:29
>    3: map_panic::main
>              at ./map-panic.rs:2:30
>    4: core::ops::function::FnOnce::call_once
>              at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5
> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
> ```
>
> [RFC 3127 said](https://rust-lang.github.io/rfcs/3127-trim-paths.html#changing-handling-of-sysroot-path-in-rustc)
>
> > We want to change this behaviour such that, when rust-src source files can be discovered, the virtual path is discarded and therefore the local path will be embedded, unless there is a --remap-path-prefix that causes this local path to be remapped in the usual way.
>
> This PR implements this behaviour. When `rust-src` is present at compile time, rustc replaces /rustc/$hash with a real path into local rust-src with best effort. To sanitise this, users must explicitly supply `--remap-path-prefix=<path to rust-src>=foo`.

cc `@cbeuw`
Fix #105907
Fix #85463

try-job: dist-x86_64-linux
try-job: x86_64-msvc
try-job: dist-x86_64-msvc
try-job: armhf-gnu
2024-09-29 03:04:05 +00:00
bors
55cb7359c7 Auto merge of #123778 - jhorstmann:optimize-upper-lower-auto-vectorization, r=the8472
Improve autovectorization of to_lowercase / to_uppercase functions

Refactor the code in the `convert_while_ascii` helper function to make it more suitable for auto-vectorization and also process the full ascii prefix of the string. The generic case conversion logic will only be invoked starting from the first non-ascii character.

The runtime on a microbenchmark with a small ascii-only input decreases from ~55ns to ~18ns per iteration. The new implementation also reduces the amount of unsafe code and encapsulates all unsafe inside the helper function.

Fixes #123712
2024-09-28 23:56:37 +00:00
Urgau
3a6c6ee3d3 remap-path-prefix-sysroot: remap {{src-base}} as well
This is done to cover the path of the test it-self as it may not live
on the same root directory as {{rust-src-base}}, which can be the case
if {{rust-src-base}} is coming from a extracted dist build (cc opt-dist)
2024-09-28 21:50:23 +02:00
Guillaume Gomez
632fed891d Improve mistyped docblock attribute warning messages 2024-09-28 18:38:11 +02:00
Guillaume Gomez
84d41e2fc1 Add regression tests for mistyped standalone-crate attribute 2024-09-28 18:38:11 +02:00
Guillaume Gomez
cdf2a8ffc5 Rename standalone doctest attribute into standalone-crate 2024-09-28 18:38:10 +02:00
Guillaume Gomez
2f16ff7b37 Make use of wait-for*-false commands 2024-09-28 18:04:00 +02:00
Matthias Krüger
cfe0cff5b9
Rollup merge of #130960 - cuviper:cdylib-soname, r=petrochenkov
Only add an automatic SONAME for Rust dylibs

#126094 added an automatic relative `SONAME` to all dynamic libraries, but it was really only needed for Rust `--crate-type="dylib"`. In Fedora, it was a surprise to see `SONAME` on `"cdylib"` libraries like Python modules, especially because that generates an undesirable RPM `Provides`. We can instead add a `SONAME` just for Rust dylibs by passing the crate-type argument farther.

Ref: https://bugzilla.redhat.com/show_bug.cgi?id=2314879
2024-09-28 15:11:22 +02:00
Matthias Krüger
5d7db93600
Rollup merge of #130953 - workingjubilee:rename-a-few-ctypes-tests, r=fee1-dead
Rename a few tests to make tidy happier

A somewhat random smattering of tests that I have recently looked at, and thus had cause to research and write down the reason for their existence.
2024-09-28 09:35:12 +02:00
Matthias Krüger
58d0730fb8
Rollup merge of #130944 - lukas-code:ptr-ptr-sub, r=compiler-errors
Allow instantiating trait object binder in ptr-to-ptr casts

For unsizing coercions between trait objects with the same principal, we already allow instantiating the for binder. For example, coercing `Box<dyn for<'a> Trait<'a>` to `Box<dyn Trait<'static>>` is allowed.

Since ptr-to-ptr casts will insert an unsizing coercion before the cast if possible, this has the consequence that the following compiles already:

```rust
// This compiles today.
fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut dyn Trait<'b> {
    // lowered as (roughly)
    // tmp: *mut dyn Trait<'?0> = Unsize(x)     // requires dyn for<'a> Trait<'a> <: dyn Trait<'?0>
    // ret: *mut dyn Trait<'b> = PtrToPtr(tmp)  // requires dyn Trait<'?0> == dyn Trait<'b>
    x as _
}
```

However, if no unsizing coercion is inserted then this currently fails to compile as one type is more general than the other. This PR will allow this code to compile, too, by changing ptr-to-ptr casts of pointers with vtable metadata to use sutyping instead of type equality.

```rust
// This will compile after this PR.
fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut Wrapper<dyn Trait<'b>> {
    // lowered as (roughly)
    // no Unsize here!
    // ret: *mut Wrapper<dyn Trait<'b>> = PtrToPtr(x)  // requires dyn for<'a> Trait<'a> == dyn Trait<'b>
    x as _
}
```

Note that it is already possible to work around the current restrictions and make the code compile before this PR by splitting the cast in two, so this shouldn't allow a new class of programs to compile:

```rust
// Workaround that compiles today.
fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut Wrapper<dyn Trait<'b>> {
    x as *mut dyn Trait<'_> as _
}
```

r? `@compiler-errors`
cc `@WaffleLapkin`
2024-09-28 09:35:12 +02:00
Matthias Krüger
2df6b0773e
Rollup merge of #130924 - surechen:fix_130851, r=compiler-errors
Make clashing_extern_declarations considering generic args for ADT field

In following example, G<u16> should be recognized as different from G<u32> :

```rust
#[repr(C)] pub struct G<T> { g: [T; 4] }

pub mod x { extern "C" { pub fn g(_: super::G<u16>); } }
pub mod y { extern "C" { pub fn g(_: super::G<u32>); } }
```

fixes #130851
2024-09-28 09:35:10 +02:00
Matthias Krüger
4e510daed7
Rollup merge of #130866 - compiler-errors:dyn-instantiate-binder, r=lcnr
Allow instantiating object trait binder when upcasting

This PR fixes two bugs (that probably need an FCP).

### We use equality rather than subtyping for upcasting dyn conversions

This code should be valid:

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

trait Foo: for<'h> Bar<'h> {}
trait Bar<'a> {}

fn foo(x: &dyn Foo) {
    let y: &dyn Bar<'static> = x;
}
```
But instead:

```
error[E0308]: mismatched types
 --> src/lib.rs:7:32
  |
7 |     let y: &dyn Bar<'static> = x;
  |                                ^ one type is more general than the other
  |
  = note: expected existential trait ref `for<'h> Bar<'h>`
             found existential trait ref `Bar<'_>`
```

And so should this:

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

fn foo(x: &dyn for<'h> Fn(&'h ())) {
    let y: &dyn FnOnce(&'static ()) = x;
}
```

But instead:

```
error[E0308]: mismatched types
 --> src/lib.rs:4:39
  |
4 |     let y: &dyn FnOnce(&'static ()) = x;
  |                                       ^ one type is more general than the other
  |
  = note: expected existential trait ref `for<'h> FnOnce<(&'h (),)>`
             found existential trait ref `FnOnce<(&(),)>`
```

Specifically, both of these fail because we use *equality* when comparing the supertrait to the *target* of the unsize goal. For the first example, since our supertrait is `for<'h> Bar<'h>` but our target is `Bar<'static>`, there's a higher-ranked type mismatch even though we *should* be able to instantiate that supertrait binder when upcasting. Similarly for the second example.

### New solver uses equality rather than subtyping for no-op (i.e. non-upcasting) dyn conversions

This code should be valid in the new solver, like it is with the old solver:

```rust
// -Znext-solver

fn foo<'a>(x: &mut for<'h> dyn Fn(&'h ())) {
   let _: &mut dyn Fn(&'a ()) = x;
}
```

But instead:

```
error: lifetime may not live long enough
 --> <source>:2:11
  |
1 | fn foo<'a>(x: &mut dyn for<'h> Fn(&'h ())) {
  |        -- lifetime `'a` defined here
2 |    let _: &mut dyn Fn(&'a ()) = x;
  |           ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
  |
  = note: requirement occurs because of a mutable reference to `dyn Fn(&())`
```

Specifically, this fails because we try to coerce `&mut dyn for<'h> Fn(&'h ())` to `&mut dyn Fn(&'a ())`, which registers an `dyn for<'h> Fn(&'h ()): dyn Fn(&'a ())` goal. This fails because the new solver uses *equating* rather than *subtyping* in `Unsize` goals.

This is *mostly* not a problem... You may wonder why the same code passes on the new solver for immutable references:

```
// -Znext-solver

fn foo<'a>(x: &dyn Fn(&())) {
   let _: &dyn Fn(&'a ()) = x; // works
}
```

That's because in this case, we first try to coerce via `Unsize`, but due to the leak check the goal fails. Then, later in coercion, we fall back to a simple subtyping operation, which *does* work.

Since `&T` is covariant over `T`, but `&mut T` is invariant, that's where the discrepancy between these two examples crops up.

---

r? lcnr or reassign :D
2024-09-28 09:35:09 +02:00
Taiki Endo
62612af372 rustc_target: Add RISC-V atomic-related features 2024-09-28 11:26:09 +09:00
Josh Stone
f46057bf1c Only add an automatic SONAME for Rust dylibs 2024-09-27 15:53:26 -07:00
Jubilee Young
19d5568ad3 tests: issue-34798.rs => allow-phantomdata-in-ffi.rs 2024-09-27 14:29:34 -07:00
bors
83e4e18896 Auto merge of #130946 - matthiaskrgr:rollup-ia4mf0y, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #130718 (Cleanup some known-bug issues)
 - #130730 (Reorganize Test Headers)
 - #130826 (Compiler: Rename "object safe" to "dyn compatible")
 - #130915 (fix typo in triagebot.toml)
 - #130926 (Update cc to 1.1.22 in library/)
 - #130932 (etc: Add sample rust-analyzer configs for eglot & helix)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-27 21:23:29 +00:00
Jubilee Young
a1fbf251b8 tests: issue-14309.* => repr-rust-is-undefined.* 2024-09-27 14:20:31 -07:00
Jubilee Young
bcf8cf2943 tests: issue-69488.rs => load-preserves-partial-init-issue-69488.rs 2024-09-27 14:18:11 -07:00