Commit Graph

48769 Commits

Author SHA1 Message Date
Stuart Cook
f8370285cf Rollup merge of #144560 - Zalathar:auto-derived, r=compiler-errors
coverage: Treat `#[automatically_derived]` as `#[coverage(off)]`

One of the contributing factors behind https://github.com/rust-lang/rust/issues/141577#issuecomment-3120667286 was the presence of derive-macro-generated code containing nested closures.

Coverage instrumentation already has a heuristic for skipping code marked with `#[automatically_derived]` (rust-lang/rust#120185), because derived code is usually not worth instrumenting, and also has a tendency to trigger vexing edge-case bugs in coverage instrumentation or coverage codegen.

However, the existing heuristic only applied to the associated items directly within an auto-derived impl block, and had no effect on closures or nested items within those associated items.

This PR therefore extends the search for `#[coverage(..)]` attributes to also treat `#[automatically_derived]` as an implied `#[coverage(off)]` for the purposes of coverage instrumentation.

---

This change doesn’t rule out an entire category of bugs, because it only affects code that actually uses the auto-derived attribute. But it should reduce the overall chance of edge-case macro span bugs being observed in the wild.
2025-07-29 23:50:35 +10:00
Stuart Cook
f5c573662e Rollup merge of #144626 - RalfJung:cc-pin-comment, r=lqd
cc dependencies: clarify comment

This caused confusion in https://github.com/rust-lang/rust/pull/144570

r? ``@jieyouxu``
2025-07-29 20:19:54 +10:00
Stuart Cook
15ddf9c7b3 Rollup merge of #144609 - Muscraft:right-align, r=compiler-errors
feat: Right align line numbers

As part of my work on getting `annotate-snipptes` to be used as `rustc`'s renderer, I realized that `rustc` left-aligned line numbers, while `annotate-snippets` right-aligned them. This PR switches `rustc` to right-align the line numbers, matching `annotate-snippets`. In practice, this change isn't very noticeable in day-to-day output, as it only shows up when a diagnostic span contains line numbers with different lengths (9->10, 99->100, 999->1000, etc.).

`rustc`
```
error[E0412]: cannot find type `F` in this scope
  --> $DIR/ui-testing-optout.rs:92:10
   |
4  | type A = B;
   | ----------- similarly named type alias `A` defined here
...
92 | type E = F;
   |          ^ help: a type alias with a similar name exists: `A`
```
`annotate-snippets`
```
error[E0412]: cannot find type `F` in this scope
  --> $DIR/ui-testing-optout.rs:92:10
   |
 4 | type A = B;
   | ----------- similarly named type alias `A` defined here
...
92 | type E = F;
   |          ^ help: a type alias with a similar name exists: `A`
```

r? ``@compiler-errors``
2025-07-29 20:19:53 +10:00
Stuart Cook
dbcf168568 Rollup merge of #144451 - ShoyuVanilla:loop-match-upvar, r=oli-obk
fix: Reject upvar scrutinees for `loop_match`

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

I think we should reject upvars as they are not locals but somewhat like field access
2025-07-29 20:19:49 +10:00
Stuart Cook
b3962e8811 Rollup merge of #144407 - godzie44:godzie44/fix_dwarf_inconsistency, r=wesleywiser
fix(debuginfo): disable overflow check for recursive non-enum types

Commit b10edb4 introduce an overflow check when generating debuginfo for expanding recursive types. While this check works correctly for enums, it can incorrectly prune valid debug information for structures.

For example see rust-lang/rust#143241 (https://github.com/rust-lang/rust/issues/143241#issuecomment-3073721477). Furthermore, for structures such check does not make sense, since structures with recursively expanding types simply will not compile (there is a `hir_analysis_recursive_generic_parameter` for that).

closes rust-lang/rust#143241
2025-07-29 20:19:49 +10:00
Zalathar
682f744f89 coverage: Treat #[automatically_derived] as #[coverage(off)] 2025-07-29 19:56:31 +10:00
Zalathar
b4d0c91635 coverage: Rename CoverageStatus to CoverageAttrKind
This patch also prepares the affected code in `coverage_attr_on` for some
subsequent changes.
2025-07-29 19:55:54 +10:00
Ralf Jung
e532080507 cc dependencies: clarify comment 2025-07-29 09:22:24 +02:00
Stuart Cook
e08a308561 Rollup merge of #144578 - FractalFir:m68k_fix, r=compiler-errors
Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments.

The compiler relies on `hir::Lifetime` being aligned to at least 4 bytes(for the purposes of pointer tagging).

However, on some systems(like m68k) with lower alignment requirements(eg. usize / u32 aligned to 2 bytes),`hir::Lifetime` will be aligned to only 2 bytes.

This causes the compilation to fail on those systems - a const assert in the compiler fails.

This PR makes the aligement requriement of hir::Lifetime explict. This has no effect on platforms where that already is the case(repr align can only raise alignment), but ensures the alignment will stay correct no matter what.
2025-07-29 16:16:45 +10:00
Stuart Cook
fce74bacf3 Rollup merge of #144573 - BoxyUwU:patkind_constant_ptr_docs, r=lcnr
Raw Pointers are Constant PatKinds too

raw pointers can be matched on with a const pattern:
```rust
const FOO: *const u8 = core::ptr::null();

fn foo(a: *const u8) {
  match a {
    FOO => (),
    _ => todo!(),
  }
}
```
as far as I can tell this is represented with a `PatKind::Constant`: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L333-L337
2025-07-29 16:16:44 +10:00
bors
cb6785f73d Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt
Remove `[T]::array_chunks(_mut)`

Since libs-api is proposing as much in https://github.com/rust-lang/rust/issues/74985#issuecomment-3024465102

Closes rust-lang/rust#74985
Closes rust-lang/rust#76354

try-job: dist-various-1
try-job: dist-various-2
2025-07-29 02:27:52 +00:00
Scott Schafer
aa9767290e feat: Right align line numbers 2025-07-28 16:32:11 -06:00
bors
e3514bde96 Auto merge of #144377 - camsteffen:simplify-impl-of-method, r=fee1-dead
Rename impl_of_method and trait_of_item

This PR used to tweak the implementation of impl_of_method, but that introduced a perf regression.

Rename impl_of_method and trait_of_item to impl_of_assoc and trait_of_assoc respectively. This reflects how the two functions are closely related. And it reflects the behavior more accurately as the functions check whether the input is an associated item.
2025-07-28 16:38:15 +00:00
Cameron Steffen
cdcfdd1a1b Tweak docs 2025-07-28 09:54:55 -05:00
Cameron Steffen
b43164cef6 Rename impl_of_method -> impl_of_assoc 2025-07-28 09:54:53 -05:00
Cameron Steffen
172af038a7 Rename trait_of_item -> trait_of_assoc 2025-07-28 09:53:50 -05:00
Cameron Steffen
0d7abc8df0 Introduce assoc_parent 2025-07-28 09:53:50 -05:00
Cameron Steffen
96aca2b442 Remove TraitAlias from trait_of_item
This is dead code.
2025-07-28 09:53:50 -05:00
Shoyu Vanilla
d87b4f2c77 fix: Reject upvar scrutinees for loop_match 2025-07-28 22:24:58 +09:00
bors
9ba00e0f9e Auto merge of #144543 - scottmcm:more-sroa, r=cjgillot
Allow more MIR SROA

This removes some guards on SROA that are no longer needed:
- With https://github.com/rust-lang/compiler-team/issues/838 it no longer needs to check for SIMD
- With https://github.com/rust-lang/compiler-team/issues/807 it no longer needs to check for niches
  - This means that `Wrapper(char)` and `Pin<&mut T>` can get SRoA'd now, where previously they weren't because the check was banning SRaA for anything with a niche -- not just things with `#[rustc_layout_scalar_valid_range_*]`.
  - Technically rust-lang/rust#133652 isn't complete yet, but `NonZero` and `NonNull` have already moved over, so this is fine.  At worst this will mean that LLVM gets less `!range` metadata on something that wasn't already fixed by rust-lang/rust#133651 or rust-lang/rust#135236, but that's still sound, and unblocking general SRoA is worth that tradeoff.
2025-07-28 11:53:15 +00:00
Boxy
2b11851452 Raw Pointers are Constant PatKinds too 2025-07-28 10:13:19 +01:00
bors
65b6cdb6a6 Auto merge of #144562 - matthiaskrgr:rollup-mlvn7qo, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#144072 (update `Atomic*::from_ptr` and `Atomic*::as_ptr` docs)
 - rust-lang/rust#144151 (`tests/ui/issues/`: The Issues Strike Back [1/N])
 - rust-lang/rust#144300 (Clippy fixes for miropt-test-tools)
 - rust-lang/rust#144399 (Add a ratchet for moving all standard library tests to separate packages)
 - rust-lang/rust#144472 (str: Mark unstable `round_char_boundary` feature functions as const)
 - rust-lang/rust#144503 (Various refactors to the codegen coordinator code (part 3))
 - rust-lang/rust#144530 (coverage: Infer `instances_used` from `pgo_func_name_var_map`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-28 08:50:59 +00:00
Matthias Krüger
c462895a6f Rollup merge of #144530 - Zalathar:instances-used, r=lqd
coverage: Infer `instances_used` from `pgo_func_name_var_map`

In obscure circumstances involving macro-expanded spans, we would sometimes emit a covfun record for a function with no physical coverage counters, and therefore no corresponding entry in the “PGO names” section of the binary. The absence of that name entry causes `llvm-cov` to fail with the cryptic error message:

```text
malformed instrumentation profile data: function name is empty
```

We can eliminate this mismatch by removing `instances_used` entirely, and instead inferring its contents from the keys of `pgo_func_name_var_map`.

This makes it impossible for a "used" function to lack a PGO name entry.

---

This is an attempt to eliminate the cause of rust-lang/rust#141577 when re-landing changes like rust-lang/rust#144298 in the future.

I haven't been able to reproduce the underlying issue in an in-tree test, because the only known repro involves a non-trivial derive proc-macro that relies on `syn` and `proc-macro2`. But I have manually verified in a separate branch that this change would have prevented the reoccurrence of https://github.com/rust-lang/rust/issues/141577#issuecomment-3120667286.
2025-07-28 08:36:54 +02:00
Matthias Krüger
ec86930c1d Rollup merge of #144503 - bjorn3:lto_refactors3, r=petrochenkov
Various refactors to the codegen coordinator code (part 3)

Continuing from https://github.com/rust-lang/rust/pull/144062 this removes an option without any known users, uses the object crate in favor of LLVM for getting the LTO bitcode and improves the coordinator channel handling.
2025-07-28 08:36:54 +02:00
Scott McMurray
173926da2b Remove [T]::array_chunks(_mut) 2025-07-27 23:03:07 -07:00
bors
d242a8bd5a Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLii
Some `let chains` clean-up

Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one

r? compiler
2025-07-28 05:25:23 +00:00
bors
733dab5589 Auto merge of #144556 - matthiaskrgr:rollup-aayo3h5, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#143607 (Port the proc macro attributes to the new attribute parsing infrastructure)
 - rust-lang/rust#144471 (Remove `compiler-builtins-{no-asm,mangled-names}`)
 - rust-lang/rust#144495 (bump cargo_metadata)
 - rust-lang/rust#144523 (rustdoc: save target modifiers)
 - rust-lang/rust#144534 (check_static_item: explain should_check_for_sync choices)
 - rust-lang/rust#144535 (miri: for ABI mismatch errors, say which argument is the problem)

Failed merges:

 - rust-lang/rust#144536 (miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-28 02:09:05 +00:00
Kivooeo
b8eb046e6e use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
Kivooeo
bae38bad78 use let chains in hir, lint, mir 2025-07-28 06:10:14 +05:00
Kivooeo
43725ed819 use let chains in ast, borrowck, codegen, const_eval 2025-07-28 06:08:48 +05:00
Matthias Krüger
d33c8f9336 Rollup merge of #144535 - RalfJung:abi-mismatch-err, r=compiler-errors
miri: for ABI mismatch errors, say which argument is the problem
2025-07-28 01:16:40 +02:00
Matthias Krüger
ea7e539386 Rollup merge of #144534 - RalfJung:should_check_for_sync, r=compiler-errors
check_static_item: explain should_check_for_sync choices

Follow-up to https://github.com/rust-lang/rust/pull/144226.

r? ``@oli-obk``
2025-07-28 01:16:40 +02:00
Matthias Krüger
6bd327374a Rollup merge of #143607 - JonathanBrouwer:proc_macro_attrs, r=jdonszelmann,traviscross
Port the proc macro attributes to the new attribute parsing infrastructure

Ports `#[proc_macro]`, `#[proc_macro_attribute]`, `#[proc_macro_derive]` and `#[rustc_builtin_macro]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163

I've split this PR into commits for reviewability, and left some comments to clarify things
I did 4 related attributes in one PR because they share a lot of their code and logic, and doing them separately is kind of annoying as I need to leave both the old and new parsing in place then.

r? ``@oli-obk``
cc ``@jdonszelmann``
2025-07-28 01:16:38 +02:00
bors
2b5e239c6b Auto merge of #144225 - purplesyringa:unwinding-intrinsics, r=nikic
Don't special-case llvm.* as nounwind

Certain LLVM intrinsics, such as `llvm.wasm.throw`, can unwind. Marking them as nounwind causes us to skip cleanup of locals and optimize out `catch_unwind` under inlining or when `llvm.wasm.throw` is used directly by user code.

The motivation for forcibly marking llvm.* as nounwind is no longer present: most intrinsics are linked as `extern "C"` or other non-unwinding ABIs, so we won't codegen `invoke` for them anyway.

Closes rust-lang/rust#132416.

`@rustbot` label +T-compiler +A-panic
2025-07-27 23:05:48 +00:00
Ralf Jung
296586fb02 miri: for ABI mismatch errors, say which argument is the problem 2025-07-27 22:26:10 +02:00
Scott McMurray
47bfa846f3 Allow more MIR SROA 2025-07-27 13:21:06 -07:00
bors
f8e355c230 Auto merge of #144434 - nnethercote:preintern-ty-bounds, r=compiler-errors
Preintern some `TyKind::Bound` values

The new trait solver produces a lot of these.

r? `@compiler-errors`
2025-07-27 18:58:43 +00:00
FractalFir
72927f6eb7 Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments. 2025-07-27 20:55:45 +02:00
bors
4b596bbd84 Auto merge of #144425 - nnethercote:avoid-new_adt-new_fn_def, r=compiler-errors
Avoid unnecessary `new_adt`/`new_fn_def` calls.

They can be skipped if there are no arguments, avoiding the "relate" operation work and also the subsequent interning.

r? `@ghost`
2025-07-27 15:56:47 +00:00
Ralf Jung
da1991d565 check_static_item: explain should_check_for_sync choices 2025-07-27 15:41:42 +02:00
bors
edc3841c5d Auto merge of #143884 - LorrensP-2158466:resolve-split-define, r=petrochenkov
Resolve: refactor `define` into `define_local` and `define_extern`

Follow up on rust-lang/rust#143550 and part of [#gsoc > Project: Parallel Macro Expansion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/with/527348747).

Split up `define` into `define_local` and `define_extern`. Refactor usages of `define` into either one where it's "correct" (idk if everything is correct atm). Big part of this is that `resolution` can now take a `&Resolver` instead of a mutable one.

r? `@petrochenkov`
2025-07-27 12:40:46 +00:00
Zalathar
89b6b0b6a4 coverage: Clarify that getting a PGO name also makes a function "used" 2025-07-27 21:49:46 +10:00
Zalathar
24e2b4832b coverage: Infer instances_used from pgo_func_name_var_map
In obscure circumstances, we would sometimes emit a covfun record for a
function with no physical coverage counters, causing `llvm-cov` to fail with
the cryptic error message:

    malformed instrumentation profile data: function name is empty

We can eliminate this mismatch by removing `instances_used` entirely, and
instead inferring its contents from the keys of `pgo_func_name_var_map`.

This makes it impossible for a "used" function to lack a PGO name entry.
2025-07-27 21:49:37 +10:00
godzie44
49eda8edd5 fix(debuginfo): disable overflow check for
recursive non-enum types
2025-07-27 14:42:07 +03:00
LorrensP-2158466
451a93e2b8 split up define into define_extern and define_local 2025-07-27 12:17:23 +02:00
bors
eed187cfce Auto merge of #144528 - matthiaskrgr:rollup-felcjc1, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#144226 (Do not assert layout in KnownPanicsLint.)
 - rust-lang/rust#144385 (Optimize performance by inline in macro hygiene system)
 - rust-lang/rust#144454 (move uefi test to run-make)
 - rust-lang/rust#144455 (Unify LLVM ctlz/cttz intrinsic generation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-27 09:38:27 +00:00
Matthias Krüger
dd6e4a9206 Rollup merge of #144455 - TDecking:ctlz-cttz, r=SparrowLii
Unify LLVM ctlz/cttz intrinsic generation

The type signature for `llvm.ctlz` is the same as the one for `llvm.cttz`, which enables a small simplification.
2025-07-27 10:19:02 +02:00
Matthias Krüger
e0a42996d5 Rollup merge of #144385 - xizheyin:macro-hygiene, r=petrochenkov
Optimize performance by inline in macro hygiene system

I inline some small method in `rustc_span/src/hygiene.rs` and so on.
2025-07-27 10:19:01 +02:00
Matthias Krüger
58f10376f4 Rollup merge of #144226 - cjgillot:known-panics-panics, r=oli-obk
Do not assert layout in KnownPanicsLint.

Fixes rust-lang/rust#121176
Fixes rust-lang/rust#129109
Fixes rust-lang/rust#130970
Fixes rust-lang/rust#131347
Fixes rust-lang/rust#139872
Fixes rust-lang/rust#140332
2025-07-27 10:19:00 +02:00
bors
86ef320294 Auto merge of #144347 - scottmcm:ssa-enums-v0, r=WaffleLapkin
No longer need `alloca`s for consuming `Result<!, i32>` and similar

In optimized builds GVN gets rid of these already, but in `opt-level=0` we actually make `alloca`s for this, which particularly impacts `?`-style things that use actually-only-one-variant types like this.

While doing so, rewrite `LocalAnalyzer::process_place` to be non-recursive, solving a 6+ year old FIXME.

r? codegen
2025-07-27 06:37:55 +00:00