Skip to content

gccrs: Only add the requested auto trait when probing for a trait - #4972

Merged
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
u7k4rs6:fix-4971-auto-trait-scan
Oct 25, 2026
Merged

CohenArthur merged 1 commit into
Rust-GCC:masterfrom
u7k4rs6:fix-4971-auto-trait-scan

Conversation

@u7k4rs6

@u7k4rs6 u7k4rs6 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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).

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
u7k4rs6 force-pushed the fix-4971-auto-trait-scan branch 3 times, most recently from 042a66e to 7cc8f98 Compare October 20, 2026 11:02

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, good find!

@CohenArthur
CohenArthur added this pull request to the merge queue Oct 25, 2026
Merged via the queue into Rust-GCC:master with commit c8ddc01 Oct 25, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type checking blows up exponentially on nested structs when auto traits are declared (libcore never finishes type checking)

2 participants