2083 Commits

Author SHA1 Message Date
Makai ece632c9f7 Remove AllVariants workaround for rust-analyzer 2026-04-24 21:25:20 +08:00
Nicholas Nethercote 3c5e7e8969 Simplify Config::track_state.
This is a callback used to track otherwise untracked state. It was added
in #116731 for Clippy. (It was originally named `hash_untracked_state`,
and examples in the rustc-dev-guide still use that name.) The
`StableHasher` argument is unused, and probably has never been used.
There is a FIXME comment pointing this out, which was added more than a
year ago.

This commit removes the `StableHasher` callback argument. This also
removes the need for `Options::untracked_state_hash`.
2026-04-23 15:02:55 +10:00
Jonathan Brouwer 074ed7b651 Rollup merge of #155389 - Zalathar:flag-macros, r=mati865
Simplify macros for target-modifier and mitigation flags

- Rebased and revised version of https://github.com/rust-lang/rust/pull/154501.
---

The macros used for handling command-line flags that are “target modifiers” or “mitigations” are quite complicated, and can be significantly simplified by tweaking their syntax and by making use of `${ignore(..)}` metavars.

It's possible that more code could be moved out of macros (e.g. declaring some of the enums by hand), but that can be investigated in a potential follow-up.

There should be no change to compiler behaviour.
2026-04-20 18:57:01 +02:00
bors 1b8f2e46e1 Auto merge of #155207 - quiode:writable, r=RalfJung
add llvm writable attribute conditionally




This PR tries to address https://github.com/rust-lang/unsafe-code-guidelines/issues/584#issue-3440604811. It is part of a bachelor thesis supervised by @JoJoDeveloping and @RalfJung, for more information, see: [Project_Description.pdf](https://github.com/user-attachments/files/26537277/Project_Description.pdf).
If the new `-Zllvm-writable` flag is set, the [llvm writable attribute](https://llvm.org/docs/LangRef.html#writable) is inserted for all mutable borrows. This can be conditionally turned off on a per-function basis using the `#[rustc_no_writable]` attribute. The new Undefined Behaviour introduced by this can detected by Miri, which is implemented here: https://github.com/rust-lang/miri/pull/4947.

Two library functions already received the `#[rustc_no_writable]` attribute, as they are known to cause problems under the Tree Borrows aliasing model with implicit writes enabled.
2026-04-17 04:13:36 +00:00
Dominik Schwaiger da2bbfbbec add llvm writable attribute conditionally 2026-04-16 12:29:39 +00:00
Zalathar fb27b3b7a7 Simplify macros for target-modifier and mitigation flags 2026-04-16 21:01:26 +10:00
Jacob Pratt 92f640115a Rollup merge of #155364 - nnethercote:reduce-err-struct-visibilities, r=Kivooeo
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`.)

r? @Kivooeo
2026-04-16 01:54:15 -04:00
Jacob Pratt a25356babb Rollup merge of #155357 - Urgau:rustdoc-remap-path-scope, r=GuillaumeGomez
Add `--remap-path-scope` as unstable in rustdoc

This PR adds support for `rustc` `--remap-path-scope` flag in rustdoc as unstable.

`rustc` documentation for the flag is [here](https://doc.rust-lang.org/nightly/rustc/remap-source-paths.html#--remap-path-scope).

I added some complementary tests for `rustdoc`, no need I think to duplicate `rustc` UI tests.
2026-04-16 01:54:07 -04:00
Nicholas Nethercote f3fc5376e8 Move MustBeNameOfAssociatedFunction to the crate that uses it. 2026-04-16 08:56:50 +10: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
Urgau ae6dbdd9f0 Add --remap-path-scope as unstable in rustdoc 2026-04-15 21:26:48 +02:00
Zalathar 4506131794 Reformat top_level_options! and options! macro declarations 2026-04-15 18:33:48 +10: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
Jacob Pratt 1700a21d10 Rollup merge of #155126 - folkertdev:target-object-format, r=Urgau
add `cfg(target_object_format = "...")`

tracking issue: https://github.com/rust-lang/rust/issues/152586

I'm implementing the predicate as `target_object_format`, because that's what is useful to me (for testing `#[link_section = "..."]` where `mach-o` has some extra restrictions) and maps cleanly to the `BinaryFormat` enum that is used internally. There is still room for a future `target_executable_format` when there is a use case.

cc @joshtriplett as the lang sponsor of this feature, @workingjubilee as the author of the proposal.

r? JonathanBrouwer a sidequest from the sidequest that is https://github.com/rust-lang/rust/pull/155065
2026-04-11 21:12:20 -04:00
Folkert de Vries 6bcd172f5a add cfg(target_object_format = "...") 2026-04-11 14:12:39 +02:00
Jake Drew 1137762b09 Suggest similar target names on unrecognized --target 2026-04-10 22:47:09 +01:00
Jonathan Brouwer 65745a1b95 Revert #152369 because of multiple regressions
The regressions are documented in the PR comments.
This reverts commit 2972b5e, reversing changes made to f908263.
2026-04-09 18:53:59 +02:00
Ariel Ben-Yehuda 1b96797c08 address review comments 2026-04-07 02:12:57 +03:00
Ariel Ben-Yehuda a0ff19d8ec reset mitigation status on a mitigation option as per the RFC 2026-04-07 00:52:42 +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 cc2d560ebf use -Z deny-partial-mitigations instead of -Z allow-partial-mitigations=! 2026-04-07 00:52:41 +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
bors 5a0d572cd1 Auto merge of #154870 - JonathanBrouwer:rollup-OFrhW8F, r=JonathanBrouwer
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#153440 (Various LTO cleanups)
 - rust-lang/rust#151899 (Constify fold, reduce and last for iterator)
 - rust-lang/rust#154561 (Suggest similar keyword when visibility is not followed by an item)
 - rust-lang/rust#154657 (Fix pattern assignment suggestions for uninitialized bindings)
 - rust-lang/rust#154717 (Fix ICE in unsafe binder discriminant helpers)
 - rust-lang/rust#154722 (fix(lints): Improve `ill_formed_attribute_input` with better help message)
 - rust-lang/rust#154777 (`#[cfg]`: suggest alternative `target_` name when the value does not match)
 - rust-lang/rust#154849 (Promote `char::is_case_ignorable` from perma-unstable to unstable)
 - rust-lang/rust#154850 (ast_validation: scalable vectors okay for rustdoc)
2026-04-06 06:45:42 +00:00
Jonathan Brouwer cbe9c4deea Rollup merge of #154777 - scrabsha:push-nunzyzrqlwqw, r=jdonszelmann
`#[cfg]`: suggest alternative `target_` name when the value does not match
2026-04-06 08:27:52 +02:00
Jacob Pratt 24223a62ae Rollup merge of #154744 - nnethercote:rm-Clone-for-StableHashingContext, r=fee1-dead
Remove `Clone` impl for `StableHashingContext`.

`HashStable::hash_stable` takes a `&mut Hcx`. In contrast, `ToStableHashKey::to_stable_hash_key` takes a `&Hcx`. But there are some places where the latter calls the former, and due to the mismatch a `clone` call is required to get a mutable `StableHashingContext`.

This commit changes `to_stable_hash_key` to instead take a `&mut Hcx`. This eliminates the mismatch, the need for the clones, and the need for the `Clone` impls.

r? @fee1-dead
2026-04-05 20:51:06 -04:00
Sasha Pourcelot 1d79216182 #[cfg]: suggest alternative target_ name when the value does not match 2026-04-05 16:50:24 +00:00
Guillaume Gomez 6f751ec182 Make DecorateDiagCompat::Dynamic take an Any reference allowing to downcast to Session 2026-04-03 21:26:10 +02:00
Edvin Bryntesson 0fa6b55198 Decouple CheckLintNameResult from rustc_lint 2026-04-03 11:08:10 +02:00
Nicholas Nethercote ff1795fe49 Remove Clone impl for StableHashingContext.
`HashStable::hash_stable` takes a `&mut Hcx`. In contrast,
`ToStableHashKey::to_stable_hash_key` takes a `&Hcx`. But there are
some places where the latter calls the former, and due to the mismatch a
`clone` call is required to get a mutable `StableHashingContext`.

This commit changes `to_stable_hash_key` to instead take a `&mut Hcx`.
This eliminates the mismatch, the need for the clones, and the need for
the `Clone` impls.
2026-04-03 15:34:33 +11:00
Nicholas Nethercote 1a9a284ad2 Simplify HashStableContext.
`derive(HashStable_Generic)` generates impls like this:
```
impl<__CTX> HashStable<__CTX> for ExpnKind
where
    __CTX: crate::HashStableContext
{
    fn hash_stable(&self, hcx : &mut __CTX, __hasher: &mut StableHasher) {
        ...
    }
}
```
This is used for crates that are upstream of `rustc_middle`.

The `crate::HashStableContext` bound means every crate that uses
`derive(HashStable_Generic)` must provide (or import) a trait
`HashStableContext` which `rustc_middle` then impls. In `rustc_span`
this trait is sensible, with three methods. In other crates, this trait
is empty, and there is the following trait hierarchy:
```
rustc_session::HashStableContext
  |              |
  |   rustc_hir::HashStableContext
  |         /                   \
rustc_ast::HashStableContext   rustc_abi::HashStableContext
  |
rustc_span::HashStableContext
```
All very strange and unnecessary. This commit changes
`derive(HashStable_Generic)` to use `rustc_span::HashStableContext`
instead of `crate::HashStableContext`. This eliminates the need for all
the empty `HashStableContext` traits and impls. Much better.
2026-04-01 17:52:43 +11:00
Nicholas Nethercote d9a8a553cd Reorder use/mod items in rustc_session.
They're in multiple sections with no rhyme or reason.
2026-04-01 16:51:01 +11:00
Jonathan Brouwer 3cef5b54bc Rollup merge of #154634 - nnethercote:hcx, r=petrochenkov
Use `Hcx`/`hcx` consistently for `StableHashingContext`.

The `HashStable` and `ToStableHashKey` traits both have a type parameter that is sometimes called `CTX` and sometimes called `HCX`. (In practice this type parameter is always instantiated as `StableHashingContext`.) Similarly, variables with these types are sometimes called `ctx` and sometimes called `hcx`. This inconsistency has bugged me for some time.

The `HCX`/`hcx` form is more informative (the `H`/`h` indicates what type of context it is) and it matches other cases like `tcx`, `dcx`, `icx`.

Also, RFC 430 says that type parameters should have names that are "concise UpperCamelCase, usually single uppercase letter: T". In this case `H` feels insufficient, and `Hcx` feels better.

Therefore, this commit changes the code to use `Hcx`/`hcx` everywhere.

r? @petrochenkov
2026-03-31 15:27:19 +02:00
Nicholas Nethercote ccc3c01162 Use Hcx/hcx consistently for StableHashingContext.
The `HashStable` and `ToStableHashKey` traits both have a type parameter
that is sometimes called `CTX` and sometimes called `HCX`. (In practice
this type parameter is always instantiated as `StableHashingContext`.)
Similarly, variables with these types are sometimes called `ctx` and
sometimes called `hcx`. This inconsistency has bugged me for some time.

The `HCX`/`hcx` form is more informative (the `H`/`h` indicates what
type of context it is) and it matches other cases like `tcx`, `dcx`,
`icx`.

Also, RFC 430 says that type parameters should have names that are
"concise UpperCamelCase, usually single uppercase letter: T". In this
case `H` feels insufficient, and `Hcx` feels better.

Therefore, this commit changes the code to use `Hcx`/`hcx` everywhere.
2026-03-31 20:16:57 +11:00
Eddy (Eduard) Stefes f39fa9e4c0 add rustc option -Zpacked-stack
this enables packed-stack just as -mpacked-stack in clang and gcc.
packed-stack is needed on s390x for kernel development.

Co-authored-by: Ralf Jung <post@ralfj.de>
2026-03-31 09:06:31 +02:00
Zalathar 29be0590f4 Use the normal arg-parsing machinery for -Zassert-incr-state 2026-03-28 21:52:55 +11:00
Zalathar d470684a43 Revert "Unstable book options parser"
This reverts commit 6fd8466768, reversing
changes made to fda6d37bb8.
2026-03-28 14:18:26 +11:00
León Orell Valerian Liehr 6fd8466768 Rollup merge of #154070 - mehdiakiki:unstable-book-options-parser, r=clubby789
Unstable book options parser

Parses the `options!` macro in `compiler/rustc_session/src/options.rs` directly to extract the unstable (-Z) compiler flag names and descriptions to generate documentation for the unstable book.

I took notice from the previous attempt which ran `rustc -Zhelp` and parsed the output and used this approach that reads the source directly.

Used claude for the tedious char by char parsing parts but verified the code, I hope that's ok!
2026-03-27 15:11:53 +01:00
John Kåre Alsaker f5aa518a77 Ensure ErasedData only implements appropriate auto traits 2026-03-26 00:40:41 +01:00
Jonathan Brouwer 0cd8de3843 Rollup merge of #153049 - Darksonn:kasan-sw-tags, r=fmease
Add `-Zsanitize=kernel-hwaddress`

The Linux kernel has a config option called `CONFIG_KASAN_SW_TAGS`  that enables `-fsanitize=kernel-hwaddress`. This is not supported by Rust.

One slightly awkward detail is that `#[sanitize(address = "off")]` applies to both `-Zsanitize=address` and `-Zsanitize=kernel-address`. Probably it was done this way because both are the same LLVM pass. I replicated this logic here for hwaddress, but it might be undesirable.

Note that `#[sanitize(kernel_hwaddress = "off")]` could be supported as an annotation on statics, but since it's also missing for `#[sanitize(hwaddress = "off")]`, I did not add it.

MCP: https://github.com/rust-lang/compiler-team/issues/975
Tracking issue: https://github.com/rust-lang/rust/issues/154171

cc @rcvalle @maurer @ojeda
2026-03-25 19:52:49 +01:00
randomicon00 75bd926afd address PR review feedback for unstable-book-gen 2026-03-24 21:49:44 -04: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
Jonathan Brouwer 7d43ebc519 Rollup merge of #153312 - b-naber:namespaced-crate-names-pt1, r=petrochenkov
Packages as namespaces part 1

Part 1 of https://github.com/rust-lang/rust/pull/152299

r? @petrochenkov
2026-03-23 12:14:52 +01:00
Ralf Jung 40ebcc031d target specs: rename abi to cfg_abi 2026-03-22 10:34:32 +01:00
randomicon00 b4f2c8a08e docs: parse unstable options with syn 2026-03-21 12:06:21 -04:00
b-naber e844c24122 resolve namespaced crates with open modules 2026-03-21 12:38:17 +00:00