split `macroless_generic_const_args` in two
Two's a crowd! But One's a lonely.
Having `macroless_generic_const_args` apply to const items was quite annoying for users especially as we moved away from `type const` to just regular const items. We would quite commonly be "guessing wrong" with no easy way for users to opt out of `const ASSOC: usize = ...` being represented directly instead of an opaque body
I just swapped any failing tests over to using macroless_const_item_generic_const_args, didnt look through the whole set :>
We should probably bikeshed the feature name rn because it's currently inconsistent with what we wanted to rename all of the other gca features too :> Maybe this should be `gca_macroless_const_items`
cc rust-lang/rust#162540
r? khyperia
deeper `rustc_builtin_macros` cleanups
As a followup to rust-lang/rust#161464, this contains a few more surface cleanups and begins simplifying the mess that `SubstructureFields` currently is by removing the `StaticFields` type in favor of just using the `VariantData` directly.
Implement arbitrary casts in custom mir
[See zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/extending.20custom.20MIR/with/613727602)
Implement custom casts using an enum in `intrinsics::mir` that closely matches the `CastKind` enum in the compiler.
We have 5 different ways to cast in custom MIR, 3 with functions (which hard code a cast kind), 1 implicit coerce (which only does subtyping i think), 1 with `as` (which does a few more). They are all different and the error messages don't tell you what to do. Some are (i think) not possible at all.
This came up [while testing miri](https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Valdity.20checks.20for.20references/near/613662285). We currently have to guess the casting syntax until we find the one that generates the MIR we want. This PR changes that by adding a custom mir operation that allows picking an arbitrary cast.
r? RalfJung
Refactor the way cg_ssa handles indirect returns (returns via `sret`) — Take 2
This continues the work that @FractalFir done in rust-lang/rust#144976.
**I managed to make this work, so this confirms the original approach works and is ready to merge.**
r? workingjubilee
(assigning the same reviewer as the original PR)
# The problem
The current way `cg_ssa` handles `PassMode::Indirect` is fundamentally incompatible with the requirements of the GCC backend. This is currently worked around in a very brittle way, that breaks on ARM.
In order to function correctly, `cg_gcc` requires the `sret`(indirect return) pointer to be treated in a special way.
# The solution
This PR separates the `sret` pointer from all the other arguments, allowing each backend to decide how it wants to handle that pointer. This will allow GCC to do it's own thing, while changing nothing on the LLVM side. Currently, the PR just makes both backends preappend the sret arg, mimicking the previous behaviour.
The PR is based on this [zulip suggestion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Bootstrap.20of.20rustc.20with.20rustc_codegen_gcc/near/526487725).
# Assumptions I made.
The PR makes certain assumptions about the ABI handling.
1. No LLVM intrinsic returns via sret. [According to my sources](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20LLVM.20intrinsics.20return.20via.20PassMode.3A.3AIndirect.3F), this is always true.
2. Tail calls don't currently return via `sret`. From [asking about](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20tail.20calls.20return.20indirectly.28via.20a.20pointer.29.3F/near/532984507), it seems like the tail call handling does not currently support indirect returns. So, I did not add support for that.
3. TLS shims don't perform indirect returns, and asserts and drops also don't perform indirect returns(since they return nothing) - those assumptions seemed reasonable.
4. Inline assembly calls don't use indirect returns. I *assumed* functions like `inline_asm_call` will not need the `sret` handling code. I am not 100% sure about this, tough.
Skip linting unused braces for FunctionArg and MethodArg context for 2024 later
Fixesrust-lang/rust#154247
`unused_braces` is a AST level lint, but in Rust 2024 braces around function and method arguments can affect temporary drop scope.
I tried to find a more complete fix for it, but seems all too heavy, which involve AST visitor or need `hir` related stuff.
Instead of teaching this lint to reason about semantics, so it's better to stop linting those argument-position braces in 2024 later edition.
Refactor `HygieneEncodeContext`
Some refactorings around `HygieneEncodeContext` with minor perf improvements, the most notable thing is that `Lock`s were removed.
First part for rust-lang/rust#161450.
r? @petrochenkov
Rollup of 3 pull requests
Successful merges:
- rust-lang/rust#162223 (`-Znext-solver` : Abort on the first overflowed obligation in fulfillment)
- rust-lang/rust#161654 (Eagerly report overflow errors in normalization query)
- rust-lang/rust#162176 (Clean up some small things related to lint `ambiguous_glob_imported_traits`)
Clean up some small things related to lint `ambiguous_glob_imported_traits`
Cleaning up things I noticed in the vicinity while reviewing PR https://github.com/rust-lang/rust/pull/157968 (which concerns lint `ambiguous_glob_imported_traits` and feature `supertrait_item_shadowing`).
Namely,
1. turning two tuple struct variants into named ones to avoid "anonymous `bool`s"
2. fixing an inaccurate `supertrait_item_shadowing`-specific doc comment
3. applying the rules listed in our [Diagnostic output style guide](https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-output-style-guide) to the diagnostic of lint `ambiguous_glob_imported_traits`
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
Eagerly report overflow errors in normalization query
Fixes https://github.com/rust-lang/rust/issues/161542
We still have rigid opaques in `TypingMode::PostAnalysis` after `PostAnalysisNormalize` pass because we ignore normalization errors in the [`PostAnalysisNormalize` pass](04a3cad16c/compiler/rustc_mir_transform/src/post_analysis_normalize.rs (L66)). We can't handle errors there as we don't have enough information to detect whether they're overflows.
This doesn't cause problems for the old solver because it eagerly emits overflow error in evaluation.
We try to do the same in the next solver.
I don't really know who to assign. Maybe r? @jdonszelmann
cc @lcnr
iter::repeat_with, iter::successors, iter::from_fn added as diagnostic items
added iter::repeat_with, iter::successors, iter::from_fn as diagnostic items, in order for clippy to be able to register them and work with them. Link to clippy issue: https://github.com/rust-lang/rust-clippy/issues/17719
Use lld by default on `loongarch64-unknown-linux-gnu` nightly
This PR makes LLD the default linker for `loongarch64-unknown-linux-gnu` on nightly.
As a prerequisite, it aligns the LoongArch64 Linux `LOAD` segment layout of LLD and other GNU-compatible linkers with GNU ld. This keeps the layout consistent and allows Linux to make better use of file-backed PMD mappings.
The LLD default is initially limited to nightly to allow some soak time before rolling it out to beta and stable.
To opt out of using LLD, `RUSTFLAGS="-Clinker-features=-lld"` would be used. To opt out of using rust-lld, falling back to the LLD installed on the system, `RUSTFLAGS="-Clink-self-contained=-linker"` would be used.
Simplify diagnostic levels
This PR separates diagnostic levels from subdiagnostic levels and does a few preliminary cleanups. Details in individual commits.
r? @oli-obk
mention the opaque when its hidden type cannot be inferred
when the hidden type of an opaque was never constrained, typeck reported `E0282` with only the shared cannot infer type label. nothing in the output said an opaque was involved, so the error read like an ordinary local inference failure.
the unconstrained hidden type arm now adds a note naming the opaque as the source of the ambiguity.
fixes https://github.com/rust-lang/rust/issues/146231
r? @lcnr
Update `windows-bindgen` to 0.100.0
This release represents a major change in the way bindings are generated. See https://github.com/microsoft/windows-rs/issues/4867 for details.
In short, it now more directly follows the C headers. For the standard library's purposes this is mostly reflected in relatively minor type changes or with some `const` pointers becoming `mut`.
There is however one big change that affects a lot of types. In the headers there are a lot of `#define`s like this:
```c
#define GENERIC_READ (0x80000000L)
#define GENERIC_WRITE (0x40000000L)
```
These are constants for the access mode. In this case they're explicitly declared as `L` (aka signed long) integer types (in other cases there's no type at all). However, this conflicts with how access mode constants are actually used. E.g., see `CreateFileW`:
```c
WINBASEAPI
HANDLE
WINAPI
CreateFileW(
_In_ LPCWSTR lpFileName,
_In_ DWORD dwDesiredAccess,
_In_ DWORD dwShareMode,
_In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
_In_ DWORD dwCreationDisposition,
_In_ DWORD dwFlagsAndAttributes,
_In_opt_ HANDLE hTemplateFile
);
```
Here `dwDesiredAccess` is a `DWORD`, which in rust equates to `u32`. The constant being signed but the usage being unsigned is not a problem for C/C++. They will happily convert between types at the drop of a hat. Rust however is stricter, as you know.
The old metadata used by `windows-bindgen` tried to try to fixup this mismatch but the new one goes strictly by what can be inferred from the headers. The hope in the future is that the headers themselves will be updated so better bindings can be directly derived from them.
Mingw used to have an incorrect import library for the synchronization functions `WaitOnAddress`, `WakeByAddressSingle` and `WakeByAddressAll`. This was fixed a long time ago and our windows-gnu targets require a much newer mingw in any case.
Currently `Level` is used for both diagnostics and subdiagnostics. But
both diagnostics and subdiagnostics only use some of the levels. This
commit introduces `Sublevel` to tighten up the representation and
prevent impossible combinations.
These are dead since the old emitter was removed in Jan 2026
(3ccabc6a8d).
Also removed: `BRIGHT_BLUE`, `Level::color`, and a couple of `level`
fn parameters.
Gate ELF code in metadata.rs for ELF only
This PR gates ELF specific code for `BinaryFormat::Elf`. With this change, fallback for PowerPC64 on AIX is no longer needed.
---------
Assisted-by: IBM Bob
The issue was discovered by IBM Bob while checking changes for other things, and I personally verified the bug. Although the fix is trivial, I ran it through IBM Bob to make sure I wasn’t missing anything.
Update wasip2/wasip3 libstd crate dependencies
Picks up the latest version of the `wit-bindgen` dependency which has improved compatibility for `wasm32-wasip3`.
doc: replace `exceeding_bitshifts` with `arithmetic_overflow`
lint `exceeding_bitshifts` has been merged into `arithmetic_overflow` in PR rust-lang/rust#69185
rustdoc: add missing CCI union logic
This fixes a bug that was found where `PathBuf` didn't show up in the standard library search results, because the crate that defined it (libstd) was merged into a crate that already had a path entry in its search index (libproc_macro).
Fixes https://github.com/rust-lang/rust/issues/162334
Fix soundness issues in std::sys::pal::sgx::waitqueue::unsafe_list
Replace invalid uses of references in `std::sys::pal::sgx::waitqueue::unsafe_list` internals with raw pointers. I tried to keep the code structure the same as much as possible. In addition to the use of references flagged in the original issue, it turns out the head/tail (raw) pointer stored in the linked list caused provenance issues in miri. Switched to using UnsafePinned for that.
PR organization:
* Commit 1: Main soundness fix.
* Commit 2: Use pinning in the `pub(crate)` API for UnsafeList. This code predates pinning in Rust. I believe this change isn't strictly necessary as I believe it's valid to document pinning requirements in the unsafe methods on UnsafeList. However, I felt it's better to be explicit about this now that pinning is available in the language.
* Commit 3: Move UnsafeList to a platform-agnostic location so miri can be run on the test suite. This also adds some tests.
This PR was developed with Claude Fable 5 through extensive interactive use, where I directed a detailed plan for making the changes needed for this fix. My input includes keeping the structure the same and the new internal abstraction for dealing with raw pointers. I'm not familiar with miri, I used Claude to test the changes with miri. It said the test suite was failing before the changes (both stacked borrows and tree borrows) but passing after. The additional tests developed this way have been added in the third commit. The head/tail pointer provenance issue was found with Claude. I thoroughly reviewed all the code, including comments, and made manual changes/deletions where necessary/appropriate. The PR description was written by me.
r? @nia-e
Fixesrust-lang/rust#114581Fixesrust-lang/rust#160603Fixesrust-lang/rust#161060
Supersedes rust-lang/rust#160641
fix perf regression from abby canonical form
https://github.com/rust-lang/rust/pull/161306 regressed performance on stable
I believe all the perf impact is due to this
d8df82673d/compiler/rustc_infer/src/infer/mod.rs (L186)
before, `SolverRegionConstraintStorage` was a dummy simple thing, no allocations.
now, it's a `RegionConstraint { and: Box([]), or: Box([Box([])]) }`
the majority of the perf impact (70%ish I think) is because the compiler is not sufficiently smart to optimize `And::new([])` into `And(Box::new([]))` (the former does a bunch of `IndexSet` allocations and stuff, the latter is a no-op, just a nullptr plus zero length metadata)
the the rest of the perf impact (30%ish) is due to the `or` case allocating the `Box([Box([])])`, it's not just a nullptr+zero
options to fix:
- option A: just fix the `And::new([])` being terrible
- option B: option A, *and also*, `SolverRegionConstraintStorage` stores an `Option` that is lazily init on first access, to prevent the perf hit from the `or` case
- option C: option A, *and also*, use some kind of `SmallVec` something or other to make the `or` case be zero-alloc. I have not profiled this due to it being an invasive change and effort, this might not actually fix the perf.
This PR is out option A to see if it actually works with the full perf machinery with PGO and whatnot instead of just on my machine (I am very inexperienced with perf testing!). It might be the case that full PGO blah blah *is* actually sufficiently smart to optimize `And::new([])`, and the actual perf diff is due to the `or` case (which I'm calling the 30%ish impact, might be actually 100%), in which case this PR should produce a no-op perf diff.
r? @BoxyUwU