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
Be more consistent about using "argument" to mean a concrete value
provided by a function caller, and "parameter" to mean the abstract
input to the function.
Retain a few instances of the phrasing "in argument position",
because it appears in the RFCs and implementation. Also make a note
about the historical terminology inconsistency.
Copy file name to clipboardExpand all lines: src/types/impl-trait.md
+5-4Lines changed: 5 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -24,8 +24,9 @@ fn bar() -> impl Trait {
24
24
## Anonymous type parameters
25
25
26
26
> Note: This is often called "impl Trait in argument position".
27
+
(The term "parameter" is more correct here, but "impl Trait in argument position" is the phrasing used during the development of this feature, and it remains in parts of the implementation.)
27
28
28
-
Functions can use `impl` followed by a set of trait bounds to declare an argument as having an anonymous type.
29
+
Functions can use `impl` followed by a set of trait bounds to declare a parameter as having an anonymous type.
29
30
The caller must provide a type that satisfies the bounds declared by the anonymous type parameter, and the function can only use the methods available through the trait bounds of the anonymous type parameter.
30
31
31
32
For example, these two forms are almost equivalent:
@@ -45,9 +46,9 @@ fn foo(arg: impl Trait) {
45
46
That is, `impl Trait` in argument position is syntactic sugar for a generic type parameter like `<T: Trait>`, except that the type is anonymous and doesn't appear in the [_GenericParams_] list.
46
47
47
48
> **Note:**
48
-
> For function arguments, generic type parameters and `impl Trait` are not exactly equivalent.
49
+
> For function parameters, generic type parameters and `impl Trait` are not exactly equivalent.
49
50
> With a generic parameter such as `<T: Trait>`, the caller has the option to explicitly specify the generic argument for `T` at the call site using [_GenericArgs_], for example, `foo::<usize>(1)`.
50
-
> If `impl Trait` is the type of *any* function argument, then the caller can't ever provide any generic arguments when calling that function.
51
+
> If `impl Trait` is the type of *any* function parameter, then the caller can't ever provide any generic arguments when calling that function.
51
52
This includes generic arguments for the return type or any const generics.
52
53
>
53
54
> Therefore, changing the function signature from either one to the other can constitute a breaking change for the callers of a function.
@@ -112,7 +113,7 @@ Instead, the function chooses the return type, but only promises that it will im
112
113
113
114
## Limitations
114
115
115
-
`impl Trait` can only appear as the argument or return type of a free or inherent function.
116
+
`impl Trait` can only appear as a parameter or return type of a free or inherent function.
116
117
It cannot appear inside implementations of traits, nor can it be the type of a let binding or appear inside a type alias.
0 commit comments