rust-lang / rust-lang/rust

Decide on keyword order for `impl`, `mut` restrictions

Open
#155,222 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

F-impl_restriction F-mut_restriction F-unsafe_fields I-lang-radar T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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 (https://github.com/rust-lang/rust/issues/105077), unsafe fields (https://github.com/rust-lang/rust/issues/132922), r-a request for supporting restrictions (https://github.com/rust-lang/rust-analyzer/issues/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RFC 3323, the unsafe fields RFC, and the linked PR review discussion; compare their grammar snippets and existing nightly behavior. Done means the lang team records a decision on keyword ordering and whether the proposed syntax remains desired.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.