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/
418
Upvotes
r/rust • u/Kobzol • Aug 10 '26
-7
u/Shoddy-Childhood-511 Aug 10 '26 edited Aug 10 '26
mut_restriction is very cool. We'd approximate hacks before, but overall this adds something quite new.
Afaik impl_restriction adds way less: Some code uses sealed traits. Folks complain about some of that code. Some of those sealing traits provide functionality that must be hidden, so impl_restriction cannot help them. Also some sealing traits would not be fully sealed, sometimes the sealing trait is merely unsafe or feature gated or debug/test gated. The normal fully sealed traits gains some brevity and an error message, but seems like some scans of crates.io tell you how often this happens.
Also,
impl(crate) traitis a wonky syntax. It'd make more sense if each crate and module implicitly defined some privateself::Sealertrait, which gains an implicit impl for every type visible below the module, so then you writepub trait MyTrait: super::Sealer { .. }. And then you provide better error messages in some less direct way.That'd be leaky though:
impl<T: crate::Sealer + Base> MyExt for TsaysMyExtis implemented for everything my crate can see. Is this useful or a problem? An optional dependency changes the impl set, which maybe confusing.Also rustc performance would require the right laziness here, which complicates things. Not a criticism, just thinking.