1
Fork 0

Clean up THIR patterns.

`thir::Pat::kind` is a `Box<PatKind>`, which doesn't follow the usual
pattern in AST/HIR/THIR which is that the "kind" enum for a node is
stored inline within the parent struct.

This commit makes the `PatKind` directly inline within the `Pat`. This
requires using `Box<Pat>` in all the types that hold a `Pat.

Ideally, `Pat` would be stored in `Thir` like `Expr` and `Stmt` and
referred to with a `PatId` rather than `Box<Pat>`. But this is hard to
do because lots of `Pat`s get created after the destruction of the `Cx`
that does normal THIR building. But this does get us a step closer to
`PatId`, because all the `Box<Pat>` occurrences would be replaced with
`PatId` if `PatId` ever happened.

At 128 bytes, `Pat` is large. Subsequent commits will shrink it.
This commit is contained in:
Nicholas Nethercote 2022-08-25 12:25:44 +10:00
parent 9af618b62e
commit 053874eecc
15 changed files with 123 additions and 121 deletions

View file

@ -1015,7 +1015,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let original_source_scope = self.source_scope;
let span = pattern.span;
self.set_correct_source_scope_for_arg(arg.hir_id, original_source_scope, span);
match *pattern.kind {
match pattern.kind {
// Don't introduce extra copies for simple bindings
PatKind::Binding {
mutability,
@ -1052,7 +1052,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Some((Some(&place), span)),
);
let place_builder = PlaceBuilder::from(local);
unpack!(block = self.place_into_pattern(block, pattern, place_builder, false));
unpack!(block = self.place_into_pattern(block, *pattern, place_builder, false));
}
}
self.source_scope = original_source_scope;