@@ -19,7 +19,7 @@ use rustc_hir as hir;
19
19
use rustc_hir:: def_id:: DefId ;
20
20
use rustc_hir:: { BindingMode , ByRef , HirId , MatchSource , RangeEnd } ;
21
21
use rustc_index:: { IndexVec , newtype_index} ;
22
- use rustc_macros:: { HashStable , TypeVisitable } ;
22
+ use rustc_macros:: { HashStable , TyDecodable , TyEncodable , TypeVisitable } ;
23
23
use rustc_span:: def_id:: LocalDefId ;
24
24
use rustc_span:: { ErrorGuaranteed , Span , Symbol } ;
25
25
use rustc_target:: asm:: InlineAsmRegOrRegClass ;
@@ -49,10 +49,13 @@ macro_rules! thir_with_elements {
49
49
}
50
50
) *
51
51
52
+ // Note: Making `Thir` implement `Clone` is useful for external tools that need access to
53
+ // THIR bodies even after the `Steal` query result has been stolen.
54
+ // One such tool is https://github.com/rust-corpus/qrates/.
52
55
/// A container for a THIR body.
53
56
///
54
57
/// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
55
- #[ derive( Debug , HashStable ) ]
58
+ #[ derive( Debug , HashStable , Clone ) ]
56
59
pub struct Thir <' tcx> {
57
60
pub body_type: BodyTy <' tcx>,
58
61
$(
@@ -90,15 +93,15 @@ thir_with_elements! {
90
93
params: ParamId => Param <' tcx> => "p{}" ,
91
94
}
92
95
93
- #[ derive( Debug , HashStable ) ]
96
+ #[ derive( Debug , HashStable , Clone ) ]
94
97
pub enum BodyTy < ' tcx > {
95
98
Const ( Ty < ' tcx > ) ,
96
99
Fn ( FnSig < ' tcx > ) ,
97
100
GlobalAsm ( Ty < ' tcx > ) ,
98
101
}
99
102
100
103
/// Description of a type-checked function parameter.
101
- #[ derive( Debug , HashStable ) ]
104
+ #[ derive( Clone , Debug , HashStable ) ]
102
105
pub struct Param < ' tcx > {
103
106
/// The pattern that appears in the parameter list, or None for implicit parameters.
104
107
pub pat : Option < Box < Pat < ' tcx > > > ,
@@ -118,7 +121,7 @@ pub enum LintLevel {
118
121
Explicit ( HirId ) ,
119
122
}
120
123
121
- #[ derive( Debug , HashStable ) ]
124
+ #[ derive( Clone , Debug , HashStable ) ]
122
125
pub struct Block {
123
126
/// Whether the block itself has a label. Used by `label: {}`
124
127
/// and `try` blocks.
@@ -138,7 +141,7 @@ pub struct Block {
138
141
139
142
type UserTy < ' tcx > = Option < Box < CanonicalUserType < ' tcx > > > ;
140
143
141
- #[ derive( Debug , HashStable ) ]
144
+ #[ derive( Clone , Debug , HashStable ) ]
142
145
pub struct AdtExpr < ' tcx > {
143
146
/// The ADT we're constructing.
144
147
pub adt_def : AdtDef < ' tcx > ,
@@ -155,7 +158,7 @@ pub struct AdtExpr<'tcx> {
155
158
pub base : AdtExprBase < ' tcx > ,
156
159
}
157
160
158
- #[ derive( Debug , HashStable ) ]
161
+ #[ derive( Clone , Debug , HashStable ) ]
159
162
pub enum AdtExprBase < ' tcx > {
160
163
/// A struct expression where all the fields are explicitly enumerated: `Foo { a, b }`.
161
164
None ,
@@ -168,7 +171,7 @@ pub enum AdtExprBase<'tcx> {
168
171
DefaultFields ( Box < [ Ty < ' tcx > ] > ) ,
169
172
}
170
173
171
- #[ derive( Debug , HashStable ) ]
174
+ #[ derive( Clone , Debug , HashStable ) ]
172
175
pub struct ClosureExpr < ' tcx > {
173
176
pub closure_id : LocalDefId ,
174
177
pub args : UpvarArgs < ' tcx > ,
@@ -177,7 +180,7 @@ pub struct ClosureExpr<'tcx> {
177
180
pub fake_reads : Vec < ( ExprId , FakeReadCause , HirId ) > ,
178
181
}
179
182
180
- #[ derive( Debug , HashStable ) ]
183
+ #[ derive( Clone , Debug , HashStable ) ]
181
184
pub struct InlineAsmExpr < ' tcx > {
182
185
pub asm_macro : AsmMacro ,
183
186
pub template : & ' tcx [ InlineAsmTemplatePiece ] ,
@@ -195,12 +198,12 @@ pub enum BlockSafety {
195
198
ExplicitUnsafe ( HirId ) ,
196
199
}
197
200
198
- #[ derive( Debug , HashStable ) ]
201
+ #[ derive( Clone , Debug , HashStable ) ]
199
202
pub struct Stmt < ' tcx > {
200
203
pub kind : StmtKind < ' tcx > ,
201
204
}
202
205
203
- #[ derive( Debug , HashStable ) ]
206
+ #[ derive( Clone , Debug , HashStable ) ]
204
207
pub enum StmtKind < ' tcx > {
205
208
/// An expression with a trailing semicolon.
206
209
Expr {
@@ -240,11 +243,11 @@ pub enum StmtKind<'tcx> {
240
243
} ,
241
244
}
242
245
243
- #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , HashStable ) ]
246
+ #[ derive( Clone , Debug , Copy , PartialEq , Eq , Hash , HashStable , TyEncodable , TyDecodable ) ]
244
247
pub struct LocalVarId ( pub HirId ) ;
245
248
246
249
/// A THIR expression.
247
- #[ derive( Debug , HashStable ) ]
250
+ #[ derive( Clone , Debug , HashStable ) ]
248
251
pub struct Expr < ' tcx > {
249
252
/// kind of expression
250
253
pub kind : ExprKind < ' tcx > ,
@@ -271,7 +274,7 @@ pub struct TempLifetime {
271
274
pub backwards_incompatible : Option < region:: Scope > ,
272
275
}
273
276
274
- #[ derive( Debug , HashStable ) ]
277
+ #[ derive( Clone , Debug , HashStable ) ]
275
278
pub enum ExprKind < ' tcx > {
276
279
/// `Scope`s are used to explicitly mark destruction scopes,
277
280
/// and to track the `HirId` of the expressions within the scope.
@@ -548,20 +551,20 @@ pub enum ExprKind<'tcx> {
548
551
/// Represents the association of a field identifier and an expression.
549
552
///
550
553
/// This is used in struct constructors.
551
- #[ derive( Debug , HashStable ) ]
554
+ #[ derive( Clone , Debug , HashStable ) ]
552
555
pub struct FieldExpr {
553
556
pub name : FieldIdx ,
554
557
pub expr : ExprId ,
555
558
}
556
559
557
- #[ derive( Debug , HashStable ) ]
560
+ #[ derive( Clone , Debug , HashStable ) ]
558
561
pub struct FruInfo < ' tcx > {
559
562
pub base : ExprId ,
560
563
pub field_types : Box < [ Ty < ' tcx > ] > ,
561
564
}
562
565
563
566
/// A `match` arm.
564
- #[ derive( Debug , HashStable ) ]
567
+ #[ derive( Clone , Debug , HashStable ) ]
565
568
pub struct Arm < ' tcx > {
566
569
pub pattern : Box < Pat < ' tcx > > ,
567
570
pub guard : Option < ExprId > ,
@@ -579,7 +582,7 @@ pub enum LogicalOp {
579
582
Or ,
580
583
}
581
584
582
- #[ derive( Debug , HashStable ) ]
585
+ #[ derive( Clone , Debug , HashStable ) ]
583
586
pub enum InlineAsmOperand < ' tcx > {
584
587
In {
585
588
reg : InlineAsmRegOrRegClass ,
@@ -616,13 +619,13 @@ pub enum InlineAsmOperand<'tcx> {
616
619
} ,
617
620
}
618
621
619
- #[ derive( Debug , HashStable , TypeVisitable ) ]
622
+ #[ derive( Clone , Debug , HashStable , TypeVisitable ) ]
620
623
pub struct FieldPat < ' tcx > {
621
624
pub field : FieldIdx ,
622
625
pub pattern : Pat < ' tcx > ,
623
626
}
624
627
625
- #[ derive( Debug , HashStable , TypeVisitable ) ]
628
+ #[ derive( Clone , Debug , HashStable , TypeVisitable ) ]
626
629
pub struct Pat < ' tcx > {
627
630
pub ty : Ty < ' tcx > ,
628
631
pub span : Span ,
@@ -729,7 +732,7 @@ impl<'tcx> Pat<'tcx> {
729
732
}
730
733
}
731
734
732
- #[ derive( Debug , HashStable , TypeVisitable ) ]
735
+ #[ derive( Clone , Debug , HashStable , TypeVisitable ) ]
733
736
pub struct Ascription < ' tcx > {
734
737
pub annotation : CanonicalUserTypeAnnotation < ' tcx > ,
735
738
/// Variance to use when relating the `user_ty` to the **type of the value being
@@ -753,7 +756,7 @@ pub struct Ascription<'tcx> {
753
756
pub variance : ty:: Variance ,
754
757
}
755
758
756
- #[ derive( Debug , HashStable , TypeVisitable ) ]
759
+ #[ derive( Clone , Debug , HashStable , TypeVisitable ) ]
757
760
pub enum PatKind < ' tcx > {
758
761
/// A wildcard pattern: `_`.
759
762
Wild ,
0 commit comments