Skip to content

Commit 8b10f6b

Browse files
committed
Add "hir::Ty and ty::Ty" section
1 parent 90e6ddc commit 8b10f6b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

book/src/development/type_checking.md

+15
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ impl LateLintPass<'_> for MyStructLint {
102102
}
103103
```
104104

105+
## `hir::Ty` and `ty::Ty`
106+
107+
We've been talking about [`ty::Ty`][middle_ty] this whole time without addressing [`hir::Ty`][hir_ty], but the latter is also important to understand.
108+
109+
`hir::Ty` would represent *what* an user wrote, while `ty::Ty` would understand the meaning of it (because it has more information).
110+
111+
**Example: `fn foo(x: u32) -> u32 { x }`**
112+
113+
Here the HIR sees the types without "thinking" about them, it knows that the function takes an `u32` and returns an `u32`. But at the `ty::Ty` level the compiler understands that they're the same type, in-depth lifetimes, etc...
114+
115+
you can use the [`hir_ty_to_ty`][hir_ty_to_ty] function to convert from a `hir::Ty` to a `ty::Ty`
116+
105117
## Useful Links
106118

107119
Below are some useful links to further explore the concepts covered
@@ -124,3 +136,6 @@ in this chapter:
124136
[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html
125137
[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html
126138
[TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html
139+
[middle_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/ty/struct.Ty.html
140+
[hir_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/struct.Ty.html
141+
[hir_ty_to_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir_analysis/fn.hir_ty_to_ty.html

0 commit comments

Comments
 (0)