← Back to Pull requests

structural match for `TypeId` #166205

Open
unknown opened this pull request with 248 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 19, 2026 13:49 UTC
Author

<!-- homu-ignore:start -->
View all comments
<!-- homu-ignore:end -->

Supports StructuralPartialEq and ConstParamTy_ for std::any::TypeId, behind feature(type_id_structural_match).

Background


Needed this while doing something silly & experimental. See tests/ui/const-generics/min_adt_const_params/type-id-arbitrary.rs for why I found this useful.

Not sure if this is really RFC-worthy. I am happy to write one quickly, but since I already had the branch ready, I thought I might as well make the PR. Happy to close this now if that is more appropriate.

Solution


The problem with putting TypeId into valtrees is provenance. Currently, TypeId stores pointers which are nothing more than integers at runtime, but are annotated with special type-specific provenance during CTFE, so that comptime shenanigans can recover the Ty from a TypeId.

To solve this, I just put a new variant on ValTreeKind, which keeps track of the Ty it is for. This was surprisingly easy to do, but is probably not a great precedent to set. If we do ever want TypeId in valtrees, I think this is all but unavoidable.

For valtree-to-pattern, the same approach as str is taken. Make references to the scrutinee and pattern constant and then compare them with PartialEq::eq.

The actual library impls are gated behind unstable_feature_bound. I don't think that causes problems here, but I'm not very familiar with how it works.

Problems


I'm not sure that I took the correct approach to symbol mangling. Currently, the bits of the hash are printed out as a u128, but that might not be appropriate stability-wise. I suppose the only other thing we can do is print out the actual type it represents, but I ran into issues with demangling that I had no idea how to solve.

Diff: 248 lines (+186 / -62) across 3 files Reviewer: oli-obk Review duration: 16066m
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 248 lines diff across 3 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.330
Real PR Conversation Timeline
1 comments
"Review active on #166205"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 38.9% (MEDIUM) · Higher = larger blast radius
38.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 20.8% · Safe to merge
20.8%
Repository