Commit Graph

2060 Commits

Author SHA1 Message Date
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
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
Guillaume Gomez bb689c41aa Create new ParseSess::dyn_buffer_lint method 2026-03-20 17:25:50 +01:00
Stuart Cook fcc1604111 Rollup merge of #152973 - RalfJung:soft-float, r=JonathanBrouwer
remove -Csoft-float

This fixes https://github.com/rust-lang/rust/issues/129893 by removing the offending flag.

The flag has been added in pre-1.0 times (https://github.com/rust-lang/rust/pull/9617) without much discussion, probably with the intent to mirror `-msoft-float` in C compilers. It never properly mirrored clang though because it only affected the LLVM float ABI setting, not the "soft-float" target feature (the clang flag sets both). It is also blatantly unsound because it affects how float arguments are passed, making it UB to invoke parts of the standard library.

The flag got deprecated with Rust 1.83 (released November 2024), and in the year since then, nobody spoke up in rust-lang/rust#129893 to have it preserved. I think it is time to remove it. I can totally imagine us bringing back a similar flag, properly registered as a target modifier to preserve soundness, but that should come with a coherent design that works for more than one architecture (the flag only does anything on ARM).

Blocked on approval of https://github.com/rust-lang/compiler-team/issues/971.
Fixes https://github.com/rust-lang/rust/issues/154106
2026-03-20 15:33:06 +11:00
Stuart Cook 845fd53500 Rollup merge of #152909 - davidtwco:branch-protection-target-modifier, r=jackh726
sess: `-Zbranch-protection` is a target modifier

`-Zbranch-protection` only makes sense if the entire crate graph has the option set, otherwise the security properties that branch protection provides won't be effective - hence a target modifier. This flag is unstable so I don't think this warrants an MCP.
2026-03-20 15:33:04 +11:00
Ralf Jung e72674e78c remove -Csoft-float 2026-03-19 21:59:10 +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
Stuart Cook 44c87292ac Rollup merge of #153778 - bjorn3:driver_cleanups, r=TaKO8Ki
Couple of driver interface improvements

* Pass Session to `make_codegen_backend` callback. This simplifies some code in miri.
* Move env/file_depinfo from ParseSess to Session. There is no reason it has to be in ParseSess rather than Session.
* Rename hash_untracked_state to track_state to indicate that it isn't just used for hashing state, but also for adding env vars and files to be tracked through the dep info file.
2026-03-18 15:07:31 +11:00
Alice Ryhl ec03f4ef29 Adjust lifetime markers comment 2026-03-17 20:24:05 +00:00
Alice Ryhl a197752e88 Add kernel-hwaddress sanitizer
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2026-03-17 20:23:59 +00:00
Mateusz Mikuła f3654324e6 Set symbol size in raw-dylib 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
bors 1e2183119f Auto merge of #153166 - reddevilmidzy:codegen-tidy, r=lcnr
Tidy: disallow TODO in other in-tree projects

Fixes: https://github.com/rust-lang/rust/issues/152280
MCP: https://github.com/rust-lang/compiler-team/issues/963

TODO

* [x] Add ci check to `cg_clif`: https://github.com/rust-lang/rustc_codegen_cranelift/pull/1632
* [x] Add ci check to `cg_gcc`: https://github.com/rust-lang/rustc_codegen_gcc/pull/861

r? lcnr
2026-03-15 20:38:45 +00:00
Kivooeo 919fd6b64c add new unstable flag for minimal recursion 2026-03-12 20:48:26 +00:00
bjorn3 2199d07e2b Move env/file_depinfo from ParseSess to Session 2026-03-12 15:35:27 +00:00
David Wood cca28656e5 sess: -Zbranch-protection is a target modifier
`-Zbranch-protection` only makes sense if the entire crate graph has
the option set, otherwise the security properties that branch protection
provides won't be effective. This flag is unstable so I don't think this
warrants an MCP.
2026-03-10 12:37:16 +00:00
Redddy 50db919f5d Change TODO in compiler to FIXME 2026-03-07 12:12:33 +00:00
bjorn3 15e839e006 Fallback to fat LTO for -Clto=thin in cg_gcc
Fallback to no LTO doesn't work in practice as Cargo asks rustc to
produce LTO-only rlibs with -Clinker-plugin-lto without providing any
indication if they will be used for thin or fat LTO, so we can't disable
-Clinker-plugin-lto for ThinLTO when using cg_gcc.
2026-03-06 15:22:17 +00:00
Jonathan Brouwer 1c44dbd580 Rollup merge of #152164 - mu001999-contrib:lint/unused_features, r=JonathanBrouwer
Lint unused features

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152164)*

Fixes rust-lang/rust#44232
Fixes rust-lang/rust#151752

---

This PR records used features through query side effect, then reports unsued features finally.
2026-03-04 19:30:36 +01:00
Stuart Cook c4f239ec6a Rollup merge of #153352 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Migration of `LintDiagnostic` - part 6

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

r? @JonathanBrouwer
2026-03-04 11:54:11 +11:00
Guillaume Gomez b5ff567193 Migrate more types from LintDiagnostic to Diagnostic 2026-03-03 21:57:02 +01:00
Daniel Scherzer 158ac1a10b Comments and docs: add missing periods to "ie."
"i.e." is short for the Latin "id est" and thus both letters should be followed
by periods.
2026-03-02 18:11:13 -08:00
mu001999 7f3bbe371f Report unused features 2026-03-02 09:38:03 +08:00
bors e7d90c695a Auto merge of #153131 - Kobzol:filesearch-opt, r=nnethercote
Optimize dependency file search

I tried to look into the slowdown reported in https://github.com/rust-lang/cargo/issues/16665.

I created a Rust hello world program, and used this Python script to create a directory containing 200k files:
```python
from pathlib import Path

dir = Path("deps")
dir.mkdir(parents=True, exist_ok=True)
for i in range(200000):
    path = dir / f"file{i:07}.o"
    with open(path, "w") as f:
        f.write("\n")
```

Then I tried to do various small microoptimalizations and simplifications to the code that iterates the search directories. Each individual commit improved performance, with the third one having the biggest effect.

Here are the results on `main` vs the last commit with the stage1 compiler on Linux, using `hyperfine "rustc +stage1 src/main.rs -L deps" -r 30` (there's IO involved, so it's good to let it run for a while):

```bash
Benchmark 1: rustc +stage1 src/main.rs -L deps
  Time (mean ± σ):     299.4 ms ±   2.7 ms    [User: 161.9 ms, System: 144.9 ms]
  Range (min … max):   294.8 ms … 307.1 ms    30 runs

Benchmark 1: rustc +stage1 src/main.rs -L deps
  Time (mean ± σ):     208.1 ms ±   4.5 ms    [User: 87.3 ms, System: 128.7 ms]
  Range (min … max):   202.4 ms … 219.6 ms    30 runs
```

Would be cool if someone could try this on macOS (maybe @ehuss - not sure if you have macOS or you only commented about its behavior on the Cargo issue :) ).

I also tried to prefilter the paths (not in this PR); right now we load everything and then we filter files with given prefixes, that's wasteful. Filtering just files starting with `lib` would get us down to ~150ms here. (The baseline without `-L` is ~80ms on my PC). The rest of the 70ms is essentially allocations from iterating the directory entries and sorting. That would be very hard to change - iterating the directory entries (de)allocates a lot of intermediate paths :( We'd have to implement the iteration by hand with either arena allocation, or at least some better management of memory.

r? @nnethercote
2026-03-01 23:00:45 +00:00
Zalathar 882ae150e9 Work around a false err.emit(); type error in rust-analyzer 2026-02-27 13:06:14 +11:00