11# Generic arguments
2- A ` ty::subst:: GenericArg<'tcx> ` represents some entity in the type system: a type
2+ A ` ty::GenericArg<'tcx> ` represents some entity in the type system: a type
33(` Ty<'tcx> ` ), lifetime (` ty::Region<'tcx> ` ) or constant (` ty::Const<'tcx> ` ).
4- ` GenericArg ` is used to perform substitutions of generic parameters for concrete
4+ ` GenericArg ` is used to perform instantiation of generic parameters to concrete
55arguments, such as when calling a function with generic parameters explicitly
6- with type arguments. Substitutions are represented using the
7- [ ` Subst ` type] ( #subst ) as described below.
6+ with type arguments. Instantiations are represented using the
7+ [ ` GenericArgs ` type] ( #genericargs ) as described below.
88
9- ## ` Subst `
10- ` ty::subst::Subst <'tcx> ` is intuitively simply a slice of ` GenericArg<'tcx> ` s,
11- acting as an ordered list of substitutions from generic parameters to
9+ ## ` GenericArgs `
10+ ` ty::GenericArgs <'tcx> ` is intuitively simply a slice of ` GenericArg<'tcx> ` s,
11+ acting as an ordered list of generic parameters instantiated to
1212concrete arguments (such as types, lifetimes and consts).
1313
1414For example, given a ` HashMap<K, V> ` with two type parameters, ` K ` and ` V ` , an
1515instantiation of the parameters, for example ` HashMap<i32, u32> ` , would be
16- represented by the substitution ` &'tcx [tcx.types.i32, tcx.types.u32] ` .
16+ represented by ` &'tcx [tcx.types.i32, tcx.types.u32] ` .
1717
18- ` Subst ` provides various convenience methods to instantiate substitutions
18+ ` GenericArgs ` provides various convenience methods to instantiate generic arguments
1919given item definitions, which should generally be used rather than explicitly
20- constructing such substitution slices.
20+ instantiating such slices.
2121
2222## ` GenericArg `
2323The actual ` GenericArg ` struct is optimised for space, storing the type, lifetime or
2424const as an interned pointer containing a tag identifying its kind (in the
25- lowest 2 bits). Unless you are working with the ` Subst ` implementation
25+ lowest 2 bits). Unless you are working with the ` GenericArgs ` implementation
2626specifically, you should generally not have to deal with ` GenericArg ` and instead
2727make use of the safe [ ` GenericArgKind ` ] ( #genericargkind ) abstraction.
2828
2929## ` GenericArgKind `
3030As ` GenericArg ` itself is not type-safe, the ` GenericArgKind ` enum provides a more
3131convenient and safe interface for dealing with generic arguments. An
3232` GenericArgKind ` can be converted to a raw ` GenericArg ` using ` GenericArg::from() `
33- (or simply ` .into() ` when the context is clear). As mentioned earlier, substitution
33+ (or simply ` .into() ` when the context is clear). As mentioned earlier, instantiation
3434lists store raw ` GenericArg ` s, so before dealing with them, it is preferable to
3535convert them to ` GenericArgKind ` s first. This is done by calling the ` .unpack() `
3636method.
@@ -44,7 +44,7 @@ fn deal_with_generic_arg<'tcx>(generic_arg: GenericArg<'tcx>) -> GenericArg<'tcx
4444 GenericArgKind::Lifetime(lt) => { /* ... */ }
4545 GenericArgKind::Const(ct) => { /* ... */ }
4646 };
47- // Pack the `GenericArgKind` to store it in a substitution list.
47+ // Pack the `GenericArgKind` to store it in a generic args list.
4848 new_generic_arg.into()
4949}
5050```
0 commit comments