Commit Graph

2067 Commits

Author SHA1 Message Date
Jonathan Brouwer
a7be2941de Rollup merge of #163083 - nnethercote:rm-Diag-G, r=oli-obk
Remove `G` generic param from `Diag<'_, G>`

The benefits are outweighed by the costs. Details in invidual commits.

some minor earlier discussion about this change in https://github.com/rust-lang/rust/pull/162630#discussion_r3988468478
2026-09-21 15:19:21 +02:00
Nicholas Nethercote
30b8dfc353 Remove G generic param from Diag<'_, G>
It encodes the `emit` behaviour, one of:
- `BugAbort`: Abort as a bug.
- `FatalAbort`: Abort as a fatal error.
- `ErrorGuaranteed`: Return an `ErrorGuaranteed` (the default).
- `()`: return `()`.

This is useful but `Diag` is very widely used and it's arguably not
useful enough to be worth the generic parameter. This commit removes it.

Benefits:
- Many fewer generic parameters, including many functions where the
  genericity is entirely uninteresting. This includes every
  `Diagnostic::into_diag` and `Subdiagnostic::add_to_diag`. Removes the
  need for the comment about `<G>` on `trait Diagnostic`.
- No `PhantomData` in `Diag`.
- Makes bootstrapping a bit faster.

The downside is there is no longer a single `emit` method.
- Getting a `!` return type requires calling `emit_bug` or `emit_fatal`.
  This only affects a few call sites.
- Getting an `ErrorGuaranteed` return type requires calling `emit_err`.
  This affects a lot of call sites. (It arguably makes call sites more
  self-documenting.)
- Using the wrong `emit_*` on a diagnostic causes a runtime abort, which
  previously couldn't occur. Seems unlikely, but it's not impossible.
- Note: If no particular return type is needed, `emit` can be used for
  any diagnostic. (Bug/fatal diagnostics will still trigger abort.)
2026-09-21 09:57:42 +10:00
Zalathar
172ae8c9af Declare multi-kind constants for MacroKinds
If rmeta encoding has to define these constants anyway, we might as well
provide them as inherent constants and use them in `descr` too.

In current versions of bitflags, flags can be combined in const contexts by
calling `union` instead of using the overloaded `|` operator.
2026-09-18 17:27:49 +10:00
Jonathan Brouwer
8297751077 Rollup merge of #162366 - TheHighestBit:copy-on-finalize-error, r=bjorn3
Replace hard linked `metadata.rmeta` with a copy when finalizing the incremental compilation session dir fails

Fixes rust-lang/rust#151181.

Since 1.90.0, on ReFS (Windows Dev Drive) volumes finalizing the incremental compilation session directory would fail with `Access is denied. (os error 5)`. The issue was caused by rust-lang/rust#114669, which meant that `metadata.rmeta` inside the session dir was a hard link to a file that was potentially being used by several other processes and ReFS seemingly refuses to rename such directories.  As a fallback, we try to replace the hard linked metadata file with a copy instead, so that the rename can succeed.

I don't think adding a test for this is possible due to the lack of a ReFS runner but I added a unit test for the `replace_hard_link_with_copy` helper.

r? @bjorn3
2026-09-17 21:00:08 +02:00
Zalathar
c095b61746 Remove Deref/DerefMut from MetadataDecodeContext
It is easy to remove these impls, now that delegating to Decoder doesn't rely
on a hardcoded `.opaque` field.
2026-09-17 12:23:44 +10:00
Zalathar
a788afabe0 Simplify the macro for forwarding Decoder methods
The old name `implement_ty_decoder!` historically made some sense, but nowadays
is quite misleading for a macro that only forwards Decoder methods.

Requiring the caller to provide the `impl` block makes the calling code
clearer, while also reducing the complexity of dealing with generics. The
downside is a little less context at the macro-definition site, which seems
fine.

The closure-like syntax allows for arbitrary expressions involving `self`,
without running into hygiene problems and without requiring separate closures
for `&self` and `&mut self` methods. It also works well with IDE hover hints.
2026-09-17 12:23:16 +10:00
Joosep Orasmäe
0bae8cff69 Move metadata work product name into a constant 2026-09-16 20:15:22 +03:00
Stuart Cook
edb6c7b600 Rollup merge of #162800 - Zalathar:ref-decodable, r=nnethercote
Cleanups related to RefDecodable

- Earlier experiments: https://github.com/rust-lang/rust/pull/162287
---

This PR is a series of cleanups to the RefDecodable trait and its associated impls.

Details in individual commits.

There should be no change to compiler output.

r? nnethercote (or compiler)
2026-09-16 23:41:57 +10:00
bors
28e8a8c81b Auto merge of #162827 - JonathanBrouwer:rollup-JmKukFg, r=JonathanBrouwer
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#161873 (move bug and span_bug macros to rustc_span)
 - rust-lang/rust#162584 (Use File::*lock*() in rustc_data_structures::flock when possible)
 - rust-lang/rust#162704 (Parser: Uninterpolate when checking for const closures, try bikeshed blocks & in relevant diagnostic code)
 - rust-lang/rust#162787 (Fix suggestions for names captured by formatting macros)
 - rust-lang/rust#159562 (Windows: cache the stdio write mode for the duration of a lock session)
 - rust-lang/rust#162813 (Pre lint port cleanups)
 - rust-lang/rust#162822 (PassWrapper: adapt for removal of EABIVersion arg in LLVM 24)
2026-09-16 01:22:39 +00:00
Zalathar
8dd9b9ab5f Remove an unused via-RefDecodable impl in rmeta decoding 2026-09-16 11:00:48 +10:00
bors
2b9a7be855 Auto merge of #161450 - aerooneqq:syntax-ctxt-non-deterministic-encoding, r=petrochenkov
Fix non-deterministic encoding of syntax contexts



Reiteration of rust-lang/rust#157409. Explanation can be found in comment for `encoding_indices` and in the issue.

Fixes rust-lang/rust#129094. Blocked by rust-lang/rust#161353.

r? @petrochenkov

_No llms used._
2026-09-15 22:12:23 +00:00
aerooneqq
2e35677688 Fix non-deterministic encoding of syntax contexts 2026-09-15 17:50:04 +03:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
Jonathan Brouwer
305d36bc80 Rollup merge of #162630 - nnethercote:simplify-Diag-G, r=oli-obk
Simplify the `G` in `Diag<'a, G>`

The `EmissionGuarantee` trait isn't necessary, and just complicates things. Details in individual commits.

r? @oli-obk
2026-09-14 15:16:02 +02:00
mejrs
8123f4ab2d querify getting fake doc items 2026-09-12 19:24:44 +02:00
Nicholas Nethercote
09bf6de39e Remove EmissionGuarantee
It's a trait that is used to give `Diag::emit` different return types
depending on the `G` in `Diag<'_, G>`. It works, but it's overkill.
There are only four different `G` types in practice (`BugAbort`,
`FatalAbort`, `ErrorGuaranteed`, and `()`) and having inherent `emit`
methods for each of those four concrete `Diag<'_, G>` types is good
enough.

This commit makes that change. This removes `EmissionGuarantee`
trait bounds from many places, which is nice.
2026-09-12 11:21:03 +10:00
khyperia
06e076ee7e yeet braces from DefKind::Const 2026-09-11 17:08:12 +02:00
khyperia
e93270b1d0 yeet type const 2026-09-11 17:08:12 +02:00
Jonathan Brouwer
70410fe0ac Rollup merge of #162520 - aerooneqq:hygiene-perf, r=petrochenkov
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
2026-09-11 12:45:00 +02:00
aerooneqq
69afc99f50 Refactor HygieneEncodeContext
* Refactor `HygieneEncodeContext`
* Review: remove comment outdated part
* Review: return `raw_encode_syntax_context` as a free function
* Review: small cleanups
* Review: add comment about expansions data `Option`
* Review: don't set explicit capacity
* Review: return `queued` -> `latest`
* Remove not needed changes
* Fix `Rc` cloning
* Return comment
2026-09-11 08:18:39 +00:00
bjorn3
e525d70b9f Avoid panic when metadata encoder is called with errors
And remove the encoded metadata if there are any errors or delayed bugs
after encoding.
2026-09-10 09:40:29 +02:00
bjorn3
8b71848ed4 Avoid fatal errors in raw-dylib handling 2026-09-09 14:03:58 +02:00
Zalathar
808023885b Use the dropless arena for query crate_extern_paths 2026-09-06 00:35:47 +10:00
Zalathar
5303664f6e Use the dropless arena for query extra_filename 2026-09-06 00:35:47 +10:00
Jonathan Brouwer
9af53e9b6d Rollup merge of #160936 - Dnreikronos:traits/live_args_bitset, r=lcnr,jackh726,adwinwhite
traits: Represent live alias arguments as bitsets

Split out of rust-lang/rust#160212 per review / Zulip: https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/rigid.20aliases.20in.20region.20handling/near/615557841

`live_args_for_alias_from_outlives_bounds` and `args_known_to_outlive_alias_params` now return identity arg indices (`DenseBitSet`) instead of `EarlyBinder<GenericArg>`. Callers just do `args[idx].visit_with(...)`, so we stop laundering rigidness through binder instantiate. Also drops the old BitSet FIXME.

imo this is worth doing on its own even without the ICE fix. every time we shoved identity params through `EarlyBinder` we were writing down something we don't actually know, and this module is only going to grow. better to make the invariant explicit now than keep paying for it later.

No behavioral change intended. the rigid-alias ICE / `extract_verify_if_eq` bits stay on rust-lang/rust#160212. btw if that one should stack on this instead of staying independent, lmk and I'll rebase it asap.
2026-09-04 22:29:07 +02:00
Jonathan Brouwer
1ac8991699 Rollup merge of #162277 - nnethercote:rustc_middle-resolution, r=petrochenkov
Introduce `rustc_middle::middel::resolve`

There are various types used to carry name resolution results across crate boundaries. They are scattered across places like `rustc_middle::ty`, `rustc_middle::metadata`, and `rustc_hir::def`.

This commit moves them into the new module, a more logical place for them to live. As part of this it eliminates the small `rustc_middle::metadata` module.

One nice consequence of this change: it removes the single use of a `LocalDefId` in `rustc_ast`. (This is what got my attention in the first place.)

r? @petrochenkov
2026-09-04 22:29:01 +02:00
khyperia
b61efecae3 type system const items via direct rhs 2026-09-04 08:01:45 +02:00
Nicholas Nethercote
1545557cd2 Introduce rustc_middle::middel::resolve
There are various types used to carry name resolution results across
crate boundaries. They are scattered across places like
`rustc_middle::ty`, `rustc_middle::metadata`, and `rustc_hir::def`.

This commit moves them into the new module, a more logical place for
them to live. As part of this it eliminates the small
`rustc_middle::metadata` module.

One nice consequence of this change: it removes the single use of a
`LocalDefId` in `rustc_ast`. (This is what got my attention in the first
place.)
2026-09-04 15:44:05 +10:00
bors
e081d6616f Auto merge of #160007 - Bryanskiy:load-injected, r=petrochenkov
allow `-Ldependency` search paths for panic runtimes



Part of [build-std=always RFC](https://rust-lang.github.io/rfcs/3874-build-std-always.html). 

This PR supports `-Ldependency=` search paths for panic runtimes.  This will allow Cargo to treat panic runtimes as regular transitive dependencies, rather than special-casing them.

To do so:
1. During panic runtime injection we remove the early‑return `only_rlib` check. As a result the panic runtime is injected as a conditional dependency when building `std` and is subsequently included in `std`'s metadata. When building a crate that uses `std`, the panic runtime is resolved through `resolve_crate_deps` in the same way as any other transitive dependency. </br>
For a prebuilt `std` (unlike `build-std`), the `-Cpanic=` option passed to `std` may differ from that passed to its dependents, so we might still need to inject another panic runtime as a direct dependency. However, this is not important in the context of prebuilt std.
2. `NoPanicStrategy` is checked only for `panic_abort`. We can compile `panic_unwind` with `-Cpanic=abort` for some targets. This was previously overlooked.

#### Summary of the history and discussions in this PR

1. In the first iteration of this PR `PathKind` for injected dependencies was simply changed from `-Lcrate=` to `-Ldependency`, but this raised a [concern](https://github.com/rust-lang/rust/pull/160007#issuecomment-5090756832). Bjorn3 [suggested](https://github.com/rust-lang/rust/pull/160007#issuecomment-5093637723) to include both panic runtimes  as a dependency of `std` so we don't have to inject it as a dependency for any user of `std`. The correct one should then be activated later in `dependency_format.rs`.
2. In the second iteration Bjorn3's suggestion was implemented. The problem was that for `build-std=always`, we might want to avoid building `panic_unwind` when not necessary. From the compiler perspective we need to </br>
2.1. Either always resolve `panic_unwind` and ignore any resulting error. (might lead to bugs)
2.2. Or conditionally resolve  `panic_unwind`.  For `build-std` we might rely on `-Cpanic=` option for this in accordance with [panic strategies](https://rust-lang.github.io/rfcs/3874-build-std-always.html#panic-strategies) but for prebuilt  `std` this will fail for some targets. </br>
It was decided to relax the implementation so we can inject panic runtime as direct dependency for prebuilt `std`. 
3. Third iteration: we are here

cc @adamgemmell
2026-08-26 09:57:36 +00:00
Jonathan Brouwer
dda473214e Rollup merge of #161443 - khyperia:abbys-tests, r=BoxyUwU
add internal DSL for testing binders

implements https://github.com/rust-lang/project-assumptions-on-binders/issues/8

apologies to the inevitable swarm of people who get pinged for this...

basically the only interesting diff is `compiler/rustc_hir_analysis/src/check/wfcheck.rs`, which actually implements the test. there's probably still features we want to add to this DSL (e.g. `RegionConstraint::AliasTyOutlivesViaEnv`), and there might be some bugs lurking, but this is at least a base to work off of. It's perma-unstable and for internal use only, so support and quality doesn't have to be incredibly high. For example, parser recovery and whatnot is just, bad, but whatever.

r? BoxyUwU
2026-08-25 18:00:01 +02:00
Waffle Lapkin
f34322b0dc remove #![feature(never_type)] from the compiler
The reason `rustc_ast_ir` and `rustc_pattern_analysis` have nested
`cfg_attr`s is so that they don't mention `cfg(bootstrap)` when nightly
or rustc cargo feature turned on. If you don't do it like that, they stop
compiling on stable (or rather, they emit unexpected cfg warnings...).
2026-08-24 19:04:00 +02:00
khyperia
210fd61779 add internal DSL for testing binders 2026-08-24 08:54:48 +02:00
Stuart Cook
b57ccdf160 Rollup merge of #158695 - blyxyas:remove-cratedump, r=fmease
Replace `CrateDump` with the Debug impl from `CStore`

Redundant struct with only one usecase in a single place while keeping the actual implementation of `Debug` in `CStore` empty.

Every line that's removed from the compiler is a win.
2026-08-24 14:21:49 +10:00
Jacob Pratt
cc58c4218f Rollup merge of #161259 - mejrs:attr_structures, r=JonathanBrouwer
move some attribute related structs out of rustc_attr_ir

This changes it so that

- rustc_session no longer depends on rustc_attr_ir
- rustc_attr_ir no longer depends on rustc_target (which is a fairly sizeable crate)
- rustc_attr_ir and rustc_target can compile in parallel

Previous graph:
<img width="985" height="512" alt="image" src="https://github.com/user-attachments/assets/cbde2414-043e-45f2-88a2-f77a5c9df60c" />

Graph with this PR:
<img width="1248" height="474" alt="image" src="https://github.com/user-attachments/assets/e0e13794-b17b-4337-8768-f0191cb1c0e6" />

r? @JonathanBrouwer
2026-08-21 08:43:39 -04:00
mejrs
8d970ffe69 Move NativeLibKind 2026-08-21 10:35:04 +02:00
mejrs
38af4a23c2 move CrateType 2026-08-21 10:35:02 +02:00
bors
16a623ad67 Auto merge of #161434 - jhpratt:rollup-hq3P7uc, r=jhpratt
Rollup of 25 pull requests

Successful merges:

 - rust-lang/rust#152617 (std: implement `sleep_until` for Fuchsia)
 - rust-lang/rust#158934 (diagnostics: fix `let x: vec![]` suggestion pointing into stdlib)
 - rust-lang/rust#160995 (Tiny readability cleanups for initialization dataflow analyses)
 - rust-lang/rust#161277 (bootstrap: Move all non-module items out of the crate root)
 - rust-lang/rust#161295 (std: don't panic on long-elapsed deadlines for `sleep_until`)
 - rust-lang/rust#161368 (Double-word align `_Unwind_Exception`)
 - rust-lang/rust#161370 (Uplift rustfmt macro formatting fix)
 - rust-lang/rust#161378 (`FlowSensitiveAnalysis` cleanups)
 - rust-lang/rust#161420 (Bump wasm-component-ld to 0.5.30)
 - rust-lang/rust#161429 (Tighten allocator `Send`/`Sync` requirements for `Arc` in preparation for refactor)
 - rust-lang/rust#158032 (Offload expose device selection)
 - rust-lang/rust#158855 (Add `desktop` method to `CommandExt`)
 - rust-lang/rust#160299 (Stabilize `bool::toggle`)
 - rust-lang/rust#160842 (Apply `&[T]` visualizer to `*const [T]`, `*mut [T]` and `Box<[T]>`)
 - rust-lang/rust#160981 (Partially support building and locating wasm proc-macros)
 - rust-lang/rust#161199 (Add regression test for non lifetime binders)
 - rust-lang/rust#161212 (rust-installer/install-template.sh: catch cp(1) error when installing…)
 - rust-lang/rust#161302 (Add regression test for inconsistent import resolution from issue 147208)
 - rust-lang/rust#161329 (Add regression tests for a few fixed issues with E-needs-test)
 - rust-lang/rust#161330 (Add regression test for nested RPIT not an iterator ICE)
 - rust-lang/rust#161331 (Bitset simplifications)
 - rust-lang/rust#161340 (rustdoc: enable scrolling only on table/code)
 - rust-lang/rust#161351 (Cleanup: Move impl of `#[rustc_dump_object_lifetime_defaults]`)
 - rust-lang/rust#161355 (Add file path to some archive build errors)
 - rust-lang/rust#161373 (Allow running EC2 jobs locally)
2026-08-21 06:25:29 +00:00
Jacob Pratt
d6998e29a5 Rollup merge of #160981 - bjorn3:proc_macro_refactors7, r=Mark-Simulacrum
Partially support building and locating wasm proc-macros

For building this currently only removes the crate type check and doesn't implement crate metadata support for wasip2 or the proc-macro ABI. And for locating wasip2 needs support for loading crate metadata. Crate metadata building and loading should work for wasip1.

Part of https://github.com/rust-lang/rust/issues/160389

r? @Mark-Simulacrum
2026-08-20 21:34:31 -04:00
mejrs
7cd9c920cd rustc_session; remove rustc_lint_defs rex-exports 2026-08-20 23:02:49 +02:00
Jonathan Brouwer
1b762978fc Rollup merge of #161332 - nnethercote:GlobalCtxt-Session-cleanups, r=Zalathar
Some `GlobalCtxt`/`Session` cleanups

Details in individual commits.

r? @Zalathar
2026-08-20 14:45:33 +02:00
Nicholas Nethercote
e0e6e1962e Introduce GlobalCaches
This commit moves the eight cache fields in `GlobalCtxt` into a single
type, just to provide some logical grouping and to reduce the number of
fields within `GlobalCtxt`.
2026-08-19 21:23:30 +10:00
bjorn3
b192a6ccba Partially support building and locating wasm proc-macros
For building this currently only removes the crate type check and
doesn't implement crate metadata support for wasip2 or the proc-macro
ABI. And for locating wasip2 needs support for loading crate metadata.
Crate metadata building and loading should work for wasip1.
2026-08-17 16:50:26 +02:00
Ralf Jung
8107229db9 remove pointless span for partial-mitigations diagnostics 2026-08-17 11:26:29 +02:00
Jacob Pratt
cd98562a9d Rollup merge of #161183 - RalfJung:target-modifier-spans, r=estebank
avoid pointless spans in target modifier errors

Fixes https://github.com/rust-lang/rust/issues/161174.

Currently the diagnostics for target modifier issues always point at the beginning of the first non-empty line in the file. That makes no sense at all IMO since the error has nothing to do with that line: the error is in the CLI flags. So let's just remove this pointless span.

While doing this I realized there are other errors also doing this, e.g. `report_incompatible_partial_mitigations` and `report_incompatible_async_drop_feature`.  Cc @arielb1 @azhogin why was this done?
@rust-lang/wg-diagnostics do you see any reason to have these diagnostics point at `krate.spans.inner_span.shrink_to_lo()`? IMO that is just never a useful thing to do.
2026-08-16 23:01:51 -04:00
Joao Roberto
c4f07b83b9 Use filled bitsets for alias liveness restrictions
Treat missing outlives information as no restriction so all sources can be
intersected uniformly. Keep bivariant alias arguments out of the final region
walk.
2026-08-16 16:33:23 -03:00
bors
34baba5394 Auto merge of #160529 - cuviper:deps, r=Mark-Simulacrum
Upgrade and deduplicate dependencies



- Upgrade from `getrandom v0.4.2` to `v0.4.3` to drop its `wasip2` and
  `wasip3` dependencies and many transitives.
- Upgrade from `gimli v0.33` to `v0.34` as a direct dependency and
  through a `thorin-dwp` upgrade.
- Upgrade from `object v0.37` and `v0.38` to `v0.39` as a direct
  dependency and via `ar_archive_writer` and `thorin-dwp` upgrades.
- Upgrade `libloading` and `wasmparser` to match other dependencies.

This also consolidates from `hashbrown v0.15`, `v0.16`, and `v0.17` to
just `v0.17.1`, which is the same that `std` currently uses.
2026-08-16 18:44:21 +00:00
Ralf Jung
8b85851cf8 avoid pointless spans in target modifier errors 2026-08-16 18:38:16 +02:00
Jacob Pratt
29b5c303bb Rollup merge of #160984 - bit-aloo:2026-08-12-mgca-const-infer-args, r=khyperia
Fix ICE on { _ } const args in bodies by tracking const-only infer args

closes: rust-lang/rust#160798

r? @khyperia

PS: Here, I am following what Boxy suggested as solution 5, here: [#project-const-generics > Should { _ } be kind ambiguous?](https://rust-lang.zulipchat.com/#narrow/channel/260443-project-const-generics/topic/Should.20.7B.20_.20.7D.20be.20kind.20ambiguous.3F/with/616005728)
2026-08-13 18:16:08 -04:00
Joao Roberto
9d3a26dde4 Use DenseBitSet<u32> for live alias args
Match the existing params_in_repr / unsizing_params convention;
the compiler already treats generic arg counts as u32-sized.
2026-08-12 11:06:41 -03:00
bjorn3
5b3e2771b1 Remove target argument from get_proc_macros
Currently it will always load proc-macros for the host. In the future it
may also start loading wasm proc-macros. This way rust-analyzer doesn't
have to pick between both options itself.
2026-08-12 15:08:50 +02:00