Skip to content

Commit 6a96392

Browse files
committed
Remove impl(mod) syntax
1 parent c199f07 commit 6a96392

File tree

1 file changed

+1
-41
lines changed

1 file changed

+1
-41
lines changed

text/3323-restrictions.md

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -286,28 +286,6 @@ In this example, `Foo::Alpha { x: 5 }` is allowed when it is in the same crate a
286286
because `x` is not restricted within this scope, so the field can be freely mutated. Because of
287287
this, the previous concern about upholding variants is not applicable.
288288

289-
## `mod` as a restriction scope
290-
291-
`pub` can be restricted in a few ways. The most common is `pub(crate)`, which restricts visibility
292-
to the current crate. However, there are other ways to restrict visibility. You can also use
293-
`pub(super)` to restrict visibility to the parent module, and `pub(in path)` to restrict visibility
294-
to `path`, as long as that path is an ancestor of the location it is used. There is one additional
295-
case you have likely never encountered: `pub(self)`. The reason you have likely never seen this
296-
before is that it is redundant: `pub(self)` is identical to private, which is the default
297-
visibility.
298-
299-
While `pub(self)` should never be needed in most code, `impl(self)` and `mut(self)` are quite
300-
different. As no restrictions apply by default (anything visible can be implemented/mutated), is
301-
more than likely that `impl(self)` and `mut(self)` will be quite common. During previous discussions
302-
about syntax, the unclear meaning of `impl(self)` and `mut(self)` was brought up. Syntax should have
303-
a clear meaning, and `impl(self)` and `mut(self)` are not clear. While they should be allowed for
304-
consistency with `pub(self)`, an alternative was needed with the same behavior. `impl(mod)` and
305-
`mut(mod)` should have a sufficiently clear meaning: implementing the trait and mutating the field
306-
are restricted to the current module. `impl(in mod)` and `mut(in mod)` are accepted as well. The
307-
behavior of `impl(mod)` is identical to `impl(self)`; likewise for `mut(mod)` and `mut(self)`.
308-
309-
For consistency with the new restriction syntax, `pub(mod)` and `pub(in mod)` are also allowed.
310-
311289
# Reference-level explanation
312290

313291
## Syntax
@@ -334,10 +312,8 @@ TupleField :
334312
+ mut
335313
+ | mut ( crate )
336314
+ | mut ( self )
337-
+ | mut ( mod )
338315
+ | mut ( super )
339316
+ | mut ( in SimplePath )
340-
+ | mut ( in mod )
341317
```
342318

343319
Trait definitions need a similar change to the [syntax for `trait`s][trait syntax] to accommodate
@@ -359,27 +335,12 @@ Trait :
359335
+ impl
360336
+ | impl ( crate )
361337
+ | impl ( self )
362-
+ | impl ( mod )
363338
+ | impl ( super )
364339
+ | impl ( in SimplePath )
365-
+ | impl ( in mod )
366340
```
367341

368342
Essentially, `mut` and `impl` have the same syntax as `pub`, just with a different keyword.
369343

370-
Finally, a minor change is needed to the syntax for visibility to permit `pub(mod)`.
371-
372-
```diff
373-
Visibility :
374-
pub
375-
| pub ( crate )
376-
| pub ( self )
377-
+ | pub ( mod )
378-
| pub ( super )
379-
| pub ( in SimplePath )
380-
+ | pub ( in mod )
381-
```
382-
383344
## Behavior
384345

385346
The current behavior of `pub` is that `pub` makes something visible within the declared scope. If no
@@ -391,8 +352,6 @@ variants, `enum` fields, and `trait` items. `impl` and `mut` will have a consist
391352
omitted entirely, the scope is inherited from `pub`. This is both what is most convenient and is
392353
what is required for backwards compatibility with existing code.
393354

394-
`pub(mod)` is equivalent to `pub(self)`; likewise for `impl(mod)` and `mut(mod)`.
395-
396355
When an `ImplRestriction` is present, implementations of the associated trait are only permitted
397356
within the designated path. Any implementation of the trait outside this scope is a compile error.
398357
When a `MutRestriction` is present, mutable uses of the associated field are only permitted within
@@ -470,3 +429,4 @@ Trait aliases cannot be implemented. As such, there is no concern about compatib
470429
- The default could be changed in a future edition, such as to make `pub field: Type` be only
471430
mutable within the module rather than mutable everywhere. This seems unlikely, as it would be an
472431
incredibly disruptive change, and the benefits would have to be significant.
432+
- Syntax such as `impl(mod)` could be added for clarity as an alternative to `impl(self)`.

0 commit comments

Comments
 (0)