diff --git a/src/generics.md b/src/generics.md index c9c75f243..2badc1136 100644 --- a/src/generics.md +++ b/src/generics.md @@ -127,9 +127,7 @@ You may have a couple of followup questions… `MyStruct`: `Adt(Foo, &[Param(0), Param(1)])`. **`instantiate`** How do we actually do the substitutions? There is a function for that too! You -use [`instantiate`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/ -generic_args/struct.EarlyBinder.html#method.instantiate) to replace a `GenericArgsRef` with -another list of types. +use [`instantiate`] to replace a `GenericArgsRef` with another list of types. [Here is an example of actually using `instantiate` in the compiler][instantiatex]. The exact details are not too important, but in this piece of code, we happen to be @@ -137,6 +135,7 @@ converting from the `rustc_hir::Ty` to a real `ty::Ty`. You can see that we firs (`args`). Then we call `type_of` to get a type and call `ty.instantiate(tcx, args)` to get a new version of `ty` with the args made. +[`instantiate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/generic_args/struct.EarlyBinder.html#method.instantiate [instantiatex]: https://github.com/rust-lang/rust/blob/8a562f9671e36cf29c9c794c2646bcf252d55535/compiler/rustc_hir_analysis/src/astconv/mod.rs#L905-L927 **Note on indices:** It is possible for the indices in `Param` to not match with what we expect. For