@@ -309,8 +309,7 @@ TupleField :
309
309
Type
310
310
311
311
+ MutRestriction :
312
- + mut
313
- + | mut ( crate )
312
+ + mut ( crate )
314
313
+ | mut ( self )
315
314
+ | mut ( super )
316
315
+ | mut ( in SimplePath )
@@ -332,25 +331,24 @@ Trait :
332
331
}
333
332
334
333
+ ImplRestriction :
335
- + impl
336
- + | impl ( crate )
334
+ + impl ( crate )
337
335
+ | impl ( self )
338
336
+ | impl ( super )
339
337
+ | impl ( in SimplePath )
340
338
```
341
339
342
- Essentially, ` mut ` and ` impl ` have the same syntax as ` pub ` , just with a different keyword.
340
+ Essentially, ` mut ` and ` impl ` have the same syntax as ` pub ` , just with a different keyword. Using
341
+ the keyword without providing a path is not allowed.
343
342
344
343
## Behavior
345
344
346
345
The current behavior of ` pub ` is that ` pub ` makes something visible within the declared scope. If no
347
346
scope is declared (such that it is just ` pub ` ), then the item is visible everywhere. This behavior
348
347
is preserved for ` impl ` and ` mut ` . When a restriction is used, the behavior is allowed only within
349
- the declared scope. When the keyword is used alone, the behavior is allowed everywhere. While in
350
- most cases the default visibility is private, ` pub ` is default in some cases, namely ` enum `
351
- variants, ` enum ` fields, and ` trait ` items. ` impl ` and ` mut ` will have a consistent default: when
352
- omitted entirely, the scope is inherited from ` pub ` . This is both what is most convenient and is
353
- what is required for backwards compatibility with existing code.
348
+ the declared scope. While in most cases the default visibility is private, ` pub ` is default in some
349
+ cases, namely ` enum ` variants, ` enum ` fields, and ` trait ` items. ` impl ` and ` mut ` will have a
350
+ consistent default: when omitted entirely, the scope is inherited from ` pub ` . This is both what is
351
+ most convenient and is what is required for backwards compatibility with existing code.
354
352
355
353
When an ` ImplRestriction ` is present, implementations of the associated trait are only permitted
356
354
within the designated path. Any implementation of the trait outside this scope is a compile error.
@@ -401,11 +399,8 @@ Trait aliases cannot be implemented. As such, there is no concern about compatib
401
399
402
400
# Unresolved questions
403
401
404
- - Should unrestricted "restrictions" be allowed to be explicitly stated, or should this be banned?
405
- If allowed, should it be a warning?
406
- - Both ` impl ` and ` mut ` make no sense to have unrestricted, as that is the default behavior. An
407
- "unnecessary" restriction lint that is warn-by-default would be ideal. This would allow macros
408
- to emit more flexible syntax. This warning could also be used for ` pub(self) ` .
402
+ - Should an "unnecessary restriction" lint be introduced? It would fire when the restriction is as
403
+ strict or less strict than the visibility. This warning could also be used for ` pub(self) ` .
409
404
- How will restrictions work with ` macro_rules! ` matchers? There is currently a ` vis ` matcher, but
410
405
it is likely unwise to add a new matcher for each restriction. Should the new syntax be included
411
406
as part of the ` vis ` matcher? If so, it is important to note that restrictions are not the same
@@ -414,7 +409,8 @@ Trait aliases cannot be implemented. As such, there is no concern about compatib
414
409
- What is the interaction between stability and restrictions?
415
410
- Suggestion: Visibility is an inherent part of the item; restrictions should be as well. Metadata
416
411
can be added in the future indicating when an item had its restriction lifted, if applicable.
417
- The design for this is left to the language team as necessary.
412
+ The design for this is left to the language team as necessary. A decision does _ not_ need to be
413
+ made prior to stabilization, as stability attributes are not stable in their own right.
418
414
419
415
# Future possibilities
420
416
@@ -430,3 +426,5 @@ Trait aliases cannot be implemented. As such, there is no concern about compatib
430
426
mutable within the module rather than mutable everywhere. This seems unlikely, as it would be an
431
427
incredibly disruptive change, and the benefits would have to be significant.
432
428
- Syntax such as ` impl(mod) ` could be added for clarity as an alternative to ` impl(self) ` .
429
+ - ` impl ` and ` mut ` could be usable without a path if deemed necessary. This behavior would be
430
+ identical to omitting the keyword entirely.
0 commit comments