1947 Commits

Author SHA1 Message Date
mu001999
fc822f8c85 Emit error when using path-segment keyword as cfg pred 2025-11-21 18:48:04 +08:00
Zalathar
9c7e7ccd25 Exhaustively specify names and stability of --print values 2025-11-21 11:35:07 +11:00
Zalathar
c81d22d506 Extract module rustc_session::config::print_request 2025-11-21 11:29:10 +11:00
David Wood
ff00110543
sess: default to v0 symbol mangling
Rust's current mangling scheme depends on compiler internals; loses
information about generic parameters (and other things) which makes for
a worse experience when using external tools that need to interact with
Rust symbol names; is inconsistent; and can contain `.` characters
which aren't universally supported. Therefore, Rust has defined its own
symbol mangling scheme which is defined in terms of the Rust language,
not the compiler implementation; encodes information about generic
parameters in a reversible way; has a consistent definition; and
generates symbols that only use the characters `A-Z`, `a-z`, `0-9`, and
`_`.

Support for the new Rust symbol mangling scheme has been added to
upstream tools that will need to interact with Rust symbols (e.g.
debuggers).

This commit changes the default symbol mangling scheme from the legacy
scheme to the new Rust mangling scheme.

Signed-off-by: David Wood <david.wood@huawei.com>
2025-11-19 11:55:09 +00:00
Stuart Cook
e34ef247cc
Rollup merge of #148855 - ZuseZ4:autodiff-lto-error, r=bjorn3
Error if an autodiff user does not set lto=fat

Based on your feedback, I started to provide a nice error message for a lack of `lto=fat`, instead of us forcing it.

In a next step, we should replace  `RUSTFLAGS="-Zautodiff=Enable"` with another Cargo.toml setting, as discussed here: https://github.com/rust-lang/rust/issues/147487#issuecomment-3446558644

As another improvement, we should also figure out why rlib builds do not properly obey the fat=lto setting.

```````@bjorn3```````
2025-11-17 16:41:02 +11:00
Manuel Drehwald
63f4b36406 provide an error if an autodiff user does not set in their Cargo.toml 2025-11-11 23:44:06 -05:00
Tamir Duberstein
fcf6809b05
rustc_target: introduce Os
Improve type safety by using an enum rather than strings.
2025-11-11 18:55:40 -05:00
Tamir Duberstein
ddd7596400
rustc_target: introduce Env
Improve type safety by using an enum rather than strings.
2025-11-11 18:34:47 -05:00
Tamir Duberstein
86c74a4d16
rustc_target: introduce Abi
Improve type safety by using an enum rather than strings.
2025-11-11 18:22:38 -05:00
bors
2636cb4c13 Auto merge of #148818 - Zalathar:rollup-4vujcg0, r=Zalathar
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#148694 (std: support `RwLock` and thread parking on TEEOS)
 - rust-lang/rust#148712 (Port `cfg_select!` to the new attribute parsing system)
 - rust-lang/rust#148760 (rustc_target: hide TargetOptions::vendor)
 - rust-lang/rust#148771 (IAT: Reinstate early bailout)
 - rust-lang/rust#148775 (Fix a typo in the documentation for the strict_shr function)
 - rust-lang/rust#148779 (Implement DynSend and DynSync for std::panic::Location.)
 - rust-lang/rust#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`)
 - rust-lang/rust#148783 (add test for assoc type norm wf check)
 - rust-lang/rust#148785 (Replace `master` branch references with `main`)
 - rust-lang/rust#148791 (fix "is_closure_like" doc comment)
 - rust-lang/rust#148792 (Prefer to use file.stable_id over file.name from source map)
 - rust-lang/rust#148805 (rustc-dev-guide subtree update)
 - rust-lang/rust#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-11 13:30:50 +00:00
Guillaume Gomez
40be1db6b8 Fix new function_casts_as_integer lint errors in core, std, panic_unwind and compiler crates 2025-11-10 16:38:28 +01:00
Guillaume Gomez
a23b8c48a5 Add new function_casts_as_integer lint 2025-11-10 16:38:27 +01:00
Tamir Duberstein
c5f2eb61a1
rustc_target: hide TargetOptions::vendor 2025-11-09 17:43:36 -05:00
bors
87f9dcd5e2 Auto merge of #147935 - luca3s:add-rtsan, r=petrochenkov
Add LLVM realtime sanitizer

This is a new attempt at adding the [LLVM real-time sanitizer](https://clang.llvm.org/docs/RealtimeSanitizer.html) to rust.

Previously this was attempted in https://github.com/rust-lang/rfcs/pull/3766.

Since then the `sanitize` attribute was introduced in https://github.com/rust-lang/rust/pull/142681 and it is a lot more flexible than the old `no_santize` attribute. This allows adding real-time sanitizer without the need for a new attribute, like it was proposed in the RFC. Because i only add a new value to a existing command line flag and to a attribute i don't think an MCP is necessary.

Currently real-time santizer is usable in rust code with the [rtsan-standalone](https://crates.io/crates/rtsan-standalone) crate. This downloads or builds the sanitizer runtime and then links it into the rust binary.

The first commit adds support for more detailed sanitizer information.
The second commit then actually adds real-time sanitizer.
The third adds a warning against using real-time sanitizer with async functions, cloures and blocks because it doesn't behave as expected when used with async functions. I am not sure if this is actually wanted, so i kept it in a seperate commit.
The fourth commit adds the documentation for real-time sanitizer.
2025-11-08 12:24:15 +00:00
Jeremy Fitzhardinge
5f29f11a4d Add -Zannotate-moves for profiler visibility of move/copy operations
This implements a new unstable compiler flag `-Zannotate-moves` that makes
move and copy operations visible in profilers by creating synthetic debug
information. This is achieved with zero runtime cost by manipulating debug
info scopes to make moves/copies appear as calls to `compiler_move<T, SIZE>`
and `compiler_copy<T, SIZE>` marker functions in profiling tools.

This allows developers to identify expensive move/copy operations in their
code using standard profiling tools, without requiring specialized tooling
or runtime instrumentation.

The implementation works at codegen time. When processing MIR operands
(`Operand::Move` and `Operand::Copy`), the codegen creates an `OperandRef`
with an optional `move_annotation` field containing an `Instance` of the
appropriate profiling marker function. When storing the operand,
`store_with_annotation()` wraps the store operation in a synthetic debug
scope that makes it appear inlined from the marker.

Two marker functions (`compiler_move` and `compiler_copy`) are defined
in `library/core/src/profiling.rs`. These are never actually called -
they exist solely as debug info anchors.

Operations are only annotated if the type:
   - Meets the size threshold (default: 65 bytes, configurable via
     `-Zannotate-moves=SIZE`)
   - Has a non-scalar backend representation (scalars use registers,
     not memcpy)

This has a very small size impact on object file size. With the default
limit it's well under 0.1%, and even with a very small limit of 8 bytes
it's still ~1.5%. This could be enabled by default.
2025-11-06 15:39:45 -08:00
Lucas Baumann
d198633b95 add realtime sanitizer 2025-11-06 13:20:12 +01:00
bors
c5e283b0d2 Auto merge of #148188 - Muscraft:annotate-snippets-default-on-nightly, r=estebank
feat: Use annotate-snippets by default on nightly

This PR switches the default renderer to use `annotate-snippets` on nightly, but does not affect stable. This is part of the ongoing effort to use `annotate-snippets` to render all diagnostics.

[MCP](https://github.com/rust-lang/compiler-team/issues/937)

Note: This contains the test change from rust-lang/rust#148004, without the change to the default emitter.

rust-lang/rust#59346
rust-lang/rust-project-goals#123

r? `@davidtwco`
2025-11-06 11:45:06 +00:00
Stuart Cook
efdc8aca3e
Rollup merge of #147043 - ilovepi:default-sanitizers, r=petrochenkov
Add default sanitizers to TargetOptions

Some sanitizers are part of a system's ABI, like the shadow call stack on Aarch64 and RISC-V Fuchsia. Typically ABI options have other spellings, but LLVM has, for historical reasons, marked this as a sanitizer instead of an alternate ABI option. As a result, Fuchsia targets may not be compiled against the correct ABI unless this option is set. This hasn't caused correctness problems, since the backend reserves the SCS register, and thus preserves its value. But this is an issue for unwinding, as the SCS will not be an array of PCs describing the call complete call chain, and will have gaps from callers that don't use the correct ABI.

In the long term, I'd like to see all the sanitizer configs that all frontends copy from clang moved into llvm's libFrontend, and exposed so that frontend consumers can use a small set of simple APIs to use sanitizers in a consistent way across the LLVM ecosystem, but that work is not yet ready today.
2025-11-06 14:07:16 +11:00
Scott Schafer
9243928c6c
feat: Use annotate-snippets by default on nightly 2025-11-05 09:01:07 -07:00
Scott Schafer
9cb7deb0b5
refactor: Make short a field on HumanReadableErrorType varinants 2025-11-05 09:01:07 -07:00
Scott Schafer
4748d92a95
feat: Always use annotate-snippets for Unicode output 2025-11-05 09:01:07 -07:00
Scott Schafer
a75bd03fb9
fix: Respect HumanReadableErrorType::AnnotateSnippet 2025-11-05 09:01:07 -07:00
Tamir Duberstein
26b0560b6d
rustc_target: allow unenumerated architectures 2025-11-04 21:28:28 -05:00
Tamir Duberstein
0c8533d690
compiler: intern architecture at compile time 2025-11-04 21:27:23 -05:00
Tamir Duberstein
270e49b307
rustc_target: introduce Arch
Improve type safety by using an enum rather than strings.
2025-11-04 21:27:22 -05:00
Paul Kirth
e207006ad3 Add default sanitizers to TargetOptions
Some sanitizers are part of a system's ABI, like the shadow call stack
on Aarch64 and RISC-V Fuchsia. Typically ABI options have other
spellings, but LLVM has, for historical reasons, marked this as a
sanitizer instead of an alternate ABI option. As a result, Fuchsia
targets may not be compiled against the correct ABI unless this option
is set. This hasn't caused correctness problems, since the backend
reserves the SCS register, and thus preserves its value. But this is an
issue for unwinding, as the SCS will not be an array of PCs describing
the call complete call chain, and will have gaps from callers that don't
use the correct ABI.

In the long term, I'd like to see all the sanitizer configs that all
frontends copy from clang moved into llvm's libFrontend, and exposed so
that frontend consumers can use a small set of simple APIs to use
sanitizers in a consistent way across the LLVM ecosystem, but that work
is not yet ready today.
2025-11-03 17:36:32 -06:00
Paul Murphy
bb9d800b78 Stabilize -Zjump-tables=<bool> into -Cjump-table=<bool> 2025-11-03 08:12:16 -06:00
Paul Murphy
4959d18a97 Rename -Zno-jump-tables to -Zjump-tables=<bool>
Both gcc and llvm accept -fjump-tables as well as -fno-jump-tables. For
consistency, allow rustc to accept -Zjump-tables=yes too.
2025-11-03 08:12:13 -06:00
bjorn3
3d035505a3 Better warning message for crate type unsupported by codegen backend 2025-11-02 12:33:38 +00:00
bors
fca2e941f8 Auto merge of #148356 - matthiaskrgr:rollup-mh4l2yi, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#135602 (Tweak output of missing lifetime on associated type)
 - rust-lang/rust#139751 (Implement pin-project in pattern matching for `&pin mut|const T`)
 - rust-lang/rust#142682 (Update bundled musl to 1.2.5)
 - rust-lang/rust#148171 (Simplify code to generate line numbers in highlight)
 - rust-lang/rust#148263 (Unpin `libc` and `rustix` in `compiler` and `rustbook`)
 - rust-lang/rust#148301 ([rustdoc search] Include extern crates when filtering on `import`)
 - rust-lang/rust#148330 (Don't require dlltool with the dummy backend on MinGW)
 - rust-lang/rust#148338 (cleanup: upstream dropped amx-transpose functionality)
 - rust-lang/rust#148340 (Clippy subtree update)
 - rust-lang/rust#148343 (`nonpoison::Condvar` should take `MutexGuard` by reference)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-01 16:44:42 +00:00
clubby789
c169ea03ab Unpin libc in compiler and rustbook 2025-10-31 19:13:45 +00:00
Matthias Krüger
3d671c0d54
Rollup merge of #148103 - Zalathar:compression, r=wesleywiser
cg_llvm: Pass `debuginfo_compression` through FFI as an enum

There are only three possible values, making an enum more appropriate.

This avoids string allocation on the Rust side, and avoids ad-hoc `!strcmp` to convert back to an enum on the C++ side.
2025-10-31 18:41:51 +01:00
Matthias Krüger
6a7bcec8da
Rollup merge of #148177 - bjorn3:codegen_backend_crate_types, r=WaffleLapkin
Allow codegen backends to indicate which crate types they support

This way cargo will drop the unsupported crate types for crates that
specify multiple crate types.

This is a prerequisite for https://github.com/rust-lang/miri/pull/4648.
2025-10-28 17:49:29 +01:00
Stuart Cook
a383fe8f20
Rollup merge of #148139 - Urgau:add-coverage-scope, r=Zalathar
Add `coverage` scope for controlling paths in code coverage

This PR adds a `coverage` scope (for `-Zremap-path-scope`) for controlling if the paths that ends up in code coverage output should be remapped or not.

Currently code coverage use the `macro` scope which is not a appropriate scope for them.

Found during the stabilization of `-Zremap-path-scope` https://github.com/rust-lang/rust/pull/147611#issuecomment-3396210043 and was asked to be in a separate PR in https://github.com/rust-lang/rust/pull/147611#issuecomment-3448455252.

r? compiler
2025-10-28 20:39:37 +11:00
bjorn3
b443a59ba8 Allow codegen backends to indicate which crate types they support
This way cargo will drop the unsupported crate types for crates that
specify multiple crate types.
2025-10-27 16:24:33 +00:00
Urgau
94c893ee2e Add coverage scope for controlling paths in code coverage 2025-10-27 12:54:24 +01:00
Zalathar
73b734bf63 Pass debuginfo_compression through FFI as an enum 2025-10-25 23:58:19 +11:00
Matthias Krüger
141c91091c
Rollup merge of #148007 - Muscraft:annotate-snippets, r=jdonszelmann
chore: Update to the latest annotate-snippets

This PR updates `annotate-snippets` to the latest version and updates the adapter code[^1] so that `AnnotateSnippetEmitter`'s output matches `HumanEmitter`'s output. If anyone would like to see the differences[^2] between `AnnotateSnippetEmitter` and `HumanEmitter`, [I have a branch](https://github.com/Muscraft/rust/tree/annotate-snippets-default-renderer) where `AnnotateSnippetEmitter` is used in place of `HumanEmitter`.

[^1]: A lot of the adapter code changes are based on code for `HumanEmitter`.
[^2]: Some of the test differences will go away when rust-lang/rust#148001 and rust-lang/rust#148004 are merged.
2025-10-25 12:57:39 +02:00
Scott Schafer
354b9779bf
chore: Update to the latest annotate-snippets 2025-10-24 12:50:19 -06:00
Pierre Tardy
c6acffeb78 fix panic when rustc tries to reduce intermediate filenames length with multi byte chars
The issue cannot be reproduced with the former testcase of creating external crates because
rust refuses to use "external crate 28_找出字符串中第一个匹配项的下标"
because it is not a valid indentifier (starts with number, and contain non ascii chars)

But still using 28_找出字符串中第一个匹配项的下标.rs as a filename is accepted by previous rustc releases
So we consider it valid, and add an integration test for it to catch any regression on other code related to non ascii filenames.
2025-10-24 16:20:29 +02:00
Stuart Cook
b397b6b5b7
Rollup merge of #147762 - weihanglo:rustdoc-depinfo-stdout, r=fmease
feat(rustdoc): `--emit=depinfo` output to stdout via `-`

rustdoc's `--emit=depinfo` flag now supports using `-` to write the output to stdout,
aligning with rustc's behavior.

This will fix <https://github.com/rust-lang/rust/issues/147649>.

### How to review

* The first commit demonstrates that `rustdoc --emit=depinfo=-` hasn't yet supported emitting to stdout.
* The second implements it and the diff shows how the behavior changes.
2025-10-23 12:06:32 +11:00
bors
96fe3c31c2 Auto merge of #147022 - Zalathar:no-args, r=wesleywiser
Remove current code for embedding command-line args in PDB

The compiler currently has code that will obtain a list of quoted command-line arguments, and pass it through to TargetMachine creation, so that the command-line args can be embedded in PDB output.

This PR removes that code, due to subtle concerns that might not have been apparent when it was originally added.

---

Those concerns include:
- The entire command-line quoting process is repeated every time a target-machine-factory is created. In incremental builds this typically occurs 500+ times, instead of happening only once. The repeated quoting constitutes a large chunk of instructions executed in the `large-workspace` benchmark.
  - See https://github.com/rust-lang/rust/pull/146804#issuecomment-3317322958 for an example of the perf consequences of skipping all that work.
  - This overhead occurs even when building for targets or configurations that don't emit PDB output.
- Command-line arguments are obtained in a way that completely bypasses the query system, which is a problem for the integrity of incremental compilation.
  - Fixing this alone is likely to inhibit incremental rebuilds for most or all CGUs, even in builds that don't emit PDB output.
- Command-line arguments and the executable path are obtained in a way that completely bypasses the compiler's path-remapping system, which is a reproducibility hazard.
  - https://github.com/rust-lang/rust/issues/128842

---

Relevant PRs:
- https://github.com/rust-lang/rust/pull/113492
- https://github.com/rust-lang/rust/pull/130446
- https://github.com/rust-lang/rust/pull/131805
- https://github.com/rust-lang/rust/pull/146700
- https://github.com/rust-lang/rust/pull/146973

Zulip thread:
- https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Some.20PDB.20info.20bypasses.20the.20query.20system.20and.20path.20remapping/with/541432211

---

According to rust-lang/rust#96475, one of the big motivations for embedding the command-line arguments was to enable tools like Live++. [It appears that Live++ doesn't actually support Rust yet](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/embeded.20compiler.20args.20and.20--remap-path-prefix/near/523800010), so it's possible that there aren't any existing workflows for this removal to break.

In the future, there could be a case for reintroducing some or all of this functionality, guarded behind an opt-in flag so that it doesn't cause problems for other users. But as it stands, the current implementation puts a disproportionate burden on other users and on compiler maintainers.
2025-10-22 00:21:08 +00:00
Zalathar
98c95c966b Remove current code for embedding command-line args in PDB 2025-10-18 12:24:40 +11:00
Osama Abdelkader
e67d502d4e Fix autodiff incorrectly applying fat-lto to proc-macro crates
When -Z autodiff=Enable is used, the compiler automatically enables
fat-lto for all crates. However, proc-macro crates cannot use fat-lto
without the -Zdylib-lto flag, causing compilation errors.

This commit modifies the lto() method in Session to exclude proc-macro
crates from fat-lto when autodiff is enabled, while preserving the
existing behavior for all other crate types.

The fix ensures that:
- Non-proc-macro crates still get fat-lto when autodiff is enabled
- Proc-macro crates are excluded from fat-lto when autodiff is enabled
- Existing autodiff functionality remains unchanged for regular crates

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
2025-10-17 16:52:55 +03:00
Weihang Lo
e7130d3085
feat(rustdoc): --emit=depinfo output to stdout via -
rustdoc's `--emit=depinfo` flag now supports using `-`
to write the output to stdout.
2025-10-16 07:47:02 -04:00
usamoi
21dd997aec support link modifier as-needed for raw-dylib-elf 2025-10-06 08:56:40 +08:00
bors
f437c86ef8 Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Fix backtraces with `-C panic=abort` on linux; emit unwind tables by default

The linux backtrace unwinder relies on unwind tables to work properly, and generating and printing a backtrace is done by for example the default panic hook.

Begin emitting unwind tables by default again with `-C panic=abort` (see history below) so that backtraces work.

Closes https://github.com/rust-lang/rust/issues/81902 which is **regression-from-stable-to-stable**
Closes https://github.com/rust-lang/rust/issues/94815

### History

Backtraces with `-C panic=abort` used to work in Rust 1.22 but broke in Rust 1.23, because in 1.23 we stopped emitting unwind tables with `-C panic=abort` (see https://github.com/rust-lang/rust/pull/45031 and https://github.com/rust-lang/rust/issues/81902#issuecomment-3046487084).

In 1.45 a workaround in the form of `-C force-unwind-tables=yes` was added (see https://github.com/rust-lang/rust/pull/69984).

`-C panic=abort` was added in [Rust 1.10](https://blog.rust-lang.org/2016/07/07/Rust-1.10/#what-s-in-1-10-stable) and the motivation was binary size and compile time. But given how confusing that behavior has turned out to be, it is better to make binary size optimization opt-in with `-C force-unwind-tables=no` rather than default since the current default breaks backtraces.

Besides, if binary size is a primary concern, there are many other tricks that can be used that has a higher impact.

# Release Note Entry Draft:

## Compatibility Notes

* [Fix backtraces with `-C panic=abort` on Linux by generating unwind tables by default](https://github.com/rust-lang/rust/pull/143613). Build with `-C force-unwind-tables=no` to keep omitting unwind tables.

try-job: aarch64-apple
try-job: armhf-gnu
try-job: aarch64-msvc-1
2025-10-03 15:02:37 +00:00
Martin Nordholts
fe66eaa67a Fix backtraces with -C panic=abort on linux; emit unwind tables by default
The linux backtrace unwinder relies on unwind tables to work properly,
and generating and printing a backtrace is done by for example the
default panic hook.

Begin emitting unwind tables by default again with `-C panic=abort` (see
history below) so that backtraces work.

History
=======

Backtraces with `-C panic=abort` used to work in Rust 1.22 but broke in
Rust 1.23, because in 1.23 we stopped emitting unwind tables with `-C
panic=abort` (see 24cc38e3b00).

In 1.45 (see cda994633ee) a workaround in the form
of `-C force-unwind-tables=yes` was added.

`-C panic=abort` was added in [Rust
1.10](https://blog.rust-lang.org/2016/07/07/Rust-1.10/#what-s-in-1-10-stable)
and the motivation was binary size and compile time. But given how
confusing that behavior has turned out to be, it is better to make
binary size optimization opt-in with `-C force-unwind-tables=no` rather
than default since the current default breaks backtraces.

Besides, if binary size is a primary concern, there are many other
tricks that can be used that has a higher impact.
2025-10-02 19:46:41 +02:00
bors
dc2c3564d2 Auto merge of #146376 - durin42:dwo-specify-path, r=davidtwco
debuginfo: add an unstable flag to write split DWARF to an explicit directory

Bazel requires knowledge of outputs from actions at analysis time, including file or directory name. In order to work around the lack of predictable output name for dwo files, we group the dwo files in a subdirectory of --out-dir as a post-processing step before returning control to bazel. Unfortunately some debugging workflows rely on directly opening the dwo file rather than loading the merged dwp file, and our trick of moving the files breaks those users. We can't just hardlink the file or copy it, because with remote build execution we wouldn't end up with the un-moved file copied back to the developer's workstation. As a fix, we add this unstable flag that causes dwo files to be written to a build-system-controllable location, which then lets bazel hoover up the dwo files, but the objects also have the correct path for the dwo files.

r? `@davidtwco`
2025-09-29 15:06:55 +00:00
Stuart Cook
6c40c16d83
Rollup merge of #147116 - workingjubilee:remove-tdl-abialign, r=Zalathar
compiler: remove AbiAlign inside TargetDataLayout

AbiAlign is a thin wrapper around Align, extant mostly because we used to track a separate quasi-notion of alignment that was never a real notion of alignment and removing all of it at once was too churny. This PR maintains AbiAlign usage in public API and most of the compiler, but direct access of these fields for TargetDataLayout is now in terms of Align only.
2025-09-29 15:44:54 +10:00