Skip to content

Commit 06a17a7

Browse files
committed
manual: disambiguate field expressions from method-call expressions.
1 parent d81196c commit 06a17a7

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

doc/rust.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ trait shape {
11781178

11791179
This defines a trait with two methods.
11801180
All values that have [implementations](#implementations) of this trait in scope can have their `draw` and `bounding_box` methods called,
1181-
using `value.bounding_box()` [syntax](#field-expressions).
1181+
using `value.bounding_box()` [syntax](#method-call-expressions).
11821182

11831183
Type parameters can be specified for a trait to make it generic.
11841184
These appear after the name, using the same syntax used in [generic
@@ -1558,13 +1558,27 @@ let base = {x: 1, y: 2, z: 3};
15581558
{y: 0, z: 10, .. base};
15591559
~~~~
15601560

1561+
### Method-call expressions
1562+
1563+
~~~~~~~~{.ebnf .gram}
1564+
method_call_expr : expr '.' ident paren_expr_list ;
1565+
~~~~~~~~
1566+
1567+
A _method call_ consists of an expression followed by a single dot, an identifier, and a parenthesized expression-list.
1568+
Method calls are resolved to methods on specific traits,
1569+
either statically dispatching to a method if the exact `self`-type of the left-hand-side is known,
1570+
or dynamically dispatching if the left-hand-side expression is an indirect [trait type](#trait-types).
1571+
1572+
15611573
### Field expressions
15621574

15631575
~~~~~~~~{.ebnf .gram}
1564-
field_expr : expr '.' expr
1576+
field_expr : expr '.' ident
15651577
~~~~~~~~
15661578

1567-
A dot can be used to access a field in a record.
1579+
A _field expression_ consists of an expression followed by a single dot and an identifier,
1580+
when not immediately followed by a parenthesized expression-list (the latter is a [method call expression](#method-call-expressions)).
1581+
A field expression denotes a field of a [structure](#structure-types) or [record](#record-types).
15681582

15691583
~~~~~~~~ {.field}
15701584
myrecord.myfield;
@@ -1574,17 +1588,9 @@ myrecord.myfield;
15741588
A field access on a record is an [lvalue](#lvalues-rvalues-and-temporaries) referring to the value of that field.
15751589
When the field is mutable, it can be [assigned](#assignment-expressions) to.
15761590

1577-
When the type of the expression to the left of the dot is a boxed
1578-
record, it is automatically derferenced to make the field access
1579-
possible.
1580-
1581-
Field access syntax is overloaded for [trait method](#traits)
1582-
access. When no matching field is found, or the expression to the left
1583-
of the dot is not a (boxed) record, an
1584-
[implementation](#implementations) that matches this type and the
1585-
given method name is looked up instead, and the result of the
1586-
expression is this method, with its _self_ argument bound to the
1587-
expression on the left of the dot.
1591+
When the type of the expression to the left of the dot is a pointer to a record or structure,
1592+
it is automatically derferenced to make the field access possible.
1593+
15881594

15891595
### Vector expressions
15901596

0 commit comments

Comments
 (0)