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.)
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.
Replace hard linked `metadata.rmeta` with a copy when finalizing the incremental compilation session dir fails
Fixesrust-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
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.
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)
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)
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.
Fixesrust-lang/rust#129094. Blocked by rust-lang/rust#161353.
r? @petrochenkov
_No llms used._
Simplify the `G` in `Diag<'a, G>`
The `EmissionGuarantee` trait isn't necessary, and just complicates things. Details in individual commits.
r? @oli-obk
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.
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
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.
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
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.)
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
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
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...).
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.
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
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`.
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.
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.
Treat missing outlives information as no restriction so all sources can be
intersected uniformly. Keep bivariant alias arguments out of the final region
walk.
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.
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.