Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 5a9a6c1

Browse files
authored
Create hir-place-target.md
1 parent 1e300d1 commit 5a9a6c1

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

hir-place-target.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
We are going to be refactoring [HIR places] to capture sufficient detail for us to use them to describe the places that a closure captures.
2+
3+
The expected target structure looks something like this:
4+
5+
```rust
6+
/// A reference to a particular place that appears in the source code
7+
struct PlaceReference<'tcx> {
8+
/// the place being referenced
9+
place: Place<'tcx>,
10+
11+
/// hir-id of source expression or pattern
12+
hir_id: HirId,
13+
14+
// Maybe no Span, since they're being removed from the Hir
15+
}
16+
17+
/// An expression that refers to some place in memory, similar
18+
/// to MIR places
19+
struct Place<'tcx> {
20+
/// start of the place expression, typically a local variable
21+
base: PlaceBase,
22+
23+
/// projections select parts of the base expression; e.g.,
24+
/// in the place expression `a.b.c`, `b` and `c` are projections
25+
projections: Vec<Projection<'tcx>>,
26+
}
27+
28+
/// *Projections* select parts of the base expression; e.g.,
29+
/// in the place expression `a.b.c`, `b` and `c` are projections
30+
struct Projection<'tcx> {
31+
/// Type of the projection thus far.
32+
ty: Ty<'tcx>,
33+
34+
///
35+
kind: ProjectionKind,
36+
}
37+
38+
/// Kinds of projections
39+
enum ProjectionKind {
40+
/// `*B`, where `B` is the base expression
41+
Deref,
42+
43+
/// `B.F` where `B` is the base expression and `F` is
44+
/// the field. The field is identified by which variant
45+
/// it appears in along with a field index. The variant
46+
/// is used for enums.
47+
Field(Field, VariantIdx),
48+
49+
/// Some index like `B[x]`, where `B` is the base
50+
/// expression. We don't preserve the index `x` because
51+
/// we won't need it.
52+
Index,
53+
54+
/// A subslice covering a range of values like `B[x..y]`.
55+
Subslice,
56+
}
57+
```

0 commit comments

Comments
 (0)