Skip to content

Commit d8f059b

Browse files
committed
Make AST nodes Clone-able
1 parent 4be533a commit d8f059b

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

compiler/ast/asdl_rs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def visitSum(self, sum, name, depth):
190190
self.sum_with_constructors(sum, name, depth)
191191

192192
def emit_attrs(self, depth):
193-
self.emit("#[derive(Debug, PartialEq)]", depth)
193+
self.emit("#[derive(Clone, Debug, PartialEq)]", depth)
194194

195195
def simple_sum(self, sum, name, depth):
196196
rustname = get_rust_type(name)

compiler/ast/src/ast_gen.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use crate::Location;
77

88
type Ident = String;
99

10-
#[derive(Debug, PartialEq)]
10+
#[derive(Clone, Debug, PartialEq)]
1111
pub struct Located<T, U = ()> {
1212
pub location: Location,
1313
pub custom: U,
@@ -24,7 +24,7 @@ impl<T> Located<T> {
2424
}
2525
}
2626

27-
#[derive(Debug, PartialEq)]
27+
#[derive(Clone, Debug, PartialEq)]
2828
pub enum Mod<U = ()> {
2929
Module {
3030
body: Vec<Stmt<U>>,
@@ -42,7 +42,7 @@ pub enum Mod<U = ()> {
4242
},
4343
}
4444

45-
#[derive(Debug, PartialEq)]
45+
#[derive(Clone, Debug, PartialEq)]
4646
pub enum StmtKind<U = ()> {
4747
FunctionDef {
4848
name: Ident,
@@ -164,7 +164,7 @@ pub enum StmtKind<U = ()> {
164164
}
165165
pub type Stmt<U = ()> = Located<StmtKind<U>, U>;
166166

167-
#[derive(Debug, PartialEq)]
167+
#[derive(Clone, Debug, PartialEq)]
168168
pub enum ExprKind<U = ()> {
169169
BoolOp {
170170
op: Boolop,
@@ -281,20 +281,20 @@ pub enum ExprKind<U = ()> {
281281
}
282282
pub type Expr<U = ()> = Located<ExprKind<U>, U>;
283283

284-
#[derive(Debug, PartialEq)]
284+
#[derive(Clone, Debug, PartialEq)]
285285
pub enum ExprContext {
286286
Load,
287287
Store,
288288
Del,
289289
}
290290

291-
#[derive(Debug, PartialEq)]
291+
#[derive(Clone, Debug, PartialEq)]
292292
pub enum Boolop {
293293
And,
294294
Or,
295295
}
296296

297-
#[derive(Debug, PartialEq)]
297+
#[derive(Clone, Debug, PartialEq)]
298298
pub enum Operator {
299299
Add,
300300
Sub,
@@ -311,15 +311,15 @@ pub enum Operator {
311311
FloorDiv,
312312
}
313313

314-
#[derive(Debug, PartialEq)]
314+
#[derive(Clone, Debug, PartialEq)]
315315
pub enum Unaryop {
316316
Invert,
317317
Not,
318318
UAdd,
319319
USub,
320320
}
321321

322-
#[derive(Debug, PartialEq)]
322+
#[derive(Clone, Debug, PartialEq)]
323323
pub enum Cmpop {
324324
Eq,
325325
NotEq,
@@ -333,15 +333,15 @@ pub enum Cmpop {
333333
NotIn,
334334
}
335335

336-
#[derive(Debug, PartialEq)]
336+
#[derive(Clone, Debug, PartialEq)]
337337
pub struct Comprehension<U = ()> {
338338
pub target: Box<Expr<U>>,
339339
pub iter: Box<Expr<U>>,
340340
pub ifs: Vec<Expr<U>>,
341341
pub is_async: usize,
342342
}
343343

344-
#[derive(Debug, PartialEq)]
344+
#[derive(Clone, Debug, PartialEq)]
345345
pub enum ExcepthandlerKind<U = ()> {
346346
ExceptHandler {
347347
type_: Option<Box<Expr<U>>>,
@@ -351,7 +351,7 @@ pub enum ExcepthandlerKind<U = ()> {
351351
}
352352
pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>;
353353

354-
#[derive(Debug, PartialEq)]
354+
#[derive(Clone, Debug, PartialEq)]
355355
pub struct Arguments<U = ()> {
356356
pub posonlyargs: Vec<Arg<U>>,
357357
pub args: Vec<Arg<U>>,
@@ -362,42 +362,42 @@ pub struct Arguments<U = ()> {
362362
pub defaults: Vec<Expr<U>>,
363363
}
364364

365-
#[derive(Debug, PartialEq)]
365+
#[derive(Clone, Debug, PartialEq)]
366366
pub struct ArgData<U = ()> {
367367
pub arg: Ident,
368368
pub annotation: Option<Box<Expr<U>>>,
369369
pub type_comment: Option<String>,
370370
}
371371
pub type Arg<U = ()> = Located<ArgData<U>, U>;
372372

373-
#[derive(Debug, PartialEq)]
373+
#[derive(Clone, Debug, PartialEq)]
374374
pub struct KeywordData<U = ()> {
375375
pub arg: Option<Ident>,
376376
pub value: Box<Expr<U>>,
377377
}
378378
pub type Keyword<U = ()> = Located<KeywordData<U>, U>;
379379

380-
#[derive(Debug, PartialEq)]
380+
#[derive(Clone, Debug, PartialEq)]
381381
pub struct AliasData {
382382
pub name: Ident,
383383
pub asname: Option<Ident>,
384384
}
385385
pub type Alias<U = ()> = Located<AliasData, U>;
386386

387-
#[derive(Debug, PartialEq)]
387+
#[derive(Clone, Debug, PartialEq)]
388388
pub struct Withitem<U = ()> {
389389
pub context_expr: Box<Expr<U>>,
390390
pub optional_vars: Option<Box<Expr<U>>>,
391391
}
392392

393-
#[derive(Debug, PartialEq)]
393+
#[derive(Clone, Debug, PartialEq)]
394394
pub struct MatchCase<U = ()> {
395395
pub pattern: Box<Pattern<U>>,
396396
pub guard: Option<Box<Expr<U>>>,
397397
pub body: Vec<Stmt<U>>,
398398
}
399399

400-
#[derive(Debug, PartialEq)]
400+
#[derive(Clone, Debug, PartialEq)]
401401
pub enum PatternKind<U = ()> {
402402
MatchValue {
403403
value: Box<Expr<U>>,
@@ -432,7 +432,7 @@ pub enum PatternKind<U = ()> {
432432
}
433433
pub type Pattern<U = ()> = Located<PatternKind<U>, U>;
434434

435-
#[derive(Debug, PartialEq)]
435+
#[derive(Clone, Debug, PartialEq)]
436436
pub enum TypeIgnore {
437437
TypeIgnore { lineno: usize, tag: String },
438438
}

compiler/ast/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use num_bigint::BigInt;
22
pub use rustpython_compiler_core::ConversionFlag;
33

4-
#[derive(Debug, PartialEq)]
4+
#[derive(Clone, Debug, PartialEq)]
55
pub enum Constant {
66
None,
77
Bool(bool),

0 commit comments

Comments
 (0)