mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Implement Copy
on simple enums
This commit is contained in:
parent
3277ec29af
commit
a913c339f6
3 changed files with 9 additions and 15 deletions
|
@ -288,7 +288,7 @@ class StructVisitor(EmitVisitor):
|
|||
def simple_sum(self, sum, name, depth):
|
||||
rust_name = rust_type_name(name)
|
||||
self.emit_attrs(depth)
|
||||
self.emit("#[derive(is_macro::Is)]", depth)
|
||||
self.emit("#[derive(is_macro::Is, Copy)]", depth)
|
||||
self.emit(f"pub enum {rust_name} {{", depth)
|
||||
for variant in sum.types:
|
||||
self.emit(f"{variant.name},", depth + 1)
|
||||
|
|
|
@ -911,20 +911,20 @@ pub enum Expr<R = TextRange> {
|
|||
Slice(ExprSlice<R>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy)]
|
||||
pub enum ExprContext {
|
||||
Load,
|
||||
Store,
|
||||
Del,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy)]
|
||||
pub enum Boolop {
|
||||
And,
|
||||
Or,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy)]
|
||||
pub enum Operator {
|
||||
Add,
|
||||
Sub,
|
||||
|
@ -941,7 +941,7 @@ pub enum Operator {
|
|||
FloorDiv,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy)]
|
||||
pub enum Unaryop {
|
||||
Invert,
|
||||
Not,
|
||||
|
@ -949,7 +949,7 @@ pub enum Unaryop {
|
|||
USub,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy)]
|
||||
pub enum Cmpop {
|
||||
Eq,
|
||||
NotEq,
|
||||
|
|
|
@ -4,20 +4,14 @@ pub(crate) fn set_context(expr: Expr, ctx: ExprContext) -> Expr {
|
|||
match expr {
|
||||
Expr::Name(ast::ExprName { id, range, .. }) => ast::ExprName { id, ctx, range }.into(),
|
||||
Expr::Tuple(ast::ExprTuple { elts, range, .. }) => ast::ExprTuple {
|
||||
elts: elts
|
||||
.into_iter()
|
||||
.map(|elt| set_context(elt, ctx.clone()))
|
||||
.collect(),
|
||||
elts: elts.into_iter().map(|elt| set_context(elt, ctx)).collect(),
|
||||
range,
|
||||
ctx,
|
||||
}
|
||||
.into(),
|
||||
|
||||
Expr::List(ast::ExprList { elts, range, .. }) => ast::ExprList {
|
||||
elts: elts
|
||||
.into_iter()
|
||||
.map(|elt| set_context(elt, ctx.clone()))
|
||||
.collect(),
|
||||
elts: elts.into_iter().map(|elt| set_context(elt, ctx)).collect(),
|
||||
range,
|
||||
ctx,
|
||||
}
|
||||
|
@ -44,7 +38,7 @@ pub(crate) fn set_context(expr: Expr, ctx: ExprContext) -> Expr {
|
|||
}
|
||||
.into(),
|
||||
Expr::Starred(ast::ExprStarred { value, range, .. }) => ast::ExprStarred {
|
||||
value: Box::new(set_context(*value, ctx.clone())),
|
||||
value: Box::new(set_context(*value, ctx)),
|
||||
range,
|
||||
ctx,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue