Commit Graph

9198 Commits

Author SHA1 Message Date
Nicholas Nethercote
66fd421208 Move rustc_middle::parameterized to rustc_metadata.
It's only used there.
2025-07-31 15:14:34 +10:00
Nicholas Nethercote
0a3eb2f88e Remove unused ParameterizedOverTcx impls. 2025-07-31 15:04:22 +10:00
Nicholas Nethercote
b44eb11bdf Move ParamTerm out of rustc_middle.
It's only used in `rustc_hir_typeck`.
2025-07-31 11:50:45 +10:00
Nicholas Nethercote
3a1f2d5cc2 Move an EarlyParamRegion impl block.
Next to all the other `EarlyParamRegion` pieces.
2025-07-31 11:50:43 +10:00
Nicholas Nethercote
790ab94798 Move ImplHeader out of rustc_middle.
It's not used in `rustc_middle`, and `rustc_trait_selection` is a better
place for it.
2025-07-31 11:50:36 +10:00
Nicholas Nethercote
e83c8cb26c Move ResolverOutputs out of rustc_middle.
It's not used in `rustc_middle`, and `rustc_resolve` is a better place
for it.
2025-07-31 11:50:23 +10:00
Nicholas Nethercote
2bf10de494 Remove unused impl_decodable_via_ref! entries. 2025-07-31 11:48:53 +10:00
bors
606dcc0d2e Auto merge of #116316 - cjgillot:incr-privacy, r=petrochenkov
Remove eval_always from check_private_in_public.

This PR attempts to avoid re-computing `check_private_in_public` query. First by marking the query as non-`eval_always`, and by reducing the amount of accesses to HIR as much as possible.

Latest perf https://github.com/rust-lang/rust/pull/116316#issuecomment-3094672105 shows that we manage it. The cost is extra dep-graph bookkeeping.
2025-07-30 21:29:47 +00:00
Ralf Jung
ba5b6b9ec4 const-eval: full support for pointer fragments 2025-07-30 08:13:58 +02:00
bors
919c409243 Auto merge of #144577 - oli-obk:wrapping-niche, r=scottmcm
Pick the largest niche even if the largest niche is wrapped around

fixes rust-lang/rust#144388

r? `@scottmcm`
2025-07-30 02:57:04 +00:00
Oli Scherer
219bad4946 Reuse sign_extend helper 2025-07-29 14:17:48 +00:00
Oli Scherer
75bdbf25e3 Pick the largest niche even if the largest niche is wrapped around 2025-07-29 14:08:15 +00: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
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
Boxy
2b11851452 Raw Pointers are Constant PatKinds too 2025-07-28 10:13:19 +01: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
Kivooeo
bae38bad78 use let chains in hir, lint, mir 2025-07-28 06:10:14 +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
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
Ralf Jung
296586fb02 miri: for ABI mismatch errors, say which argument is the problem 2025-07-27 22:26:10 +02: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
Camille GILLOT
a1f5a6d781 Perform check_private_in_public by module. 2025-07-26 21:21:04 +00:00
Jonathan Brouwer
ec637000c6 Use the new attributes throughout the codebase
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-26 20:26:05 +02:00
Trevor Gross
bfacbf2a3d Rollup merge of #144412 - camsteffen:localkey-cell-refactors, r=petrochenkov
Small cleanup: Use LocalKey<Cell> methods more
2025-07-26 02:19:30 -05:00
Josh Triplett
715088094c Improve and regularize comment placement in doc code
Because doc code does not get automatically formatted, some doc code has
creative placements of comments that automatic formatting can't handle.
Reformat those comments to make the resulting code support standard Rust
formatting without breaking; this is generally an improvement to
readability as well.

Some comments are not indented to the prevailing indent, and are instead
aligned under some bit of code. Indent them to the prevailing indent,
and put spaces *inside* the comments to align them with code.

Some comments span several lines of code (which aren't the line the
comment is about) and expect alignment. Reformat them into one comment
not broken up by unrelated intervening code.

Some comments are placed on the same line as an opening brace, placing
them effectively inside the subsequent block, such that formatting would
typically format them like a line of that block. Move those comments to
attach them to what they apply to.

Some comments are placed on the same line as a one-line braced block,
effectively attaching them to the closing brace, even though they're
about the code inside the block. Reformat to make sure the comment will
stay on the same line as the code it's commenting.
2025-07-25 22:02:09 -07:00
Nicholas Nethercote
837b6106a3 Pre-intern some TyKind::Bound values.
We already do the same thing for bound regions. This is a small perf win
for the new trait solver.
2025-07-25 13:26:20 +10:00
Nicholas Nethercote
bc64bfd75b Tweak bound region pre-interning.
- Cover `DebruijnIndex(2)`, for slightly better coverage.
- Rename some things, to account for other region things that were
  renamed.
2025-07-25 13:24:36 +10:00
Camille GILLOT
a2320b2553 Remove eval_always from check_private_in_public. 2025-07-25 02:41:26 +00:00
Cameron Steffen
b8d628c1e1 Use LocalKey<Cell> methods more 2025-07-24 13:21:25 -05:00
León Orell Valerian Liehr
40482a2ffa Rollup merge of #144094 - saethlin:codegen-the-main-fn, r=petrochenkov
Ensure we codegen the main fn

This fixes two bugs. The one that was identified in the linked issue is that when we have a `main` function, mono collection didn't consider it as an extra collection root.

The other is that since CGU partitioning doesn't  know about the call edges between the entrypoint functions, naively it can put them in different CGUs and mark them all as internal. Which would result in LLVM just deleting all of them. There was an existing hack to exclude `lang = "start"` from internalization, which I've extended to include `main`.

Fixes https://github.com/rust-lang/rust/issues/144052
2025-07-24 15:08:21 +02:00
León Orell Valerian Liehr
404f904f76 Rollup merge of #143374 - cjgillot:bare-extern-crate-map, r=petrochenkov
Unquerify extern_mod_stmt_cnum.

Based on https://github.com/rust-lang/rust/pull/143247
r? `````@ghost````` for perf
2025-07-24 15:08:19 +02:00
Camille GILLOT
0460c92d52 Remove useless lifetime parameter. 2025-07-23 23:54:37 +00:00
Camille GILLOT
9ff071219b Give an AllocId to ConstValue::Slice. 2025-07-23 23:54:37 +00:00
Ralf Jung
efcae7d31d properly use caller-side panic location for some GenericArgs methods 2025-07-23 08:32:55 +02:00
Camille GILLOT
3440bc92f9 Unquerify extern_mod_stmt_cnum. 2025-07-22 22:37:50 +00:00
Matthias Krüger
b934f1adca Rollup merge of #143373 - cjgillot:bare-unused-trait-imports, r=petrochenkov
Unquerify maybe_unused_trait_imports.

Based on https://github.com/rust-lang/rust/pull/143247
r? ```@ghost``` for perf
2025-07-22 10:26:14 +02:00
Ben Kimock
c4eb077616 Ensure we codegen and don't internalize the entrypoint 2025-07-21 19:54:37 -04:00
许杰友 Jieyou Xu (Joe)
ef4a7fb1b7 Rollup merge of #144080 - jieyouxu:realign, r=BoxyUwU
Mitigate `#[align]` name resolution ambiguity regression with a rename

Mitigates beta regression rust-lang/rust#143834 after a beta backport.

### Background on the beta regression

The name resolution regression arises due to rust-lang/rust#142507 adding a new feature-gated built-in attribute named `#[align]`. However, unfortunately even [introducing new feature-gated unstable built-in attributes can break user code](https://www.github.com/rust-lang/rust/issues/134963) such as

```rs
macro_rules! align {
    () => {
        /* .. */
    };
}

pub(crate) use align; // `use` here becomes ambiguous
```

### Mitigation approach

This PR renames `#[align]` to `#[rustc_align]` to mitigate the beta regression by:

1. Undoing the introduction of a new built-in attribute with a common name, i.e. `#[align]`.
2. Renaming `#[align]` to `#[rustc_align]`. The renamed attribute being `rustc_align` will not introduce new stable breakages, as attributes beginning with `rustc` are reserved and perma-unstable. This does mean existing nightly code using `fn_align` feature will additionally need to specify `#![feature(rustc_attrs)]`.

This PR is very much a short-term mitigation to alleviate time pressure from having to fully fix the current limitation of inevitable name resolution regressions that would arise from adding any built-in attributes. Long-term solutions are discussed in [#t-lang > namespacing macro attrs to reduce conflicts with new adds](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/namespacing.20macro.20attrs.20to.20reduce.20conflicts.20with.20new.20adds/with/529249622).

### Alternative mitigation options

[Various mitigation options were considered during the compiler triage meeting](https://github.com/rust-lang/rust/issues/143834#issuecomment-3084415277), and those consideration are partly reproduced here:

- Reverting the PR doesn't seem very minimal/trivial, and carries risks of its own.
- Rename to a less-common but aim-to-stabilization name is itself not safe nor convenient, because (1) that risks introducing new regressions (i.e. ambiguity against the new name), and (2) lang would have to FCP the new name hastily for the mitigation to land timely and have a chance to be backported. This also makes the path towards stabilization annoying.
- Rename the attribute to a rustc attribute, which will be perma-unstable and does not cause new ambiguities in stable code.
    - This alleviates the time pressure to address *this* regression, or for lang to have to rush an FCP for some new name that can still break user code.
    - This avoids backing out a whole implementation.

### Review advice

This PR is best reviewed commit-by-commit.

- Commit 1 adds a test `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` which demonstrates the current name resolution regression re. `align`. This test fails against current master.
- Commit 2 carries out the renames and test reblesses. Notably, commit 2 will cause `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` to change from fail (nameres regression) to pass.

This PR, if the approach still seems acceptable, will need a beta-backport to address the beta regression.
2025-07-22 00:54:28 +08:00
Jacob Pratt
830b8237de Rollup merge of #144216 - Nadrieril:revert-pin-hack, r=compiler-errors
Don't consider unstable fields always-inhabited

This reverts the hack in https://github.com/rust-lang/rust/pull/133889 now that `Pin`'s field is no longer public.

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

r? ```@compiler-errors```
2025-07-20 23:11:22 -04:00
Nadrieril
3567ab19a0 Don't consider unstable fields always-inhabited
This reverts the hack in https://github.com/rust-lang/rust/pull/133889
now that `Pin`'s field is no longer public.
2025-07-20 18:23:18 +02:00
Camille GILLOT
258e410feb Unquerify maybe_unused_trait_imports. 2025-07-20 13:19:05 +00:00
Matthias Krüger
82c48e1c69 Rollup merge of #144148 - compiler-errors:async-print-hack, r=lqd
Remove pretty print hack for async blocks

I introduced this hack 3 years ago, but it's not needed anymore, probably due to https://github.com/rust-lang/rust/pull/104321.
2025-07-20 08:56:10 +02:00
bors
1079c5edb2 Auto merge of #144145 - matthiaskrgr:rollup-swc74s4, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#138554 (Distinguish delim kind to decide whether to emit unexpected closing delimiter)
 - rust-lang/rust#142673 (Show the offset, length and memory of uninit read errors)
 - rust-lang/rust#142693 (More robustly deal with relaxed bounds and improve their diagnostics)
 - rust-lang/rust#143382 (stabilize `const_slice_reverse`)
 - rust-lang/rust#143928 (opt-dist: make llvm builds optional)
 - rust-lang/rust#143961 (Correct which exploit mitigations are enabled by default)
 - rust-lang/rust#144050 (Fix encoding of link_section and no_mangle cross crate)
 - rust-lang/rust#144059 (Refactor `CrateLoader` into the `CStore`)
 - rust-lang/rust#144123 (Generalize `unsize` and `unsize_into` destinations)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-19 05:02:40 +00:00
Jieyou Xu
69b71e4410 Mitigate #[align] name resolution ambiguity regression with a rename
From `#[align]` -> `#[rustc_align]`. Attributes starting with `rustc`
are always perma-unstable and feature-gated by `feature(rustc_attrs)`.

See regression RUST-143834.

For the underlying problem where even introducing new feature-gated
unstable built-in attributes can break user code such as

```rs
macro_rules! align {
    () => {
        /* .. */
    };
}

pub(crate) use align; // `use` here becomes ambiguous
```

refer to RUST-134963.

Since the `#[align]` attribute is still feature-gated by
`feature(fn_align)`, we can rename it as a mitigation. Note that
`#[rustc_align]` will obviously mean that current unstable user code
using `feature(fn_aling)` will need additionally `feature(rustc_attrs)`,
but this is a short-term mitigation to buy time, and is expected to be
changed to a better name with less collision potential.

See
<https://rust-lang.zulipchat.com/#narrow/channel/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202025-07-17/near/529290371>
where mitigation options were considered.
2025-07-19 01:42:30 +08:00
Michael Goulet
e6f283080c Remove pretty print hack for async blocks 2025-07-18 17:30:02 +00:00
Matthias Krüger
b3827e4f37 Rollup merge of #142673 - oli-obk:uninit-read-mem, r=RalfJung
Show the offset, length and memory of uninit read errors

r? ``@RalfJung``

I want to improve memory dumps in general. Not sure yet how to do so best within rust diagnostics, but in a perfect world I could generate a dummy in-memory file (that contains the rendered memory dump) that we then can then provide regular rustc `Span`s to. So we'd basically report normal diagnostics for them with squiggly lines and everything.
2025-07-18 19:14:43 +02:00