Commit Graph

10440 Commits

Author SHA1 Message Date
Nicholas Nethercote 22cf1fb6fe Split LintExpectationId
`LintExpectationId` has two variants, `Unstable` and `Stable`. There are
some places where both variants are possible, but there are also places
where only one of `Unstable` or `Stable` is possible.

This commit encodes this into the type system by introducing
new types `UnstableLintExpectationId` and `StableLintExpectationId`. The
variants of `LintExpectationId` now enclose these. This makes it clearer
what values are possible where.

Other things of note:
- `LintLevelsProvider` gets an associated type and some method changes.
- `LintContext` gets an associated type.
- `LevelSpec` is made generic. `UnstableLevelSpec` and `StableLevelSpec`
  typedefs are added.
- The unstable types are now guaranteed by the type system to never be
  stably hashed. Previously this was a runtime check.
2026-05-16 21:16:35 +10:00
Guillaume Gomez 1f5737c853 Rollup merge of #156564 - nnethercote:LevelSpec, r=GuillaumeGomez
Lint level cleanups

Some naming improvements, some type safety improvements, and some simplifications. Details in individual commits.

r? @GuillaumeGomez
2026-05-14 16:51:08 +02:00
Nicholas Nethercote 530a73f17e Prevent invalid LevelSpec values
`LevelSpec` has two related fields, `level` and `lint_id`. This commit
makes the fields private (and introduces getters) to ensure they are set
together using only valid combinations.

The commit also introduces `is_allow` and `is_expect` methods because
those are useful.
2026-05-14 16:28:50 +10:00
Nicholas Nethercote ccfac5469a Rename LevelAndSource
It is misnamed, given that it has three fields: `level`, `lint_id`, and
`src`. (Presumably the `lint_id` was added later.)

This commit renames it as `LevelSpec`. (I also considered `LevelInfo`
but that's very generic. `Spec` has pre-existing uses in
`LintLevelsProvider::current_specs` and `LintSet::specs` and
`ShallowLintLevelMap::specs`.)

Related things renamed as well:
- `level` -> `level_spec` (where appropriate)
- `lint_levels` -> `lint_level_specs`
- `get_lint_level` -> `get_lint_level_spec`
- `level_and_source` -> `level_spec`
- `CodegenLintLevels` -> `CodegenLintLevelSpecs`
- `raw_lint_id_level` -> `raw_lint_level_spec`
- `lint_level_at_node` -> `lint_level_spec_at_node`
- `reveal_actual_level` -> `reveal_actual_level_spec`
- `probe_for_lint_level` -> `probe_for_lint_level_spec`

This clears up a lot of `Level` vs. `LevelSpec` ambiguity. E.g. no more
`level.level` expressions.
2026-05-14 13:20:57 +10:00
Jonathan Brouwer 604d124199 Rollup merge of #156500 - Bryanskiy:macros_vis, r=petrochenkov
Privacy: move macros handling to early stage

The patch moves effective visibility computation for macros from `rustc_privacy` to `rustc_resolve`. It will enable this optimization: https://github.com/rust-lang/rust/pull/156228.

However, I found some problems with macro handling while I was doing this. The current implementation was written ~6 years ago and checks the reachability of a definition from a macro by nominal visibility. In general this is incorrect.

For example, in the current implementation modules are not traversed if their nominal visibility is less then the nominal visibility of a module defining macro: https://github.com/rust-lang/rust/blob/29b7590130c83542a095cdf1323ed0f78eec2bb8/compiler/rustc_privacy/src/lib.rs#L618-L626

As a result, in order to compile code like  `tests/ui/definition-reachable/auxiliary/field-method-macro.rs`. we have to additionally traverse types of adt fields: https://github.com/rust-lang/rust/blob/29b7590130c83542a095cdf1323ed0f78eec2bb8/compiler/rustc_privacy/src/lib.rs#L628-L638

This is a hack and the proper solution would be to check definitions with `EffectiveVisibilities::is_reachable`. I haven’t done this yet, as it would start to trigger many lints as more items become reachable. I think it’s better to leave the change to another commit.

r? @petrochenkov
2026-05-14 00:35:36 +02:00
bors ff9a9ea07b Auto merge of #138995 - oli-obk:split-resolver, r=petrochenkov
Split the node_id_to_def_id table into a per-owner table

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/138995)*

My goal is to split all the resolver tables that get passed to act lowering into per-owner tables, so that all information that ast lowering needs from the resolver is separated by owners. This should allow us to fully split ast lowering to have one query invocation per owner that steal the individual resolver results for each owner.

part of https://github.com/rust-lang/rust-project-goals/issues/620
2026-05-13 19:02:46 +00:00
Bryanskiy 3d0ee528cb Privacy: move macros handling to early stage 2026-05-13 20:04:42 +03:00
Jonathan Brouwer 68e98f0d40 Rollup merge of #156536 - nnethercote:reveal_actual_level-improvements, r=GuillaumeGomez
`reveal_actual_level` improvements

Details in individual commits.

r? @GuillaumeGomez
2026-05-13 15:16:19 +02:00
Jonathan Brouwer 0705b602f0 Rollup merge of #155815 - djc:swift-cc, r=jieyouxu
Add Swift function call ABI

Adds an unstable `extern "Swift"` ABI behind the `abi_swift` feature gate, mapping to LLVM's `swiftcc` calling convention. This is only allowed (a) for `is_darwin_like` targets, since the [ABI is only stable for those platforms](https://www.swift.org/blog/abi-stability-and-more/) and (b) with the LLVM backend, since the other backends don't support it.

Current approaches to interoperability with Swift lower to Objective-C (or require a Swift stub exposing a C ABI), but that is an optional mapping on the Swift side that some newer Apple frameworks omit. It would be great to be able to more directly/natively be able to call into Swift code directly via its stable API (on Apple platforms at least).

Reimplements rust-lang/rust#64582 on top of current main. The main objection to the previous PR seemed to be that it needed an RFC, but there was pushback (which seems sensible to me) that an RFC could be deferred until stabilization.

I think this needs a tracking issue? Would be happy to write one up if/when there is a consensus that this will be merged.
2026-05-13 15:16:17 +02:00
Nicholas Nethercote b86ef89082 Change reveal_actual_level's closure's return type, again
Again, the returned triple is equivalent to `LevelAndSource`.
2026-05-13 19:54:30 +10:00
Nicholas Nethercote 7cd42a77fb Change reveal_actual_level's closure's return type
It's currrently `(Option<(Level, Option<LintExpectationId>)>,
LintLevelSource)`. But when the first element of the pair is `None` the
second element is always `LintLevelSource::Default`. So this commit
moves the `LintLevelSource` within the `Option`, which simplifies
things a bit.
2026-05-13 19:54:30 +10:00
Nicholas Nethercote 202e86102c Change reveal_actual_level return type
It currently returns a triple: `(Level, Option<LintExpectationId>,
LintLevelSource)`. That's structurally identical to `LevelAndSource`, so
this commit changes it accordingly.
2026-05-13 19:54:30 +10:00
Nicholas Nethercote 9de0b2dd65 Improve reveal_actual_level
`reveal_actual_level` has two call sites, which look like this:
```
let (level, mut src) = self.raw_lint_id_level(lint, idx, aux);
let (level, lint_id) = reveal_actual_level(level, &mut src, sess, lint, |id| {
    self.raw_lint_id_level(id, idx, aux)
});
```
and:
```
let (level, mut src) = self.probe_for_lint_level(tcx, lint, cur);
let (level, lint_id) = reveal_actual_level(level, &mut src, tcx.sess, lint, |lint| {
    self.probe_for_lint_level(tcx, lint, cur)
});
```
They both have the same pattern: there's a prior call expression that is then
repeated within a closure passed to `reveal_actual_level`.

This commit moves that prior call inside `reveal_actual_level`, making things
simpler.
2026-05-13 19:54:28 +10:00
Oli Scherer 3a2ae6a204 Stop putting owner's DefId into their own node_id_to_def_id map
Now they unfortunately land in their parent, which is not necessary
2026-05-13 09:29:22 +02:00
Oli Scherer adb2b0fd57 Split the resolver tables into per-owner tables, starting with node_id_to_def_id 2026-05-13 09:22:55 +02:00
bors c8c4c83d57 Auto merge of #156224 - khyperia:unnormalized-migration, r=BoxyUwU
Unnormalized migration: assert_fully_normalized, struct_tail, and `field.ty`



tracking issue: https://github.com/rust-lang/rust/issues/155345 (first checkbox, and partial second checkbox, of that issue)

I'm going a bit slower than expected (less free time than I'd hope, lots of GCA work that I'm doing instead), and figured I'd just submit what I have now rather than building up a big batch of changes. Slow and steady!

r? @lcnr
2026-05-13 00:16:00 +00:00
lcnr 950bbe7269 self review 2026-05-12 22:03:27 +02:00
lcnr 3fb166fb6f tiny PR 2026-05-12 21:58:50 +02:00
khyperia 57b3e84ed4 Unnormalized migration: struct_tail takes fn taking Unnormalized 2026-05-12 20:45:13 +02:00
khyperia 869c941be9 Unnormalized migration: introduce assert_fully_normalized 2026-05-12 20:45:13 +02:00
Jonathan Brouwer 4ce7ac120c Rollup merge of #156287 - cyrgani:unbox-2, r=petrochenkov
move more compiler crates away from `box_patterns`

Part of https://github.com/rust-lang/rust/issues/156110.
2026-05-12 18:53:35 +02:00
Dirkjan Ochtman f49e45101c Add Swift function call ABI
Adds an unstable `extern "Swift"` ABI behind the `abi_swift` feature
gate, mapping to LLVM's `swiftcc` calling convention. Cranelift and
GCC backends fall back to the platform default since they have no
equivalent.
2026-05-12 17:09:19 +02:00
bors 29b7590130 Auto merge of #155887 - BoxyUwU:higher_ranked_assumptions_v2, r=lcnr
-Zassumptions-on-binders



r? lcnr

cc https://rust-lang.github.io/rust-project-goals/2026/assumptions_on_binders.html I would cc a tracking issue but the project goals haven't been finalized yet ^^'

Implements `-Zassumptions-on-binders`. This has a few main components:
1. We introduce a new form of region constraints for use by the trait solver which supports ORs
2. When entering binders universally inside of the trait solver we walk the bound thing and compute a list of region assumptions. We then track in the `InferCtxt` all the region outlives and type outlives mentioning a placeholder from the binder for use when handling constraints involving placeholders
3. Ideally when exiting a binder, but currently actually when computing a response inside the solver, we look through all of region constraints involving placeholders and eagerly handle these region constraints instead of returning them to the caller

This is very much a first-draft impl (though it is vaguely functional), there's a lot we need to change going forwards:
- We should really be using this new form of region constraint everywhere/more generally we shouldnt have two kinds of region constraints
- We shouldn't be computing implied bounds when entering binders, instead they should be explicit everywhere and actually checked when instantiating binders. As-is `-Zassumptions-on-binders` probably widens existing soundness holes around implied bounds due to having significantly more implied bounds
- We should be eagerly handling placeholders *everywhere* not just inside of the trait solver. Right now there will still be missing assumptions for placeholders when we do higher ranked type relations during type checking outside of the trait solver.
- I'm not normalizing our assumptions or our constraints and we should be doing both 
- Handling of alias outlives' involving placeholders is incomplete in a number of ways
- We should handle placeholders when leaving binders not when computing responses IMO
- Actually support OR region constraints in borrow checking and region checking  right now all our OR constraints are converted into normal ANDed region constraints in root contexts.
- Right now diagnostics just point to the whole item which the unsatisfied constraints came from. this is suboptimal! fix this!
- Move universe information into InferCtxtInner so it can be rolled back by probes
- we should make some kind of test suite helper so we can directly write universal/existential quantifiers and assumptions rather than having to go through rust syntax :')

How do we actually eagerly handle constraints?

The general idea is that we have some function (`eagerly_handle_placeholders_in_universe`) which takes:
- A set of region constraints
- The universe which we want to eagerly handle constraints in
- A set of outlives assumptions associated with that universe/binder

This function will rewrite all of the region constraints which involve placeholders from the passed in universe to be in terms of variables from smaller universes (or drop the constraints if we know them to be satisfied). For example:
```rust
for<'a> where('a: 'b) {
    prove ('a: 'c)
}
```
when exiting `for<'a>` we want to handle the `'!a: 'c` constraint *somehow* and we can do that by requiring that *any* of the lifetimes which `'!a` outlives, themselves outlive `'c`. In this case we can require `Or('b: 'c)` and instead of `'!a: 'c` which gives us a constraint that makes sense after exiting the forall.

some more examples:
```rust
for<'a> where('a: 'b, 'a: 'c) {
    prove('a: 'd)
}
// rewritten to Or('b: 'd, 'c: 'd)

for<'a> where('b: 'a) {
    prove(T: 'a)
}
// rewritten to Or(T: 'b)
```

The tricky thing here is that we want/need to avoid the trait solver knowing about *all* type outlives/region outlives assumptions. So this algorithm is implemented with only knowing about the assumptions coming from the binder that is being exited.

We want to avoid passing all outlives assumptions through the trait solver for two main reasons. The first is just perf, augmenting the `ParamEnv` with significant amounts of outlives assumptions could easily mess up caching. 

The second is that it's Not Possible™️ to implement. Type checking requires trait solving inside of a closure which still has an uninferred signature, this means that there are some set of implied bounds that we just don't know about yet because we only know some inference variable is well formed and nothing else.

---

Long term we should be able to wholly rip out placeholder handling from borrow checking and we won't ever encounter placeholders outside of the binders they were produced from.
2026-05-12 01:40:56 +00: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
Boxy df7bb96831 review 2026-05-11 21:32:42 +02:00
Boxy ae6b75e395 new stuff 2026-05-11 20:48:08 +02:00
Boxy 90e6c79079 rewrite region constraints to smaller universes 2026-05-11 20:48:08 +02:00
Boxy 335e25eed0 new region constraint representation 2026-05-11 20:48:07 +02:00
Jonathan Brouwer 7843355462 Rollup merge of #156384 - Zalathar:pretty-def-id, r=tiif
Remove some dead code for dumping MIR for a single DefId

The functions that call `dump_mir_def_ids` are themselves never called with a specific DefId; they always dump MIR for the entire crate.
2026-05-11 10:29:20 +02:00
cyrgani e722c36d83 use deref_patterns in rustc_middle 2026-05-10 21:05:37 +00:00
bors 4b0c9d76ae Auto merge of #156405 - JonathanBrouwer:rollup-yJcad1j, r=JonathanBrouwer
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#156394 (miri subtree update)
 - rust-lang/rust#154972 (Implement `core::arch::return_address` and tests)
 - rust-lang/rust#155679 (rustdoc: Reify emission types)
 - rust-lang/rust#155982 (Fix closure HIR span context mismatch)
 - rust-lang/rust#156323 (Handle --print=backend-has-mnemonic in cg_clif)
 - rust-lang/rust#156387 (std fs tests: avoid matching on OS-provided error string)
 - rust-lang/rust#156129 (compiletest: Migrate from `PassMode`/`FailMode` to `PassFailMode`)
 - rust-lang/rust#156192 (core: Replace `ptr::slice_from_raw_parts` with `slice::from_raw_parts`)
 - rust-lang/rust#156365 (stream_send_recv_stress tests: wait for threads to finish)
 - rust-lang/rust#156368 (Fix invalid unreachable in is_known_valid_scrutinee for Reborrow)
2026-05-10 19:58:51 +00:00
Jonathan Brouwer 29961709f1 Rollup merge of #155982 - cijiugechu:gio-ice-repro, r=chenyukang
Fix closure HIR span context mismatch

Ensure span has the closure expression's SyntaxContext.

Closes rust-lang/rust#155724
2026-05-10 19:05:44 +02:00
bors e8f92f5769 Auto merge of #144537 - frank-king:feature/pin-drop, r=petrochenkov
Add `Drop::pin_drop` for pinned drops





This PR is part of the `pin_ergonomics` experiment (the tracking issue is rust-lang/rust#130494). It allows implementing `Drop` with a pinned `self` receiver, which is required for safe pin-projection.

Implementations:
- [x] At least and at most one of `drop` and `pin_drop` should be implemented.
- [x] No direct call of `drop` or `pin_drop`. They should only be called by the drop glue.
- [x] `pin_drop` must and must only be used with types that support pin-projection (i.e. types with `#[pin_v2]`).
- [ ] Allows writing `fn drop(&pin mut self)` and desugars to `fn pin_drop(&pin mut self)`. (Will be in the next PRs)
2026-05-10 16:43:01 +00:00
bors 99eed207b4 Auto merge of #156185 - petrochenkov:queffvis, r=mu001999
resolve: Evaluate private visibilities eagerly in eff vis computation

It's cheaper to evaluate them now when `Decl`arations keep their parent modules.
2026-05-10 09:28:26 +00:00
Zalathar 9d01bf83f9 Remove some dead code for dumping MIR for a single DefId 2026-05-10 17:18:35 +10:00
Vadim Petrochenkov cc630bc470 resolve: Evaluate private visibilities eagerly in eff vis computation 2026-05-10 08:06:03 +03:00
Matthias Krüger 02f733bb48 Rollup merge of #156169 - nnethercote:simplify-SwitchInt-stuff, r=cjgillot
Change `SwitchInt` handling in dataflow analysis.

We call `get_switch_int_data` once for the switch and then pass that data to `apply_switch_int_edge_effect` for each switch target.

The only case in practice is `MaybePlacesSwitchIntData` which does an awkward thing, maintaining an index into the discriminants and updating it on each call to `apply_switch_int_edge_effect`.

This commit changes things to do more work up front in `get_switch_int_data`, in order to then do less work in `apply_switch_int_edge_effect`. This avoids the need for the `variants` and `next_discr` methods and the discriminants index. Overall it's a little simpler.

r? @cjgillot
2026-05-10 03:17:00 +02:00
Jacob Pratt 80263e17a3 Rollup merge of #156235 - rajgandhi1:compiler_stack_overflow_fix, r=adwinwhite
fix: Guard SizeSkeleton::compute against stack overflow

Fixes rust-lang/rust#156137

Fix: extract the recursion into a private `compute_inner` that carries a depth counter. When depth exceeds the crate's recursion limit, return `LayoutError::Unknown` and let the existing transmute size-check produce a normal error instead of crashing.

A regression test is included in `tests/ui/transmute/`.
2026-05-09 09:27:58 -04:00
Jacob Pratt 71e64b9d25 Rollup merge of #156124 - nnethercote:StableHash-renamings-2, r=jieyouxu
Make stable hashing names consistent (part 2)

This PR finishes the implementation of MCP 893.

r? @jieyouxu
2026-05-09 09:27:58 -04:00
Frank King 0fc0057f8d Fix: Add a span to AttributeKind::PinV2 2026-05-09 19:10:18 +08:00
rajgandhi1 7a900df1b9 Guard SizeSkeleton::compute against stack overflow 2026-05-09 16:02:15 +05:30
Scott McMurray 05f52c7a99 Have arrays' drop_glue just unsize and call the slice version 2026-05-09 01:01:03 -07:00
Matthias Krüger dbc4f62a0b Rollup merge of #156141 - jdonszelmann:use-right-typingmode, r=lcnr
Resolve some cases of #132279 by using the right typing mode in the next solver

r? @lcnr

Convert 3 FIXMEs of rust-lang/rust#132279 to using the right typing mode when we can (`tcx.use_typing_mode_borrowck()`)

Also resolves https://github.com/rust-lang/rust/pull/155093, which I closed
2026-05-08 20:39:24 +02:00
bors 8068e2fc9a Auto merge of #156324 - JonathanBrouwer:rollup-HKA8242, r=JonathanBrouwer
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#156246 (Introduce a `RerunNonErased` error type mirroring `NoSolution`, to better track when we're bailing)
 - rust-lang/rust#156038 (turn `compute_goal_fast_path` into a single match)
 - rust-lang/rust#156291 (Treat MSVC "performing full link" message as informational)
 - rust-lang/rust#156301 (Avoid ICE when suggesting as_ref for ill-typed closure receivers)
2026-05-08 14:56:56 +00:00
Jana Dönszelmann 687f839266 return faster from internal iterators 2026-05-08 14:10:56 +02:00
Jana Dönszelmann 68f9143013 use the right typing mode for each mir phase 2026-05-08 14:07:46 +02:00
Jana Dönszelmann 22d28263cf remove param_env from HasTypingEnv 2026-05-08 14:07:46 +02:00
Jonathan Brouwer 565ee37312 Rollup merge of #156214 - qaijuang:fix-lints-that-dont-need-to-run-incr, r=nnethercote
Do not cache `lints_that_dont_need_to_run` across sessions

The `lints_that_dont_need_to_run` query depends on the lint store (which includes internal lints under `-Zunstable-options`). Because that flag is deliberately not part of the incremental command-line hash, incremental builds could load stale results from sessions with a different lint configuration, leading to an ICE.

This PR marks the query `eval_always` so it is recomputed for the current session instead of being loaded from cache.

Fixes rust-lang/rust#156182.
2026-05-08 11:35:34 +02:00
Jonathan Brouwer 91d4f8b71b Rollup merge of #156175 - nnethercote:dep_graph-cleanups, r=adwinwhite
Dep graph cleanups

Minor cleanups I found while looking at dep graph code. Details in individual commits.

r? @adwinwhite
2026-05-08 11:35:33 +02:00
Jonathan Brouwer a71746c1d9 Rollup merge of #156123 - cjgillot:synthetic-hir, r=JonathanBrouwer
Simplify the creation of synthetic HIR.
2026-05-08 11:35:32 +02:00