Commit Graph

46712 Commits

Author SHA1 Message Date
dianne
f2d94c1d93 unpretty=thir-tree: don't require the final expr to be the entrypoint 2025-05-21 09:32:59 -07:00
dianne
2a403dc81d lower bodies' params to thir before the body's value 2025-05-21 09:17:11 -07:00
bjorn3
96ac571445 Move -Zcrate-attr injection to just after crate root parsing
This way after_crate_root_parsing and -Zpretty will see them.
2025-05-21 14:32:40 +00:00
lcnr
5d9141c6c8 fix better_any breakage by making the solver more unsound 2025-05-21 13:54:19 +00:00
Matthias Krüger
9fd0ab6876 Rollup merge of #141334 - lcnr:coerce-nested-obligations, r=compiler-errors
eagerly check nested obligations when coercing fndefs

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/212

r? `@compiler-errors`
2025-05-21 15:38:12 +02:00
Matthias Krüger
ab9109ad19 Rollup merge of #141333 - compiler-errors:param-env-candidate-unnorm, r=lcnr
Use `DeepRejectCtxt` in `assemble_inherent_candidates_from_param`

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

We were not properly considering unnormalized param-env candidates in `assemble_inherent_candidates_from_param`.

r? lcnr
2025-05-21 15:38:12 +02:00
Matthias Krüger
6606fd9a14 Rollup merge of #141332 - compiler-errors:no-fold-const, r=lcnr
Do not eagerly fold consts in `normalize_param_env_or_error` if new solver

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

Given:

```
trait Trait: Deref<Target = [u8; { 1 + 1 }]> {}
```

when elaborating param env for `Trait`, we have `Self: Trait`, `Self: Deref<Target = [u8; {anon const}]>`.

Before this PR, we would fold the anon consts away *before* elaborating. However, we end up getting another *un-folded* copy of the anon const from elaborating `Self: Trait`. This leads to normalization ambiguity.

r? lcnr
2025-05-21 15:38:11 +02:00
Matthias Krüger
1461ca3f39 Rollup merge of #141328 - azhogin:azhogin/async-drop-ice-for-empty-impl-fix, r=oli-obk
When AsyncDrop impl is empty, sync drop generated in elaborator

Fixes #140974.
2025-05-21 15:38:10 +02:00
Matthias Krüger
ad6fb066dd Rollup merge of #141296 - azhogin:azhogin/async-drop-broken-mir-place-deref-fix, r=oli-obk
Async drop fix for 'broken mir, place has deref as later projection'

fixes #140975

Problem in codegen fixed with an additional temporary local.
2025-05-21 15:38:10 +02:00
Matthias Krüger
af081a4247 Rollup merge of #141267 - dianne:fix-141265, r=oli-obk
only resolve top-level guard patterns' guards once

We resolve guard patterns' guards in `resolve_pattern_inner`, so to avoid resolving them multiple times, we must avoid doing so earlier. To accomplish this, `LateResolutionVisitor::visit_pat` contains a case for guard patterns that avoids visiting their guards while walking patterns.

This PR fixes #141265, which was due to `visit::walk_pat` being used instead; this meant guards at the top level of a pattern would be visited twice. e.g. it would ICE on `for x if x in [] {}`, but not `for (x if x) in [] {}`. `visit_pat` was already used for the guard pattern in the second example, on account of the top-level pattern being parens.
2025-05-21 15:38:08 +02:00
bors
356f2d0774 Auto merge of #140386 - oli-obk:match-on-lang-item-kind, r=compiler-errors
Match on lang item kind instead of using an if/else chain

Similar to how the new solver does this. Just noticed while I was adding a new entry to the chain 😆
2025-05-21 13:31:13 +00:00
Andrew Zhogin
7c38b6fd28 Async drop fix for 'broken mir in AsyncDropGlue, place has deref as a later projection' (#140975) 2025-05-21 18:29:13 +07:00
Andrew Zhogin
dc794f18a4 When AsyncDrop impl is empty, sync drop generated in elaborator (Fixes #140974) 2025-05-21 18:18:27 +07:00
lcnr
196c3b3ef4 eagerly check nested obligations when coercing fndefs 2025-05-21 11:09:48 +00:00
Michael Goulet
ad59f0b6e6 Use DeepRejectCtxt in assemble_inherent_candidates_from_param 2025-05-21 10:02:54 +00:00
Matthias Krüger
5b150e3122 Rollup merge of #141318 - nnethercote:fix-140884, r=compiler-errors
Avoid creating an empty identifer in `Symbol::to_ident_string`.

Because that causes an assertion failure in debug builds.

Fixes #140884.

r? `@oli-obk`
2025-05-21 11:28:47 +02:00
Matthias Krüger
aaa684fd1d Rollup merge of #141317 - dianne:continue-liveness-ice-fix, r=compiler-errors
typeck: catch `continue`s pointing to blocks

This taints the typeck results with errors if a `continue` is found not pointing to a loop.

A few things were going wrong here. First, since this wasn't caught in typeck, we'd end up building the THIR and then running liveness lints on ill-formed HIR. Since liveness assumes all `continue`s point to loops, it wasn't setting a live node for the `continue`'s destination. There was a fallback for if it couldn't retrieve that live node, but it was faulty; it would create a new live node to represent an erroneous state after the analysis's RWU table had already been built. This would ICE if the new live node was used in operations, such as merging results from the arms of a match. I've removed this error-recovery since it was buggy, and we should really catch bad labels before liveness.

I've also replaced an outdated comment about when liveness lints are run. At this point, I think the call to `check_liveness` could be moved elsewhere, but if it can be run when the typeck results are tainted by errors, it'll need some slight refactoring so it can bail out in that case. In lieu of that, I've added an assert.

Fixes #113379
Fixes #121623
2025-05-21 11:28:46 +02:00
Matthias Krüger
e4836fbb89 Rollup merge of #141284 - compiler-errors:query-nit, r=oli-obk
Allow trailing comma after argument in query definition

Don't catastrophically fail the query macro if you put a comma after your query key!

r? oli-obk
2025-05-21 11:28:46 +02:00
Matthias Krüger
d30f0471c3 Rollup merge of #141213 - xizheyin:issue-141136, r=nnethercote
Suggest use "{}", self.x instead of {self.x} when resolve x as field of `self`

Fixes #141136

Changes can be seen in the second commit: 9de7fff0d8

r? compiler
2025-05-21 11:28:45 +02:00
Michael Goulet
44a2af3068 Do not eagerly fold consts in normalize_param_env_or_error if new solver 2025-05-21 09:23:36 +00:00
Nicholas Nethercote
1cc0e38fdc Avoid creating an empty identifer in Symbol::to_ident_string.
Because that causes an assertion failure in debug builds.

Fixes #140884.
2025-05-21 18:59:04 +10:00
xizheyin
84f67a5e51 Downgrade the confident of suggestion available field in format string and optimize expression
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-21 16:23:52 +08:00
Matthias Krüger
1b3159a4c0 Rollup merge of #141308 - spastorino:fix-rpitit-error-reporting-ice, r=nnethercote
Do not call name() on rpitit assoc_item

Fixes #141143

r? `@nnethercote`
2025-05-21 08:05:25 +02:00
bors
87b4541569 Auto merge of #127721 - bvanjoi:issue-124273, r=petrochenkov
collect doc alias as tips during resolution

Close #124273

Collect the symbol in the doc alias attributes and provide a tip when a match is found.

r? `@estebank`
2025-05-21 02:21:28 +00:00
dianne
ed01a20514 typeck: catch continues pointing to blocks
This taints the typeck results with errors if a `continue` is found not
pointing to a loop, which fixes an ICE.

A few things were going wrong here. First, since this wasn't caught in
typeck, we'd end up building the THIR and then running liveness lints on
ill-formed HIR. Since liveness assumes all `continue`s point to loops,
it wasn't setting a live node for the `continue`'s destination. However,
the fallback for this was faulty; it would create a new live node to
represent the erroneous state after the analysis's RWU table had already
been built. This would ICE if the new live node was used in operations,
such as merging results from the arms of a match. I've removed this
error-recovery since it was buggy, and we should really catch bad labels
before liveness.

I've also replaced an outdated comment about when liveness lints are
run. At this point, I think the call to `check_liveness` could be moved
elsewhere, but if it can be run when the typeck results are tainted by
errors, it'll need some slight refactoring so it can bail out in that
case. In lieu of that, I've added an assertion.
2025-05-20 17:45:16 -07:00
bors
2b96ddca12 Auto merge of #141305 - matthiaskrgr:rollup-l6nwaht, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #140972 (Add TRACING_ENABLED to Machine and add enter_trace_span!())
 - #141282 (`core_float_math`: Move functions to `math` module)
 - #141288 (Get rid of unnecessary `BufDisplay` abstraction)
 - #141289 (use `Self` alias in self types rather than manually substituting it)
 - #141291 (link tracking issue in explicit-extern-abis.md)
 - #141294 (triagebot: ping me if rustdoc js is modified)
 - #141303 (Fix pagetoc inactive color in rustc book)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-20 23:18:26 +00:00
Trevor Gross
999967a57d Rename cfg_match! to cfg_select!
At [1] it was pointed out that `cfg_match!` syntax does not actually
align well with match syntax, which is a possible source of confusion.
The comment points out that usage is instead more similar to ecosystem
`select!` macros. Rename `cfg_match!` to `cfg_select!` to match this.

Tracking issue: https://github.com/rust-lang/rust/issues/115585

[1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605
2025-05-20 21:16:23 +00:00
Santiago Pastorino
66d47c1687 Do not call name() on rpitit assoc_item 2025-05-20 17:30:08 -03:00
Matthias Krüger
221d6c734c Rollup merge of #140972 - Stypox:machine-tracing-flag, r=RalfJung
Add TRACING_ENABLED to Machine and add enter_trace_span!()

This PR adds the necessary infrastructure to make it possible to do tracing calls from within `rustc_const_eval` when running Miri, while making sure they don't impact the performance of normal compiler execution. This is done by adding a `const` boolean to `Machine`, false by default, but that will be set to true in Miri only. The tracing macro `enter_trace_span!()` checks if it is true before doing anything, and since the value of a `const` is known at compile time, if it it false it the whole tracing call should be optimized out.

I will soon open further PRs to add tracing macro calls similar to this one, so that afterwards it will be possible to learn more about Miri's time spent in the various interpretation steps:
```rs
let _guard = enter_trace_span!(M, "eval_statement", "{:?}", stmt);
```

r? `@RalfJung`
2025-05-20 20:57:26 +02:00
bohan
097b7a2ac7 collect doc alias as tips during resolution 2025-05-21 00:47:36 +08:00
Stypox
28db348fdd Add enter_trace_span!() that checks if tracing is enabled 2025-05-20 17:28:30 +02:00
Matthias Krüger
cc0ee34b43 Rollup merge of #141285 - compiler-errors:tick, r=lcnr
Add tick to `RePlaceholder` debug output

Present when debug printing canonical queries

r? lcnr
2025-05-20 16:50:43 +02:00
Matthias Krüger
3b9ccbbaf1 Rollup merge of #141279 - nnethercote:lower_to_hir, r=compiler-errors
`lower_to_hir` cleanups

Some minor cleanups I made when reading this code.

r? `@Nadrieril`
2025-05-20 16:50:42 +02:00
Matthias Krüger
ac500add80 Rollup merge of #141275 - dianne:gather-guard-pat-locals-once, r=compiler-errors
`gather_locals`: only visit guard pattern guards when checking the guard

When checking a pattern with guards in it, `GatherLocalsVisitor` will visit both the pattern (when type-checking the let, arm, or param containing it) and local declarations in the guard expression (when checking the guard itself). This keeps it from visiting the guard when visiting the pattern, since otherwise it would gather locals from the guard twice, which would lead to a delayed bug: "evaluated expression more than once".

Tracking issue for guard patterns: #129967
2025-05-20 16:50:41 +02:00
Matthias Krüger
5364668fb5 Rollup merge of #141253 - azhogin:azhogin/async-drop-feature-inconsistency-warning, r=oli-obk
Warning added when dependency crate has async drop types, and the feature is disabled

In continue of https://github.com/rust-lang/rust/pull/141031.

When dependency crate has non-empty `adt_async_destructor` table in metadata, and `async_drop` feature is disabled for local crate, warning will be emitted.

Test `dependency-dropped` has two revisions - with and without feature enabled. With feature enabled, async drop for dropee is executed ("Async drop" printed). Without the feature enabled, sync drop is executed ("Sync drop" printed) and warning is emitted.

Warning example:
```
warning: found async drop types in dependecy `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped`
  --> $DIR/dependency-dropped.rs:7:1
   |
LL | #![cfg_attr(with_feature, feature(async_drop))]
   | ^
   |
   = help: if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used
```
2025-05-20 16:50:40 +02:00
Matthias Krüger
42ed69c756 Rollup merge of #141236 - jagunter:issue-140823, r=compiler-errors
Resolved issue with mismatched types triggering ICE in certain scenarios

## Background

The function `annotate_mut_binding_to_immutable_binding` called in `emit_coerce_suggestions` performs a type comparison between the `expected` and `found` types from `ExpectedFound` in the `TypeError`. This can fail if the `found` type contains a region variable that's been rolled back.

## What is being changed?

This updates `annotate_mut_binding_to_immutable_binding` to use `expr_ty` and `expected` from the parent function instead of the types from the `TypeError`. This sidesteps the issue of using `found` from `TypeError` which may leak lingering inference region variables.

This does change the diagnostic behavior to _only_ support cases where the expected outermost type is `&T`, but that seems to be the intended functionality.

Also fixed the example in the `annotate_mut_binding_to_immutable_binding` rustdocs.

r? rust-lang/types

Fixes #140823
2025-05-20 16:50:39 +02:00
Michael Goulet
6555ef7f09 Querify coroutine_hidden_types 2025-05-20 11:50:25 +00:00
Michael Goulet
1d8db54f76 Add tick to RePlaceholder debug output 2025-05-20 10:30:07 +00:00
Michael Goulet
37260e1c5b Allow trailing comma after argument in query definition 2025-05-20 10:22:08 +00:00
Michael Goulet
47b9e373cb Revert "Fix stack overflow in exhaustiveness due to recursive HIR opaque type values"
This reverts commit b08e9c2a60.
2025-05-20 10:09:01 +00:00
Michael Goulet
7e7c2c3947 Just error on recursive opaque ty in HIR typeck 2025-05-20 10:08:56 +00:00
dianne
c343b2a47c gather_locals: only visit guard pattern guards when checking the guard
When checking a pattern with guards in it, `GatherLocalsVisitor` will
visit both the pattern (when type-checking the let, arm, or param
containing it) and the guard expression (when checking the guard
itself). This keeps it from visiting the guard when visiting the
pattern, since otherwise it would gather locals from the guard twice,
which would lead to a delayed bug: "evaluated expression more than
once".
2025-05-19 23:18:08 -07:00
Nicholas Nethercote
8a927e63ff Inline and remove lower_* methods.
They are all short and have a single call site.
2025-05-20 14:13:33 +10:00
Nicholas Nethercote
7c62e78cf9 Hoist ItemLowerer out of a loop. 2025-05-20 14:04:24 +10:00
Nicholas Nethercote
0c0b2cbcb5 Remove unused return value from lower_node. 2025-05-20 14:01:58 +10:00
Stuart Cook
6461160e8d Rollup merge of #141261 - RalfJung:current_dll_path, r=Noratrieb
current_dll_path: fix mistake in assertion message

Follow-up to https://github.com/rust-lang/rust/pull/141239
r? `@Noratrieb`
2025-05-20 12:53:15 +10:00
dianne
ed983c2184 only resolve top-level guard patterns' guards once
We resolve guard patterns' guards in `resolve_pattern_inner`, so to
avoid resolving them multiple times, we must avoid doing so earlier. To
accomplish this, `LateResolutionVisitor::visit_pat` contains a case for
guard patterns that avoids visiting their guards while walking patterns.
This fixes an ICE due to `visit::walk_pat` being used instead, which
meant guards at the top level of a pattern would be visited twice.
2025-05-19 18:02:54 -07:00
Andrew Zhogin
4a99cbbf6b Warning when dependency crate has async drop types, and the feature is disabled - typo fixed 2025-05-20 04:36:33 +07:00
Ralf Jung
c99c4b17b2 current_dll_path: fix mistake in assertion message 2025-05-19 20:20:54 +02:00
Josh Gunter
db1ac98081 Fixed possible ICE in annotate_mut_binding_to_immutable_binding 2025-05-19 10:16:29 -07:00