Skip to content

Commit 9c59366

Browse files
committed
Include example lint.
1 parent 113c8bd commit 9c59366

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

text/3519-arbitrary-self-types-v2.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,34 @@ The existing branches in the compiler for "arbitrary self types" already emit ex
309309
We don't know a use-case for this. There are several cases where this can result in misleading diagnostics. (For instance, if such a method is called with an incorrect type (for example `smart_ptr.a::<&Foo>()` instead of `smart_ptr.a::<Foo>()`). We could attempt to find and fix all those cases. However, we feel that generic receiver types might risk subtle interactions with method resolutions and other parts of the language. We think it is a safer choice to generate an error on any declaration of a generic `self` type.
310310
- As noted in [#compiler-changes-deshadowing](the section about compiler changes for deshadowing) we will downgrade an existing error to a warning if there are multiple
311311
method candidates found, if one of those candidates is further along the chain of `Receiver`s than the others.
312-
- As also noted in [#compiler-changes-deshadowing](the section about compiler changes for deshadowing), we will produce a new warning if a method in an inner type is chosen
313-
in preference to a method in an outer type ("inner" = further along the `Receiver` chain) and the inner type is either `self: &T` or `self: &mut T` and we're choosing it
314-
in preference to `self: T` or `self: &T` in the outer type.
312+
- As also noted in [#compiler-changes-deshadowing](the section about compiler changes for deshadowing), we will produce a new warning if a method in an inner type is chosen in preference to a method in an outer type ("inner" = further along the `Receiver` chain) and the inner type is either `self: &T` or `self: &mut T` and we're choosing it in preference to `self: T` or `self: &T` in the outer type. An example warning might be:
313+
314+
```
315+
warning[W0666]: ambiguous function call
316+
--> src/main.rs:13:4
317+
|
318+
13 | orbit_weak.retrograde();
319+
| ^^^^^^^^^^^^
320+
|
321+
= note: you may have intended a call to `Orbit::retrograde` or
322+
to `Weak::retrograde`
323+
= note: this method won't be called
324+
--> src/rc/rc.rs:136:21
325+
|
326+
136 | fn retrograde(&self) {
327+
| ^^^^^^^^^^^^^^^^^
328+
|
329+
= note: because we'll call this method instead
330+
--> src/space/near_earth.rs:357:68
331+
|
332+
357 | fn retrograde(self: Weak<Self>) {
333+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
334+
|
335+
= help: call as a function not a method:
336+
~ Orbit::retrograde(orbit_weak)
337+
= help: call as a function not a method:
338+
~ Weak::retrograde(orbit_weak)
339+
```
315340

316341
# Drawbacks
317342
[drawbacks]: #drawbacks

0 commit comments

Comments
 (0)