Skip to content

Commit c4673dc

Browse files
committed
improve hir/lowering.md
1 parent f133cf2 commit c4673dc

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/hir/lowering.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The AST lowering step converts AST to [HIR](../hir.md).
44
This means many structures are removed if they are irrelevant
5-
for type analysis or similar syntax agnostic analyses.
5+
for type analysis or similar syntax-agnostic analyses.
66
Examples of such structures include but are not limited to
77

88
* Parenthesis
@@ -40,21 +40,21 @@ Lowering needs to uphold several invariants in order to not trigger the
4040
sanity checks in [`compiler/rustc_passes/src/hir_id_validator.rs`][hir_id_validator]:
4141

4242
1. A `HirId` must be used if created.
43-
So if you use the `lower_node_id`,
44-
you *must* use the resulting `NodeId` or `HirId` (either is fine, since
45-
any `NodeId`s in the `HIR` are checked for existing `HirId`s)
43+
So, if you use the `lower_node_id`,
44+
you *must* use the resulting `NodeId` or `HirId` (either is fine, since
45+
any `NodeId`s in the `HIR` are checked for existing `HirId`s).
4646
2. Lowering a `HirId` must be done in the scope of the *owning* item.
47-
This means you need to use `with_hir_id_owner` if you are creating parts
48-
of an item other than the one being currently lowered.
49-
This happens for example during the lowering of existential `impl Trait`
47+
This means you need to use `with_hir_id_owner` if you are creating parts
48+
of an item other than the one being currently lowered.
49+
This happens, for example, during the lowering of existential `impl Trait`.
5050
3. A `NodeId` that will be placed into a HIR structure must be lowered,
51-
even if its `HirId` is unused.
52-
Calling `let _ = self.lower_node_id(node_id);` is perfectly legitimate.
51+
even if its `HirId` is unused.
52+
Calling `let _ = self.lower_node_id(node_id);` is perfectly legitimate.
5353
4. If you are creating new nodes that didn't exist in the `AST`, you *must*
54-
create new ids for them.
55-
This is done by calling the `next_id` method,
56-
which produces both a new `NodeId` as well as automatically lowering it
57-
for you so you also get the `HirId`.
54+
create new ids for them.
55+
This is done by calling the `next_id` method,
56+
which produces both a new `NodeId` as well as automatically lowering it
57+
for you so you also get the `HirId`.
5858

5959
[`rustc_ast_lowering`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_lowering/index.html
6060
[`lower_to_hir`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_lowering/fn.lower_to_hir.html
@@ -74,7 +74,7 @@ the advantage of creating a way to find the `DefId` of something via its
7474
If lowering needs this `DefId` in multiple places, you can't
7575
generate a new `NodeId` in all those places because you'd also get a new
7676
`DefId` then.
77-
With a `NodeId` from the `AST` this is not an issue.
77+
With a `NodeId` from the `AST`, this is not an issue.
7878

7979
Having the `NodeId` also allows the `DefCollector` to generate the `DefId`s
8080
instead of lowering having to do it on the fly.

0 commit comments

Comments
 (0)