Skip to content

Commit a9bd2bb

Browse files
camelidJoshua Nelson
authored and
Joshua Nelson
committed
Improve formatting and update info in "method lookup" section
1 parent 31e44f4 commit a9bd2bb

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/method-lookup.md

+12-21
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ file provides an overview of the process. More detailed notes are in
66
the code itself, naturally.
77

88
One way to think of method lookup is that we convert an expression of
9-
the form:
9+
the form `receiver.method(...)` into a more explicit [fully-qualified syntax][]
10+
(formerly called [UFCS][]):
1011

11-
```rust,ignore
12-
receiver.method(...)
13-
```
14-
15-
into a more explicit [UFCS] form:
16-
17-
```rust,ignore
18-
Trait::method(ADJ(receiver), ...) // for a trait call
19-
ReceiverType::method(ADJ(receiver), ...) // for an inherent method call
20-
```
12+
- `Trait::method(ADJ(receiver), ...)` for a trait call
13+
- `ReceiverType::method(ADJ(receiver), ...)` for an inherent method call
2114

2215
Here `ADJ` is some kind of adjustment, which is typically a series of
2316
autoderefs and then possibly an autoref (e.g., `&**receiver`). However
@@ -37,6 +30,7 @@ probe phase produces a "pick" (`probe::Pick`), which is designed to be
3730
cacheable across method-call sites. Therefore, it does not include
3831
inference variables or other information.
3932

33+
[fully-qualified syntax]: https://doc.rust-lang.org/nightly/book/ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name
4034
[UFCS]: https://github.com/rust-lang/rfcs/blob/master/text/0132-ufcs.md
4135
[probe]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/method/probe/
4236
[confirm]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/method/confirm/
@@ -51,12 +45,10 @@ until it cannot be deref'd anymore, as well as applying an optional
5145
"unsize" step. So if the receiver has type `Rc<Box<[T; 3]>>`, this
5246
might yield:
5347

54-
```rust,ignore
55-
Rc<Box<[T; 3]>>
56-
Box<[T; 3]>
57-
[T; 3]
58-
[T]
59-
```
48+
1. `Rc<Box<[T; 3]>>`
49+
2. `Box<[T; 3]>`
50+
3. `[T; 3]`
51+
4. `[T]`
6052

6153
### Candidate assembly
6254

@@ -99,10 +91,9 @@ So, let's continue our example. Imagine that we were calling a method
9991
that defines it with `&self` for the type `Rc<U>` as well as a method
10092
on the type `Box` that defines `Foo` but with `&mut self`. Then we
10193
might have two candidates:
102-
```text
103-
&Rc<Box<[T; 3]>> from the impl of `Foo` for `Rc<U>` where `U=Box<[T; 3]>
104-
&mut Box<[T; 3]>> from the inherent impl on `Box<U>` where `U=[T; 3]`
105-
```
94+
95+
- `&Rc<Box<[T; 3]>>` from the impl of `Foo` for `Rc<U>` where `U=Box<[T; 3]>`
96+
- `&mut Box<[T; 3]>>` from the inherent impl on `Box<U>` where `U=[T; 3]`
10697

10798
### Candidate search
10899

0 commit comments

Comments
 (0)