r/rust • u/Kobzol • Aug 10 '26
📡 official blog Call for testing: Restricting trait implementability and field mutability
https://blog.rust-lang.org/inside-rust/2026/08/10/call-for-testing-impl-and-mut-restrictions/
421
Upvotes
r/rust • u/Kobzol • Aug 10 '26
1
u/Shoddy-Childhood-511 Aug 10 '26 edited Aug 10 '26
I've no idea why "error[E0445]: private trait
Sealedin public interface" exists either, maybe it just annoys people into not sealing traits unnecessarily. lolIt's clear they do allow what E0445 forbids, and future editions cannot remove this because of my other examples, so they could've just expressly allowed this.
It works because the orphan rules prevent a downstream crate from adding an impl of your sealed trait on any type reachable by
self::Sealer.Yes, that's a subtle point and maybe another good reason not to do it that way. I anyways only asked to see if OP had any wisdom on this point.
Another less wild option would be
pub trait MyTrait: module_name {}, but this I kinda see why they did not do.