Repository navigation
gccrs: Only add the requested auto trait when probing for a trait - #4972
Merged
Merged
Conversation
This was referenced Oct 9, 2026
TypeBoundsProbe::scan added every auto trait to every probe, and checking an auto trait on an ADT probes each of its fields again, so a bound check on nested structs took time and memory exponential in the nesting depth. libcore never finished type checking because of it. Callers that probe for a specific trait only look at that trait in the result, and an auto trait has no supertraits, so only add the requested one. Fixes Rust-GCC#4971 Assisted-by: Claude Opus 5.5 (Anthropic) gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Only add the requested auto trait when probing for a specific trait. gcc/testsuite/ChangeLog: * rust/compile/auto-trait-nested-negative.rs: New test. * rust/compile/issues/issue-4971.rs: New test. Signed-off-by: Utkarsh Bahuguna <[email protected]>
u7k4rs6
force-pushed
the
fix-4971-auto-trait-scan
branch
3 times, most recently
from
October 20, 2026 11:02
042a66e to
7cc8f98
Compare
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.
TypeBoundsProbe::scan added every auto trait to every probe, even when the caller asked about one specific trait, and checking an auto trait on a struct probes each of its fields again. On nested structs that made a bound check exponential in the nesting depth, and it is what kept libcore from finishing type checking. With this change core gets past num/f32.rs.
Every caller that asks for a specific trait only keeps the results for that trait, and auto traits cannot have supertraits, so only the requested one is added now. This is meant as a stopgap: Philip's predicate environment work changes how bounds are stored and this applies cleanly on top of it, and a cache in the probe would be the real fix for the remaining cost.
Fixes #4971
For reference, the test cases were made with help of Claude (Opus 5.5).