@@ -220,6 +220,9 @@ exact `self`-type of the left-hand-side is known, or dynamically dispatching if
220
220
the left-hand-side expression is an indirect [ trait
221
221
object] ( types.html#trait-objects ) .
222
222
223
+ [ UFCS] ( #unambiguous-function-call-syntax ) allows method invocation using
224
+ function-like syntax.
225
+
223
226
## Field expressions
224
227
225
228
A _ field expression_ consists of an expression followed by a single dot and an
@@ -544,6 +547,41 @@ let x: i32 = add(1i32, 2i32);
544
547
let pi : Result <f32 , _ > = " 3.14" . parse ();
545
548
```
546
549
550
+ Function calls may sometimes result in ambiguities about receiver or referent.
551
+ See [ UFCS] ( #unambiguous-function-call-syntax ) for how to resolve this.
552
+
553
+ ### Unambiguous Function Call Syntax
554
+
555
+ Several situations often occur which result in ambiguities about the receiver or
556
+ referent of method or associated function calls. These situations may include:
557
+
558
+ * Multiple in-scope traits define the same method for the same types
559
+ * Auto-` deref ` is undesirable; for example, distinguishing between methods on a
560
+ smart pointer itself and the pointer's referent.
561
+ * Methods which take no arguments and return properties of a type, like
562
+ ` SizeOf::size_of() `
563
+
564
+ The programmer may unambiguously refer to their desired method or function using
565
+ Unambiguous Function Call Syntax (UFCS), specifying only as much type and path
566
+ information as necessary.
567
+
568
+ For example,
569
+
570
+ ``` rust,ignore
571
+ // shorthand, only if `T` is a path
572
+ T::size_of()
573
+
574
+ // infer trait `SizeOf` based on traits in scope.
575
+ <T>::size_of()
576
+
577
+ // completely unambiguous; works if multiple in-scope traits define `size_of()`
578
+ <T as SizeOf>::size_of()
579
+ ```
580
+
581
+ Refer to [ RFC 132] for further details, motivations, and subtleties of syntax.
582
+
583
+ [ RFC 132 ] : https://github.com/rust-lang/rfcs/blob/master/text/0132-ufcs.md
584
+
547
585
## Lambda expressions
548
586
549
587
A _ lambda expression_ (sometimes called an "anonymous function expression")
0 commit comments