Skip to content

Decide on keyword order for impl, mut restrictions #155222

@jhpratt

Description

@jhpratt

Both impl and mut restrictions were approved in RFC 3323.

For mut restrictions, the syntax was specified as

StructField :
   OuterAttribute*
   Visibility?
+  MutRestriction?
   IDENTIFIER : Type

TupleField :
   OuterAttribute*
   Visibility?
+  MutRestriction?
   Type

Neither the restrictions RFC nor unsafe fields RFC specify the relative order of the newly-introduced keywords (both appearing between visibility and the identifier/type).

Similarly, the restrictions RFC specifies

Trait :
   unsafe?
+  ImplRestriction?
   trait IDENTIFIER
   GenericParams? ( : TypeParamBounds? )? WhereClause? {
     InnerAttribute*
     AssociatedItem*
   }

as the syntax for impl restrictions.

In my PRs parsing impl restrictions, I put the restriction before unsafety, so as to group it with visibility. This was contrary to what was specified in the RFC and was noticed during review.

Given that I personally authored the restrictions RFC,the initial version of the unsafe fields RFC, and the initial (though ultimately closed) implementation for the restrictions, the fact that I did not know the ordering is concerning. Now that impl restrictions are available on nightly and mut restrictions will be shortly, this is something that should be decided sooner rather than later.

cc tracking issue for restrictions (#105077), unsafe fields (#132922), r-a request for supporting restrictions (rust-lang/rust-analyzer#22021)

Nominating for the lang team to discuss and hopefully decide. I will note that this presumes that the keywords as originally proposed is the desired syntax, which is explicitly an unresolved question from the RFC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-impl_restriction`#![feature(impl_restriction)]`F-mut_restriction`#![feature(mut_restriction)]`F-unsafe_fields`#![feature(unsafe_fields)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions