about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorBoxy <supbscripter@gmail.com>2024-05-27 21:57:35 +0100
committerBoxy <supbscripter@gmail.com>2024-05-31 01:27:28 +0100
commitde61e2c1e610986ec109623c3dfdf5a14dbcbe69 (patch)
treefab454a75271590f02517e8ff2d897acc599b378 /src/doc
parent2b77e6a1015a350925784dc216d163ed14555ba8 (diff)
downloadrust-de61e2c1e610986ec109623c3dfdf5a14dbcbe69.tar.gz
rust-de61e2c1e610986ec109623c3dfdf5a14dbcbe69.zip
Introduce chapter for defining generic parameters
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/rustc-dev-guide/src/SUMMARY.md7
-rw-r--r--src/doc/rustc-dev-guide/src/generic_parameters_summary.md7
-rw-r--r--src/doc/rustc-dev-guide/src/what_is_ty_generics.md18
3 files changed, 30 insertions, 2 deletions
diff --git a/src/doc/rustc-dev-guide/src/SUMMARY.md b/src/doc/rustc-dev-guide/src/SUMMARY.md
index f78e54dcd9e..a2d287e6bcb 100644
--- a/src/doc/rustc-dev-guide/src/SUMMARY.md
+++ b/src/doc/rustc-dev-guide/src/SUMMARY.md
@@ -114,8 +114,11 @@
 # Analysis
 
 - [Prologue](./part-4-intro.md)
-- [The `ty` module: representing types](./ty.md)
-    - [Generics and substitutions](./generics.md)
+- [Generic parameter definitions](./generic_parameters_summary.md)
+    - [What is `ty::Generics`](./what_is_ty_generics.md)
+    - [Early vs Late bound parameters](./early-late-bound-params/early-late-bound-summary.md)
+        - [Implementation nuances of early/late bound parameters](./early-late-bound-params/early-late-bound-implementation-nuances.md)
+        - [Interactions with turbofishing](./early-late-bound-params/turbofishing-and-early-late-bound.md)
     - [`TypeFolder` and `TypeFoldable`](./ty-fold.md)
     - [Generic arguments](./generic_arguments.md)
     - [Constants in the type system](./constants.md)
diff --git a/src/doc/rustc-dev-guide/src/generic_parameters_summary.md b/src/doc/rustc-dev-guide/src/generic_parameters_summary.md
new file mode 100644
index 00000000000..ee2b3b8934e
--- /dev/null
+++ b/src/doc/rustc-dev-guide/src/generic_parameters_summary.md
@@ -0,0 +1,7 @@
+# Generic parameter definitions
+
+This chapter will discuss how rustc tracks what generic parameters are introduced by an item. For example given some struct defined via `struct Foo<T>` how does rustc track that `Foo` defines some type parameter `T` and nothing else?
+
+This will *not* cover how we track generic parameters introduced via `for<'a>` syntax (i.e. in where clauses or `fn` types), which is covered elsewhere in the [chapter on `Binder`s ][ch_binders].
+
+[ch_binders]: ./ty_module/binders.md
\ No newline at end of file
diff --git a/src/doc/rustc-dev-guide/src/what_is_ty_generics.md b/src/doc/rustc-dev-guide/src/what_is_ty_generics.md
new file mode 100644
index 00000000000..c3cf7d1c4fa
--- /dev/null
+++ b/src/doc/rustc-dev-guide/src/what_is_ty_generics.md
@@ -0,0 +1,18 @@
+# What is `ty::Generics`
+
+The generic parameters introduced by an item are tracked the [`ty::Generics`] struct. Sometimes items allows usage of generics of parent items inside of them, this is accomplished via the `ty::Generics` struct having an optional field to specify a parent item to inherit generic parameters of. For example given the following code:
+
+```rust,ignore
+trait Trait<T> {
+    fn foo<U>(&self);
+}
+```
+
+The `ty::Generics` used for `foo` would contain `[U]` and a parent of `Some(Trait)`. `Trait` would have a `ty::Generics` containing `[Self, T]` with a parent of `None`.
+
+The [`GenericParamDef`] struct is used to represent each individual generic parameter in a `ty::Generics` listing. The `GenericParamDef` struct contains information about the generic parameter, for example its name, defid, what kind of parameter it is (i.e. type, const, lifetime). It also contains a `u32` index representing what position the parameter is (starting from the outtermost parent).
+
+Interestingly, `ty::Generics` does not currently contain _every_ generic parameter defined on an item. In the case of functions it only contains the _early bound_ lifetime parameters. See the next chapter for information on what "early bound" and "late bound" parameters are.
+
+[`ty::Generics`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Generics.html
+[`GenericParamDef`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/generics/struct.GenericParamDef.html
\ No newline at end of file