Commit Graph

1787 Commits

Author SHA1 Message Date
bors 281c97c324 Auto merge of #156518 - estebank:match-rustfmt, r=mejrs
[style] rustfmt `match`es with comments in or-patterns

Using https://github.com/rust-lang/rustfmt/pull/6893, I reformatted the whole codebase. The result is that `match`es that *should have* been formatted under normal circumstances but are getting skipped now got their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.

(Introduced and) removed a bunch of stray backticks \` likely left after an editor autoclosed the intended closing \`, resulting in <code>\`name\`\`</code> in comments.
2026-05-17 01:27:37 +00:00
Jonathan Brouwer df20e79dfc Rollup merge of #156600 - cijiugechu:false-negative-test, r=BoxyUwU
Make const param default test reproduce original ICE

As discussed in [comment](https://github.com/rust-lang/rust/pull/156325#discussion_r3247360505).

ICE using old logic:
[old-logic-ice.txt](https://github.com/user-attachments/files/27797628/old-logic-ice.txt)

r? BoxyUwU
2026-05-15 20:11:44 +02:00
Jonathan Brouwer 62c2da091b Rollup merge of #148788 - TomtheCoder2:unconstrained-parameter-fix, r=davidtwco
Unconstrained parameter fix

This PR is an attempt to solve the issue described in the issue rust-lang/rust#107295
2026-05-15 20:11:41 +02:00
cijiugechu d24fd77ebe Make const param default test reproduce original ICE 2026-05-15 18:32:42 +08:00
Jonathan Brouwer f6faa05477 Rollup merge of #156325 - cijiugechu:generics-transmutefrom, r=BoxyUwU
Don't treat const param default as projection

Avoid treating const param default as associated const projection.

Closes rust-lang/rust#156293
2026-05-13 11:46:41 +02:00
Esteban Küber 701e4942ed Remove a bunch of stray backticks
Thanks VSCode!
2026-05-13 02:40:58 +00:00
lcnr 44c49506bd update tests 2026-05-12 23:28:32 +02:00
cijiugechu b11537fa0e remove transmutability feature 2026-05-12 09:16:16 +08:00
janwi_mac d02b4c8e77 Improve suggestions for unconstrained parameters in impl blocks
When an unconstrained type or lifetime parameter is detected in an
`impl`, provide more specific help based on its usage:
- If the parameter is entirely unused, suggest removing it.
- If it is used in the `impl` body but not the `Self` type, suggest
  including it in the `Self` type and the struct definition.

This also adds a comprehensive UI test for these cases.
2026-05-09 17:50:35 +12:00
cijiugechu 5148dacbb8 Don't treat const param default as projection 2026-05-08 22:13:42 +08:00
bors f964de49bc Auto merge of #149468 - chenyukang:yukang-fix-ice-149278, r=lcnr
Skipping borrowck because of trivial const



r? @saethlin

the [assertion](https://github.com/chenyukang/rust/blob/31c38576a4cf1a0864af536f62d11f829db1c7c8/compiler/rustc_mir_transform/src/lib.rs#L424) is added in PR: https://github.com/rust-lang/rust/pull/148040

I think we also need to skip trvial const in `mir_borrowck`.
2026-05-07 19:45:59 +00:00
yukang 8e1f263f66 Skipping borrowck because of trivial const 2026-05-07 22:18:58 +08:00
Jonathan Brouwer 80af49a07f Rollup merge of #156250 - lqd:normalization-tests, r=lcnr
add a few new solver normalization tests

As discussed [on zulip](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/ask.20for.20help/near/593097133), this PR adds the handful of new solver revisions and tests from https://github.com/rust-lang/trait-system-refactor-initiative/issues/139. Most cases that issue mentions were already fixed by https://github.com/rust-lang/rust/pull/140672 in 1.88, and some cases, we expect, by https://github.com/rust-lang/rust/pull/155767.

The issue about defaulted type parameters applies to both solvers and will be tracked in https://github.com/rust-lang/rust/issues/156271 instead.

Closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/139.

r? lcnr
I'm not sure where the best place for the tests would be, do you have a better location in mind?
2026-05-07 14:13:55 +02:00
Jonathan Brouwer ce44b53e77 Rollup merge of #154846 - Zoxc:ty-def-span, r=lcnr
Add better default spans for the `Ty` impl of `QueryKey`

This add default spans for `Ty` in its implementation of `QueryKey`. This is useful so we can get spans for the `layout_of`  query which shows up in cycle errors.
2026-05-07 14:13:52 +02:00
Rémy Rakic 130b1d881c move some normalization tests to the dedicated folder 2026-05-07 12:11:55 +02:00
Rémy Rakic 6cc6a63392 add normalization test with defaulted type param with diverging alias
Another example from https://github.com/rust-lang/trait-system-refactor-initiative/issues/139
and which was fixed in 1.89 `nightly-2025-06-18`.
2026-05-07 12:11:55 +02:00
Rémy Rakic 4922210ea6 add normalization test with field with diverging alias
Another example from https://github.com/rust-lang/trait-system-refactor-initiative/issues/139
and which was likely fixed by https://github.com/rust-lang/rust/pull/140672 as well.
2026-05-07 12:11:55 +02:00
bors 365c0e1d7a Auto merge of #155443 - jdonszelmann:canonical, r=lcnr
Improve caching by introducing `TypingMode::ErasedNotCoherence`



r? @lcnr


This introduces `TypingMode::ErasedNotCoherence`. Most typing modes contain a list of opaque types, which are quite often unused during canonicalization. With this change, any time we try canonicalization, we replace whichever typing mode we're currently in with `ErasedNotcoherence`, attempt to canonicalize, and if that fails *retry* in the original typing mode. If erased mode succeeds, this is beneficial because that way the opaque types don't end up in the cache key, allowing more cache reuse.

This seems to have a small (0.5%) slowdown on most programs, but a dramatic (>60%) speedup in specific cases like the rustc-perf `wg-grammar` benchmark. Some more improvements are expected with "eager normalization", which is work that's under way right now.
2026-05-06 13:55:09 +00:00
Jana Dönszelmann 7ff71be015 Try to canonicalize with erased opaques, retry when opaques are used. 2026-05-06 10:18:21 +02:00
Jacob Pratt e826e3f3bf Rollup merge of #156205 - lcnr:move-generalization-test, r=lqd
move generalization test

The forth test of https://github.com/rust-lang/trait-system-refactor-initiative/issues/191#issuecomment-3351555279 isn't actually related to closure signature inference.

closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/191, which has already been fixed by https://github.com/rust-lang/rust/pull/155767

r? types
2026-05-05 22:50:27 -04:00
lcnr 8634d63321 move test 2026-05-05 22:31:00 +02:00
lapla 0e72a29c93 Always use ConstFn context for const closures 2026-05-05 22:43:54 +09:00
John Kåre Alsaker 25e018de2d Add better default spans for the Ty impl of QueryKey 2026-05-04 16:56:59 +02:00
inkyu d4c413e348 Apply suggestion from @lcnr
Co-authored-by: lcnr <rust@lcnr.de>
2026-05-04 15:05:04 +07:00
inq 44a7eb01fc Regression test for trait-system-refactor#7 2026-05-04 04:00:57 +07:00
Jacob Pratt b7c65513ba Rollup merge of #155940 - mejrs:filter, r=jdonszelmann
refactor rustc_on_unimplemented's filtering

Previously when you had a
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub condition: Option<OnUnimplementedCondition>,
    pub subcommands: ThinVec<Directive>,
    pub message: Option<(Span, FormatString)>,
    ...
}
```
that condition would control the emission of the message, label, notes etc. I've changed that to
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub filters: ThinVec<(Filter, Directive)>,
    pub message: Option<(Span, FormatString)>,
    ...
```

so that the message etc is always emitted, and there's a vec of tuples with (filter, directive) where the filter controls whether that directive is even emitted,  which i think is much clearer. That also makes it easier to not have to do the reverse iteration thing and this makes it so that notes are emitted in declaration order (with nonfiltered options always last).

The rename is because I plan on making it available to other diagnostic attributes at some point (very wip) so `OnUnimplementedCondition` and the like would have to be renamed anyway.
2026-05-03 00:25:32 -04:00
mejrs d6969da512 rustc_on_unimplemented: emit notes in declared order 2026-05-02 17:59:25 +02:00
Adwin White 03cabe7bab bless more than merely diagnostics change 2026-05-02 21:07:24 +08:00
Adwin White 1c1372c908 bless diagnostics change 2026-05-02 21:07:23 +08:00
Shoyu Vanilla e43a1b5b44 -Znext-solver Ignore region constraints from the nested goals in leakcheck 2026-05-02 00:11:43 +09:00
Jonathan Brouwer a0ef691e5a Rollup merge of #155861 - oli-obk:effect-bound-suggestions, r=jdonszelmann
Suggest `[const] Trait` bounds in more places

Right now we have some special logic in the const checker for emitting `[const] Trait` suggestions, but I'm trying to handle that similarly to how it is handled for normal `Trait` clauses. This is just a small step in how it will look on the UX side, which should make my follow-up PRs affect tests less and just be a refactoring
2026-04-29 23:51:35 +02:00
Shoyu Vanilla 25c241c1b0 Propagate stalled_on_coroutines as a field in Certainty::Maybe 2026-04-29 02:28:38 +09:00
Oli Scherer 61e876fe76 Suggest various missing trait bounds on HostEffect clauses not being satisfied 2026-04-28 12:54:55 +02:00
Jonathan Brouwer f13610a4b5 Rollup merge of #155865 - lcnr:add-test, r=lqd
add test for accidentally fixed `binius_field` issue

cc https://github.com/rust-lang/rust/pull/153614#issuecomment-4281857186

r? @lqd
2026-04-27 14:44:20 +02:00
Jonathan Brouwer 2cd70607e7 Rollup merge of #155355 - erickt:trait-solver-hang, r=lcnr
Fix pathological performance in trait solver cycles with errors

Fuchsia's Starnix system has had a multi-year long bug where occasionally a typo could cause the rust compiler to take 10+ hours to report an error (see rust-lang/rust#136516 and rust-lang/rust#150907). This was particularly hard to trace down since Starnix's codebase is massive, over 384 thousand lines as of writing.

With the help of treereduce, cargo-minimize, and rustmerge, after about a month of running we reduced it down to a couple [lines of code], which only takes about 35 seconds to report an error on my machine. The bug also appears to happen with `-Z next-solver=no` and `-Z next-solver=coherence`, but does not occur with `-Z next-solver` or `-Z next-solver=globally`.

I used Gemini to help diagnose the problem and proposed solution (which is the one proposed in this patch):

1. The trait solver gets stuck in an exponential loop evaluating auto-trait bounds (like Send and Sync) on cyclic types that contain compilation errors (TyKind::Error).

2. Normally, if the solver detects a cycle, it prevents the result from being stored in the Global Cache because the result depends on the current evaluation stack. However, when an error is involved, the depth tracking gets pinned to a low value, forcing the solver to rely on the short-lived Provisional Cache. Since the provisional cache is cleared between high-level iterations of the fulfillment loop, the solver ends up re-discovering and re-evaluating the same large cycle thousands of times.

3. Allow global caching of results even if they appear stack-dependent, provided that the inference context is already "tainted by errors" (`self.infcx.tainted_by_errors().is_some()`). This violates the strict invariant that global cache entries shouldn't depend on the stack, but it is safe because the compilation is already guaranteed to fail due to the presence of errors. Prioritizing compiler responsiveness and termination over perfect correctness in error states is the correct trade-off here.

I added the reduction as the test case for this. However, I don't see an easy way to catch if this bug comes back. Should we add some way to timeout the test if it takes longer than 10 seconds to compile? That could be a source of flakes though.

I don't have any experience with the trait solver code, but I did try to review the code to the best of my ability. This approach seems a bit of a bandaid to the solution, but I don't see a better solution. We could try to teach the solver to not clear the provisional cache in this circumstance, but I suspect that'd be a pretty invasive change.

I'm guessing if this does cause problems, it might report an incorrect error, but I (and Gemini) were unable to come up with an example that reported a different error with and without this fix.

Resolves rust-lang/rust#150907

[lines of code]: https://gist.github.com/erickt/255bc4006292cac88de906bd6bd9220a
2026-04-27 14:44:18 +02:00
lcnr 23abf90ff8 add test 2026-04-27 10:05:57 +02:00
Oli Scherer 8e1c34f5cc Check closure's constness validity in the constness query
instead of during ast lowering, where it's not easily possible to obtain all the right information in time
2026-04-27 07:44:19 +02:00
Oli Scherer 7dcedafff2 Reject implementing const Drop for types that are not const Destruct already 2026-04-25 20:56:32 +02:00
Guillaume Gomez 8a4df7744f Rollup merge of #155637 - qaijuang:fix-e0191-empty-dyn-trait-suggestion, r=fmease
Fix E0191 suggestion for empty dyn trait args

Fixes rust-lang/rust#155578.
2026-04-23 14:42:49 +02:00
Guillaume Gomez abce9f98d7 Rollup merge of #155442 - CoCo-Japan-pan:impl-restriction-reorder, r=Urgau,fmease,jhpratt
Change keyword order for `impl` restrictions

Based on rust-lang/rust#155222, this PR reorders keywords in trait definitions to group restrictions with visibility. It changes the order from `pub(...) const unsafe auto impl(...) trait Foo {...}`  to `pub(...) impl(...) const unsafe auto trait Foo {...}`.

Tracking issue for restrictions: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-04-23 14:42:47 +02:00
Guillaume Gomez 0595fcd195 Rollup merge of #154957 - lapla-cogito:issue_153891, r=oli-obk
Fix ICE when const closure appears inside a non-const trait method

Fixes rust-lang/rust#153891

`hir_body_const_context()` unconditionally delegated to the parent's const context for const closures, returning `None` when the parent had no const context. This caused `mir_const_qualif()` to hit a `span_bug!`, since `mir_promoted()` had already decided to call it based on the closure's own syntactic constness. Fall back to `ConstContext::ConstFn` when the parent's const context is `None`, so that the const closure body is still properly const-checked rather than triggering an ICE.

Examining [another attempt](https://github.com/rust-lang/rust/pull/153900/changes) at this issue (which has already been closed), I thought that its approach represents a workaround fix to avoid inconsistencies in the caller of `mir_promoted()`, whereas I think the correct behavior is for `hir_body_const_context()` itself to return the proper value.
2026-04-23 14:42:47 +02:00
Qai Juang 4d2b607aa8 Fix E0191 suggestion for empty dyn trait args
* Fix E0191 suggestion for empty dyn trait args
* Fix tidy check
* address code nit
* fold test into existing E0191 test
2026-04-23 12:32:33 +00:00
lapla 9be8fca54e Fix ICE when const closure appears inside a non-const trait method 2026-04-22 15:41:31 +09:00
bors cf1817bc6e Auto merge of #155634 - jhpratt:rollup-lo99oO5, r=jhpratt
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#155589 (Forbid `check-pass`/`build-pass`/`run-pass` directives in incremental tests)
 - rust-lang/rust#155610 (Add missing `dyn` keyword to `trait_alias` page of the Unstable Book)
 - rust-lang/rust#155615 (test cleanups for `ui/derives` and `ui/deriving`)
 - rust-lang/rust#154874 (Fix ICE for inherited const conditions on const closures)
 - rust-lang/rust#155605 (std: Update support for `wasm32-wasip3`)
 - rust-lang/rust#155613 (c-variadic: tweak `std` docs)
 - rust-lang/rust#155619 (Remove a bunch of unnecessary explicit lifetimes from the ast validator)
2026-04-22 06:20:12 +00:00
Jacob Pratt b622dd00fb Rollup merge of #154874 - cijiugechu:fix-const-closure-inherited-conditions, r=oli-obk
Fix ICE for inherited const conditions on const closures

Synchronize `evaluate_host_effect_for_fn_goal` with the behavior of `extract_fn_def_from_const_callable` in new solver.

Closes rust-lang/rust#153861 .
2026-04-22 01:53:41 -04:00
CoCo-Japan-pan 470e4623db Rule out const unsafe impl from FnHeader to
correctly parse `const unsafe trait` implementations.
2026-04-21 22:17:23 +09:00
Waffle Lapkin 59be02e594 bless ui tests 2026-04-21 12:28:25 +02:00
Muhtasim-Rasheed b1786813df Make E0284 generic argument suggestions more explicit 2026-04-20 16:46:57 +06:00
Jacob Pratt db3d08421c Rollup merge of #154935 - Darksonn:dyn-trait-dyn-compat, r=scottmcm
Add Sized supertrait for CoerceUnsized and DispatchFromDyn

This is part of rust-lang/rust#149094. I did not include `Receiver` because I think it is correct to allow non-sized receivers.
2026-04-18 00:05:15 -04:00
Erick Tryzelaar 0f19b6d173 Fix pathological performance in trait solver cycles with errors
Fuchsia's Starnix system has had a multi-year long bug where
occasionally a typo could cause the rust compiler to take 10+ hours to
report an error. This was particularly hard to trace down since
Starnix's codebase is massive, over 384 thousand lines as of writing.

With the help of treereduce, cargo-minimize, and rustmerge, after about
a month of running we reduced it down to a couple [lines of code], which
only takes about 35 seconds to report an error on my machine. The bug
also appears to happen with `-Z next-solver=no` and `-Z
next-solver=coherence`, but does not occur with `-Z next-solver` or `-Z
next-solver=globally`.

I used Gemini to help diagnose the problem and proposed solution (which
is the one proposed in this patch):

1. The trait solver gets stuck in an exponential loop evaluating
   auto-trait bounds (like Send and Sync) on cyclic types that contain
   compilation errors (TyKind::Error).

2. Normally, if the solver detects a cycle, it prevents the result from
   being stored in the Global Cache because the result depends on the
   current evaluation stack. However, when an error is involved, the
   depth tracking gets pinned to a low value, forcing the solver to rely
   on the short-lived Provisional Cache. Since the provisional cache is
   cleared between high-level iterations of the fulfillment loop, the
   solver ends up re-discovering and re-evaluating the same large cycle
   thousands of times.

3. Allow global caching of results even if they appear stack-dependent,
   provided that the inference context is already "tainted by errors"
   (`self.infcx.tainted_by_errors().is_some()`). This violates the
   strict invariant that global cache entries shouldn't depend on the
   stack, but it is safe because the compilation is already guaranteed
   to fail due to the presence of errors. Prioritizing compiler
   responsiveness and termination over perfect correctness in error
   states is the correct trade-off here.

I added the reduction as the test case for this. However, I don't see an
easy way to catch if this bug comes back. Should we add some way to
timeout the test if it takes longer than 10 seconds to compile? That
could be a source of flakes though.

I don't have any experience with the trait solver code, but I did try to
review the code to the best of my ability. This approach seems a bit of
a bandaid to the solution, but I don't see a better solution. We could
try to teach the solver to not clear the provisional cache in this
circumstance, but I suspect that'd be a pretty invasive change.

I'm guessing if this does cause problems, it might report an incorrect
error, but I (and Gemini) were unable to come up with an example that
reported a different error with and without this fix.

[lines of code]: https://gist.github.com/erickt/255bc4006292cac88de906bd6bd9220a
2026-04-17 21:05:23 +00:00