You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What this RFC had referred to as "name resolution" is actually method
selection, as pointed out by compiler-errors, so let's fix this
everywhere.
In doing this, we remove one of the purported drawbacks of RFC 2845,
as it makes less sense as stated after this fix.
Copy file name to clipboardExpand all lines: text/3624-supertrait-item-shadowing-v2.md
+5-8Lines changed: 5 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
# Summary
7
7
[summary]: #summary
8
8
9
-
When name resolution encounters an ambiguity between two trait methods when both traits are in scope, if one trait is a subtrait of the other then select that method instead of reporting an ambiguity error.
9
+
When method selection encounters an ambiguity between two trait methods when both traits are in scope, if one trait is a subtrait of the other then select that method instead of reporting an ambiguity error.
10
10
11
11
# Motivation
12
12
[motivation]: #motivation
@@ -40,7 +40,7 @@ Attempts to stabilize `intersperse` have failed with a large number of regressio
40
40
# Proposed solution
41
41
[proposed-solution]: #proposed-solution
42
42
43
-
This RFC proposes to change name resolution to resolve the ambiguity in the following specific circumstances:
43
+
This RFC proposes to change method selection to resolve the ambiguity in the following specific circumstances:
44
44
45
45
- All method candidates are trait methods (inherent methods are already prioritized over trait methods).
46
46
- One trait is transitively a subtrait of all other traits in the candidate list.
@@ -63,9 +63,9 @@ If we choose not to accept this RFC then there doesn't seem to be a reasonable p
63
63
64
64
## Only doing this for specific traits
65
65
66
-
One possible alternative to a general change to the name resolution rules would be to only do so on a case-by-case basis for specific methods in standard library traits. This could be done by using a perma-unstable `#[shadowable]` attribute specifically on methods like `Iterator::intersperse`.
66
+
One possible alternative to a general change to the method selection rules would be to only do so on a case-by-case basis for specific methods in standard library traits. This could be done by using a perma-unstable `#[shadowable]` attribute specifically on methods like `Iterator::intersperse`.
67
67
68
-
There are both advantages and inconveniences to this approach. While it allows most Rust users to avoid having to think about this issue for most traits, it does make the `Iterator` trait more "magical" in that it doesn't follow the same rules as the rest of the language. Having a consistent rule for how name resolution works is easier to teach people.
68
+
There are both advantages and inconveniences to this approach. While it allows most Rust users to avoid having to think about this issue for most traits, it does make the `Iterator` trait more "magical" in that it doesn't follow the same rules as the rest of the language. Having a consistent rule for how method selection works is easier to teach people.
69
69
70
70
## Preferring the supertrait method instead
71
71
@@ -118,10 +118,7 @@ Resolving in favor of `a` is a breaking change; resolving in favor of `b` is not
118
118
119
119
### RFC 2845
120
120
121
-
RFC 2845 was a previous attempt to address this problem, but it has several drawbacks:
122
-
123
-
- It doesn't fully address the problem since it only changes name resolution when trait methods are resolved due to generic bounds. In practice, most of the ambiguity from stabilizing `intersperse` comes from non-generic code.
124
-
- It adds a lot of complexity because name resolution depends on the specific trait bounds that have been brought into scope.
121
+
RFC 2845 was a previous attempt, but it did not fully address the problem since it only changes method selection when trait methods are resolved due to generic bounds. In practice, most of the ambiguity from stabilizing `intersperse` comes from non-generic code.
0 commit comments