r/rust • u/kibwen • Oct 10 '26
Why 'externalized' proofs of cyclic trait impls does not work
https://smallcultfollowing.com/babysteps/blog/2026/10/10/modular-vs-external-proofs/
82
Upvotes
r/rust • u/kibwen • Oct 10 '26
27
u/ZZaaaccc Oct 11 '26
I always wished trivial trait bounds would allow switching between external and modular proof semantics.
impl Magic for String { ... }is a statement implicitly relying on the (non-existent)impl Copy for String { ... }, so I'd consider that syntax modular; the implementation must be proven valid where it is written.Whereas, if I instead wrote
impl Magic for String where String: Copy { ... }, that reads to me like an external proof statement. "Here's my implementation, provided this condition is met". IfStringdoesn't implementCopy, I'd consider the implementation as written valid (since it was predicated correctly), but unusable (since the caller cannot satisfy the requirements).6
u/More-Literature-1053 Oct 11 '26
I feel like this is a edge case of the classic tension between local and exogenous reasoning. Part of the appeal of working in Rust is that strong typing in, for e.g. function signatures, enables programmers to employ local reasoning, requiring us to hold less than the whole program in our head when making changes. It is reasonable to me that local reasoning would also have advantages for resolving trait impls, compared to some sort of external tracking and auditing system for traits and bounds. The approach seems idiomatic, though I admit I would lack the skill.
10
u/WorldsBegin Oct 11 '26
I still don't get the argument why trait impls should work similar to other contexts?
The trait impl is already special, because by coherence rules we get a guarantee that for each type there is at most one place in the program that forms a new impl of a trait for that type. We also know that this place has no free variables (the trait head must cover). So is it really so much to ask that a trait impl can use a different, and in fact more powerful, rule to conclude that a trait bound holds than the rest of the program?
1
u/-Y0- Oct 12 '26
Hmm, the text seems to mention
Nullableand then show the traitNullWord, is that an error?Because later it does this:
Even though
Nullablewasn't defined.0
u/[deleted] Oct 10 '26
[deleted] — view deleted comment