Skip to content

Tracking Issue for Restrictions #105077

Open
@tmandry

Description

@tmandry

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

Unresolved Questions

  • Should a simpler syntax be provided for common cases? For instance, sealed or readonly. A
    different syntax altogether could be used as well.
  • 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 for pub(self).
    • Does this necessarily have to be decided as part of this RFC?
  • How will restrictions work with macro_rules! matchers? There is currently a vis 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 and impl_restriction are relatively long.
  • 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.
  • 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 for impl. For mut, 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?

Implementation history

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-impl_restriction`#![feature(impl_restriction)]`F-mut_restriction`#![feature(mut_restriction)]`T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions