Skip to content

Commit cf099ff

Browse files
authored
Merge pull request RustPython#4218 from charliermarsh/charlie/clone
Make AST nodes Clone-able
2 parents 72332c9 + d8f059b commit cf099ff

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 end_location: Option<Location>,
@@ -26,7 +26,7 @@ impl<T> Located<T> {
2626
}
2727
}
2828

29-
#[derive(Debug, PartialEq)]
29+
#[derive(Clone, Debug, PartialEq)]
3030
pub enum Mod<U = ()> {
3131
Module {
3232
body: Vec<Stmt<U>>,
@@ -44,7 +44,7 @@ pub enum Mod<U = ()> {
4444
},
4545
}
4646

47-
#[derive(Debug, PartialEq)]
47+
#[derive(Clone, Debug, PartialEq)]
4848
pub enum StmtKind<U = ()> {
4949
FunctionDef {
5050
name: Ident,
@@ -166,7 +166,7 @@ pub enum StmtKind<U = ()> {
166166
}
167167
pub type Stmt<U = ()> = Located<StmtKind<U>, U>;
168168

169-
#[derive(Debug, PartialEq)]
169+
#[derive(Clone, Debug, PartialEq)]
170170
pub enum ExprKind<U = ()> {
171171
BoolOp {
172172
op: Boolop,
@@ -283,20 +283,20 @@ pub enum ExprKind<U = ()> {
283283
}
284284
pub type Expr<U = ()> = Located<ExprKind<U>, U>;
285285

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

293-
#[derive(Debug, PartialEq)]
293+
#[derive(Clone, Debug, PartialEq)]
294294
pub enum Boolop {
295295
And,
296296
Or,
297297
}
298298

299-
#[derive(Debug, PartialEq)]
299+
#[derive(Clone, Debug, PartialEq)]
300300
pub enum Operator {
301301
Add,
302302
Sub,
@@ -313,15 +313,15 @@ pub enum Operator {
313313
FloorDiv,
314314
}
315315

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

324-
#[derive(Debug, PartialEq)]
324+
#[derive(Clone, Debug, PartialEq)]
325325
pub enum Cmpop {
326326
Eq,
327327
NotEq,
@@ -335,15 +335,15 @@ pub enum Cmpop {
335335
NotIn,
336336
}
337337

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

346-
#[derive(Debug, PartialEq)]
346+
#[derive(Clone, Debug, PartialEq)]
347347
pub enum ExcepthandlerKind<U = ()> {
348348
ExceptHandler {
349349
type_: Option<Box<Expr<U>>>,
@@ -353,7 +353,7 @@ pub enum ExcepthandlerKind<U = ()> {
353353
}
354354
pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>;
355355

356-
#[derive(Debug, PartialEq)]
356+
#[derive(Clone, Debug, PartialEq)]
357357
pub struct Arguments<U = ()> {
358358
pub posonlyargs: Vec<Arg<U>>,
359359
pub args: Vec<Arg<U>>,
@@ -364,42 +364,42 @@ pub struct Arguments<U = ()> {
364364
pub defaults: Vec<Expr<U>>,
365365
}
366366

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

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

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

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

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

402-
#[derive(Debug, PartialEq)]
402+
#[derive(Clone, Debug, PartialEq)]
403403
pub enum PatternKind<U = ()> {
404404
MatchValue {
405405
value: Box<Expr<U>>,
@@ -434,7 +434,7 @@ pub enum PatternKind<U = ()> {
434434
}
435435
pub type Pattern<U = ()> = Located<PatternKind<U>, U>;
436436

437-
#[derive(Debug, PartialEq)]
437+
#[derive(Clone, Debug, PartialEq)]
438438
pub enum TypeIgnore {
439439
TypeIgnore { lineno: usize, tag: String },
440440
}

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)