From 0a6d73b203e93f12c6513e64c75668eb48cffe57 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 20 Aug 2023 15:29:31 +0800 Subject: [PATCH 1/2] Update outdated doc for types --- src/ty.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ty.md b/src/ty.md index 4a6cdb7c7..afebb30fc 100644 --- a/src/ty.md +++ b/src/ty.md @@ -74,9 +74,9 @@ HIR is built, some basic type inference and type checking is done. During the ty figure out what the `ty::Ty` of everything is and we also check if the type of something is ambiguous. The `ty::Ty` is then used for type checking while making sure everything has the expected type. The [`astconv` module][astconv] is where the code responsible for converting a -`rustc_hir::Ty` into a `ty::Ty` is located. This occurs during the type-checking phase, -but also in other parts of the compiler that want to ask questions like "what argument types does -this function expect?" +`rustc_hir::Ty` into a `ty::Ty` is located. The main routine used is `ast_ty_to_ty`. This occurs +during the type-checking phase, but also in other parts of the compiler that want to ask +questions like "what argument types does this function expect?" [astconv]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/astconv/index.html @@ -137,11 +137,13 @@ benefits of interning. ## Allocating and working with types -To allocate a new type, you can use the various `mk_` methods defined on the `tcx`. These have names +To allocate a new type, you can use the various `new_*` methods defined on +[`Ty`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html). +These have names that correspond mostly to the various kinds of types. For example: ```rust,ignore -let array_ty = tcx.mk_array(elem_ty, len * 2); +let array_ty = Ty::new_array_with_const_len(tcx, ty, count) ``` These methods all return a `Ty<'tcx>` – note that the lifetime you get back is the lifetime of the From ad298e47eafb8af8dd49bbb9115c032856709493 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 20 Aug 2023 00:39:38 -0700 Subject: [PATCH 2/2] Update src/ty.md --- src/ty.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ty.md b/src/ty.md index afebb30fc..624fa4211 100644 --- a/src/ty.md +++ b/src/ty.md @@ -143,7 +143,7 @@ These have names that correspond mostly to the various kinds of types. For example: ```rust,ignore -let array_ty = Ty::new_array_with_const_len(tcx, ty, count) +let array_ty = Ty::new_array_with_const_len(tcx, ty, count); ``` These methods all return a `Ty<'tcx>` – note that the lifetime you get back is the lifetime of the