@@ -6,20 +6,20 @@ inference, type checking, and trait solving. Conceptually, during these routines
6
6
that one type is equal to another type and want to swap one out for the other and then swap that out
7
7
for another type and so on until we eventually get some concrete types (or an error).
8
8
9
- In rustc this is done using [ GenericArgsRef ] .
10
- Conceptually, you can think of ` GenericArgsRef ` as a list of types that are to be substituted for
9
+ In rustc this is done using [ GenericArgs ] .
10
+ Conceptually, you can think of ` GenericArgs ` as a list of types that are to be substituted for
11
11
the generic type parameters of the ADT.
12
12
13
- ` GenericArgsRef ` is a type alias of ` &'tcx List<GenericArg<'tcx>> ` (see [ ` List ` rustdocs] [ list ] ).
13
+ ` GenericArgs ` is a type alias of ` &'tcx List<GenericArg<'tcx>> ` (see [ ` List ` rustdocs] [ list ] ).
14
14
[ ` GenericArg ` ] is essentially a space-efficient wrapper around [ ` GenericArgKind ` ] , which is an enum
15
15
indicating what kind of generic the type parameter is (type, lifetime, or const).
16
- Thus, ` GenericArgsRef ` is conceptually like a ` &'tcx [GenericArgKind<'tcx>] ` slice (but it is
16
+ Thus, ` GenericArgs ` is conceptually like a ` &'tcx [GenericArgKind<'tcx>] ` slice (but it is
17
17
actually a ` List ` ).
18
18
19
19
[ list ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.List.html
20
20
[ `GenericArg` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.GenericArg.html
21
21
[ `GenericArgKind` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.GenericArgKind.html
22
- [ GenericArgsRef ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/type.GenericArgsRef .html
22
+ [ GenericArgs ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/type.GenericArgs .html
23
23
24
24
So why do we use this ` List ` type instead of making it really a slice? It has the length "inline",
25
25
so ` &List ` is only 32 bits. As a consequence, it cannot be "subsliced" (that only works if the
@@ -37,10 +37,10 @@ struct MyStruct<T>
37
37
38
38
- There would be an ` AdtDef ` (and corresponding ` DefId ` ) for ` MyStruct ` .
39
39
- There would be a ` TyKind::Param ` (and corresponding ` DefId ` ) for ` T ` (more later).
40
- - There would be a ` GenericArgsRef ` containing the list ` [GenericArgKind::Type(Ty(T))] `
40
+ - There would be a ` GenericArgs ` containing the list ` [GenericArgKind::Type(Ty(T))] `
41
41
- The ` Ty(T) ` here is my shorthand for entire other ` ty::Ty ` that has ` TyKind::Param ` , which we
42
42
mentioned in the previous point.
43
- - This is one ` TyKind::Adt ` containing the ` AdtDef ` of ` MyStruct ` with the ` GenericArgsRef ` above.
43
+ - This is one ` TyKind::Adt ` containing the ` AdtDef ` of ` MyStruct ` with the ` GenericArgs ` above.
44
44
45
45
Finally, we will quickly mention the
46
46
[ ` Generics ` ] ( https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Generics.html ) type. It
@@ -114,7 +114,7 @@ This example has a few different substitutions:
114
114
115
115
Let’s look a bit more closely at that last substitution to see why we use indexes. If we want to
116
116
find the type of ` foo.x ` , we can get generic type of ` x ` , which is ` Vec<Param(0)> ` . Now we can take
117
- the index ` 0 ` and use it to find the right type substitution: looking at ` Foo ` 's ` GenericArgsRef ` ,
117
+ the index ` 0 ` and use it to find the right type substitution: looking at ` Foo ` 's ` GenericArgs ` ,
118
118
we have the list ` [u32, f32] ` , since we want to replace index ` 0 ` , we take the 0-th index of this
119
119
list, which is ` u32 ` . Voila!
120
120
@@ -127,7 +127,7 @@ You may have a couple of followup questions…
127
127
` MyStruct ` : ` Adt(Foo, &[Param(0), Param(1)]) ` .
128
128
129
129
How do we actually do the substitutions? There is a function for that too! You
130
- use [ ` instantiate ` ] to replace a ` GenericArgsRef ` with another list of types.
130
+ use [ ` instantiate ` ] to replace a ` GenericArgs ` with another list of types.
131
131
132
132
[ Here is an example of actually using ` instantiate ` in the compiler] [ instantiatex ] .
133
133
The exact details are not too important, but in this piece of code, we happen to be
0 commit comments