Commit Graph

47859 Commits

Author SHA1 Message Date
Camille GILLOT
8e9552a6b5 Add a few inline directives in rustc_serialize. 2025-06-21 23:54:16 +00:00
Mark Rousskov
1f40573507 Skip collecting no-op DropGlue in vtables
Since 122662 this no longer gets used in vtables, so we're safe to fully
drop generating these empty functions. Those are eventually cleaned up
by LLVM, but it's wasteful to produce them in the first place.

This also adds a missing test for fn-ptr casts, which do still need to
generate no-op drop glue. It's possible a future optimization could
point all of those at the same drop glue (e.g., for *mut ()) rather than
for each separate type, but that would require extra work for CFI and
isn't particularly easy to do anyway.
2025-06-21 18:59:36 -04:00
Folkert de Vries
a123a36a1f centralize -Zmin-function-alignment logic 2025-06-22 00:47:10 +02:00
bors
d4e1159b8c Auto merge of #142546 - cjgillot:reachable-jump, r=compiler-errors
Only traverse reachable blocks in JumpThreading.

Fixes https://github.com/rust-lang/rust/issues/131451

We only compute loop headers for reachable blocks. We shouldn't try to perform an opt on unreachable blocks anyway.
2025-06-21 18:54:29 +00:00
Pavel Grigorenko
d86d3f3742 Port #[rustc_pub_transparent] to the new attribute system 2025-06-21 21:52:25 +03:00
David Tolnay
6729b667ce All HIR attributes are outer 2025-06-21 11:11:34 -07:00
David Tolnay
86f40acce3 Remove style() from AttributeExt trait 2025-06-21 11:09:13 -07:00
David Tolnay
e51c37c34c Add AttributeExt::doc_resolution_scope 2025-06-21 11:09:12 -07:00
Jana Dönszelmann
c693bc268a Rollup merge of #142698 - tgross35:concat-byte-cstr-diag, r=petrochenkov
Improve diagnostics for `concat_bytes!` with C string  literals

Use the same error as other invalid types for `concat_bytes!`, rather
than using `ConcatCStrLit` from `concat!`. Also add more information
with a note about why this doesn't work, and a suggestion to use a
null-terminated byte string instead.
2025-06-21 15:32:06 +02:00
Jana Dönszelmann
6ed5d48cec Rollup merge of #142690 - petrochenkov:expnoparam, r=compiler-errors
expand: Remove some unnecessary generic parameters
2025-06-21 15:32:06 +02:00
Jana Dönszelmann
cd857f4bef Rollup merge of #142539 - GrigorenkoPV:attributes/may_dangle, r=jdonszelmann
Port `#[may_dangle]` to the new attribute system

Very similar to rust-lang/rust#142498.

This is a part of rust-lang/rust#131229, so
r? `@jdonszelmann`
2025-06-21 15:32:05 +02:00
Urgau
1b5ec3fa1d Add emit_span_lint_lazy to lazily create LintDiagnostic structs 2025-06-21 13:40:05 +02:00
Urgau
8b88265133 Lazily collect NonUpperCaseGlobalSubTool diagnostics 2025-06-21 13:26:57 +02:00
Matthias Krüger
4e87031f2e Rollup merge of #142804 - zachs18:rename-layouts-to-layoutdata-in-comments, r=saethlin
Rename `LayoutS` to `LayoutData` in comments

`LayoutS` was renamed to `LayoutData`, but some comments in the compiler were not changed. This updates comments in the compiler (and one section of commented-out code in rust-analyzer) to refer to `LayoutData` instead of `LayoutS`.

cc <https://github.com/rust-lang/rust/pull/132252>, `@workingjubilee`
2025-06-21 10:53:28 +02:00
Matthias Krüger
6a49a35109 Rollup merge of #142801 - compiler-errors:gen-blocks, r=oli-obk
Use gen blocks in the compiler instead of `from_coroutine`

r? oli-obk
2025-06-21 10:53:28 +02:00
Matthias Krüger
24f797ed84 Rollup merge of #142787 - samueltardieu:diag-items-for-clippy, r=Manishearth,Urgau
Add diagnostic items for Clippy

Clippy still uses some paths to access items from the standard library. Adding the missing diagnostic items allows removing the last remaining paths.

Closes rust-lang/rust-clippy#5393
2025-06-21 10:53:26 +02:00
Matthias Krüger
504092f415 Rollup merge of #142597 - folkertdev:abi-cannot-be-called, r=workingjubilee
error on calls to ABIs that cannot be called

We recently added `extern "custom"`, which cannot be called using a rust call expression. But there are more ABIs that can't be called in that way, because the call does not semantically make sense.

More details are in https://github.com/rust-lang/rust/issues/140566#issuecomment-2846205457

r? `@workingjubilee`

try-job: x86_64-gnu-llvm-19-3
2025-06-21 10:53:25 +02:00
Trevor Gross
432c7d0235 Rollup merge of #142765 - workingjubilee:more-abimap-docs, r=compiler-errors
rustc_target: document public AbiMap-related fn and variants
2025-06-20 23:25:58 -04:00
Trevor Gross
44d50f9acf Rollup merge of #142716 - nnethercote:adjust-with_generic_param_rib, r=petrochenkov
Adjust `with_generic_param_rib`.

Currently all of its call sites construct a `LifetimeRibKind::Generics` value, which `with_generic_param_rib` then deconstructs (and panics if it's a different `LifetimeRibKind` variant).

This commit makes the code simpler and shorter: the call sites just pass in the three values and `with_generic_param_rib` constructs the `LifetimeRibKind::Generics` value from them.

r? `@petrochenkov`
2025-06-20 23:25:57 -04:00
Trevor Gross
4455d1e57b Rollup merge of #142571 - cjgillot:borrowed-classes, r=oli-obk
Reason about borrowed classes in CopyProp.

Fixes https://github.com/rust-lang/rust/issues/141122

The current implementation of `CopyProp` avoids unifying two borrowed locals, as this would change the result of address comparison.

However, the implementation was inconsistent with the general algorithm, which identifies equivalence classes of locals and then replaces all locals by a single representative of their equivalence class.

This PR fixes it by forbidding the unification of two *classes* if any of those contain a borrowed local.
2025-06-20 23:25:55 -04:00
Trevor Gross
c93fac7d64 Rollup merge of #142485 - mu001999-contrib:dead-code/adt-pattern, r=petrochenkov
Marks ADT live if it appears in pattern

Marks ADT live if it appears in pattern, it implies the construction of the ADT.
1. Then we can detect unused private ADTs impl `Default`, without special logics for `Default` and other std traits.
2. We can also remove `rustc_trivial_field_reads` on `Default`, and the logic in `should_ignore_item` (introduced by rust-lang/rust#126302).

Fixes rust-lang/rust#120770

Extracted from rust-lang/rust#128637.
r? `@petrochenkov`
2025-06-20 23:25:55 -04:00
Trevor Gross
8751016e20 Rollup merge of #142476 - dtolnay:attrbinop, r=fmease
Insert parentheses around binary operation with attribute

Fixes the bug found by `@fmease` in https://github.com/rust-lang/rust/pull/134661#pullrequestreview-2538983253.

Previously, `-Zunpretty=expanded` would expand this program as follows:

```rust
#![feature(stmt_expr_attributes)]
#![allow(unused_attributes)]

macro_rules! group {
    ($e:expr) => {
        $e
    };
}

macro_rules! extra {
    ($e:expr) => {
        #[allow()] $e
    };
}

fn main() {
    let _ = #[allow()] 1 + 1;
    let _ = group!(#[allow()] 1) + 1;
    let _ = 1 + group!(#[allow()] 1);
    let _ = extra!({ 0 }) + 1;
    let _ = extra!({ 0 } + 1);
}
```

```console
let _ = #[allow()] 1 + 1;
let _ = #[allow()] 1 + 1;
let _ = 1 + #[allow()] 1;
let _ = #[allow()] { 0 } + 1;
let _ = #[allow()] { 0 } + 1;
```

The first 4 statements are the correct expansion, but the last one is not. The attribute is supposed to apply to the entire binary operation, not only to the left operand.

After this PR, the 5th statement will expand to:

```console
let _ = #[allow()] ({ 0 } + 1);
```

In the future, as some subset of `stmt_expr_attributes` approaches stabilization, it is possible that we will need to do parenthesization for a number of additional cases depending on the outcome of https://github.com/rust-lang/rust/issues/127436. But for now, at least this PR makes the pretty-printer align with the current behavior of the parser.

r? fmease
2025-06-20 23:25:54 -04:00
Trevor Gross
7b355110df Rollup merge of #142384 - celinval:chores-rayon-mv, r=oli-obk
Bringing `rustc_rayon_core` in tree as `rustc_thread_pool`

This PR moves [`rustc_rayon_core`](https://github.com/rust-lang/rustc-rayon/tree/5fadf44/rayon-core) from commit `5fadf44` as suggested in [this zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/187679-t-compiler.2Fparallel-rustc/topic/Bringing.20.60rustc_rayon_core.60.20in.20tree). I tried to split the work into separate commits so it is easy to review. The first commit is a simple copy and paste from the fork, and subsequent changes were made to use the new crate and to ensure the new crate complies with different format and lint expectations.

**Call-out:** I was also wondering if I need to make any further changes to accommodate licensing requirements.

r? oli-obk
2025-06-20 23:25:54 -04:00
bors
15c701fbc9 Auto merge of #142794 - tgross35:rollup-iae7okj, r=tgross35
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#142331 (Add `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types.)
 - rust-lang/rust#142491 (Rework #[cold] attribute parser)
 - rust-lang/rust#142494 (Fix missing docs in `rustc_attr_parsing`)
 - rust-lang/rust#142495 (Better template for `#[repr]` attributes)
 - rust-lang/rust#142497 (Fix random failure when JS code is executed when the whole file was not read yet)
 - rust-lang/rust#142575 (Ensure copy* intrinsics also perform the static self-init checks)
 - rust-lang/rust#142650 (Refactor Translator)
 - rust-lang/rust#142713 (mbe: Refactor transcription)
 - rust-lang/rust#142755 (rustdoc: Remove `FormatRenderer::cache`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-20 23:09:48 +00:00
David Tolnay
12a855d2c8 Insert parentheses around binary operation with attribute 2025-06-20 13:49:12 -07:00
Cameron Steffen
26a6b55717 Recover from semicolon field separator 2025-06-20 15:30:09 -05:00
Pavel Grigorenko
045faa8c5c Port #[may_dangle] to the new attribute system 2025-06-20 22:39:14 +03:00
Michael Goulet
48060c97c8 Use gen blocks in the compiler instead of from_coroutine 2025-06-20 18:57:52 +00:00
Michael Goulet
582c2df9dd Collapse Analysis|Borrowck|PostBorrowckAnalysis when there are no opaques 2025-06-20 18:57:00 +00:00
Jakub Beránek
e7cc4ec8f7 Rollup merge of #142769 - jdonszelmann:remove-useless-new-method, r=tgross35
remove equivalent new method on context

Noticed the two had converged so much they literally became equivalent. So one could go hehe
2025-06-20 20:03:25 +02:00
Jakub Beránek
31663db896 Rollup merge of #142767 - nnethercote:symbol-cleanups, r=petrochenkov
Some symbol and PathRoot cleanups

I'm looking into unifying how we join and print paths. Here are some preliminary cleanups.

r? ``@petrochenkov``
2025-06-20 20:03:24 +02:00
Jakub Beránek
065a5fb225 Rollup merge of #142715 - folkertdev:fn-align-corrections, r=jdonszelmann
correct template for `#[align]` attribute

Tracking issue: https://github.com/rust-lang/rust/issues/82232
related: https://github.com/rust-lang/rust/pull/142507

I didn't fully understand what `template!` did, clearly. An empty `#[align]` attribute was still rejected later, but without this change it does get suggested in certain cases.

I've also updated some outdated references to `#[repr(align)]` on functions.

r? ``@jdonszelmann``
2025-06-20 20:03:21 +02:00
Zachary S
78c2ef2d48 compiler: Rename LayoutS to LayoutData in comments 2025-06-20 12:50:12 -05:00
Cameron Steffen
6809ec1648 Factor out seen_comma variable 2025-06-20 12:45:26 -05:00
Trevor Gross
e7a2c40919 Rollup merge of #142713 - tgross35:mbe-transcribe-refactor, r=petrochenkov
mbe: Refactor transcription

Introduce `MacroTcbCtx` that holds everything relevant to transcription. This allows for the following changes:

* Split `transcribe_sequence` and `transcribe_metavar` out of the heavily nested `transcribe`
* Split `metavar_expr_concat` out of `transcribe_metavar_expr`

This is a nonfunctional change.
2025-06-20 13:36:02 -04:00
Trevor Gross
38600a6640 Rollup merge of #142650 - camsteffen:refactor-translator, r=petrochenkov
Refactor Translator

My main motivation was to simplify the usage of `SilentEmitter` for users like rustfmt. A few refactoring opportunities arose along the way.

* Replace `Translate` trait with `Translator` struct
* Replace `Emitter: Translate` with `Emitter::translator`
* Split `SilentEmitter` into `FatalOnlyEmitter` and `SilentEmitter`
2025-06-20 13:36:01 -04:00
Trevor Gross
5d6ecf584e Rollup merge of #142575 - oli-obk:sneaky-self-init, r=RalfJung
Ensure copy* intrinsics also perform the static self-init checks

fixes rust-lang/rust#142532

r? `@RalfJung`
2025-06-20 13:36:01 -04:00
Trevor Gross
1e2ac532e4 Rollup merge of #142495 - jdonszelmann:better-repr-template, r=oli-obk
Better template for `#[repr]` attributes
2025-06-20 13:36:00 -04:00
Trevor Gross
d2a00eb65f Rollup merge of #142494 - jdonszelmann:missing-attr-parsing-docs, r=oli-obk
Fix missing docs in `rustc_attr_parsing`
2025-06-20 13:35:59 -04:00
Trevor Gross
f0374dced5 Rollup merge of #142491 - jdonszelmann:cold, r=oli-obk
Rework #[cold] attribute parser

r? `@oli-obk`
2025-06-20 13:35:59 -04:00
Folkert de Vries
a32d085680 error on calls to ABIs that cannot be called 2025-06-20 19:09:02 +02:00
Urgau
09d0a739f7 Switch non_upper_case_globals suggestions to being machine-applicable 2025-06-20 18:59:34 +02:00
Samuel Tardieu
6a9f223f00 Add diagnostic items for Clippy 2025-06-20 17:53:09 +02:00
Jana Dönszelmann
b9107a83a1 expected word diagnostic test 2025-06-20 15:06:29 +02:00
Jana Dönszelmann
de0fd27f34 cold 2025-06-20 15:06:29 +02:00
bors
9c4ff566ba Auto merge of #142316 - compiler-errors:cache-param-env, r=lcnr
[perf] Cache the canonical *instantiation* of param-envs

r? lcnr
2025-06-20 12:57:46 +00:00
Oli Scherer
cfc22cfffb Ensure copy* intrinsics also perform the static self-init checks 2025-06-20 07:30:36 +00:00
Trevor Gross
dd41c06e27 Rollup merge of #142687 - cjgillot:less-hir_crate, r=oli-obk
Reduce uses of `hir_crate`.

I tried rebasing my old incremental-HIR branch. This is a by-product, which is required if we want to get rid of `hir_crate` entirely.

The second commit is a drive-by cleanup. It can be pulled into its own PR.

r? ````@oli-obk````
2025-06-20 02:50:40 -04:00
Trevor Gross
c117ebefd2 Rollup merge of #140920 - RalfJung:target-feature-unification, r=nnethercote,WaffleLapkin
Extract some shared code from codegen backend target feature handling

There's a bunch of code duplication between the GCC and LLVM backends in target feature handling. This moves that into new shared helper functions in `rustc_codegen_ssa`.

The first two commits should be purely refactoring. I am fairly sure the LLVM-side behavior stays the same; if the GCC side deliberately diverges from this then I may have missed that. I did account for one divergence, which I do not know is deliberate or not: GCC does not seem to use the `-Ctarget-feature` flag to populate `cfg(target_feature)`. That seems odd, since the `-Ctarget-feature` flag is used to populate the return value of `global_gcc_features` which controls the target features actually used by GCC. ``@GuillaumeGomez`` ``@antoyo`` is there a reason `target_config` ignores `-Ctarget-feature` but `global_gcc_features`  does not? The second commit also cleans up a bunch of unneeded complexity added in https://github.com/rust-lang/rust/pull/135927.

The third commit extracts some shared logic out of the functions that populate `cfg(target_feature)` and the backend target feature set, respectively. This one actually has some slight functional changes:
- Before, with `-Ctarget-feature=-feat`, if there is some other feature `x` that implies `feat` we would *not* add `-x` to the backend target feature set. Now, we do. This fixes rust-lang/rust#134792.
- The logic that removes `x` from `cfg(target_feature)` in this case also changed a bit, avoiding a large number of calls to the (uncached) `sess.target.implied_target_features` (if there were a large number of positive features listed before a negative feature) but instead constructing a full inverse implication map when encountering the first negative feature. Ideally this would be done with queries but the backend target feature logic runs before `tcx` so we can't use that...
- Previously, if feature "a" implied "b" and "b" was unstable, then using `-Ctarget-feature=+a` would also emit a warning about `b`. I had to remove this since when accounting for negative implications, this emits a ton of warnings in a bunch of existing tests... I assume this was unintentional anyway.

The fourth commit increases consistency of the GCC backend with the LLVM backend.

The last commit does some further cleanup:
- Get rid of RUSTC_SPECIAL_FEATURES. It was only needed for s390x "backchain", but since LLVM 19 that is always a regular target feature so we don't need this hack any more. The hack also has various unintended side-effects so we don't want to keep it. Fixes https://github.com/rust-lang/rust/issues/142412.
- Move RUSTC_SPECIFIC_FEATURES handling into the shared parse_rust_feature_flag helper so all consumers of `-Ctarget-feature` that only care about actual target features (and not "crt-static") have it. Previously, we actually set `cfg(target_feature = "crt-static")` twice: once in the backend target feature logic, and once specifically for that one feature. IIUC, some targets are meant to ignore `-Ctarget-feature=+crt-static`, it seems like before this PR that flag still incorrectly enabled `cfg(target_feature = "crt-static")` (but I didn't test this).
- Move fixed_x18 handling together with retpoline handling.
- Forbid setting fixed_x18 as a regular target feature, even unstably. It must be set via the `-Z` flag.

``@bjorn3`` I did not touch the cranelift backend here, since AFAIK it doesn't really support target features. But if you ever do, please use the new helpers. :)

Cc ``@workingjubilee``
2025-06-20 02:50:38 -04:00
Trevor Gross
bab4ca914e Rollup merge of #138291 - jdonszelmann:optimize-attr, r=oli-obk
rewrite `optimize` attribute to use new attribute parsing infrastructure

r? ```@oli-obk```

I'm afraid we'll get quite a few of these PRs in the future. If we get a lot of trivial changes I'll start merging multiple into one PR. They should be easy to review :)

Waiting on #138165 first
2025-06-20 02:50:37 -04:00