Commit Graph

285807 Commits

Author SHA1 Message Date
Thalia Archibald
781b92c3f1 Implement AsRef<OsStr> for Cow<'_, Path>
In #31751, `impl AsRef<Path> for Cow<'_, OsStr>` was added, but the
converse was omitted and it wasn't mentioned in discussion. This seems
to have been a simple oversight, as it otherwise implemented traits
mutually between `OsStr` and `Path`.
2025-04-05 19:54:21 -07:00
bors
c2110769cd Auto merge of #139275 - cuviper:min-llvm-19, r=nikic
Update the minimum external LLVM to 19

With this change, we'll have stable support for LLVM 19 and 20.
For reference, the previous increase to LLVM 18 was #130487.

cc `@rust-lang/wg-llvm`
r? nikic
2025-04-05 22:00:33 +00:00
bors
5e17a2a91d Auto merge of #139417 - matthiaskrgr:rollup-ktf1d6s, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #136877 (Fix missing const for inherent pointer `replace` methods)
 - #138797 (Fix `ProvenVia` for global where clauses)
 - #139121 (Rename internal module from `statik` to `no_threads`)
 - #139319 (StableMIR: Prepare for refactoring)
 - #139404 (Small smir cleanup)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-05 18:54:05 +00:00
Josh Stone
12167d7064 Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
Matthias Krüger
91377bd4ca
Rollup merge of #139404 - yotamofek:pr/smir/cleanup, r=compiler-errors
Small smir cleanup

First commit might have small positive perf effect, second one is just to make code a bit shorter
2025-04-05 19:40:26 +02:00
Matthias Krüger
2769522e6e
Rollup merge of #139319 - makai410:refactor, r=celinval
StableMIR: Prepare for refactoring

Temporarily make `stable_mir` "parasitic" on the `rustc_smir` crate.

It aims to resolve the circular dependency that would arise if we directly invert the dependency order between `rustc_smir` and `stable_mir`.

Once the refactoring is complete (`rustc_smir` does not depend on `stable_mir`), we will migrate it back to the `stable_mir` crate. See more details: [here](https://hackmd.io/jBRkZLqAQL2EVgwIIeNMHg).
2025-04-05 19:40:25 +02:00
Matthias Krüger
527725b025
Rollup merge of #139121 - thaliaarchi:rename-thread_local-statik, r=Noratrieb
Rename internal module from `statik` to `no_threads`

This module is named in reference to the keyword, but the term is somewhat overloaded. Rename it to more clearly describe it and avoid the misspelling.
2025-04-05 19:40:24 +02:00
Matthias Krüger
6d88291d3c
Rollup merge of #138797 - compiler-errors:global-proven-via, r=lcnr
Fix `ProvenVia` for global where clauses

When we're merging one (or more) global where clauses in the presence of no other candidates, ensure that we return `TraitGoalProvenVia::ParamEnv` so that rigid projections work correctly. This fixes some tests with `feature(trivial_bounds)`.

Fixes #139408
2025-04-05 19:40:24 +02:00
Matthias Krüger
0b342873e3
Rollup merge of #136877 - Sky9x:const-inherent-ptr-replace, r=jhpratt
Fix missing const for inherent pointer `replace` methods

`ptr::replace` (the free fn) is already const stable. However, there are inherent convenience methods on `*mut T` and `NonNull<T>`, allowing you to write eg. `unsafe { foo.replace(bar) }` where `foo` is `*mut T` or `NonNull<T>`.

It seems const was never added to the inherent method (likely oversight), so this PR adds it.
I don't believe this needs another[^1] FCP as the inherent methods are already stable and `ptr::replace` is already const stable, so this adds no new API.

Original tracking issue: #83164
`ptr::replace` constified in #83091
`ptr::replace` const stabilized in #130954

[^1]: `const_replace` FCP completed: https://github.com/rust-lang/rust/issues/83164#issuecomment-2385670050
2025-04-05 19:40:23 +02:00
Michael Goulet
89d0e7c033 Fix ProvenVia for global where clauses 2025-04-05 16:23:25 +00:00
bors
0c478fdfe1 Auto merge of #139292 - compiler-errors:folder-experiment-7, r=lqd
Folder experiment: Micro-optimize RegionEraserVisitor

**NOTE:** This is one of a series of perf experiments that I've come up with while sick in bed. I'm assigning them to lqd b/c you're a good reviewer and you'll hopefully be awake when these experiments finish, lol.

r? lqd

The region eraser is very hot, so let's see if we can avoid erasing types (and visiting consts and preds that don't have region-ful types) unnecessarily.
2025-04-05 12:33:47 +00:00
Makai
707d356d00 let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00
bors
0e9c3e52e4 Auto merge of #139401 - matthiaskrgr:rollup-uqdfj6u, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #138368 (KCFI: Add KCFI arity indicator support)
 - #138381 (Implement `SliceIndex` for `ByteStr`)
 - #139092 (Move `fd` into `std::sys`)
 - #139398 (Change notifications for Exploit Mitigations PG)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-05 09:25:41 +00:00
Yotam Ofek
33d62dd208 Dedup call to layout query 2025-04-05 08:59:49 +00:00
Yotam Ofek
89d9dd6e15 Only format! error message on failure 2025-04-05 08:59:13 +00:00
Matthias Krüger
0823b34bfb
Rollup merge of #139398 - rcvalle:rust-exploit-mitigations-pg-notifications, r=cuviper
Change notifications for Exploit Mitigations PG

Reduce the amount of notifications sent to all the Exploit Mitigations PG by removing it from some of the paths.
2025-04-05 10:18:05 +02:00
Matthias Krüger
a64ccf4a46
Rollup merge of #139092 - thaliaarchi:move-fd-pal, r=joboet
Move `fd` into `std::sys`

Move platform definitions of `fd` into `std::sys`, as part of https://github.com/rust-lang/rust/issues/117276.

Unlike other modules directly under `std::sys`, this is only available on some platforms and I have not provided a fallback abstraction for unsupported platforms. That is similar to how `std::os::fd` is gated to only supported platforms.

Also, fix the `unsafe_op_in_unsafe_fn` lint, which was allowed for the Unix fd impl. Since macro expansions from `std::sys::pal::unix::weak` trigger this lint, fix it there too.

cc `@joboet,` `@ChrisDenton`

try-job: x86_64-gnu-aux
2025-04-05 10:18:04 +02:00
Matthias Krüger
56ffb43629
Rollup merge of #138381 - thaliaarchi:bstr-sliceindex, r=joshtriplett
Implement `SliceIndex` for `ByteStr`

Implement `Index` and `IndexMut` for `ByteStr` in terms of `SliceIndex`. Implement it for the same types that `&[u8]` supports (a superset of those supported for `&str`, which does not have `usize` and `ops::IndexRange`).

At the same time, move compare and index traits to a separate file in the `bstr` module, to give it more space to grow as more functionality is added (e.g., iterators and string-like ops). Order the items in `bstr/traits.rs` similarly to `str/traits.rs`.

cc `@joshtriplett`

`ByteStr`/`ByteString` tracking issue: https://github.com/rust-lang/rust/issues/134915
2025-04-05 10:18:03 +02:00
Matthias Krüger
543160dd62
Rollup merge of #138368 - rcvalle:rust-kcfi-arity, r=davidtwco
KCFI: Add KCFI arity indicator support

Adds KCFI arity indicator support to the Rust compiler (see https://github.com/rust-lang/rust/issues/138311, https://github.com/llvm/llvm-project/pull/121070, and https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).
2025-04-05 10:18:03 +02:00
bors
da8321773a Auto merge of #139281 - petrochenkov:ctxtdecod6, r=wesleywiser
hygiene: Avoid recursion in syntax context decoding

#139241 has two components
- Avoiding recursion during syntax context decoding
- Encoding/decoding only the non-redundant data, and recalculating the redundant data again during decoding

Both of these parts may influence compilation times, possibly in opposite directions.
So this PR contains only the first part to evaluate its effect in isolation.
2025-04-05 06:18:04 +00:00
Ramon de C Valle
a98546b961 KCFI: Add KCFI arity indicator support
Adds KCFI arity indicator support to the Rust compiler (see rust-lang/rust#138311,
https://github.com/llvm/llvm-project/pull/121070, and
https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).
2025-04-05 04:05:04 +00:00
Thalia Archibald
9b889e9198 Rename internal module from statik to no_threads
This module is named in reference to the keyword, but the term is
somewhat overloaded. Rename it to more clearly describe it and avoid the
misspelling.
2025-04-04 20:31:15 -07:00
Thalia Archibald
3ab22fabf1 Fix unsafe_op_in_unsafe_fn for Unix fd and weak 2025-04-04 20:11:08 -07:00
Thalia Archibald
4085af0183 Move fd into sys 2025-04-04 20:11:08 -07:00
bors
1e008dd5d8 Auto merge of #139396 - Zalathar:rollup-lmoqvru, r=Zalathar
Rollup of 11 pull requests

Successful merges:

 - #136457 (Expose algebraic floating point intrinsics)
 - #137880 (Autodiff batching)
 - #137897 (fix pthread-based tls on apple targets)
 - #138024 (Allow optimizing out `panic_bounds_check` in Unicode checks.)
 - #138546 (Add integer to string formatting tests)
 - #138826 (StableMIR: Add `associated_items`.)
 - #138950 (replace extra_filename with strict version hash in metrics file names)
 - #139274 (Rustdoc: typecheck settings.js)
 - #139285 (use lower case to match other error messages)
 - #139341 (Apply `Recovery::Forbidden` when reparsing pasted macro fragments.)
 - #139389 (make `Arguments::as_statically_known_str` doc(hidden))

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-05 03:09:33 +00:00
Ramon de C Valle
8c891ba222 Change notifications for Exploit Mitigations PG
Reduce the amount of notifications sent to all the Exploit Mitigations
PG by removing it from some of the paths.
2025-04-05 03:08:49 +00:00
Stuart Cook
e31ce50698
Rollup merge of #139389 - mejrs:hidden, r=workingjubilee
make `Arguments::as_statically_known_str` doc(hidden)

Fixes `as_statically_known_str` being [visible](https://doc.rust-lang.org/nightly/std/fmt/struct.Arguments.html#method.as_statically_known_str) ([Rendered](https://github.com/user-attachments/assets/45482d9f-2ec5-4610-be9c-b231bd2850c6))

This snuck in with https://github.com/rust-lang/rust/pull/138650, cc `@thaliaarchi`

This is also visible in the beta docs.

`@rustbot` label +beta-nominated
2025-04-05 13:18:17 +11:00
Stuart Cook
66ccc4fe28
Rollup merge of #139341 - nnethercote:fix-137874, r=petrochenkov
Apply `Recovery::Forbidden` when reparsing pasted macro fragments.

Fixes #137874.

The changes to the output of `tests/ui/associated-consts/issue-93835.rs`
partly undo the changes seen when `NtTy` was removed in #133436, which
is good.

r? ``@petrochenkov``
2025-04-05 13:18:17 +11:00
Stuart Cook
6907e011e4
Rollup merge of #139285 - tshepang:uniform-case, r=jieyouxu
use lower case to match other error messages
2025-04-05 13:18:16 +11:00
Stuart Cook
f04c935cf1
Rollup merge of #139274 - lolbinarycat:rustdoc-js-less-expect-error-part5, r=notriddle
Rustdoc: typecheck settings.js

This makes the file fully typechecked with no instances of ``````@ts-expect-error`````` and no type casts.

r? `````@notriddle`````
2025-04-05 13:18:16 +11:00
Stuart Cook
ae745a06fa
Rollup merge of #138950 - yaahc:svh-metrics-name, r=bjorn3
replace extra_filename with strict version hash in metrics file names

Should resolve the potential issue of overwriting metrics from the same crate when compiled with different features or flags.

r? `````@estebank`````

try-job: test-various
2025-04-05 13:18:15 +11:00
Stuart Cook
93f7583491
Rollup merge of #138826 - makai410:assoc-items, r=celinval
StableMIR: Add `associated_items`.

Resolves: https://github.com/rust-lang/project-stable-mir/issues/87
2025-04-05 13:18:15 +11:00
Stuart Cook
338b8787b9
Rollup merge of #138546 - GuillaumeGomez:integer-to-string-tests, r=Amanieu
Add integer to string formatting tests

As discussed in https://github.com/rust-lang/rust/pull/136264, there doesn't seem to have tests to ensure that int to string conversion is performed correctly, only sporadic tests here and there. Now we have some basic tests. :)

r? `````@Mark-Simulacrum`````
2025-04-05 13:18:14 +11:00
Stuart Cook
a038028eca
Rollup merge of #138024 - reitermarkus:unicode-panic-optimization, r=ibraheemdev
Allow optimizing out `panic_bounds_check` in Unicode checks.

Allow optimizing out `panic_bounds_check` in Unicode checks.

For context, see https://github.com/japaric/ufmt/issues/52#issuecomment-2699207241.
2025-04-05 13:18:14 +11:00
Stuart Cook
92bb7261c4
Rollup merge of #137897 - xTachyon:tls-fix, r=thomcc,jieyouxu
fix pthread-based tls on apple targets

Tries to fix #127773.
2025-04-05 13:18:13 +11:00
Stuart Cook
c6bf3a01ef
Rollup merge of #137880 - EnzymeAD:autodiff-batching, r=oli-obk
Autodiff batching

Enzyme supports batching, which is especially known from the ML side when training neural networks.
There we would normally have a training loop, where in each iteration we would pass in some data (e.g. an image), and a target vector. Based on how close we are with our prediction we compute our loss, and then use backpropagation to compute the gradients and update our weights.
That's quite inefficient, so what you normally do is passing in a batch of 8/16/.. images and targets, and compute the gradients for those all at once, allowing better optimizations.

Enzyme supports batching in two ways, the first one (which I implemented here) just accepts a Batch size,
and then each Dual/Duplicated argument has not one, but N shadow arguments.  So instead of
```rs
for i in 0..100 {
   df(x[i], y[i], 1234);
}
```
You can now do
```rs
for i in 0..100.step_by(4) {
   df(x[i+0],x[i+1],x[i+2],x[i+3], y[i+0], y[i+1], y[i+2], y[i+3], 1234);
}
```
which will give the same results, but allows better compiler optimizations. See the testcase for details.

There is a second variant, where we can mark certain arguments and instead of having to pass in N shadow arguments, Enzyme assumes that the argument is N times longer. I.e. instead of accepting 4 slices with 12 floats each, we would accept one slice with 48 floats. I'll implement this over the next days.

I will also add more tests for both modes.

For any one preferring some more interactive explanation, here's a video of Tim's llvm dev talk, where he presents his work. https://www.youtube.com/watch?v=edvaLAL5RqU
I'll also add some other docs to the dev guide and user docs in another PR.

r? ghost

Tracking:

- https://github.com/rust-lang/rust/issues/124509
- https://github.com/rust-lang/rust/issues/135283
2025-04-05 13:18:13 +11:00
Stuart Cook
2e4e196a5b
Rollup merge of #136457 - calder:master, r=tgross35
Expose algebraic floating point intrinsics

# Problem

A stable Rust implementation of a simple dot product is 8x slower than C++ on modern x86-64 CPUs. The root cause is an inability to let the compiler reorder floating point operations for better vectorization.

See https://github.com/calder/dot-bench for benchmarks. Measurements below were performed on a i7-10875H.

### C++: 10us 

With Clang 18.1.3 and `-O2 -march=haswell`:
<table>
<tr>
    <th>C++</th>
    <th>Assembly</th>
</tr>
<tr>
<td>
<pre lang="cc">
float dot(float *a, float *b, size_t len) {
    #pragma clang fp reassociate(on)
    float sum = 0.0;
    for (size_t i = 0; i < len; ++i) {
        sum += a[i] * b[i];
    }
    return sum;
}
</pre>
</td>
<td>
<img src="https://github.com/user-attachments/assets/739573c0-380a-4d84-9fd9-141343ce7e68" />
</td>
</tr>
</table>

### Nightly Rust: 10us 

With rustc 1.86.0-nightly (8239a37f9) and `-C opt-level=3 -C target-feature=+avx2,+fma`:
<table>
<tr>
    <th>Rust</th>
    <th>Assembly</th>
</tr>
<tr>
<td>
<pre lang="rust">
fn dot(a: &[f32], b: &[f32]) -> f32 {
    let mut sum = 0.0;
    for i in 0..a.len() {
        sum = fadd_algebraic(sum, fmul_algebraic(a[i], b[i]));
    }
    sum
}
</pre>
</td>
<td>
<img src="https://github.com/user-attachments/assets/9dcf953a-2cd7-42f3-bc34-7117de4c5fb9" />
</td>
</tr>
</table>

### Stable Rust: 84us 

With rustc 1.84.1 (e71f9a9a9) and `-C opt-level=3 -C target-feature=+avx2,+fma`:
<table>
<tr>
    <th>Rust</th>
    <th>Assembly</th>
</tr>
<tr>
<td>
<pre lang="rust">
fn dot(a: &[f32], b: &[f32]) -> f32 {
    let mut sum = 0.0;
    for i in 0..a.len() {
        sum += a[i] * b[i];
    }
    sum
}
</pre>
</td>
<td>
<img src="https://github.com/user-attachments/assets/936a1f7e-33e4-4ff8-a732-c3cdfe068dca" />
</td>
</tr>
</table>

# Proposed Change

Add `core::intrinsics::f*_algebraic` wrappers to `f16`, `f32`, `f64`, and `f128` gated on a new `float_algebraic` feature.

# Alternatives Considered

https://github.com/rust-lang/rust/issues/21690 has a lot of good discussion of various options for supporting fast math in Rust, but is still open a decade later because any choice that opts in more than individual operations is ultimately contrary to Rust's design principles.

In the mean time, processors have evolved and we're leaving major performance on the table by not supporting vectorization. We shouldn't make users choose between an unstable compiler and an 8x performance hit.

# References

* https://github.com/rust-lang/rust/issues/21690
* https://github.com/rust-lang/libs-team/issues/532
* https://github.com/rust-lang/rust/issues/136469
* https://github.com/calder/dot-bench
* https://www.felixcloutier.com/x86/vfmadd132ps:vfmadd213ps:vfmadd231ps

try-job: x86_64-gnu-nopt
try-job: x86_64-gnu-aux
2025-04-05 13:18:12 +11:00
Calder Coalson
8ff70529f2 Expose algebraic floating point intrinsics 2025-04-04 16:13:57 -07:00
bors
bad13a970a Auto merge of #139390 - matthiaskrgr:rollup-l64euwx, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #139041 (Remove `rustc_middle::ty::util::ExplicitSelf`.)
 - #139328 (Fix 2024 edition doctest panic output)
 - #139339 (unstable book: document tait)
 - #139348 (AsyncDestructor: replace fields with impl_did)
 - #139353 (Fix `Debug` impl for `LateParamRegionKind`.)
 - #139366 (ToSocketAddrs: fix typo)
 - #139374 (Use the span of the whole bound when the diagnostic talks about a bound)
 - #139378 (Use target-agnostic LLD flags in bootstrap for `use-lld`)
 - #139384 (Add `compiletest` adhoc_group for `r? compiletest`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-04 23:03:57 +00:00
Matthias Krüger
a612ee78c1
Rollup merge of #139384 - jieyouxu:compiletest-reviewers, r=Kobzol
Add `compiletest` adhoc_group for `r? compiletest`

r? `@Kobzol` (or bootstrap/compiler)
2025-04-04 21:55:01 +02:00
Matthias Krüger
bad6b7bad6
Rollup merge of #139378 - Kobzol:bootstrap-use-lld-fix, r=petrochenkov
Use target-agnostic LLD flags in bootstrap for `use-lld`

[Before](https://github.com/rust-lang/rust/pull/135001), I hardcoded LLD flags that pretty much only worked on GNU. The right way is to use `-Zlinker-features` instead though.

I *think* that this should also make this work on Windows mingw, and thus `@petrochenkov's` workaround is no longer necessary.

Fixes: https://github.com/rust-lang/rust/issues/139372
Closes: https://github.com/rust-lang/rust/pull/139375

r? `@lqd`
2025-04-04 21:55:00 +02:00
Matthias Krüger
f074bbff7a
Rollup merge of #139374 - oli-obk:const-trait-bound, r=compiler-errors
Use the span of the whole bound when the diagnostic talks about a bound

While it makes sense that the host predicate only points to the `~const` part, as whether the actual trait bound is satisfied is checked separately, the user facing diagnostic is talking about the entire trait bound, at which point it makes more sense to just highlight the entire bound

r? `@compiler-errors` or `@fee1-dead`
2025-04-04 21:55:00 +02:00
Matthias Krüger
fa7d66eaaa
Rollup merge of #139366 - RalfJung:ToSocketAddrs, r=jieyouxu
ToSocketAddrs: fix typo

It's "a function", never "an function".

I noticed the same typo somewhere in the compiler sources so figured I'd fix it there as well.
2025-04-04 21:54:59 +02:00
Matthias Krüger
e3c73c7a2f
Rollup merge of #139353 - nnethercote:LateAnon, r=compiler-errors
Fix `Debug` impl for `LateParamRegionKind`.

It uses `Br` prefixes which are inappropriate and appear to have been incorrectly copy/pasted from the `Debug` impl for `BoundRegionKind`.

r? `@BoxyUwU`
2025-04-04 21:54:58 +02:00
Matthias Krüger
d61a4735f7
Rollup merge of #139348 - meithecatte:async-destructor-minify, r=petrochenkov
AsyncDestructor: replace fields with impl_did

The future and ctor fields aren't actually used, and the way they are extracted is obviously wrong – swapping the order of the items in the source code will give wrong results.

Instead, store just the LocalDefId of the impl, which is enough for the only use of this data.
2025-04-04 21:54:58 +02:00
Matthias Krüger
8b86782ef0
Rollup merge of #139339 - mejrs:tait, r=oli-obk
unstable book: document tait

Documents the type alias impl trait feature.

Rendered:
![image](https://github.com/user-attachments/assets/1d904ff9-e1e1-4ef0-a62d-cbe2d480dce0)
![image](https://github.com/user-attachments/assets/9e877ad1-0f73-4ead-a4ac-0e106512cef8)
![image](https://github.com/user-attachments/assets/86663a23-9824-406d-a5e1-1e0c1662b5f5)

because you are deeply involved in this I'll r you but feel free to reroll
r? `@oli-obk`
2025-04-04 21:54:57 +02:00
Matthias Krüger
cfc2297cfc
Rollup merge of #139328 - GuillaumeGomez:fix-panic-output-137970, r=fmease
Fix 2024 edition doctest panic output

Fixes #137970.

The problem was that the output was actually displayed by rustc itself because we're exiting with `Result<(), String>`, and the display is really not great. So instead, we get the output, we print it and then we return an `ExitCode`.

r? ````@aDotInTheVoid````
2025-04-04 21:54:57 +02:00
Matthias Krüger
00f608af18
Rollup merge of #139041 - nnethercote:rm-rustc_middle-ty-util-ExplicitSelf, r=BoxyUwU
Remove `rustc_middle::ty::util::ExplicitSelf`.

It's an old (2017 or earlier) type that describes a `self` receiver. It's only used in `rustc_hir_analysis` for two error messages, and much of the complexity isn't used. I suspect it used to be used for more things.

This commit removes it, and moves a greatly simplified version of the `determine` method into `rustc_hir_analysis`, renamed as `get_self_string`. The big comment on the method is removed because it no longer seems relevant.

r? `@BoxyUwU`
2025-04-04 21:54:56 +02:00
bors
17ffbc81a3 Auto merge of #138785 - lcnr:typing-mode-borrowck, r=compiler-errors,oli-obk
add `TypingMode::Borrowck`

Shares the first commit with #138499, doesn't really matter which PR to land first 😊 😁

Introduces `TypingMode::Borrowck` which unlike `TypingMode::Analysis`, uses the hidden type computed by HIR typeck as the initial value of opaques instead of an unconstrained infer var. This is a part of https://github.com/rust-lang/types-team/issues/129.

Using this new `TypingMode` is unfortunately a breaking change for now, see tests/ui/impl-trait/non-defining-uses/as-projection-term.rs. Using an inference variable as the initial value results in non-defining uses in the defining scope. We therefore only enable it if with `-Znext-solver=globally` or `-Ztyping-mode-borrowck`

To do that the PR contains the following changes:
- `TypeckResults::concrete_opaque_type` are already mapped to the definition of the opaque type
  - writeback now checks that the non-lifetime parameters of the opaque are universal
  - for this, `fn check_opaque_type_parameter_valid` is moved from `rustc_borrowck` to `rustc_trait_selection`
- we add a new `query type_of_opaque_hir_typeck` which, using the same visitors as MIR typeck, attempts to merge the hidden types from HIR typeck from all defining scopes
  - done by adding a `DefiningScopeKind` flag to toggle between using borrowck and HIR typeck
  - the visitors stop checking that the MIR type matches the HIR type. This is trivial as the HIR type are now used as the initial hidden types of the opaque. This check is useful as a safeguard when not using `TypingMode::Borrowck`, but adding it to the new structure is annoying and it's not soundness critical, so I intend to not add it back.
- add a `TypingMode::Borrowck`  which behaves just like `TypingMode::Analysis` except when normalizing opaque types
   - it uses `type_of_opaque_hir_typeck(opaque)` as the initial value after replacing its regions with new inference vars
   - it uses structural lookup in the new solver

fixes #112201, fixes #132335, fixes #137751

r? `@compiler-errors` `@oli-obk`
2025-04-04 19:54:42 +00:00
mejrs
cfcc47ea54 make Arguments::as_statically_known_str doc(hidden) 2025-04-04 21:43:03 +02:00