Open
Description
This is a tracking issue for the RFC "Restrictions" (rust-lang/rfcs#3323).
The feature gates for the issue are:
#![feature(impl_restriction)]
#![feature(mut_restriction)]
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
- Implement the RFC (@jhpratt has a branch in progress)
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
Unresolved Questions
- Should a simpler syntax be provided for common cases? For instance,
sealed
orreadonly
. A
different syntax altogether could be used as well.- Also see Restrictions rfcs#3323 (comment).
- Should an "unnecessary restriction" lint be introduced? It would fire when the restriction is as
strict or less strict than the visibility. This warning could also be used forpub(self)
.- Does this necessarily have to be decided as part of this RFC?
- How will restrictions work with
macro_rules!
matchers? There is currently avis
matcher, but
it is likely unwise to add a new matcher for each restriction.- The proposed syntax cannot be added to the
vis
matcher, as it does not current restrict the
tokens that can follow. For this reason, it could break existing code, such as the following
example.macro_rules! foo { ($v:vis impl(crate) trait Foo) => {} } foo!(pub impl(crate) trait Foo);
- A
restriction
matcher could work, but restrictions are not the same everywhere. mut_restriction
andimpl_restriction
are relatively long.
- The proposed syntax cannot be added to the
- What is the interaction between stability and restrictions?
- Suggestion: Visibility is an inherent part of the item; restrictions should be as well. Metadata
can be added in the future indicating when an item had its restriction lifted, if applicable.
The design for this is left to the language team as necessary. A decision does not need to be
made prior to stabilization, as stability attributes are not stable in their own right.
- Suggestion: Visibility is an inherent part of the item; restrictions should be as well. Metadata
- Should the
in
syntax be permitted for restrictions? Including it is consistent with the existing
syntax for visibility. Further, the lack of inclusion would lead to continued use of the
workaround forimpl
. Formut
, there is no workaround. The syntax is not used often for
visibility, but it is very useful when it is used. - Should
struct
expressions be disallowed?- Where would it be desirable to prohibit mutability after construction, but still permit
construction with unchecked values?
- Where would it be desirable to prohibit mutability after construction, but still permit