Skip to content

Commit 3091989

Browse files
committed
Grammar: Paths
This includes a variety of things all related to paths: - Paths - Path expressions - Method call expression - Attribute clarifications - Visibility fixes
1 parent 38a98e0 commit 3091989

File tree

10 files changed

+221
-66
lines changed

10 files changed

+221
-66
lines changed

src/attributes.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
>    `#[` MetaItem `]`
1212
>
1313
> _MetaItem_ :\
14-
>       IDENTIFIER\
15-
>    | IDENTIFIER `=` LITERAL\
16-
>    | IDENTIFIER `(` _MetaSeq_ `)`
14+
>       [_SimplePath_]\
15+
> &nbsp;&nbsp; | [_SimplePath_] `=` [_LiteralExpression_]<sub>_without suffix_</sub>\
16+
> &nbsp;&nbsp; | [_SimplePath_] `(` _MetaSeq_ `)`
1717
>
1818
> _MetaSeq_ :\
1919
> &nbsp;&nbsp; &nbsp;&nbsp; EMPTY\
2020
> &nbsp;&nbsp; | _MetaItem_\
21-
> &nbsp;&nbsp; | LITERAL\
21+
> &nbsp;&nbsp; | [_LiteralExpression_]<sub>_without suffix_</sub>\
2222
> &nbsp;&nbsp; | _MetaItem_ `,` _MetaSeq_
2323
2424
An _attribute_ is a general, free-form metadatum that is interpreted according
@@ -33,6 +33,8 @@ Attributes may appear as any of:
3333
* An identifier followed by a parenthesized list of sub-attribute arguments
3434
which include literals
3535

36+
Literal values must not include integer or float type suffixes.
37+
3638
_Inner attributes_, written with a bang ("!") after the hash ("#"), apply to the
3739
item that the attribute is declared within. _Outer attributes_, written without
3840
the bang after the hash, apply to the thing that follows the attribute.
@@ -522,6 +524,8 @@ impl<T: PartialEq> PartialEq for Foo<T> {
522524

523525
You can implement `derive` for your own traits through [procedural macros].
524526

527+
[_LiteralExpression_]: expressions/literal-expr.html
528+
[_SimplePath_]: paths.html#simple-paths
525529
[Doc comments]: comments.html#doc-comments
526530
[The Rustdoc Book]: ../rustdoc/the-doc-attribute.html
527531
[procedural macros]: procedural-macros.html

src/expressions/method-call-expr.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Method-call expressions
22

3+
> **<sup>Syntax</sup>**\
4+
> _MethodCallExpression_ :\
5+
> &nbsp;&nbsp; [_Expression_] `.` [_PathExprSegment_] `(`[_CallParams_]<sup>?</sup> `)`
6+
37
A _method call_ consists of an expression (the *receiver*) followed by a single
4-
dot, an [identifier], and a parenthesized expression-list. Method calls are
8+
dot, an expression path segment, and a parenthesized expression-list. Method calls are
59
resolved to associated [methods] on specific traits, either statically
610
dispatching to a method if the exact `self`-type of the left-hand-side is known,
711
or dynamically dispatching if the left-hand-side expression is an indirect
@@ -93,7 +97,9 @@ method and you'll be fine.
9397
9498
</div>
9599
96-
[IDENTIFIER]: identifiers.html
100+
[_CallParams_]: expressions/call-expr.html
101+
[_Expression_]: expressions.html
102+
[_PathExprSegment_]: paths.html#paths-in-expressions
97103
[visible]: visibility-and-privacy.html
98104
[array]: types.html#array-and-slice-types
99105
[trait objects]: types.html#trait-objects

src/expressions/operator-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,4 @@ assert_eq!(x, 14);
460460
[_CompoundAssignmentExpression_]: #compound-assignment-expressions
461461

462462
[_Expression_]: expressions.html
463-
[_PathInExpression_]: paths.html
463+
[_PathInExpression_]: paths.html#paths-in-expressions

src/expressions/path-expr.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Path expressions
22

3+
> **<sup>Syntax</sup>**\
4+
> _PathExpression_ :\
5+
> &nbsp;&nbsp; &nbsp;&nbsp; [_PathInExpression_]\
6+
> &nbsp;&nbsp; | [_QualifiedPathInExpression_]
7+
38
A [path] used as an expression context denotes either a local
49
variable or an item. Path expressions that resolve to local or static variables
510
are [place expressions], other paths are [value expressions]. Using a
@@ -19,8 +24,10 @@ let push_integer = Vec::<i32>::push;
1924
let slice_reverse = <[i32]>::reverse;
2025
```
2126

27+
[_PathInExpression_]: paths.html#paths-in-expressions
28+
[_QualifiedPathInExpression_]: paths.html#qualified-paths
2229
[place expressions]: expressions.html#place-expressions-and-value-expressions
2330
[value expressions]: expressions.html#place-expressions-and-value-expressions
2431
[path]: paths.html
2532
[`static mut`]: items/static-items.html#mutable-statics
26-
[`unsafe` block]: expressions/block-expr.html#unsafe-blocks
33+
[`unsafe` block]: expressions/block-expr.html#unsafe-blocks

src/items/structs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
>
2626
> _StructField_ :\
2727
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup>\
28-
> &nbsp;&nbsp; [_Visibility_]
28+
> &nbsp;&nbsp; [_Visibility_]<sup>?</sup>\
2929
> &nbsp;&nbsp; [IDENTIFIER] `:` [_Type_]
3030
>
3131
> _TupleFields_ :\
3232
> &nbsp;&nbsp; _TupleField_ (`,` _TupleField_)<sup>\*</sup> `,`<sup>?</sup>
3333
>
3434
> _TupleField_ :\
3535
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup>\
36-
> &nbsp;&nbsp; [_Visibility_]
36+
> &nbsp;&nbsp; [_Visibility_]<sup>?</sup>\
3737
> &nbsp;&nbsp; [_Type_]
3838
3939
A _struct_ is a nominal [struct type] defined with the keyword `struct`.

src/items/use-declarations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> **<sup>Syntax:</sup>**\
44
> _UseDeclaration_ :\
5-
> &nbsp;&nbsp; ([_Visibility_])<sup>?</sup> `use` _UseTree_ `;`
5+
> &nbsp;&nbsp; [_Visibility_]<sup>?</sup> `use` _UseTree_ `;`
66
>
77
> _UseTree_ :\
88
> &nbsp;&nbsp; &nbsp;&nbsp; ([_SimplePath_]<sup>?</sup> `::`)<sup>?</sup> `*`\
@@ -123,5 +123,5 @@ fn main() {}
123123
```
124124

125125
[IDENTIFIER]: identifiers.html
126-
[_SimplePath_]: paths.html
126+
[_SimplePath_]: paths.html#simple-paths
127127
[_Visibility_]: visibility-and-privacy.html

0 commit comments

Comments
 (0)