Commit graph

2631 commits

Author SHA1 Message Date
Camille Gillot
6d4b1b38e7 Remove ShallowInitBox. 2026-02-17 11:25:50 +00:00
Jonathan Brouwer
018a5efcf7
Rename inline_fluent! to msg! 2026-02-14 13:47:52 +01:00
Jacob Pratt
4bcbf6274a
Rollup merge of #152587 - lqd:tiny-things, r=jackh726
A couple of tiny polonius things

Here's a couple of tiny things I had ready to go @jackh726
- a tiny cleanup to avoid round-tripping through `Location`s to check for liveness, since we're already working with points
- while I was there, I fixed the doc which wasn't showing up properly (maybe a rustdoc or bootstrap bug when we build locally or during dist, either way, both don't show up correctly linked most of the time) for `PointIndex`es.
- and in the second commit slightly expand test coverage with [an example](https://internals.rust-lang.org/t/get-mut-map-back-from-entry-api/24003) that would have needed stdlib changes (cc author @Darksonn for visibility here)

More soon.

r? @jackh726
2026-02-13 22:26:36 -05:00
Rémy Rakic
be204dd047 make per-point liveness accessible
It avoids round-tripping through `Location`s if you're working with
`Point`s already.
2026-02-13 17:10:29 +00:00
Jonathan Brouwer
98e8f99bc0
Rollup merge of #152218 - adwinwhite:fix-mir-borrowck-opaque-handling-keep-all-errors, r=lcnr
Report unconstrained region in hidden types lazily

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/264

I didn't copy the mechanism of HIR typeck as I found that we just need to be lax in the unconstrained region case.
It already ignores non-defining uses and invalid params.

About tests, I'm having trouble coming up with more complex ones. 🙁

This fixes `ukanren` and `codecrafters-redis-rust` but not rust-lang/rust#151322 and rust-lang/rust#151323.
I believe they are a [different problem](https://github.com/rust-lang/rust/issues/151322#issuecomment-3864656974).

r? @lcnr
2026-02-13 13:35:00 +01:00
Adwin White
20c46d647f report unconstrained region in hidden types lazily 2026-02-13 11:38:53 +08:00
Rémy Rakic
285e1be7b4 reduce duplication when finding a successor 2026-02-12 18:29:38 +00:00
Rémy Rakic
880d73396f merge remaining contexts
now that we need to hold the graph for MIR dumping, and the associated
data to traverse it, there is no difference between the main context and
diagnostics context, so we merge them.
2026-02-12 18:29:38 +00:00
Rémy Rakic
1b63325435 adapt polonius MIR dump to lazy graph traversal 2026-02-12 18:29:38 +00:00
Rémy Rakic
7de450ad52 introduce graph traversal abstraction and visitor
we may need to traverse the lazy graph multiple times:
- to record loan liveness
- to dump the localized outlives constraint in the polonius MIR dump

to do that we extract the previous loan liveness code into an abstract
traversal + visitor handling the liveness-specific parts, while the MIR
dump will be able to record constraints in its own visitor.
2026-02-12 18:29:38 +00:00
Rémy Rakic
f4abd15bc5 remove unneeded liveness context
now that the analysis is only using the regular liveness shape, we don't
need to store it transposed, and thus don't need the container where it
was stored: the liveness context would be alone in the polonius context.

we thus remove the latter, and rename the former.
2026-02-12 18:29:38 +00:00
Rémy Rakic
5d151083fc optimization: do nothing if there are no loans 2026-02-12 18:29:38 +00:00
Rémy Rakic
6dcf65a1cb optimization: no need to convert liveness data shape anymore 2026-02-12 18:29:38 +00:00
Rémy Rakic
279d55c30a remove eager constraint conversion 2026-02-12 18:29:38 +00:00
Rémy Rakic
0941151f30 introduce lazy traversal for the polonius constraint graph 2026-02-12 18:29:37 +00:00
bors
7ad4e69ad5 Auto merge of #152517 - jhpratt:rollup-fGRcId6, r=jhpratt
Rollup of 17 pull requests

Successful merges:

 - rust-lang/rust#142415 (Add note when inherent impl for a alias type defined outside of the crate)
 - rust-lang/rust#142680 (Fix passing/returning structs with the 64-bit SPARC ABI)
 - rust-lang/rust#150768 (Don't compute FnAbi for LLVM intrinsics in backends)
 - rust-lang/rust#151152 (Add FCW for derive helper attributes that will conflict with built-in attributes)
 - rust-lang/rust#151814 (layout: handle rigid aliases without params)
 - rust-lang/rust#151863 (Borrowck: simplify diagnostics for placeholders)
 - rust-lang/rust#152159 (Add note for `?Sized` params in int-ptr casts diag)
 - rust-lang/rust#152434 (Clarify names of `QueryVTable` functions for "executing" a query)
 - rust-lang/rust#152478 (Remove tm_factory field from CodegenContext)
 - rust-lang/rust#152498 (Partially revert "resolve: Update `NameBindingData::vis` in place")
 - rust-lang/rust#152316 (fix: add continue)
 - rust-lang/rust#152394 (Correctly check if a macro call is actually a macro call in rustdoc highlighter)
 - rust-lang/rust#152425 (Port #![test_runner] to the attribute parser)
 - rust-lang/rust#152481 (Use cg_ssa's produce_final_output_artifacts in cg_clif)
 - rust-lang/rust#152485 (fix issue#152482)
 - rust-lang/rust#152495 (Clean up some subdiagnostics)
 - rust-lang/rust#152502 (Implement `BinaryHeap::from_raw_vec`)
2026-02-12 06:57:59 +00:00
Jacob Pratt
3ba1a835d1
Rollup merge of #152316 - cuiweixie:bugfix-continue, r=petrochenkov
fix: add continue

 should be same in:
d3ec6a351a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs (L156-L159)
2026-02-12 00:41:09 -05:00
Jacob Pratt
e4375da4e8
Rollup merge of #151863 - amandasystems:streamline-borrow-error-handling, r=lcnr
Borrowck: simplify diagnostics for placeholders

This folds the call to `region_from_element` into `RegionInferenceContext`, and simplifies the error variant for this case to only talk about regions as opposed to elements. This is the only case where a `RegionElement` leaks out of region inference, so now they can be considered internal to region inference (though that currently isn't expressed). It also clarifies the type information on the methods called to emphasise the fact that they only ever use placeholder regions in the diagnostics completely ignore any other element.

It also adds a bunch of FIXMEs to some fishy statements that conjure universes from what seems like arbitrary integers.

This was lifted from rust-lang/rust#142623.

r? @lcnr
2026-02-12 00:41:07 -05:00
Urgau
050b48a693
Rollup merge of #152281 - JohnTitor:sugg-mut-deref-borrows, r=estebank
borrowck: suggest `&mut *x` for pattern reborrows

Fixes rust-lang/rust#81059
r? @estebank as you should have some context here, but feel free to re-assign if you don't have time to review right now.
2026-02-12 00:04:14 +01:00
Lukas Bergdoll
2f3b952349 Stabilize assert_matches 2026-02-11 14:13:44 +01:00
Amanda Stjerna
f53eed56d2
Borrowck: simplify diagnostics for placeholders.
This essentially folds the call to `region_from_element` into `RegionInferenceContext`,
and simplifies the error variant for this case. It also clarifies the type
information on the methods called to emphasise the fact that they only ever use
placeholder regions in the diagnostics, and completely ignore any other element.
2026-02-10 19:39:57 +01:00
Matthias Krüger
1f0e21584e
Rollup merge of #152327 - adwinwhite:fix-non-defining-use-ices-ready, r=lcnr
Check stalled coroutine obligations eagerly

Fixes rust-lang/rust#151322
Fixes rust-lang/rust#151323
Fixes rust-lang/rust#137916
Fixes rust-lang/rust#138274

The problem is that stalled coroutine obligations can't be satisifed so that they cause normalization to fail in `mir_borrowck`.
Thus, we failed to register any opaque to storage in the next solver.
I fix it by checking these obligations earlier in `mir_borrowck`.

r? @lcnr
2026-02-09 18:39:43 +01:00
Matthias Krüger
7ecefd01d5
Rollup merge of #152315 - cuiweixie:bugfix-span, r=jieyouxu
fix: rhs_span to rhs_span_new
2026-02-09 18:39:43 +01:00
Weixie Cui
40a264cd45 fix: rhs_span to rhs_span_new 2026-02-09 22:16:36 +08:00
Adwin White
d8ff397cd6 check stalled coroutine obligations eagerly 2026-02-08 23:57:50 +08:00
Stuart Cook
8e16ea8749
Rollup merge of #152037 - eggyal:unused-mut-due-to-borrowck-error, r=jackh726
Suppress unused_mut lint if mutation fails due to borrowck error

Remedying the borrowck error will likely result in the mut becoming used, and therefore the lint is likely incorrect.

Fixes rust-lang/rust#152024
r? compiler
2026-02-08 16:58:24 +11:00
Stuart Cook
68f4a99963
Rollup merge of #151887 - scottmcm:homogeneous-try-in-compiler, r=jackh726
Remove some unnecessary `try`-related type annotations

I left a few, like
```rust
let result: Result<_, ModError<'_>> = try {
```
where it felt like seeing it might still be useful for the reader.

Feel free to push back on any of these changes if you think they should be left alone.
2026-02-08 16:58:23 +11:00
Weixie Cui
d3ec6a351a fix: add continue 2026-02-08 11:40:56 +08:00
Jana Dönszelmann
cf1a784f3f
Port rustc_regions to the new attribute parser 2026-02-07 17:24:40 +01:00
Yuki Okushi
0de7415875 borrowck: suggest &mut *x for pattern reborrows 2026-02-07 20:29:15 +09:00
Jonathan Brouwer
65a1d9708d
Rollup merge of #152107 - JonathanBrouwer:convert_borrowck, r=lqd
Convert to inline diagnostics in `rustc_borrowck`

For https://github.com/rust-lang/rust/issues/151366
r? @jdonszelmann
2026-02-06 10:06:43 +01:00
许杰友 Jieyou Xu (Joe)
7b821d1752
Rollup merge of #151278 - estebank:issue-108894, r=davidtwco
Provide more context on trait bounds being unmet due to imperfect derive

When encountering a value that has a borrow checker error where the type was previously moved, when suggesting cloning verify that it is not already being derived. If it is, explain why the `derive(Clone)` doesn't apply:

```
note: if `TypedAddress<T>` implemented `Clone`, you could clone the value
  --> $DIR/derive-clone-implicit-bound.rs:6:1
   |
LL | #[derive(Clone, Copy)]
   |          ----- derived `Clone` adds implicit bounds on type parameters
LL | pub struct TypedAddress<T>{
   | ^^^^^^^^^^^^^^^^^^^^^^^^-^
   | |                       |
   | |                       introduces an implicit `T: Clone` bound
   | consider manually implementing `Clone` for this type
...
LL |         let old = self.return_value(offset);
   |                                     ------ you could clone this value
```

When encountering a bound coming from a derive macro, suggest manual impl of the trait.

Use the span for the specific param when adding bounds in builtin derive macros, so the diagnostic will point at them as well as the derive macro itself.

```
note: required for `Id<SomeNode>` to implement `PartialEq`
  --> $DIR/derive-implicit-bound.rs:5:10
   |
LL | #[derive(PartialEq, Eq)]
   |          ^^^^^^^^^
LL | pub struct Id<T>(PhantomData<T>);
   |               - unsatisfied trait bound introduced in this `derive` macro
   = help: consider manually implementing `PartialEq` to avoid undesired bounds
```

Mention that the trait could be manually implemented in E0599.

Fix rust-lang/rust#108894. Address rust-lang/rust#143714. Address #rust-lang/rust#146515 (but ideally would also suggest constraining the fn bound correctly as well).
2026-02-06 10:25:43 +08:00
Jonathan Brouwer
dd61998e74
Convert to inline diagnostics in rustc_borrowck 2026-02-05 16:55:55 +01:00
Alan Egerton
5405e5d06e
Suppress unused_mut lint if mutation fails due to borrowck error
Remedying the borrowck error will likely result in the mut becoming
used.
2026-02-03 11:52:00 +00:00
Jonathan Brouwer
5144366f4a
Rollup merge of #151172 - estebank:default-field-values, r=dianne
Use default field values in a few more cases

Makes the use expressions significantly shorter.
2026-02-02 18:52:13 +01:00
Esteban Küber
dffec20dee Tweak help to unify formatting and wording 2026-02-01 18:20:31 +00:00
Esteban Küber
879633f97b Change note to help 2026-02-01 18:20:31 +00:00
Esteban Küber
7b62d97abd Mention implicit bounds from #[derive(Clone)] on moved value
When encountering a value that has a borrow checker error where the type was previously moved, when suggesting cloning verify that it is not already being derived. If it is, explain why the `derive(Clone)` doesn't apply:

```
note: if `TypedAddress<T>` implemented `Clone`, you could clone the value
  --> $DIR/derive-clone-implicit-bound.rs:6:1
   |
LL | #[derive(Clone, Copy)]
   |          ----- derived `Clone` adds implicit bounds on type parameters
LL | pub struct TypedAddress<T>{
   | ^^^^^^^^^^^^^^^^^^^^^^^^-^
   | |                       |
   | |                       introduces an implicit `T: Clone` bound
   | consider manually implementing `Clone` for this type
...
LL |         let old = self.return_value(offset);
   |                                     ------ you could clone this value
```
2026-02-01 18:20:30 +00:00
Scott McMurray
f7931c8050 Remove some unnecessary try-related type annotations
I left a few, like
```rust
let result: Result<_, ModError<'_>> = try {
```
where it felt like seeing it might still be useful for the reader.

Feel free to push back on any of these changes if you think seeing the type would be better.
2026-01-30 18:21:19 -08:00
Jonathan Brouwer
40d7cb890f
Rollup merge of #150271 - Jamesbarford:chore/refactor-struct-placeholder-pt2, r=lcnr
Move struct placeholder pt2

r? ghost
2026-01-29 17:47:29 +01:00
James Barford-Evans
25c1365507 Part 2 refactoring of moving placeholder types to rustc_type_ir 2026-01-29 11:11:40 +00:00
Stuart Cook
9f551d31e4
Rollup merge of #150572 - heathdutton:issue-150174-asyncfn-diagnostic-v2, r=lcnr
Improve move error diagnostic for `AsyncFn` closures

When an async closure captures a variable by move but is constrained to `AsyncFn` or `AsyncFnMut`, the error message now explains that the closure kind is the issue and points to the trait bound, similar to the existing diagnostic for `Fn`/`FnMut` closures.

**Before:**
```
error[E0507]: cannot move out of `foos` which is behind a shared reference
  --> src/lib.rs:12:20
   |
11 | async fn foo(foos: &mut [&mut Foo]) -> Result<(), ()> {
   |              ---- move occurs because `foos` has type...
12 |     in_transaction(async || -> Result<(), ()> {
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^ `foos` is moved here
13 |         for foo in foos {
   |                    ---- variable moved due to use in coroutine
```

**After:**
```
error[E0507]: cannot move out of `y`, a captured variable in an `AsyncFn` closure
  --> src/lib.rs:9:10
   |
LL |     let y = vec![format!("World")];
   |         - captured outer variable
LL |     call(async || {
   |          ^^^^^^^^ captured by this `AsyncFn` closure
...
help: `AsyncFn` and `AsyncFnMut` closures require captured values to be able
      to be consumed multiple times, but `AsyncFnOnce` closures may consume
      them only once
  --> src/lib.rs:5:27
   |
LL | fn call<F>(_: F) where F: AsyncFn() {}
   |                           ^^^^^^^^^
```

Fixes rust-lang/rust#150174
2026-01-29 19:03:29 +11:00
Heath Dutton🕴️
f5f2ca0dc6 Improve move error diagnostic for AsyncFn closures
When an async closure captures a variable by move but is constrained to
`AsyncFn` or `AsyncFnMut`, the error message now explains that the
closure kind is the issue and points to the trait bound, similar to the
existing diagnostic for `Fn`/`FnMut` closures.
2026-01-28 13:19:05 -05:00
Amanda Stjerna
4bdccabda5 Borrowck: Simplify SCC annotation computation, placeholder rewriting
This simplifies the `PlaceholderReachability` `enum` by
replacing the case when no placeholders were reached with
a standard `Option::None`.

It also rewrites the API for `scc::Annotations` to be update-mut
rather than a more Functional programming style. This showed some slight
performance impact in early tests of the PR and definitely makes
the implementation simpler.
2026-01-27 14:22:53 +01:00
Jonathan Brouwer
e875916a05
Rollup merge of #151374 - BoxyUwU:borrowck_cleanup_3, r=lcnr
some more rustc_borrowck cleanups

r? lcnr
2026-01-26 18:19:14 +01:00
Boxy
dab7c0923e Misc cleanups to borrowck crate 2026-01-26 10:24:15 +00:00
Jonathan Brouwer
ae31dd7b28
Rollup merge of #149639 - lqd:fix-typeck-constraints, r=jackh726
inline constant localized typeck constraint computation

This fixes an oversight in the previous PRs, this constraint is local to a point (and liveness does the rest) and so has a fixed direction.

I wasn't planning on trying to improve the impl for perf, versus computing loan liveness without first unifying the cfg and subset graph, but it's like a 20x improvement for typeck constraints on wg-grammar (-15% end-to-end) for a trivial fix.

r? @jackh726

In general, I want to cleanup these edges to avoid off-by-one errors in constraints at effectful statements and ensure the midpoint-avoidance strategy is sound and works well, in particular with respect to edges that flow backwards from the result into its inputs. But I'd like to start from something that passes all tests and is simpler, because the eventual solution may
1. involve localizing these edges differently than *separate* liveness and typeck lowering passes/approaches, which would need to be lowered at the same time for example. I'm already doing the latter in the loan liveness rewrite as part of creating edges on-demand during traversal, and this new structure would be a better fit to verify, or fix, these subtle edges.
2. also require changes in MIR typeck to track the flow across points more precisely, and I don't know how hard that would be. *Computing* the constraint direction is currently a workaround for that.

Therefore, in a future PR, I'll also remove this computation from the terminator constraints, but I can also do that in this PR if you'd prefer.
2026-01-23 11:07:55 +01:00
Jonathan Brouwer
958d1f907b
Rollup merge of #150879 - remove_diag_lints, r=Kivooeo
Remove the diagnostic lints

Removes the `untranslatable_diagnostic` and `diagnostic_outside_of_impl` lints
These lints are allowed for a while already. Per https://github.com/rust-lang/compiler-team/issues/959, we no longer want to enforce struct diagnostics for all usecases, so this is no longer useful.

r? @Kivooeo
I recommend reviewing commit by commit (also feel free to wait with reviewing until the MCP is accepted)

@rustbot +S-blocked
Blocked by https://github.com/rust-lang/compiler-team/issues/959
2026-01-19 20:53:20 +01:00
Jonathan Brouwer
a66a2e31eb
Rollup merge of #150550 - borrowck_cleanup_2, r=lcnr
Miscellaneous cleanups to borrowck related code

r? lcnr
2026-01-19 20:53:20 +01:00
Jonathan Brouwer
0ee7d96253
Remove all allows for diagnostic_outside_of_impl and untranslatable_diagnostic throughout the codebase
This PR was mostly made by search&replacing
2026-01-19 17:39:49 +01:00