You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(checker): satisfy Hashable/Eq bounds via Hash/Eq derives
Extend the generic protocol-bound check so a user struct/sum satisfies
`Hashable` when it `derives(Hash)` and `Eq` when it `derives(Eq)` (or
`Ord`, which implies `Eq`). Builtin hashable scalars (Int family, String,
Bool, etc.) satisfy both directly, and `List`/`Option`/`Result` keys are
satisfiable structurally from their element types. Give RS0032 a
protocol-aware cause/fix so the suggestion is `derives(Eq, Hash)` for a
Map/Set key instead of the Ord-flavored comparator wording.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
"A `Map` key / `Set` element must be `Hashable` (and therefore `Eq`). Hashability is a compiler-derived structural contract: a builtin scalar key, or a managed struct/sum that derives `Eq` and `Hash`.",
1573
+
format!("Add `derives(Eq, Hash)` to `{actual}` so the compiler derives a structural hash and equality, or use a hashable key type."),
1574
+
),
1575
+
"Eq" => (
1576
+
"Equality is a compiler-derived structural contract: a builtin scalar, or a managed struct/sum that derives `Eq` (or `Ord`, which implies `Eq`).",
1577
+
format!("Add `derives(Eq)` to `{actual}`, or use an equatable type."),
1578
+
),
1579
+
_ => (
1580
+
"Generic protocol bounds are nominal. Use a type with a matching derive, add a compatible generic bound, or pass an explicit comparator API.",
1581
+
format!("Add `derives({protocol})` to `{actual}` if the compiler-owned ordering is intended, or call an API that accepts an explicit comparator."),
1582
+
),
1583
+
}
1584
+
}
1585
+
1556
1586
fnbuiltin_type_is_ord(type_name:&str) -> bool{
1557
1587
matches!(type_name,"Int" | "String" | "Bool")
1558
1588
}
1559
1589
1590
+
/// Builtin scalar types that are `Hashable`/`Eq` directly (no derive needed).
1591
+
/// Mirrors the structural derive support in the analyzer (`Float` is excluded
0 commit comments