structural match for `TypeId` #166205
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
oli-obk
<!-- homu-ignore:start -->
View all comments
<!-- homu-ignore:end -->
Supports
StructuralPartialEqandConstParamTy_forstd::any::TypeId, behindfeature(type_id_structural_match).Background
Needed this while doing something silly & experimental. See
tests/ui/const-generics/min_adt_const_params/type-id-arbitrary.rsfor 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
TypeIdinto valtrees is provenance. Currently,TypeIdstores 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 theTyfrom aTypeId.To solve this, I just put a new variant on
ValTreeKind, which keeps track of theTyit is for. This was surprisingly easy to do, but is probably not a great precedent to set. If we do ever wantTypeIdin valtrees, I think this is all but unavoidable.For valtree-to-pattern, the same approach as
stris taken. Make references to the scrutinee and pattern constant and then compare them withPartialEq::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.