Skip to content

Commit 41ef767

Browse files
committed
Auto merge of #96226 - xldenis:thir-clone, r=oli-obk
Make all thir types implement clone This PR adds `Clone` impl to all of the `Thir<'tcx>` types. I would like to be able to clone a `Thir` body so that I can make a copy in my rustc driver without breaking further compilation. Without this my driver is forced to run in the `after_expansion` callback and thus doesn't benefit from running all the safety checks that `rustc` usually does, instead i need to do them all myself.
2 parents a8272f2 + eed91ee commit 41ef767

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

compiler/rustc_middle/src/thir.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ macro_rules! thir_with_elements {
6666
/// A container for a THIR body.
6767
///
6868
/// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
69-
#[derive(Debug, HashStable)]
69+
#[derive(Debug, HashStable, Clone)]
7070
pub struct Thir<'tcx> {
7171
$(
7272
pub $name: IndexVec<$id, $value>,
@@ -106,7 +106,7 @@ pub enum LintLevel {
106106
Explicit(hir::HirId),
107107
}
108108

109-
#[derive(Debug, HashStable)]
109+
#[derive(Clone, Debug, HashStable)]
110110
pub struct Block {
111111
/// Whether the block itself has a label. Used by `label: {}`
112112
/// and `try` blocks.
@@ -125,7 +125,7 @@ pub struct Block {
125125
pub safety_mode: BlockSafety,
126126
}
127127

128-
#[derive(Debug, HashStable)]
128+
#[derive(Clone, Debug, HashStable)]
129129
pub struct Adt<'tcx> {
130130
/// The ADT we're constructing.
131131
pub adt_def: AdtDef<'tcx>,
@@ -151,13 +151,13 @@ pub enum BlockSafety {
151151
ExplicitUnsafe(hir::HirId),
152152
}
153153

154-
#[derive(Debug, HashStable)]
154+
#[derive(Clone, Debug, HashStable)]
155155
pub struct Stmt<'tcx> {
156156
pub kind: StmtKind<'tcx>,
157157
pub opt_destruction_scope: Option<region::Scope>,
158158
}
159159

160-
#[derive(Debug, HashStable)]
160+
#[derive(Clone, Debug, HashStable)]
161161
pub enum StmtKind<'tcx> {
162162
/// An expression with a trailing semicolon.
163163
Expr {
@@ -196,7 +196,7 @@ pub enum StmtKind<'tcx> {
196196
rustc_data_structures::static_assert_size!(Expr<'_>, 104);
197197

198198
/// A THIR expression.
199-
#[derive(Debug, HashStable)]
199+
#[derive(Clone, Debug, HashStable)]
200200
pub struct Expr<'tcx> {
201201
/// The type of this expression
202202
pub ty: Ty<'tcx>,
@@ -212,7 +212,7 @@ pub struct Expr<'tcx> {
212212
pub kind: ExprKind<'tcx>,
213213
}
214214

215-
#[derive(Debug, HashStable)]
215+
#[derive(Clone, Debug, HashStable)]
216216
pub enum ExprKind<'tcx> {
217217
/// `Scope`s are used to explicitly mark destruction scopes,
218218
/// and to track the `HirId` of the expressions within the scope.
@@ -461,20 +461,20 @@ impl<'tcx> ExprKind<'tcx> {
461461
/// Represents the association of a field identifier and an expression.
462462
///
463463
/// This is used in struct constructors.
464-
#[derive(Debug, HashStable)]
464+
#[derive(Clone, Debug, HashStable)]
465465
pub struct FieldExpr {
466466
pub name: Field,
467467
pub expr: ExprId,
468468
}
469469

470-
#[derive(Debug, HashStable)]
470+
#[derive(Clone, Debug, HashStable)]
471471
pub struct FruInfo<'tcx> {
472472
pub base: ExprId,
473473
pub field_types: Box<[Ty<'tcx>]>,
474474
}
475475

476476
/// A `match` arm.
477-
#[derive(Debug, HashStable)]
477+
#[derive(Clone, Debug, HashStable)]
478478
pub struct Arm<'tcx> {
479479
pub pattern: Pat<'tcx>,
480480
pub guard: Option<Guard<'tcx>>,
@@ -485,7 +485,7 @@ pub struct Arm<'tcx> {
485485
}
486486

487487
/// A `match` guard.
488-
#[derive(Debug, HashStable)]
488+
#[derive(Clone, Debug, HashStable)]
489489
pub enum Guard<'tcx> {
490490
If(ExprId),
491491
IfLet(Pat<'tcx>, ExprId),
@@ -499,7 +499,7 @@ pub enum LogicalOp {
499499
Or,
500500
}
501501

502-
#[derive(Debug, HashStable)]
502+
#[derive(Clone, Debug, HashStable)]
503503
pub enum InlineAsmOperand<'tcx> {
504504
In {
505505
reg: InlineAsmRegOrRegClass,

0 commit comments

Comments
 (0)