Skip to content

Commit e2d1ee5

Browse files
Merge pull request #230 from pietroalbini/use-nested-groups-reference
Add mention of RFC 2128 (use_nested_groups) in the reference
2 parents 52843c7 + 75d473b commit e2d1ee5

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/items/use-declarations.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# Use declarations
22

3-
> **<sup>Syntax:<sup>**
3+
> **<sup>Syntax:</sup>**
44
> _UseDeclaration_ :
5-
> &nbsp;&nbsp; &nbsp;&nbsp; `use` [_SimplePath_]&nbsp;(`as` [IDENTIFIER])<sup>?</sup> `;`
6-
> &nbsp;&nbsp; | `use` ([_SimplePath_]<sup>?</sup> `::`)<sup>?</sup> `{` _UseDeclarationItems_ `}` `;`
7-
> &nbsp;&nbsp; | `use` ([_SimplePath_]<sup>?</sup> `::`)<sup>?</sup> `*` `;`
5+
> &nbsp;&nbsp; ([_Visibility_])<sup>?</sup> `use` _UseTree_ `;`
86
>
9-
> _UseDeclarationItems_ :
10-
> &nbsp;&nbsp; _UseDeclarationItem_ ( `,` _UseDeclarationItem_ )<sup>*</sup> `,`<sup>?<sup>
11-
>
12-
> _UseDeclarationItem_ :
13-
> &nbsp;&nbsp; ( `self` | [IDENTIFIER] ) ( `as` [IDENTIFIER] )<sup>?</sup>
7+
> _UseTree_ :
8+
> &nbsp;&nbsp; &nbsp;&nbsp; ([_SimplePath_]<sup>?</sup> `::`)<sup>?</sup> `*`
9+
> &nbsp;&nbsp; | ([_SimplePath_]<sup>?</sup> `::`)<sup>?</sup> `{` (_UseTree_ ( `,` _UseTree_ )<sup>*</sup> `,`<sup>?</sup>)<sup>?</sup> `}`
10+
> &nbsp;&nbsp; | [_SimplePath_] `as` [IDENTIFIER]
1411
1512
A _use declaration_ creates one or more local name bindings synonymous with
1613
some other [path]. Usually a `use` declaration is used to shorten the path
@@ -27,16 +24,17 @@ and [blocks], usually at the top.
2724
2825
Use declarations support a number of convenient shortcuts:
2926

30-
* Simultaneously binding a list of paths differing only in their final element,
31-
using the glob-like brace syntax `use a::b::{c,d,e,f};`
32-
* Simultaneously binding a list of paths differing only in their final element
33-
and their immediate parent module, using the `self` keyword, such as `use
34-
a::b::{self, c, d};`
27+
* Simultaneously binding a list of paths with a common prefix, using the
28+
glob-like brace syntax `use a::b::{c, d, e::f, g::h::i};`
29+
* Simultaneously binding a list of paths with a common prefix and their common
30+
parent module, using the `self` keyword, such as `use a::b::{self, c, d::e};`
3531
* Rebinding the target name as a new local name, using the syntax `use p::q::r
36-
as x;`. This can also be used with the last two features: `use a::b::{self as
37-
ab, c as abc}`.
32+
as x;`. This can also be used with the last two features:
33+
`use a::b::{self as ab, c as abc}`.
3834
* Binding all paths matching a given prefix, using the asterisk wildcard syntax
39-
`use a::b::*;`
35+
`use a::b::*;`.
36+
* Nesting groups of the previous features multiple times, such as
37+
`use a::b::{self as ab, c, d::{*, e::f}};`
4038

4139
An example of `use` declarations:
4240

@@ -126,3 +124,4 @@ fn main() {}
126124

127125
[IDENTIFIER]: identifiers.html
128126
[_SimplePath_]: paths.html
127+
[_Visibility_]: visibility-and-privacy.html

0 commit comments

Comments
 (0)