Commit Graph

325657 Commits

Author SHA1 Message Date
Josh Triplett df8a13ecf4 Hand-implement impl Debug for NumBuffer to avoid constraining T or printing MaybeUninit
The derived implementation requires `T: Debug`, and doesn't need to.
2026-05-02 22:47:13 -07:00
bors a3e96d8cb8 Auto merge of #155767 - adwinwhite:eager-norm-outside, r=lcnr
`-Znext-solver` Eager normalization outside of solver 




This PR adds a normalization routine for the next solver that behaves the same as the normalization in the old solver.
The new routine is used to normalize eagerly outside of the next solver.

This is [part 2](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/Eager.20normalization.2C.20ahoy.21/near/582996783) of modifying the next solver to support eager normalization.

Those test changes are mostly wording changes, duplicating some errors or reducing some duplicates. But I could have overlooked something.
Notably it fixes the first, third and fourth examples in https://github.com/rust-lang/trait-system-refactor-initiative/issues/191, but not the second variant.

It's probably easier to review commit by commit.

Fixes rust-lang/rust#151308
Fixes rust-lang/rust#101557
Fixes rust-lang/rust#119692
Fixes rust-lang/rust#136859
2026-05-02 20:56:41 +00:00
bors 20de910db4 Auto merge of #154341 - RalfJung:retag-on-typed-copy, r=oli-obk
Make retags an implicit part of typed copies



Ever since Stacked Borrows was first implemented in Miri, that was done with `Retag` statements: given a place (usually a local variable), those statements find all references stored inside the place and refresh their tags to ensure the aliasing requirements are upheld. However, this is a somewhat unsatisfying approach for multiple reasons:
- It leaves open the [question](https://github.com/rust-lang/unsafe-code-guidelines/issues/371) of where to even put `Retag` statements. Over time, the AddRetag pass settled on one possible answer to this, but it wasn't very canonical.
- For assignments of the form `*ptr = expr`, if the assignment involves copying a reference, we probably want to do a retag -- but if we do a `Retag(*ptr)` as the next instruction, it can be non-trivial to argue that this even retags the right value, so we refrained from doing retags in that case. This has [come up](https://github.com/llvm/llvm-project/pull/160913#issuecomment-3341908717) as a potential issue for Rust making better use of LLVM "captures" annotations. (That said, there might be [other ways](https://github.com/rust-lang/unsafe-code-guidelines/issues/593#issuecomment-4328112031) to obtain this desired optimization.)
- Normal compilation avoids generating retags, but we still generate LLVM IR with `noalias`. What does that even mean? How do MIR optimization passes interact with retags? These are questions we have to figure out to make better use of aliasing information, but currently we can't even really ask such questions.

I think we should resolve all that by making retags part of what happens during a typed copy (a concept and interpreter infrastructure that did not exist yet when retags were initially introduced). Under this proposal, when executing a MIR assignment statement, what conceptually happens is as follows:
- We evaluate the LHS to a place.
- We evaluate the RHS to a value. This does a typed load from memory if needed, raising UB if memory does not contain a valid representation of the assignment's type.
- We walk that value, identify all references inside of it, and retag them. If this happens as part of passing a function argument, this is a protecting retag.
- We store (a representation of) the value into the place.

However, this semantics doesn't fully work: there's a mandatory MIR pass that turns expressions like `&mut ***ptr` into intermediate deref's. Those must *not* do any retags. So far this happened because the AddRetag pass did not add retags for assignments to deref temporaries, but that information is not recorded in cross-crate MIR. Therefore I instead added a field to `Rvalue::Use` to indicate whether this value should be retagged or not. A non-retagging copy seems like a sufficiently canonical primitive that we should be able to express it. Dealing with the fallout from that is a large chunk of the overall diff. (I also considered adding this field to `StatementKind::Assign` instead, but decided against that as we only actually need it for `Rvalue::Use`. I am not sure if this was the right call...)

This neatly answers the question of when retags should occur, and handles cases like `*ptr = expr`. It avoids traversing values twice in Miri. It makes codegen's use of `noalias` sound wrt the actual MIR that it is working on. It also gives us a target semantics to evaluate MIR opts against. However, I did not carefully check all MIR opts -- in particular, GVN needs a thorough look under the new semantics; it currently can turn alias-correct code into alias-incorrect code. (But this PR doesn't make things any worse for normal compilation where the retag indicator is anyway ignored.)

Another side-effect of this PR is that `-Zmiri-disable-validation` now also disables alias checking. It'd be nicer to keep them orthogonal but I find this an acceptable price to pay.

- [rustc benchmark results](https://github.com/rust-lang/rust/pull/154341#issuecomment-4125313290)
- [miri benchmark results](https://github.com/rust-lang/rust/pull/154341#issuecomment-4129840926)
2026-05-02 17:42:41 +00:00
Ralf Jung e402c1edf0 miri: remove retag statements, make typed copies retag implicitly instead 2026-05-02 17:40:33 +02:00
bors 3d5dfdc29f Auto merge of #156088 - JonathanBrouwer:rollup-qdmx6JQ, r=JonathanBrouwer
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#156074 (Add extra symbol check for `.to_owned()`)
 - rust-lang/rust#156045 (Move tests associated consts)
 - rust-lang/rust#156064 (Do not depend on typeck to borrow-check inline consts.)
 - rust-lang/rust#156083 (Move tests attributes)
2026-05-02 14:30:57 +00:00
Jonathan Brouwer dd3cb25042 Rollup merge of #156083 - danieljofficial:move-tests-attributes, r=JonathanBrouwer
Move tests attributes

I moved some attribute tests out of the issues folder into the attribute folder, please find time to review
2026-05-02 16:19:21 +02:00
Jonathan Brouwer 1f97ab1a31 Rollup merge of #156064 - cjgillot:borrowck-no-typeck, r=dingxiangfei2009
Do not depend on typeck to borrow-check inline consts.

Instead fetch the type from the inline-const's MIR, which comes from exactly the same typeck information.
2026-05-02 16:19:20 +02:00
Jonathan Brouwer 8de6b7aaf7 Rollup merge of #156045 - danieljofficial:move-tests-associated-consts, r=Kivooeo
Move tests associated consts

r? @Kivooeo moved tests into associated-consts
2026-05-02 16:19:20 +02:00
Jonathan Brouwer 6fa22653f9 Rollup merge of #156074 - EvoPot:cow-diag-item, r=chenyukang
Add extra symbol check for `.to_owned()`

Follow up of rust-lang/rust#154646

Previously when adding a suggestion for using `Cow::into_owned()` instead of `ToOwned::to_owned()`, the compiler would just convert the methods `Span` into a `String` and do checks on that `String`. This PR adds an extra guard to that suggestion by checking if the method is `sym::to_owned_method`.

r? @davidtwco since you added the review to the previous PR
2026-05-02 16:19:19 +02:00
Adwin White 03cabe7bab bless more than merely diagnostics change 2026-05-02 21:07:24 +08:00
Adwin White 1c1372c908 bless diagnostics change 2026-05-02 21:07:23 +08:00
EvoPot 8a77369ca4 Add extra symbol check for .to_owned()
Previously when adding a suggestion for using `Cow::into_owned()`
instead of `ToOwned::to_owned()`, the compiler would just convert the
methods `Span` into a `String` and do checks on that `String`. This PR
adds an extra guard to that suggestion by checking if the method is
`sym::to_owned_method`.
2026-05-02 14:47:29 +03:00
bors 696d5929af Auto merge of #156078 - JonathanBrouwer:rollup-WF8BsN3, r=JonathanBrouwer
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#156030 (Make stable hashing names consistent (part 1))
 - rust-lang/rust#156020 (Improve source code for `librustdoc/visit_ast.rs`)
 - rust-lang/rust#156021 (Clean up some traits)
 - rust-lang/rust#156028 (Add a `Local::arg(i)` helper constructor)
 - rust-lang/rust#156037 (Add AcceptContext::expect_no_args)
 - rust-lang/rust#156040 (Add missing alias to mailmap)
 - rust-lang/rust#156048 (Make `diverging_type_vars` a vec of `TyVid`)
 - rust-lang/rust#156053 (Reuse CTFE MIR for constructors.)
 - rust-lang/rust#156059 (compiler: Print valid `-Zmir-enable-passes` names if invalid name is used)

Failed merges:

 - rust-lang/rust#155940 (refactor rustc_on_unimplemented's filtering)
 - rust-lang/rust#156065 (Remove unused spans from AttributeKind)
2026-05-02 11:16:52 +00:00
danieljofficial 40904ddd75 add issue links and bless attribute tests 2026-05-02 12:02:25 +01:00
danieljofficial 200d4e3b8a move tests from issues into attributes folder 2026-05-02 11:38:56 +01: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 8db83b1d26 Rollup merge of #156048 - JonathanBrouwer:diverging_ty_vids, r=WaffleLapkin
Make `diverging_type_vars` a vec of `TyVid`

r? @lcnr

The following changes, in separate commits:
* Make its elements a `TyVid`, since there should never by any other types than `TyVars` in there
* Make it a vec, since it being a set doesn't make much sense. You never really should do a `contains` on it, since you should normalize the tyvids in the set to their root var first.
2026-05-02 10:18:30 +02:00
Jonathan Brouwer a62c64562d Rollup merge of #156040 - GuillaumeGomez:mailmap, r=lqd
Add missing alias to mailmap

Fixes https://github.com/rust-lang/thanks/issues/103.
2026-05-02 10:18:30 +02:00
Jonathan Brouwer 985bb41c29 Rollup merge of #156037 - scrabsha:attributes/expect-no-args, r=JonathanBrouwer
Add AcceptContext::expect_no_args
2026-05-02 10:18:29 +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
Jonathan Brouwer 9149135815 Rollup merge of #156021 - nnethercote:clean-up-some-traits, r=jackh726
Clean up some traits

I was looking at various traits and found some unnecessary trait bounds, and some unnecessary traits. Details in individual commits.

r? @Nadrieril
2026-05-02 10:18:28 +02:00
Jonathan Brouwer f6f03a1651 Rollup merge of #156020 - GuillaumeGomez:cleanup-code, r=urgau
Improve source code for `librustdoc/visit_ast.rs`

While working on this part of rustdoc, got annoyed at the tuples and decided to transform them into types. Code is now much easier to follow. :3

r? @Urgau
2026-05-02 10:18:27 +02:00
Jonathan Brouwer 52b4eb2318 Rollup merge of #156030 - nnethercote:StableHash-renamings, r=JonathanBrouwer
Make stable hashing names consistent (part 1)

This PR starts the implementation of MCP 893. It renames the things that appear in the `HashStable` trait, changing this:
```
pub trait HashStable {
    fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
```
to this:
```
pub trait StableHash {
    fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
```
Details in individual commits.

This is the biggest part of the renaming. A follow-up PR will rename the remaining things.

r? @jieyouxu
2026-05-02 10:18:26 +02:00
Nicholas Nethercote e7d28d3e9b Rename the HashStable* trait/derives as StableHash*.
Specifically:
- `HashStable` -> `StableHash` (trait)
- `HashStable` -> `StableHash` (derive)
- `HashStable_NoContext` -> `StableHash_NoContext` (derive)

Note: there are some names in `compiler/rustc_macros/src/hash_stable.rs`
that are still to be renamed, e.g. `HashStableMode`.

Part of MCP 983.
2026-05-02 10:16:40 +02:00
Nicholas Nethercote 846267e725 Rename the HashStableContext trait as StableHashCtxt.
Part of MCP 983.
2026-05-02 10:16:39 +02:00
Nicholas Nethercote 851049cf58 Rename the hash_stable method as stable_hash.
Part of MCP 983.
2026-05-02 10:15:59 +02:00
Nicholas Nethercote ab9c9bf850 Fix a comment. 2026-05-02 10:15:59 +02:00
Adwin White 4767f23f58 remove normalize_capture_place 2026-05-02 16:11:12 +08:00
Adwin White c50bbc2b88 remove try_structurally_resolve_type 2026-05-02 16:11:12 +08:00
Adwin White dbba04e032 use the new routine to eagerly normalize 2026-05-02 16:11:12 +08:00
Adwin White e82c3c80ef add a new normalization routine that can handle ambiguity 2026-05-02 16:11:12 +08:00
bors 8275de8cdd Auto merge of #156069 - weihanglo:update-cargo, r=weihanglo
Update cargo submodule

10 commits in eb9b60f1f6604b5e022c56be31692c215b8ba11d..4f9b52075316e9ced380c8fa492858048d5758b6
2026-04-24 20:52:07 +0000 to 2026-05-01 22:36:41 +0000
- chore(deps): update compatible (rust-lang/cargo#16952)
- feat(lints): Add deny-by-default text_direction_codepoint lints (rust-lang/cargo#16950)
- chore(deps): update embarkstudios/cargo-deny-action action to v2.0.17 (rust-lang/cargo#16953)
- docs(guide): Switch from third-party to first-party unused deps detection (rust-lang/cargo#16946)
- Remove curl dependency from crates-io crate (rust-lang/cargo#16936)
- chore(deps): update gix to 0.83 (rust-lang/cargo#16945)
- fix(compile): Where possible, hint about misplaced deps  (rust-lang/cargo#16940)
- Remove `windows-sys` from `home` (rust-lang/cargo#16918)
- docs(resolver): `--precise <yanked>` is on stable (rust-lang/cargo#16944)
- Update `gix` to 0.82 (with security fixes and hardened parsers) (rust-lang/cargo#16941)
2026-05-02 07:58:56 +00: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
bors 39ef8aa1d5 Auto merge of #156072 - GuillaumeGomez:rollup-9U8oPPe, r=GuillaumeGomez
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#154571 (Fix alias path for rustdoc)
 - rust-lang/rust#155749 (`-Znext-solver` Ignore region constraints from the nested goals in leakcheck)
 - rust-lang/rust#156026 (`bufreader::Buffer`: Remove leftover note about `initialized` field)
 - rust-lang/rust#156063 (Map `WSAESHUTDOWN` to `io::ErrorKind::BrokenPipe`)
2026-05-02 04:46:31 +00:00
Guillaume Gomez 50805a9859 Rollup merge of #156063 - WhySoBad:wsaeshutdown-error-kind, r=joshtriplett
Map `WSAESHUTDOWN` to `io::ErrorKind::BrokenPipe`

As discussed in [#t-libs > WSAESHUTDOWN error on Windows](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/WSAESHUTDOWN.20error.20on.20Windows/with/591883531), this adds the mapping for `WSAESHUTDOWN` on Windows to `io::ErrorKind::BrokenPipe`.

r? RalfJung
2026-05-02 04:12:07 +02:00
Guillaume Gomez 3bf51d00ab Rollup merge of #156026 - InsertCreativityHere:patch-1, r=jhpratt
`bufreader::Buffer`: Remove leftover note about `initialized` field

Just a boring little doc fix! : v)

https://github.com/rust-lang/rust/pull/150129 reworked the `initialized` field to be a `bool` instead of a `usize`.
And then https://github.com/rust-lang/rust/pull/155314 reworked this field's comment (among other things).
But, there's still a leftover note in the comment, which no longer makes sense:
``Note that while this often the same as `filled`, it doesn't need to be.``
This is referencing that back when `initialized` was a `usize`, it was common for it to have the same value as `filled`.

----

Fun fact: there's a typo in the note too! It's missing an "is" before or after "often".
2026-05-02 04:12:06 +02:00
Guillaume Gomez e95df7d6d5 Rollup merge of #155749 - ShoyuVanilla:leakcheck-vis, r=lcnr
`-Znext-solver` Ignore region constraints from the nested goals in leakcheck

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/251
Fixes https://github.com/rust-lang/rust/issues/140577
Fixes https://github.com/rust-lang/rust/issues/153596
2026-05-02 04:12:05 +02:00
Guillaume Gomez 201d567654 Rollup merge of #154571 - chenyukang:yukang-fix-alias-path, r=clubby789
Fix alias path for rustdoc

I ran this command:

```console
x build --stage 1  --skip rustdoc
Building bootstrap
   Compiling bootstrap v0.0.0 (/Users/yukang/rust/src/bootstrap)
    Finished `dev` profile [unoptimized] target(s) in 1.08s
/Users/yukang/rust/build/aarch64-apple-darwin/ci-llvm/bin/llvm-strip does not exist; skipping copy
Building stage1 compiler artifacts (stage0 -> stage1, aarch64-apple-darwin)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.45s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage1 library artifacts{alloc, compiler_builtins, core, panic_abort, panic_unwind, proc_macro, rustc-std-workspace-core, std, std_detect, sysroot, test, unwind} (stage1 -> stage1, aarch64-apple-darwin)
    Finished `dist` profile [optimized + debuginfo] target(s) in 0.10s
Skipping Set({build::src/tools/rustdoc}) because it is excluded
Building stage1 rustdoc_tool_binary (stage0 -> stage1, aarch64-apple-darwin)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.19s
```

expect all `rustdoc` related compiling phase will be exlcuded, but from the log we can see `rustdoc_tool_binary` is still compiled.

`src/tools/rustdoc` and `src/librustdoc` are documented as aliases in path set here:
https://github.com/rust-lang/rust/blob/a25435bcf7cfc9b953d356eda3a51db8da9e3386/src/bootstrap/src/core/builder/mod.rs#L355-L360

we can also see here two paths are treated as alias:
https://github.com/rust-lang/rust/blob/a25435bcf7cfc9b953d356eda3a51db8da9e3386/src/bootstrap/src/core/build_steps/check.rs#L818-L822

but bootstrap registered them as two different sets with `.path(..).path(...)`:
https://github.com/rust-lang/rust/blob/a25435bcf7cfc9b953d356eda3a51db8da9e3386/src/bootstrap/src/core/build_steps/tool.rs#L691-L693

That meant commands like `x build --skip rustdoc`, `--skip src/tools/rustdoc`, or `--skip src/librustdoc` only excluded one side.
2026-05-02 04:12:05 +02:00
Weihang Lo acf0736c63 Update cargo submodule 2026-05-01 20:57:09 -04:00
Josh Triplett e6c358bf66 Typo fix: s/prefect/perfect/ 2026-05-01 16:19:50 -07:00
WhySoBad 3fe9b2ecd3 fix: update comment 2026-05-01 22:48:22 +02:00
Camille Gillot f4c3a71a9f Do not depend on typeck to borrow-check inline consts. 2026-05-01 20:39:17 +00:00
WhySoBad 52b3f048cd feat: map WSAESHUTDOWN to BrokenPipe 2026-05-01 22:29:07 +02:00
bors 67bcaa9c4b Auto merge of #153968 - jyn514:jyn/linker-warn-by-default, r=mati865
linker-messages is warn-by-default again

cc rust-lang/rust#136096 

I ended up keeping it a lint and adding an option for lints to ignore `-Dwarnings` (there was already a lint that did that actually, it was just hard-coded in rustc_middle instead of in rustc_lint_defs like I'd expect). This allows people to actually see the warnings without them failing the build in CI.
2026-05-01 17:15:17 +00:00
Camille Gillot b14a811b4b Reuse CTFE MIR for constructors. 2026-05-01 15:41:27 +00:00
Shoyu Vanilla e43a1b5b44 -Znext-solver Ignore region constraints from the nested goals in leakcheck 2026-05-02 00:11:43 +09:00
Jonathan Brouwer c17d24e1f7 Make diverging_type_vars a Vec
It being a `Set` does not really make sense. You never really should do a `contains` on it, since you should normalize the tyvid to its root var first.
2026-05-01 16:52:20 +02:00
Jonathan Brouwer f14ce9dab4 Make diverging_type_vars a set of TyVid 2026-05-01 16:39:12 +02:00
Guillaume Gomez f19e850f59 Improve source code for librustdoc/visit_ast.rs 2026-05-01 16:20:39 +02:00