fix: Panic when trait solver re-enters itself - #23367
Merged
ChayimFriedman2 merged 1 commit intoSep 15, 2026
Merged
Conversation
rust-analyzer would panic when the trait solver called itself, which can happen during const evaluation. rustc has the same function, but doesn't panic, so just copy the rustc implementation: https://github.com/rust-lang/rust/blob/5392d2f545c6836dc79f209bcc14ac7179dbc4f2/compiler/rustc_middle/src/ty/context/impl_interner.rs#L155 This caused SCIP crashes on the dudykr/stc, renegade-fi/renegade, and tikv/tikv GitHub repositories, so would presumably cause LSP crashes too. The linked trait-system-refactor-initiative issue has a repro, but for reference I minimised a repro independently: trait Tr { const N: usize; } struct A<const N: usize>; impl<const N: usize> Tr for A<N> { const N: usize = N; } const fn k<T: Tr>() -> usize { T::N } struct B<const N: usize>; impl<const N: usize> Tr for B<N> where A<{ k::<A<3>>() }>: Tr { const N: usize = 0; } fn need<T: Tr>() {} fn f() { need::<B<1>>(); } Since this is strictly removing a panic and copying rustc, I haven't added a unit test with this. AI disclosure: Triaged and minimised with help by an LLM, but commit message and final code by me.
ChayimFriedman2
approved these changes
Sep 15, 2026
This was referenced Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rust-analyzer would panic when the trait solver called itself, which can happen during const evaluation.
rustc has the same function, but doesn't panic, so just copy the rustc implementation:
https://github.com/rust-lang/rust/blob/5392d2f545c6836dc79f209bcc14ac7179dbc4f2/compiler/rustc_middle/src/ty/context/impl_interner.rs#L155
This caused SCIP crashes on the dudykr/stc, renegade-fi/renegade, and tikv/tikv GitHub repositories, so would presumably cause LSP crashes too.
The linked trait-system-refactor-initiative issue has a repro, but for reference I minimised a repro independently:
Since this is strictly removing a panic and copying rustc, I haven't added a unit test with this.
AI disclosure: Triaged and minimised with help by an LLM, but commit message and final code by me.