Implement Copy on simple enums

This commit is contained in:
Micha Reiser 2023-05-13 19:33:53 +02:00
parent 3277ec29af
commit a913c339f6
No known key found for this signature in database
3 changed files with 9 additions and 15 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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,
}