Commit Graph

3331 Commits

Author SHA1 Message Date
Guillaume Gomez 3e15f828f6 Rollup merge of #156955 - P8L1:fix-reborrow-promotion-consteval, r=RalfJung
Fix const-eval of shared generic reborrows

`Rvalue::Reborrow` const-eval now handles shared generic reborrows produced by `CoerceShared`. Those reborrows intentionally copy from the source ADT into a distinct same-layout target ADT, so the interpreter uses the transmute-capable copy path for `Mutability::Not`.

Promotion is intentionally kept conservative: promotion candidates whose validated temporary graph contains `Rvalue::Reborrow` are rejected, so generic/user-defined reborrows are not promoted.

Fixes rust-lang/rust#156313.
cc @aapoalas
Tracking: rust-lang/rust#145612
@rustbot label F-reborrow
2026-05-27 20:45:13 +02:00
Guillaume Gomez dc05df7ebe Rollup merge of #157022 - RalfJung:inline-intrinsics-v2, r=oli-obk
MIR inlining: allow backends to opt-in to inlining intrinsics

This is the same as https://github.com/rust-lang/rust/pull/156398. Github stopped processing updates on that other branch.

r? @oli-obk
2026-05-27 20:45:10 +02:00
Pieter-Louis Schoeman 56f5c38840 Fix const-eval of shared generic reborrows 2026-05-27 18:17:14 +02:00
Ralf Jung 59428e76e8 MIR inlining: allow backends to opt-in to inlining intrinsics 2026-05-27 13:59:25 +02:00
qaijuang cf3249c0cc coverage: Use original HIR info for synthetic by-move coroutine bodies 2026-05-26 10:01:36 -04:00
Jonathan Brouwer 8a34a4e505 Rollup merge of #156847 - sappho3:fix-suggestion-unused-variables-struct-pattern, r=JonathanBrouwer
Fix suggestion of unused variables with raw identifier in struct pattern

This MR fixes a broken lint suggestion that occurs when a struct pattern contains an unused variable written with a raw identifier.

In the following fragment, `r#move` is an unused variable. The compiler suggested to change it to `move: _` which doesn’t compile since move is a keyword. This change makes it so that the suggestion becomes `r#move: _`

```rust
struct Foo {
    r#move: u32
}

fn bar(foo: Foo) -> u32 {
    match foo {
         Foo { r#move } => 0
    }
}
```

r? JonathanBrouwer
2026-05-24 21:28:53 +02:00
Sappho de Nooij 8604f001a9 Fix suggestion of unused variables with raw identifier in struct pattern
This commit fixes a broken suggestion that occurs when a struct pattern contains an unused
variable written with a raw identifier.
2026-05-23 09:33:09 +02:00
Jonathan Brouwer 8162cf582b Rollup merge of #156242 - Jamesbarford:feat/remove-alwaysinline+target-feature, r=RalfJung,saethlin
Remove unsound `target_feature_inline_always` feature

## Summary
- Remove `target_feature_inline_always`
- Update stdarch generators to only use `#[inline]` & regenerate stdarch.

## Why?
Succinctly; the feature relies on LLVMs `AlwaysInlinerPass()` running before LLVMs heuristic based inliner pass. Which is not a basis for sound code.

This has been discussed in [the tracking issue](https://github.com/rust-lang/rust/issues/145574).

If the ordering of the passes were to change, of which they have in the past, it is very possible we could inline functions across callsites with mismatching target features leading to unsound code. Checks proposed in; https://github.com/rust-lang/rust/pull/155426 would only take into account caller -> callee which is not enough to guard against possibly of generating unsound code if the pass ordering were to change.

There doesn't seem to be a way, presently, this this mechanism to provide soundness guarantees nor does it seem like `AlwaysInlinerPass()` is a desired feature of LLVM, which this feature relies on.

r? @RalfJung
2026-05-21 12:21:45 +02:00
Jonathan Brouwer fc7ac3de0c Rollup merge of #156636 - Human9000-bit:mir-transform-ref, r=Kivooeo
minor `rustc_mir_transform` cleanup

Some minor things I noticed here and there while reading though code
2026-05-17 15:52:43 +02:00
bors 281c97c324 Auto merge of #156518 - estebank:match-rustfmt, r=mejrs
[style] rustfmt `match`es with comments in or-patterns

Using https://github.com/rust-lang/rustfmt/pull/6893, I reformatted the whole codebase. The result is that `match`es that *should have* been formatted under normal circumstances but are getting skipped now got their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.

(Introduced and) removed a bunch of stray backticks \` likely left after an editor autoclosed the intended closing \`, resulting in <code>\`name\`\`</code> in comments.
2026-05-17 01:27:37 +00:00
human9000 053761df0a minor rustc_mir_transform cleanup 2026-05-16 14:06:44 +05:00
bors 3514361554 Auto merge of #156617 - JonathanBrouwer:rollup-M30TGcY, r=JonathanBrouwer
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#148788 (Unconstrained parameter fix)
 - rust-lang/rust#156319 (Require EIIs to be defined when we compile a rust dylib)
 - rust-lang/rust#156452 (Implement pinned drop sugar)
 - rust-lang/rust#156554 (Allow user-provided `llvm_args` to override target spec arguments)
 - rust-lang/rust#156571 (Disable `main_needs_argc_argv` for Wasm)
 - rust-lang/rust#156600 (Make const param default test reproduce original ICE)
 - rust-lang/rust#156493 (actually run the temp_dir doctest)
 - rust-lang/rust#156556 (Require UTF-8 in `Utf8Pattern::StringPattern`)
 - rust-lang/rust#156565 (delegation: emit error when self type is not specified and accessed)
 - rust-lang/rust#156586 (Use DropCtxt::new_block and new_block_with_statements systematically.)
 - rust-lang/rust#156587 (Correctly handle associated items in rustdoc macro expansion)
 - rust-lang/rust#156604 (coverage: Reduce and clarify the context-mismatch test case)
2026-05-15 21:40:32 +00:00
Jonathan Brouwer 7e35a7ef98 Rollup merge of #156586 - cjgillot:elaborate-new-block, r=oli-obk
Use DropCtxt::new_block and new_block_with_statements systematically.

Misc cleanups I found while staring at that code.
2026-05-15 20:11:47 +02:00
bors d7f14d3d89 Auto merge of #156218 - cjgillot:dest-prop-range, r=Amanieu
DestinationPropagation: compute liveness as ranges instead of traveling bitsets

The current implementation of `save_as_liveness` is very slow, and consists in inserting a traveling bitset in an interval set.

As the `MaybeLiveLocals` has a gen-kill property, we can leverage it to make it faster. "Gen" is creating a new interval. "Kill" is ending this interval, ripe to save in the interval set.
2026-05-15 18:05:42 +00:00
Camille Gillot 6e7b089cb9 Use DropCtxt::new_block and new_block_with_statements systematically. 2026-05-14 22:15:20 +00:00
Camille Gillot d76d4cd69e Untuple method parameters. 2026-05-14 22:15:20 +00:00
Camille Gillot 5a12d48b62 Prefer tracing::instrument. 2026-05-14 22:15:19 +00:00
Camille Gillot 5e4399027b Introduce TwoStepIndex::effect. 2026-05-13 20:31:06 +00:00
Camille Gillot 161efa96b3 DestinationPropagation: compute liveness as ranges instead of traveling bitsets. 2026-05-13 20:24:31 +00:00
cyrgani d5f8ddf14c use deref_patterns in rustc_mir_transform 2026-05-13 19:47:14 +00:00
Jonathan Brouwer aeae08587c Rollup merge of #156425 - chenyukang:yukang-fix-156416-unused-assignments-diverging, r=oli-obk
Fix unused assignments in diverging branches

Fixes rust-lang/rust#156416

Add `location` and use `is_predecessor_of` to check in the control flow graph.

r? @ghost
I'd like to see whether there is performence regression.
2026-05-13 15:16:18 +02:00
Zalathar 281ccf80f8 Remove the dummy PreCodegen mir-opt pass
This dummy pass is not needed, because the `runtime-optimized` phase transition
can be used to dump the final pre-codegen MIR.
2026-05-13 15:40:23 +10:00
Zalathar ccb9305e20 Move emit_mir out of rustc_mir_transform::dump_mir
This function doesn't have an obvious home, but there's little reason for it to
be in mir-transform, and having it in `rustc_driver_impl::pretty` at least puts
it near other callers of `write_mir_pretty`.
2026-05-13 14:54:31 +10:00
Esteban Küber 31e0383ea6 rustfmt matches with comments in or-patterns
Using https://github.com/rust-lang/rustfmt/pull/6893, reformat the codebase. The result is that matches that *would have* been formatted under normal circumstances get their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.
2026-05-13 02:35:29 +00:00
lcnr 3fb166fb6f tiny PR 2026-05-12 21:58:50 +02:00
Jonathan Brouwer aeffd1585a Rollup merge of #155184 - scottmcm:intercept-array-drop-shim, r=WaffleLapkin
Have arrays' `drop_glue` just unsize and call the slice version

It's silly to emit two loops (because of the drop ladder -- just one in panic=abort) for every array length that's dropped when we can just polymorphize to the slice version.

Built atop rust-lang/rust#154327 to avoid conflicts later, so draft for now.

r? @WaffleLapkin
2026-05-11 23:03:06 +02:00
Jonathan Brouwer f91de350ee Rollup merge of #156429 - scottmcm:raw-eq-transmute, r=oli-obk
Simplify `intrinsic::raw_eq` in MIR when possible

After https://github.com/rust-lang/rust/pull/150945 things can inline enough to have this end up specific enough that we can remove it, for example changing `raw_eq::<[u8; 4]>(a, b)` → `Transmute(a) == Transmute(b)`.

The LLVM backend can also do this (and in more cases too) but we might as well do it in MIR instead when we can so it applies to all backends and other MIR optimizations can apply afterwards.
2026-05-11 23:03:04 +02:00
yukang 64e93266ce Fix unused assignments in diverging branches 2026-05-12 02:11:07 +08:00
Scott McMurray c468ee3386 Simplify raw_eq to Transmute+Eq for sizes with primitives 2026-05-10 19:28:57 -07:00
Zalathar 9d01bf83f9 Remove some dead code for dumping MIR for a single DefId 2026-05-10 17:18:35 +10:00
Scott McMurray 05f52c7a99 Have arrays' drop_glue just unsize and call the slice version 2026-05-09 01:01:03 -07:00
bors 63b1dfc0e0 Auto merge of #156290 - JonathanBrouwer:rollup-PNM9rEm, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#156061 (Support `-Cpanic=unwind` on WASI targets)
 - rust-lang/rust#151753 (Experiment: Reborrow traits)
 - rust-lang/rust#156280 (Add regression test for closure return ICE)
 - rust-lang/rust#152487 (core: drop unmapped ZSTs in array `map`)
 - rust-lang/rust#153759 (Add a suite of ChunkedBitSet union/subtract/intersect test scenarios)
 - rust-lang/rust#156198 (Add `sync` option to `-Z threads` to force synchronization on one thread)
2026-05-07 23:03:11 +00:00
Aapo Alasuutari 2d88ee87dd Reborrow traits 2026-05-07 21:55:44 +03:00
yukang 8e1f263f66 Skipping borrowck because of trivial const 2026-05-07 22:18:58 +08:00
James Barford-Evans c6d2da90b5 Remove #[inline(always)] + #[target_feature(enable = "<feature>")] support, reinstating error message and providing a link to the tracking issue for the full rationale. 2026-05-07 08:28:09 +01:00
bors 4ddd4538a8 Auto merge of #154327 - WaffleLapkin:drop_in_place_ref, r=RalfJung,scottmcm,saethlin
change the type of the argument of `drop_in_place` lang item to `&mut _`



We used to special case `core::ptr::drop_in_place` when computing LLVM argument attributes with this hack:

https://github.com/rust-lang/rust/blob/db5e2dc248fe5bb26f70d7baec46a3bca9fa3e1d/compiler/rustc_ty_utils/src/abi.rs#L383-L392

This is because even though `drop_in_place` takes a `*mut T` it is semantically a `&mut T` (remember how `&mut Self` is passed to `Drop::drop`). This is apparently relevant for perf.

This PR replaces this hack with a simpler solution -- it makes `drop_in_place` a thin wrapper around newly added `core::ptr::drop_glue`, which is the actual lang item and takes a `&mut T`:

https://github.com/rust-lang/rust/blob/d2563d5003bbecff1efc40c1f5673ceec603825b/library/core/src/ptr/mod.rs#L810-L833

------

The rest of the PR is blessing tests and cleaning up things which are not necessary after this change.

One thing that is a bit awkward is that now that `drop_glue` is the actual lang item, a lot of the comments referring to `drop_in_place` are outdated. Should I try fixing that?

I've also changed `async_drop_in_place` to take a `&mut T`, and it simplified the code handling it a bit. (since it's unstable we don't need to introduce a wrapper)

-------

cc @RalfJung 
Closes https://github.com/rust-lang/rust/issues/154274
2026-05-07 00:52:53 +00:00
Jana Dönszelmann f0c1798a3a prefer assert_not_erased over matching+unreachable 2026-05-06 10:18:21 +02:00
Jana Dönszelmann 630f0d2bbb type safety for typing mode outside trait solver which can't be erased-not-coherence 2026-05-06 10:18:21 +02:00
Jana Dönszelmann a93f8c0579 Introduce ErasedNotCoherence typing mode 2026-05-06 10:13:29 +02:00
Waffle Lapkin 2051cb8e00 change type of async_drop_in_place to accept &mut _ 2026-05-05 12:36:39 +02:00
Waffle Lapkin 810eae99af rename drop_in_place lang item to drop_glue 2026-05-05 12:36:39 +02:00
Waffle Lapkin d2d56584e6 fixup a comment left by an unrelated refactor
(scottmcm left this while adding `Local::arg`...)
2026-05-04 15:35:40 +02:00
Waffle Lapkin d5bde6b59a change type argument of drop_in_place lang item to &mut _ 2026-05-04 15:35:40 +02:00
Jacob Pratt c3afa21a40 Rollup merge of #156065 - mejrs:spanculler, r=JonathanBrouwer
Remove unused spans from AttributeKind

Recently I noticed some spans in diagnostic attributes were never used. I went through and checked the other variants too.
2026-05-03 00:25:33 -04:00
mejrs 4a13f36265 Remove more spans from AttributeKind 2026-05-02 17:41:30 +02:00
Ralf Jung e402c1edf0 miri: remove retag statements, make typed copies retag implicitly instead 2026-05-02 17:40:33 +02:00
Jonathan Brouwer a1a8e57a35 Rollup merge of #156059 - Enselic:print-mir-passes, r=mu001999
compiler: Print valid `-Zmir-enable-passes` names if invalid name is used

If a user passes an invalid name to `-Zmir-enable-passes`, print the valid names as a note.

To avoid the annoyance of having to keep blessing test output, completely normalize away the list of names in the test.

The diagnostic is duplicated, but that is not introduced by this commit. In other words, we don't make matters worse. The existing "is unknown and will be ignored" diagnostic is already duplicated, as can be seen in the existing test stderr.

The output is on one long line, but that makes normalization in tests easier, and I don't think we have to overdo this. We can let terminals wrap the line.

<details>

<summary>Click to expand current output</summary>

`note: valid MIR pass names are: AbortUnwindingCalls, AddCallGuards, AddMovesForPackedDrops, AddRetag, CheckAlignment, CheckCallRecursion, CheckConstItemMutation, CheckDropRecursion, CheckEnums, CheckForceInline, CheckInlineAlwaysTargetFeature, CheckLiveDrops, CheckNull, CheckPackedRef, CleanupPostBorrowck, CopyProp, CtfeLimit, DataflowConstProp, DeadStoreElimination-final, DeadStoreElimination-initial, Derefer, DestinationPropagation, EarlyOtherwiseBranch, ElaborateBoxDerefs, ElaborateDrops, EnumSizeOpt, EraseDerefTemps, ForceInline, FunctionItemReferences, GVN, ImpossiblePredicates, Inline, InstSimplify-after-simplifycfg, InstSimplify-before-inline, InstrumentCoverage, JumpThreading, KnownPanicsLint, LowerIntrinsics, LowerSliceLenCalls, Marker, MatchBranchSimplification, MentionedItems, MultipleReturnTerminators, PostAnalysisNormalize, PreCodegen, PromoteTemps, ReferencePropagation, RemoveNoopLandingPads, RemovePlaceMention, RemoveStorageMarkers, RemoveUninitDrops, RemoveUnneededDrops, RemoveZsts, ReorderBasicBlocks, ReorderLocals, RequiredConstsVisitor, SanityCheck, ScalarReplacementOfAggregates, SimplifyCfg-after-unreachable-enum-branching, SimplifyCfg-final, SimplifyCfg-initial, SimplifyCfg-make_shim, SimplifyCfg-post-analysis, SimplifyCfg-pre-optimizations, SimplifyCfg-promote-consts, SimplifyCfg-remove-false-edges, SimplifyComparisonIntegral, SimplifyConstCondition-after-const-prop, SimplifyConstCondition-after-inst-simplify, SimplifyConstCondition-final, SimplifyLocals-after-value-numbering, SimplifyLocals-before-const-prop, SimplifyLocals-final, SingleUseConsts, SsaRangePropagation, StateTransform, StripDebugInfo, Subtyper, UnreachableEnumBranching, UnreachablePropagation, Validator`

</details>
2026-05-02 10:18:32 +02:00
Jonathan Brouwer 3903d9436c Rollup merge of #156053 - cjgillot:optimized-reuse-ctfe, r=oli-obk
Reuse CTFE MIR for constructors.

For constructors, we manually build the MIR shim we want. We can just have `optimized_mir` call `mir_for_ctfe` instead of rebuilding the shim.
2026-05-02 10:18:31 +02:00
Jonathan Brouwer 716bccea07 Rollup merge of #156028 - scottmcm:local-arg, r=wesleywiser
Add a `Local::arg(i)` helper constructor

While reading through stuff I was noticing just how many `+1` fixes there were in various places (and comments explaining those fixups), so this adds a new inherent helper on `Local` for making an argument to help make this clearer.

r? mir
2026-05-02 10:18:28 +02:00
Martin Nordholts e906d1f9eb compiler: Print valid -Zmir-enable-passes names if invalid name is used
If a user passes an invalid name to `-Zmir-enable-passes`, print the
valid names as a note.

The diagnostic is duplicated, but that is not introduced by this commit.
In other words, we don't make matters worse. The existing "is unknown
and will be ignored" diagnostic is already duplicated.

To avoid the annoyance of having to keep blessing test output,
completely normalize away the list of names in the test.
2026-05-02 08:29:55 +02:00