Implement restrictions, prepare for stabilization (original) (raw)

Summary

RFC 3323 will be implemented and feature-complete, with all syntax questions resolved. The features will be prepared for stabilization.

Motivation

The RFC for restrictions was accepted over two years ago, but the pull request implementing it has been stalled for a long time for a variety of reasons. Implementing the feature will permit testing, feedback, and stabilization.

The status quo

Sealed traits are a common pattern in Rust, but are not currently supported by the language itself. Instead, they are implemented using a combination of visibility modifiers and nested modules. Fields with restricted mutability are currently only possible with getters and setters, setting aside (ab)using Deref implementations.

More details are available in the RFC.

The next 6 months

The accepted restrictions RFC represents the end goal of this project goal. All unresolved questions should be discussed and resolved, with the two features (impl_restrictions andmut_restrictions) being ready for stabilization. Future possibilities are likely considered at a high level, but are not the focus of this project goal.

Ownership and team asks

Owner: Jacob Pratt

Definitions

Definitions for terms used above:

Frequently asked questions

Isn't the syntax already decided?

While the RFC was accepted without this being an unresolved question (aside from a simpler syntax for common cases), I believe that an attribute-based syntax such as #[restrict(impl(crate))] may be, but is not necessarily, favorable to the syntax in the RFC. This is because it is backwards-compatible with all existing macros and prevents nontrivial additions to the width of code.