Skip to content

Commit 3dafa09

Browse files
committed
Small tweaks
1 parent 5d808a5 commit 3dafa09

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/ty.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ The `ty` module defines how the Rust compiler represents types internally. It al
1010
When we talk about how rustc represents types, we usually refer to a type called `Ty` . There are
1111
quite a few modules and types for `Ty` in the compiler ([Ty documentation][ty]).
1212

13-
[ty]: https://doc.rust-lang.org/nightly/nightly-rustc/ru
14-
]stc_middle/ty/index.html
13+
[ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/index.html
1514

1615
The specific `Ty` we are referring to is [`rustc_middle::ty::Ty`][ty_ty] (and not
1716
[`rustc_hir::Ty`][hir_ty]). The distinction is important, so we will discuss it first before going

src/ty_module/generic_arguments.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ADTs and Generic Arguments
22

3+
The term `ADT` stands for "Algebraic data type", in rust this refers to a struct, enum, or union.
4+
35
## ADTs Representation
46

57
Let's consider the example of a type like `MyStruct<u32>`, where `MyStruct` is defined like so:
@@ -123,4 +125,4 @@ For the `MyStruct<U>` written in the `Foo` type alias, we would represent it in
123125

124126
- There would be an `AdtDef` (and corresponding `DefId`) for `MyStruct`.
125127
- There would be a `GenericArgs` containing the list `[GenericArgKind::Type(Ty(u32))]`
126-
- This is one `TyKind::Adt` containing the `AdtDef` of `MyStruct` with the `GenericArgs` above.
128+
- And finally a `TyKind::Adt` with the `AdtDef` and `GenericArgs` listed above.

src/what_is_ty_generics.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ trait Trait<T> {
1010

1111
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`.
1212

13-
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).
13+
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).
14+
15+
`GenericParamDef` also contains a `u32` index representing what position the parameter is (starting from the outermost parent), this is the value used to represent usages of generic parameters (more on this in the [chapter on representing types][ch_representing_types]).
1416

1517
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.
1618

19+
[ch_representing_types]: ./ty.md
1720
[`ty::Generics`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Generics.html
1821
[`GenericParamDef`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/generics/struct.GenericParamDef.html

0 commit comments

Comments
 (0)