1905 Commits

Author SHA1 Message Date
Nicholas Nethercote 804e419ed8 Eliminate CrateMetadataRef.
There are a number of things I dislike about `CrateMetadataRef`.
- It contains two fields `cstore` and `cdata`. The latter points to data
  within the former. It's like having an `Elem` type that has a
  reference to a vec element and also a reference to the vec itself.
  Weird.
- The `cdata` field gets a lot of use, and the `Deref` impl just derefs
  that field. The `cstore` field is rarely used.
- `CrateMetadataRef` is not a good name.
- Variables named `cdata` sometimes refer to values of this type and
  sometimes to values of type `CrateMetadata`, which is confusing.

The good news is that `CrateMetadataRef` is not necessary and can be
replaced with `&CrateMetadata`. Why? Everywhere that `CrateMetadataRef`
is used, a `TyCtxt` is also present, and the `CStore` is accessible from
the `TyCtxt` with `CStore::from_tcx`.

So this commit removes `CrateMetadataRef` and replaces all its uses with
`&CrateMetadata`. Notes:
- This requires adding only two uses of `CStore::from_tcx`, which shows
  how rarely the `cstore` field was used.
- `get_crate_data` now matches `get_crate_data_mut` more closely.
- A few variables are renamed for consistency, e.g. `data`/`cmeta` ->
  `cdata`.
- An unnecessary local variable (`local_cdata`) in `decode_expn_id` is
  removed.
- All the `CrateMetadataRef` methods become `CrateMetadata` methods, and
  their receiver changes from `self` to `&self`.
- `RawDefId::decode_from_cdata` is inlined and removed, because it has a
  single call site.
2026-04-24 10:02:13 +10:00
bors 2eaa5de4a3 Auto merge of #155628 - nnethercote:CStore-from_tcx, r=mu001999
Streamline `CrateMetadataRef` construction in `provide_one!`.

`cstore.get_crate_data()` creates a `CrateMetadataRef`, which is exactly what we need. The current code is very confused and does several unnecessary things: mapping the `FreezeReadGuard` and calling `CStore::from_tcx` a second time to construct a second `CrateMetadataRef`.

This is a small perf win.

r? @mu001999
2026-04-23 12:32:22 +00:00
Nicholas Nethercote f0ebd66eaa Remove unused tcx params.
They are unused because of the previous commit.
2026-04-22 13:54:57 +10:00
Nicholas Nethercote be52e75d69 Simplify one MetaBlob impl.
It's currently an impl for `(CrateMetadataRef, TyCtxt)`, but (a) the
`TyCtxt` is not used, and (b) the `CrateMetadataRef` can be simplified
to a `CrateMetadata` because `CStore` access isn't required. This
require changing `blob` to take `&self`, which is no big deal, and it
simplifies many `get` calls.
2026-04-22 13:25:15 +10:00
Nicholas Nethercote 2f864a9d03 Split Metadata trait into MetaBlob and MetaDecoder.
`Metadata` has two methods, `blob` and `decoder`, which are not used
together. Splitting the trait in two will allow some cleanups in
subsequent commits.
2026-04-22 13:13:25 +10:00
Nicholas Nethercote cb3df68743 Streamline CrateMetadataRef construction in provide_one!.
`cstore.get_crate_data()` creates a `CrateMetadataRef`, which is exactly
what we need. The current code is very confused and does several
unnecessary things: mapping the `FreezeReadGuard` and calling
`CStore::from_tcx` a second time to construct a second
`CrateMetadataRef`.

This is a small perf win.
2026-04-22 12:21:04 +10:00
Adwin White 6279106e72 fix all errors 2026-04-20 00:18:28 +08:00
Nicholas Nethercote 9b64d52d78 Reduce diagnostic type visibilities.
Most diagnostic types are only used within their own crate, and so have
a `pub(crate)` visibility. We have some diagnostic types that are
unnecessarily `pub`. This is bad because (a) information hiding, and (b)
if a `pub(crate)` type becomes unused the compiler will warn but it
won't warn for a `pub` type.

This commit eliminates unnecessary `pub` visibilities for some
diagnostic types, and also some related things due to knock-on effects.
(I found these types with some ad hoc use of `grep`.)
2026-04-16 07:42:17 +10:00
Jacob Pratt aeaa84995e Rollup merge of #155319 - nnethercote:rm-dead-error-structs, r=Kivooeo
Remove dead diagnostic structs.

One of these has a "FIXME(autodiff): I should get used somewhere" comment, but I figure YAGNI applies and it's so small that reinstating it if necessary would be trivial.

r? @Kivooeo
2026-04-14 23:02:37 -04:00
Nicholas Nethercote f093767036 Remove dead diagnostic structs.
One of these has a "FIXME(autodiff): I should get used somewhere"
comment, but I figure YAGNI applies and it's so small that reinstating
it if necessary would be trivial.
2026-04-15 08:54:46 +10:00
bors 12f35ad39e Auto merge of #155209 - JonathanBrouwer:attr_cleanup2, r=jdonszelmann
Post-attribute ports cleanup pt. 1 (again)

This is a re-implementation of most (but not all) of https://github.com/rust-lang/rust/pull/154808

The code is the same as in that PR, other than a few changes, I'll leave comments where I changed things.
I did re-implement most of the commits rather than cherry-picking, so it's probably good to check the entire diff regardless

r? @jdonszelmann
2026-04-14 08:59:40 +00:00
Jacob Pratt 7d1b042d45 Rollup merge of #149357 - arielb1:enforce-partial-mitigations, r=rcvalle
Implement `-Z allow-partial-mitigations` (RFC 3855)

This implements `-Z allow-partial-mitigations` as an unstable option, currently with support for control-flow-guard and stack-protector.

As a difference from the RFC, we have `-Z allow-partial-mitigations=!foo` rather than `-Z deny-partial-mitigations=foo`, since I couldn't find an easy way to have an allow/deny pair of flags where the latter flag wins.

To allow for stabilization, this is only enabled starting from the next edition. Maybe a better policy is possible (bikeshed).

r? @rcvalle
2026-04-13 20:12:05 -04:00
Jonathan Brouwer ad41fc08b3 Remove EncodeCrossCrate from BUILTIN_ATTRIBUTES 2026-04-13 20:51:30 +02:00
Jonathan Brouwer 2f607ee662 Rollup merge of #153997 - nnethercote:closure-consistency, r=petrochenkov
Use closures more consistently in `dep_graph.rs`.

This file has several methods that take a `FnOnce() -> R` closure:
- `DepGraph::with_ignore`
- `DepGraph::with_query_deserialization`
- `DepGraph::with_anon_task`
- `DepGraphData::with_anon_task_inner`

It also has two methods that take a faux closure via an `A` argument and a `fn(TyCtxt<'tcx>, A) -> R` argument:
- DepGraph::with_task
- DepGraphData::with_task

The rationale is that the faux closure exercises tight control over what state they have access to. This seems silly when (a) they are passed a `TyCtxt`, and (b) when similar nearby functions take real closures. And they are more awkward to use, e.g. requiring multiple arguments to be gathered into a tuple. This commit changes the faux closures to real closures.

r? @Zalathar
2026-04-13 14:02:35 +02:00
Matthias Krüger 56ecb157e2 Rollup merge of #153630 - arferreira:fix-doc-hidden-reexport-diagnostic-path, r=jackh726
Deprioritize doc(hidden) re-exports in diagnostic paths

Fixes rust-lang/rust#153477.

This is the other half of rust-lang/rust#99698, which fixed the case where the *parent module* is `#[doc(hidden)]` but left the case where the re-export itself is `#[doc(hidden)]` as a FIXME (with a tracking test in `dont-suggest-doc-hidden-variant-for-enum/hidden-child.rs`).

The problem: when a crate does `#[doc(hidden)] pub use core::error::Error`, diagnostics pick up the hidden re-export path instead of the canonical one. For example, `snafu::Error` instead of `std::error::Error`.

Two changes:

In `visible_parent_map`, the `add_child` closure now checks whether the re-export itself is `#[doc(hidden)]` via `reexport_chain` and sends it to `fallback_map`, same treatment as doc-hidden parents and underscore re-exports.

`should_encode_attrs` now returns `true` for `DefKind::Use`. Without this, `#[doc(hidden)]` on `use` items was never written to crate metadata, so `is_doc_hidden` always returned `false` cross-crate. This was the actual root cause, the check in `visible_parent_map` alone isn't enough if the attribute isn't in the metadata.

The existing FIXME test now serves as the regression test. The `.stderr` goes from suggesting `hidden_child::__private::Some(1i32)` to just `Some(1i32)`.

cc @eggyal
2026-04-12 08:15:46 +02:00
Jonathan Brouwer 30107e89e6 Revert #154808 because it is based on #152369
This reverts commit 0c94559d48, reversing
changes made to 33528612ba.
2026-04-09 18:32:49 +02:00
Jacob Pratt 827c27d39a Rollup merge of #154856 - bjorn3:fix_dylib_profiler_builtins, r=mati865
Fix linking two dylibs together when both depend on profiler_builtins

See the comment inside this commit for why.

Fixes a regression from https://github.com/rust-lang/rust/pull/150014 reported at [#t-compiler > 1.94 profiler_builtin linkage in dylibs](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/1.2E94.20profiler_builtin.20linkage.20in.20dylibs/with/583704962).
2026-04-08 23:03:57 -04:00
Jonathan Brouwer 0c94559d48 Rollup merge of #154808 - JonathanBrouwer:attr_cleanup, r=jdonszelmann
Post-attribute ports cleanup pt. 1

r? @jdonszelmann

This cleans up some checks I could find were for non-parsed attributes, and works towards removing BUILTIN_ATTRIBUTES

All commits do one thing and every commit passes tests, so best reviewed commit by commit
2026-04-07 17:26:32 +02:00
Jonathan Brouwer edddc2137d Rollup merge of #154147 - mati865:raw-dylib-extern-types, r=petrochenkov
Do not attempt generating DllImport for extern types

Fixes https://github.com/rust-lang/rust/issues/154111
2026-04-07 17:26:22 +02:00
Ariel Ben-Yehuda 1b96797c08 address review comments 2026-04-07 02:12:57 +03:00
Ariel Ben-Yehuda b4bfd7fa43 address review comments 2026-04-07 00:52:42 +03:00
Ariel Ben-Yehuda c55bfc66a6 enforcable -> enforceable 2026-04-07 00:52:42 +03:00
Ariel Ben-Yehuda 3600f4cd2c EnforcableMitigation => DeniedPartialMitigation 2026-04-07 00:52:41 +03:00
Ariel Ben-Yehuda eb89ca9b77 enforced => enforcable mitigation 2026-04-07 00:52:41 +03:00
Ariel Ben-Yehuda 51b2b93239 allow denying mitigations in earlier editions 2026-04-07 00:52:41 +03:00
Ariel Ben-Yehuda daedc77e84 address review comments 2026-04-07 00:52:41 +03:00
Ariel Ben-Yehuda de2408aeed Implement -Z allow-partial-mitigations (RFC 3855)
This implements `-Z allow-partial-mitigations` as an unstable option,
currently with support for control-flow-guard and stack-protector.

As a difference from the RFC, we have `-Z allow-partial-mitigations=!foo`
rather than `-Z deny-partial-mitigations=foo`, since I couldn't find an easy
way to have an allow/deny pair of flags where the latter flag wins.

To allow for stabilization, this is only enabled starting from the next edition. Maybe a
better policy is possible (bikeshed).
2026-04-07 00:52:41 +03:00
bjorn3 642f348805 Fix linking two dylibs together when both depend on profiler_builtins
See the comment inside this commit for why.
2026-04-05 20:24:31 +02:00
Jonathan Brouwer f967bf3f29 Remove EncodeCrossCrate from BUILTIN_ATTRIBUTES 2026-04-05 11:57:05 +02:00
yukang cd95593755 ignore compiler injected crate loading failure 2026-04-03 09:16:26 +08:00
yukang 0f603290db Stop compiling when we get load crate failure 2026-04-02 18:28:54 +08:00
Nicholas Nethercote deb901c896 Use closures more consistently in dep_graph.rs.
This file has several methods that take a `FnOnce() -> R` closure:
- `DepGraph::with_ignore`
- `DepGraph::with_query_deserialization`
- `DepGraph::with_anon_task`
- `DepGraphData::with_anon_task_inner`

It also has two methods that take a faux closure via an `A` argument and
a `fn(TyCtxt<'tcx>, A) -> R` argument:
- DepGraph::with_task
- DepGraphData::with_task

The rationale is that the faux closure exercises tight control over what
state they have access to. This seems silly when (a) they are passed a
`TyCtxt`, and (b) when similar nearby functions take real closures. And
they are more awkward to use, e.g. requiring multiple arguments to be
gathered into a tuple. This commit changes the faux closures to real
closures.
2026-03-31 20:21:05 +11:00
Manuel Drehwald a3261a2307 Revert "Link LLVM dynamically on aarch64-apple-darwin"
This reverts commit e7c268f883.
2026-03-28 05:11:48 +01:00
Daria Sukhonina 2bb9d70b1e Use stable_crate_id more often 2026-03-27 15:36:28 +03:00
Jonathan Brouwer d54a564510 Rollup merge of #154336 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Remove more BuiltinLintDiag variants - part 3

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

Last part of the "easy" migration.

r? @JonathanBrouwer
2026-03-24 22:36:57 +01:00
Guillaume Gomez c17dec615d Remove BuiltinLintDiag usage in rustc_metadata 2026-03-24 19:45:17 +01:00
bors cde9cf08d7 Auto merge of #151063 - sgasho:aarch64-dist-enzyme, r=ZuseZ4
Link LLVM dynamically on aarch64-apple-darwin



Follow-up to rust-lang/rust#152768.

* Link LLVM dynamically on MacOS
* Fix a macOS LLVM dylib name mismatch
2026-03-24 08:05:38 +00:00
Jonathan Brouwer 6e6e266520 Rollup merge of #153857 - RalfJung:cfg-abi, r=Mark-Simulacrum
Rename `target.abi` to `target.cfg_abi` and enum-ify llvm_abiname

See [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/De-spaghettifying.20ABI.20controls/with/578893542) for more context. Discussed a bit in https://github.com/rust-lang/rust/pull/153769#discussion_r2934399038 too.

This renames `target.abi` to `target.cfg_abi` to make it less likely that someone will use it to determine things about the actual ccABI, i.e. the calling convention used on the target. `target.abi` does not control that calling convention, it just *sometimes* informs the user about that calling convention (and also about other aspects of the ABI).

Also turn llvm_abiname into an enum to make it more natural to match on.
Cc @workingjubilee @madsmtm
2026-03-23 12:14:54 +01:00
Ralf Jung 40ebcc031d target specs: rename abi to cfg_abi 2026-03-22 10:34:32 +01:00
sgasho e7c268f883 Link LLVM dynamically on aarch64-apple-darwin 2026-03-22 16:06:31 +09:00
Mateusz Mikuła 93b960ee72 Do not attempt generating imports for extern types 2026-03-20 16:39:42 +01:00
Stuart Cook c0172a38cd Rollup merge of #153580 - mati865:elf-raw-dylib-static-and-tls, r=bjorn3
Handle statics and TLS in raw-dylib for ELF

Follow-up to https://github.com/rust-lang/rust/pull/153090
2026-03-18 21:26:32 +11:00
Zalathar fb850aebcd Remove unused types UnusedGenericParams and FiniteBitSet
These types have been unused since polymorphization was removed in
<https://github.com/rust-lang/rust/pull/133883>.
2026-03-18 10:36:19 +11:00
Mateusz Mikuła f3654324e6 Set symbol size in raw-dylib for ELF 2026-03-17 21:23:16 +01:00
Mateusz Mikuła 2fad36b93d Extend raw-dylib to handle statics and TLS for ELF 2026-03-17 21:23:16 +01:00
Mateusz Mikuła 82727b0c0f Refactor DllImport to better differentiate types 2026-03-17 21:21:25 +01:00
mu001999 2d419b597c Rename parent_module to parent_scope 2026-03-16 22:21:54 +08:00
arferreira 4d3f0db260 Deprioritize doc(hidden) re-exports in diagnostic paths 2026-03-09 18:31:29 -04:00
Zalathar 0a369a799f Replace the try_mark_green hook with direct calls to tcx.dep_graph
All of the existing call sites are directly touching `tcx.dep_graph` anyway, so
the extra layer of indirection provides no real benefit.
2026-03-08 21:53:13 +11:00
Josh Stone eb093cfd5d Reformat with the new stage0 2026-03-07 10:42:02 -08:00