9154 Commits

Author SHA1 Message Date
ywxt
075ce31bd3 Fix parallel rustc not being reproducible due to unstable sorting of items. 2025-08-13 08:59:32 +08:00
Jana Dönszelmann
7aa8707639
make no_mangle explicit on foreign items 2025-08-12 12:07:14 +02:00
Esteban Küber
29d26f27a6 review comments 2025-08-10 19:15:20 +00:00
Esteban Küber
464a6b1b4a Detect struct construction with private field in field with default
When trying to construct a struct that has a public field of a private type, suggest using `..` if that field has a default value.

```
error[E0603]: struct `Priv1` is private
  --> $DIR/non-exhaustive-ctor.rs:25:39
   |
LL |     let _ = S { field: (), field1: m::Priv1 {} };
   |                            ------     ^^^^^ private struct
   |                            |
   |                            while setting this field
   |
note: the struct `Priv1` is defined here
  --> $DIR/non-exhaustive-ctor.rs:14:4
   |
LL |    struct Priv1 {}
   |    ^^^^^^^^^^^^
help: the field `field1` you're trying to set has a default value, you can use `..` to use it
   |
LL |     let _ = S { field: (), .. };
   |                            ~~
```
2025-08-10 19:15:18 +00:00
Stuart Cook
b30fe4bb8b
Rollup merge of #145147 - fee1-dead-contrib:push-mxxpmlpmzmsz, r=compiler-errors
rename `TraitRef::from_method` to `from_assoc`

also add a note to `GenericArgs::truncate_to`
2025-08-10 19:45:53 +10:00
bors
ca77504943 Auto merge of #145142 - Zalathar:rollup-oi6s8kg, r=Zalathar
Rollup of 23 pull requests

Successful merges:

 - rust-lang/rust#141658 (rustdoc search: prefer stable items in search results)
 - rust-lang/rust#141828 (Add diagnostic explaining STATUS_STACK_BUFFER_OVERRUN not only being used for stack buffer overruns if link.exe exits with that exit code)
 - rust-lang/rust#144823 (coverage: Extract HIR-related helper code out of the main module)
 - rust-lang/rust#144883 (Remove unneeded `drop_in_place` calls)
 - rust-lang/rust#144923 (Move several more float tests to floats/mod.rs)
 - rust-lang/rust#144988 (Add annotations to the graphviz region graph on region origins)
 - rust-lang/rust#145010 (Couple of minor abi handling cleanups)
 - rust-lang/rust#145017 (Explicitly disable vector feature on s390x baseline of bad-reg test)
 - rust-lang/rust#145027 (Optimize `char::is_alphanumeric`)
 - rust-lang/rust#145050 (add member constraints tests)
 - rust-lang/rust#145073 (update enzyme submodule to handle llvm 21)
 - rust-lang/rust#145080 (Escape diff strings in MIR dataflow graphviz)
 - rust-lang/rust#145082 (Fix some bad formatting in `-Zmacro-stats` output.)
 - rust-lang/rust#145083 (Fix cross-compilation of Cargo)
 - rust-lang/rust#145096 (Fix wasm target build with atomics feature)
 - rust-lang/rust#145097 (remove unnecessary `TypeFoldable` impls)
 - rust-lang/rust#145100 (Rank doc aliases lower than equivalently matched items)
 - rust-lang/rust#145103 (rustc_metadata: remove unused private trait impls)
 - rust-lang/rust#145115 (defer opaque type errors, generally greatly reduce tainting)
 - rust-lang/rust#145119 (rustc_public: fix missing parenthesis in pretty discriminant)
 - rust-lang/rust#145124 (Recover `for PAT = EXPR {}`)
 - rust-lang/rust#145132 (Refactor map_unit_fn lint)
 - rust-lang/rust#145134 (Reduce indirect assoc parent queries)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-09 08:57:23 +00:00
Deadbeef
2736d66a1f rename TraitRef::from_method to from_assoc
also add a note to `GenericArgs::truncate_to`
2025-08-09 14:22:01 +08:00
Stuart Cook
e68d621321
Rollup merge of #145097 - lcnr:type-foldable-yeet, r=wesleywiser
remove unnecessary `TypeFoldable` impls
2025-08-09 13:58:51 +10:00
bors
2de2456fb7 Auto merge of #143376 - dianne:guard-scope, r=matthewjasper
add a scope for `if let` guard temporaries and bindings

This fixes my concern with `if let` guard drop order, namely that the guard's bindings and temporaries were being dropped after their arm's pattern's bindings, instead of before (https://github.com/rust-lang/rust/pull/141295#issuecomment-2968975596). The guard's bindings and temporaries now live in a new scope, which extends until (but not past) the end of the arm, guaranteeing they're dropped before the arm's pattern's bindings.

This only introduces a new scope for match arms with guards. Perf results (https://github.com/rust-lang/rust/pull/143376#issuecomment-3034922617) seemed to indicate there wasn't a significant hit to introduce a new scope on all match arms, but guard patterns (rust-lang/rust#129967) will likely benefit from only adding new scopes when necessary (with some patterns requiring multiple nested scopes).

Tracking issue for `if_let_guard`: rust-lang/rust#51114

Tests are adapted from examples by `@traviscross,` `@est31,` and myself on rust-lang/rust#141295.
2025-08-09 03:19:26 +00:00
Trevor Gross
6fa6a854cd
Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikic
atomicrmw on pointers: move integer-pointer cast hacks into backend

Conceptually, we want to have atomic operations on pointers of the form `fn atomic_add(ptr: *mut T, offset: usize, ...)`. However, LLVM does not directly support such operations (https://github.com/llvm/llvm-project/issues/120837), so we have to cast the `offset` to a pointer somewhere.

This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely.

Cc ```@nikic``` -- this is the best we can do right now, right?
Fixes https://github.com/rust-lang/rust/issues/134617
2025-08-08 14:22:44 -05:00
Trevor Gross
f5dda19775
Rollup merge of #144039 - estebank:short-paths, r=fee1-dead
Use `tcx.short_string()` in more diagnostics

`TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`.

We add support for shortening the path of "trait path only".

Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).
2025-08-08 14:22:43 -05:00
lcnr
988569f337 remove unnecessary TypeFoldable impls 2025-08-08 15:30:15 +02:00
Stuart Cook
0d22b2e449
Rollup merge of #145009 - jackh726:ra-next-solver-changes, r=compiler-errors
A couple small changes for rust-analyzer next-solver work

Originally written by `@flodiebold`
2025-08-08 12:52:55 +10:00
Stuart Cook
562222b737
Rollup merge of #144999 - Zalathar:remove-mcdc, r=oli-obk
coverage: Remove all unstable support for MC/DC instrumentation

Preliminary support for a partial implementation of “Modified Condition/Decision Coverage” instrumentation was added behind the unstable flag `-Zcoverage-options=mcdc` in 2024. These are the most substantial PRs involved:

- rust-lang/rust#123409
- rust-lang/rust#126733

At the time, I accepted these PRs with relatively modest scrutiny, because I did not want to stand in the way of independent work on MC/DC instrumentation. My hope was that ongoing work by interested contributors would lead to the code becoming clearer and more maintainable over time.

---

However, that MC/DC code has proven itself to be a major burden on overall maintenance of coverage instrumentation, and a major obstacle to other planned improvements, such as internal changes needed for proper support of macro expansion regions.

I have also become reluctant to accept any further MC/DC-related changes that would increase this burden.

That tension has resulted in an unhappy impasse. On one hand, the present MC/DC implementation is not yet complete, and shows little sign of being complete at an acceptable level of code quality in the foreseeable future. On the other hand, the continued existence of this partial MC/DC implementation is imposing serious maintenance burdens on every other aspect of coverage instrumentation, and is preventing some of the very improvements that would make it easier to accept expanded MC/DC support in the future.

While I know this will be disappointing to some, I think the healthy way forward is accept that I made the wrong call in accepting the current implementation, and to remove it entirely from the compiler.
2025-08-08 12:52:54 +10:00
Stuart Cook
bdb082b763
Rollup merge of #144914 - estebank:short-paths-2, r=fee1-dead
Add support for `ty::Instance` path shortening in diagnostics

Make `ty::Instance` able to use `short_string` and usable in structured errors directly. Remove some ad-hoc type shortening logic.
2025-08-08 12:52:53 +10:00
dianne
b2241c78c8 add a scope for if let guard temporaries and bindings
This ensures `if let` guard temporaries and bindings are dropped before
the match arm's pattern's bindings.
2025-08-07 16:43:20 -07:00
Esteban Küber
99196657fc Use tcx.short_string() in more diagnostics
`TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`.

We add support for shortening the path of "trait path only".

Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).

When we don't actually print out a shortened type we don't need the "use `--verbose`" note.

On E0599 show type identity to avoid expanding the receiver's generic parameters.

Unify wording on `long_ty_path` everywhere.
2025-08-07 21:18:00 +00:00
Florian Diebold
29799c2e21 Add a missing UpcastFrom impl in rustc_type_ir 2025-08-07 15:16:12 +00:00
Esteban Küber
025fbe8f69 Add support for shortening Instance and use it
Replace ad-hoc type path shortening logic for recursive mono instantiation errors to use `tcx.short_string()` instead.
2025-08-06 22:21:49 +00:00
Guillaume Gomez
c152aa87a1
Rollup merge of #144998 - dianqk:visit-no-use-proj, r=cjgillot
mir: Do not modify NonUse in `super_projection_elem`

Split from rust-lang/rust#142771.
r? cjgillot
2025-08-06 21:29:34 +02:00
dianqk
d55cc9a9bd
mir: Do not modify NonUse in super_projection_elem 2025-08-06 20:41:39 +08:00
Zalathar
81ed042c8c coverage: Remove all unstable support for MC/DC instrumentation 2025-08-06 22:38:52 +10:00
bors
ec7c026125 Auto merge of #144863 - cjgillot:live-or-dead, r=Urgau
Simplify dead code lint

This PR scratches a few itches I had when looking at that code.

The perf improvement comes from keeping the `scanned` set through several marking phases. This pretty much divides by 2 the number of HIR traversals.
2025-08-05 18:10:21 +00:00
Samuel Tardieu
5c11681820
Rollup merge of #144920 - compiler-errors:span-arg, r=lqd
Dont print arg span in MIR dump for tail call

r? WaffleLapkin

This makes the MIR dump for tail call terminators consistent w/ regular calls.
2025-08-05 03:51:42 +02:00
Samuel Tardieu
58a7b873cf
Rollup merge of #144890 - WaffleLapkin:project_fields, r=lcnr
Add `InterpCx::project_fields`

I was hoping for a much bigger improvement and this is lukewarm at best ^^'

Still, I think this makes sense.
2025-08-05 03:51:40 +02:00
Samuel Tardieu
eee8d775fe
Rollup merge of #144817 - WaffleLapkin:reject-referety, r=Urgau
Properly reject tail calls to `&FnPtr` or `&FnDef`

Fixes rust-lang/rust#144795
2025-08-05 03:51:36 +02:00
Samuel Tardieu
a1e41a0227
Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillot
`Printer` cleanups

The trait `Printer` is implemented by six types, and the sub-trait `PrettyPrinter` is implemented by three of those types. The traits and the impls are complex and a bit of a mess. This PR starts to clean them up.

r? ``@davidtwco``
2025-08-05 03:51:34 +02:00
Michael Goulet
878acaa795 Dont print arg span in MIR dump for tail call 2025-08-04 18:35:43 +00:00
Waffle Lapkin
e3ed3e0f1c
small refactor of InterpResult
- don't need type alias to default type argument
- `Residual` impl allows to use more std APIs (like `<[T; N]>::try_map`)
2025-08-04 10:08:01 +02:00
Waffle Lapkin
4f94bbf13d
drive-by cleanup: fix outdated documentation 2025-08-04 09:06:02 +02:00
Nicholas Nethercote
cc62d55298 Avoid some code duplication.
`print_binder` can call `wrap_binder`.
2025-08-04 08:18:28 +10:00
Samuel Tardieu
5b751d75b4
Rollup merge of #144822 - Zalathar:hash-owner-nodes, r=compiler-errors
Return a struct with named fields from `hash_owner_nodes`

While looking through this code for other reasons, I noticed a nice opportunity to return a struct with named fields instead of a tuple. The first patch also introduces an early-return to flatten the rest of `hash_owner_nodes`.

There are further changes that could potentially be made here (renaming things, `Option<Hashes>` instead of optional fields), but I'm not deeply familiar with this code so I didn't want to disturb the calling code too much.
2025-08-03 21:56:59 +02:00
Nicholas Nethercote
2434d8cecf Remove unused arg from path_append_impl.
None of the impls use it.
2025-08-03 19:58:59 +10:00
Nicholas Nethercote
03dab500a2 Remove p!.
It's a cryptic macro that makes some things slightly more concise in
`PrettyPrinter`. E.g. if you declare `define_scope_printer!(p)` in a
scope you can then call `p! to get these transformations:
```
p!("foo");         -->  write!(p, "foo")?;
p!(print(ty));     -->  ty.print(p)?;
p!(method(args));  -->  p.method(args)?;
```
You can also chain calls, e.g.:
```
p!("foo", print(ty));  -->  write!(p, "foo")?; ty.print(p)?;
```
Ultimately this doesn't seem worth it. The macro definition is hard to
read, the call sites are hard to read, `define_scope_printer!` is pretty
gross, and the code size reductions are small. Tellingly, many normal
`write!` and `print` calls are sprinkled throughout the code, probably
because people have made modifications and didn't want to use or
understand how to use `p!`.

This commit removes it.
2025-08-03 19:58:56 +10:00
Nicholas Nethercote
1698c8e322 Rename Printer variables.
Currently they are mostly named `cx`, which is a terrible name for a
type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with
other types like `TyCtxt`. This commit changes them to `p`. A couple of
existing `p` variables had to be renamed to make way.
2025-08-03 19:58:00 +10:00
Nicholas Nethercote
bd0a308ca2 Inline and remove two FmtPrinter methods.
They each have a single call site.
2025-08-03 19:58:00 +10:00
bors
da19b9d24c Auto merge of #144677 - nnethercote:bound-const-handling, r=lcnr
Improve bound const handling

A few changes to make const handling more similar to type handling.

r? `@compiler-errors` -errors
2025-08-03 05:26:43 +00:00
Camille GILLOT
bc177055f7 Do not record derived impl def-id for dead code. 2025-08-02 19:19:17 +00:00
Zalathar
d3e597a132 Return a struct with named fields from hash_owner_nodes 2025-08-02 23:11:53 +10:00
Zalathar
40f587aa0d Flatten hash_owner_nodes with an early-return 2025-08-02 23:07:45 +10:00
Samuel Tardieu
d082ff4c04
Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=Amanieu
Improve formatting of doc code blocks

We don't currently apply automatic formatting to doc comment code blocks. As a
result, it has built up various idiosyncracies, which make such automatic
formatting difficult. Some of those idiosyncracies also make things harder for
human readers or other tools.

This PR makes a few improvements to doc code formatting, in the hopes of making
future automatic formatting easier, as well as in many cases providing net
readability improvements.

I would suggest reading each commit separately, as each commit contains one
class of changes.
2025-08-02 11:24:24 +02:00
bors
c23f07d8c5 Auto merge of #144479 - cjgillot:incr-privacy-mod, r=petrochenkov
Perform check_private_in_public by module.

Based on https://github.com/rust-lang/rust/pull/116316
2025-08-02 01:59:11 +00:00
bors
63f6845e57 Auto merge of #144458 - compiler-errors:no-witness-mini, r=lcnr
Remove the witness type from coroutine *args* (without actually removing the type)

This does as much of rust-lang/rust#144157 as we can without having to break rust-lang/rust#143545 and/or introduce some better way of handling higher ranked assumptions.

Namely, it:
* Stalls coroutines based off of the *coroutine* type rather than the witness type.
* Reworks the dtorck constraint hack to not rely on the witness type.
* Removes the witness type from the args of the coroutine, eagerly creating the type for nested obligations when needed (auto/clone impls).

I'll experiment with actually removing the witness type in a follow-up.

r? lcnr
2025-08-01 21:07:49 +00:00
Michael Goulet
e9765781b2 Remove the witness type from coroutine args 2025-07-31 17:38:28 +00:00
Jana Dönszelmann
26c28ee2ef
Rollup merge of #144726 - jdonszelmann:move-attr-data-structures, r=lcnr
merge rustc_attr_data_structures into rustc_hir

this move was discussed on zulip: [#t-compiler > attribute parsing rework @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/528530091)

Many PRs in the attribute rework depend on this move.
2025-07-31 17:19:40 +02:00
Jana Dönszelmann
5712d50648
Rollup merge of #144712 - nnethercote:dedup-num-types, r=fmease
Deduplicate `IntTy`/`UintTy`/`FloatTy`.

There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed.

r? `@fmease`
2025-07-31 17:19:39 +02:00
Jana Dönszelmann
e1d3ad89c7
remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
Nicholas Nethercote
1901dde97b Deduplicate IntTy/UintTy/FloatTy.
There are identical definitions in `rustc_type_ir` and `rustc_ast`. This
commit removes them and places a single definition in `rustc_ast_ir`.
This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but
means a bunch of silly conversion functions can be removed.

The one annoying wrinkle is that the old version had differences in
their `Debug` impls, e.g. one printed `u32` while the other printed
`U32`. Some compiler error messages rely on the former (yuk), and some
clippy output depends on the latter. So the commit also changes clippy
to not rely on `Debug` and just implement what it needs itself.
2025-07-31 19:56:11 +10:00
Nicholas Nethercote
64be8bb599 Check consts in ValidateBoundVars.
Alongside the existing type and region checking.
2025-07-31 19:54:58 +10:00
Nicholas Nethercote
507dec4dc3 Make const bound handling more like types/regions.
Currently there is `Ty` and `BoundTy`, and `Region` and `BoundRegion`,
and `Const` and... `BoundVar`. An annoying inconsistency.

This commit repurposes the existing `BoundConst`, which was barely used,
so it's the partner to `Const`. Unlike `BoundTy`/`BoundRegion` it lacks
a `kind` field but it's still nice to have because it makes the const
code more similar to the ty/region code everywhere.

The commit also removes `impl From<BoundVar> for BoundTy`, which has a
single use and doesn't seem worth it.

These changes fix the "FIXME: We really should have a separate
`BoundConst` for consts".
2025-07-31 19:29:40 +10:00