diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 5a3c20e4da..1d47a1676f 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -2727,73 +2727,6 @@ pub enum ExprContext { Store, Del, } -impl ExprContext { - #[inline] - pub const fn load(&self) -> Option { - match self { - ExprContext::Load => Some(ExprContextLoad), - _ => None, - } - } - - #[inline] - pub const fn store(&self) -> Option { - match self { - ExprContext::Store => Some(ExprContextStore), - _ => None, - } - } - - #[inline] - pub const fn del(&self) -> Option { - match self { - ExprContext::Del => Some(ExprContextDel), - _ => None, - } - } -} - -pub struct ExprContextLoad; -impl From for ExprContext { - fn from(_: ExprContextLoad) -> Self { - ExprContext::Load - } -} - -impl std::cmp::PartialEq for ExprContextLoad { - #[inline] - fn eq(&self, other: &ExprContext) -> bool { - matches!(other, ExprContext::Load) - } -} - -pub struct ExprContextStore; -impl From for ExprContext { - fn from(_: ExprContextStore) -> Self { - ExprContext::Store - } -} - -impl std::cmp::PartialEq for ExprContextStore { - #[inline] - fn eq(&self, other: &ExprContext) -> bool { - matches!(other, ExprContext::Store) - } -} - -pub struct ExprContextDel; -impl From for ExprContext { - fn from(_: ExprContextDel) -> Self { - ExprContext::Del - } -} - -impl std::cmp::PartialEq for ExprContextDel { - #[inline] - fn eq(&self, other: &ExprContext) -> bool { - matches!(other, ExprContext::Del) - } -} /// See also [boolop](https://docs.python.org/3/library/ast.html#ast.BoolOp) #[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] @@ -2801,51 +2734,6 @@ pub enum BoolOp { And, Or, } -impl BoolOp { - #[inline] - pub const fn and(&self) -> Option { - match self { - BoolOp::And => Some(BoolOpAnd), - BoolOp::Or => None, - } - } - - #[inline] - pub const fn or(&self) -> Option { - match self { - BoolOp::Or => Some(BoolOpOr), - BoolOp::And => None, - } - } -} - -pub struct BoolOpAnd; -impl From for BoolOp { - fn from(_: BoolOpAnd) -> Self { - BoolOp::And - } -} - -impl std::cmp::PartialEq for BoolOpAnd { - #[inline] - fn eq(&self, other: &BoolOp) -> bool { - matches!(other, BoolOp::And) - } -} - -pub struct BoolOpOr; -impl From for BoolOp { - fn from(_: BoolOpOr) -> Self { - BoolOp::Or - } -} - -impl std::cmp::PartialEq for BoolOpOr { - #[inline] - fn eq(&self, other: &BoolOp) -> bool { - matches!(other, BoolOp::Or) - } -} /// See also [operator](https://docs.python.org/3/library/ast.html#ast.operator) #[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] @@ -2864,293 +2752,6 @@ pub enum Operator { BitAnd, FloorDiv, } -impl Operator { - #[inline] - pub const fn operator_add(&self) -> Option { - match self { - Operator::Add => Some(OperatorAdd), - _ => None, - } - } - - #[inline] - pub const fn operator_sub(&self) -> Option { - match self { - Operator::Sub => Some(OperatorSub), - _ => None, - } - } - - #[inline] - pub const fn operator_mult(&self) -> Option { - match self { - Operator::Mult => Some(OperatorMult), - _ => None, - } - } - - #[inline] - pub const fn operator_mat_mult(&self) -> Option { - match self { - Operator::MatMult => Some(OperatorMatMult), - _ => None, - } - } - - #[inline] - pub const fn operator_div(&self) -> Option { - match self { - Operator::Div => Some(OperatorDiv), - _ => None, - } - } - - #[inline] - pub const fn operator_mod(&self) -> Option { - match self { - Operator::Mod => Some(OperatorMod), - _ => None, - } - } - - #[inline] - pub const fn operator_pow(&self) -> Option { - match self { - Operator::Pow => Some(OperatorPow), - _ => None, - } - } - - #[inline] - pub const fn operator_l_shift(&self) -> Option { - match self { - Operator::LShift => Some(OperatorLShift), - _ => None, - } - } - - #[inline] - pub const fn operator_r_shift(&self) -> Option { - match self { - Operator::RShift => Some(OperatorRShift), - _ => None, - } - } - - #[inline] - pub const fn operator_bit_or(&self) -> Option { - match self { - Operator::BitOr => Some(OperatorBitOr), - _ => None, - } - } - - #[inline] - pub const fn operator_bit_xor(&self) -> Option { - match self { - Operator::BitXor => Some(OperatorBitXor), - _ => None, - } - } - - #[inline] - pub const fn operator_bit_and(&self) -> Option { - match self { - Operator::BitAnd => Some(OperatorBitAnd), - _ => None, - } - } - - #[inline] - pub const fn operator_floor_div(&self) -> Option { - match self { - Operator::FloorDiv => Some(OperatorFloorDiv), - _ => None, - } - } -} - -pub struct OperatorAdd; -impl From for Operator { - fn from(_: OperatorAdd) -> Self { - Operator::Add - } -} - -impl std::cmp::PartialEq for OperatorAdd { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Add) - } -} - -pub struct OperatorSub; -impl From for Operator { - fn from(_: OperatorSub) -> Self { - Operator::Sub - } -} - -impl std::cmp::PartialEq for OperatorSub { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Sub) - } -} - -pub struct OperatorMult; -impl From for Operator { - fn from(_: OperatorMult) -> Self { - Operator::Mult - } -} - -impl std::cmp::PartialEq for OperatorMult { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Mult) - } -} - -pub struct OperatorMatMult; -impl From for Operator { - fn from(_: OperatorMatMult) -> Self { - Operator::MatMult - } -} - -impl std::cmp::PartialEq for OperatorMatMult { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::MatMult) - } -} - -pub struct OperatorDiv; -impl From for Operator { - fn from(_: OperatorDiv) -> Self { - Operator::Div - } -} - -impl std::cmp::PartialEq for OperatorDiv { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Div) - } -} - -pub struct OperatorMod; -impl From for Operator { - fn from(_: OperatorMod) -> Self { - Operator::Mod - } -} - -impl std::cmp::PartialEq for OperatorMod { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Mod) - } -} - -pub struct OperatorPow; -impl From for Operator { - fn from(_: OperatorPow) -> Self { - Operator::Pow - } -} - -impl std::cmp::PartialEq for OperatorPow { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Pow) - } -} - -pub struct OperatorLShift; -impl From for Operator { - fn from(_: OperatorLShift) -> Self { - Operator::LShift - } -} - -impl std::cmp::PartialEq for OperatorLShift { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::LShift) - } -} - -pub struct OperatorRShift; -impl From for Operator { - fn from(_: OperatorRShift) -> Self { - Operator::RShift - } -} - -impl std::cmp::PartialEq for OperatorRShift { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::RShift) - } -} - -pub struct OperatorBitOr; -impl From for Operator { - fn from(_: OperatorBitOr) -> Self { - Operator::BitOr - } -} - -impl std::cmp::PartialEq for OperatorBitOr { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::BitOr) - } -} - -pub struct OperatorBitXor; -impl From for Operator { - fn from(_: OperatorBitXor) -> Self { - Operator::BitXor - } -} - -impl std::cmp::PartialEq for OperatorBitXor { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::BitXor) - } -} - -pub struct OperatorBitAnd; -impl From for Operator { - fn from(_: OperatorBitAnd) -> Self { - Operator::BitAnd - } -} - -impl std::cmp::PartialEq for OperatorBitAnd { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::BitAnd) - } -} - -pub struct OperatorFloorDiv; -impl From for Operator { - fn from(_: OperatorFloorDiv) -> Self { - Operator::FloorDiv - } -} - -impl std::cmp::PartialEq for OperatorFloorDiv { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::FloorDiv) - } -} /// See also [unaryop](https://docs.python.org/3/library/ast.html#ast.unaryop) #[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] @@ -3160,95 +2761,6 @@ pub enum UnaryOp { UAdd, USub, } -impl UnaryOp { - #[inline] - pub const fn invert(&self) -> Option { - match self { - UnaryOp::Invert => Some(UnaryOpInvert), - _ => None, - } - } - - #[inline] - pub const fn not(&self) -> Option { - match self { - UnaryOp::Not => Some(UnaryOpNot), - _ => None, - } - } - - #[inline] - pub const fn u_add(&self) -> Option { - match self { - UnaryOp::UAdd => Some(UnaryOpUAdd), - _ => None, - } - } - - #[inline] - pub const fn u_sub(&self) -> Option { - match self { - UnaryOp::USub => Some(UnaryOpUSub), - _ => None, - } - } -} - -pub struct UnaryOpInvert; -impl From for UnaryOp { - fn from(_: UnaryOpInvert) -> Self { - UnaryOp::Invert - } -} - -impl std::cmp::PartialEq for UnaryOpInvert { - #[inline] - fn eq(&self, other: &UnaryOp) -> bool { - matches!(other, UnaryOp::Invert) - } -} - -pub struct UnaryOpNot; -impl From for UnaryOp { - fn from(_: UnaryOpNot) -> Self { - UnaryOp::Not - } -} - -impl std::cmp::PartialEq for UnaryOpNot { - #[inline] - fn eq(&self, other: &UnaryOp) -> bool { - matches!(other, UnaryOp::Not) - } -} - -pub struct UnaryOpUAdd; -impl From for UnaryOp { - fn from(_: UnaryOpUAdd) -> Self { - UnaryOp::UAdd - } -} - -impl std::cmp::PartialEq for UnaryOpUAdd { - #[inline] - fn eq(&self, other: &UnaryOp) -> bool { - matches!(other, UnaryOp::UAdd) - } -} - -pub struct UnaryOpUSub; -impl From for UnaryOp { - fn from(_: UnaryOpUSub) -> Self { - UnaryOp::USub - } -} - -impl std::cmp::PartialEq for UnaryOpUSub { - #[inline] - fn eq(&self, other: &UnaryOp) -> bool { - matches!(other, UnaryOp::USub) - } -} /// See also [cmpop](https://docs.python.org/3/library/ast.html#ast.cmpop) #[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] @@ -3264,227 +2776,6 @@ pub enum CmpOp { In, NotIn, } -impl CmpOp { - #[inline] - pub const fn cmp_op_eq(&self) -> Option { - match self { - CmpOp::Eq => Some(CmpOpEq), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_not_eq(&self) -> Option { - match self { - CmpOp::NotEq => Some(CmpOpNotEq), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_lt(&self) -> Option { - match self { - CmpOp::Lt => Some(CmpOpLt), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_lt_e(&self) -> Option { - match self { - CmpOp::LtE => Some(CmpOpLtE), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_gt(&self) -> Option { - match self { - CmpOp::Gt => Some(CmpOpGt), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_gt_e(&self) -> Option { - match self { - CmpOp::GtE => Some(CmpOpGtE), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_is(&self) -> Option { - match self { - CmpOp::Is => Some(CmpOpIs), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_is_not(&self) -> Option { - match self { - CmpOp::IsNot => Some(CmpOpIsNot), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_in(&self) -> Option { - match self { - CmpOp::In => Some(CmpOpIn), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_not_in(&self) -> Option { - match self { - CmpOp::NotIn => Some(CmpOpNotIn), - _ => None, - } - } -} - -pub struct CmpOpEq; -impl From for CmpOp { - fn from(_: CmpOpEq) -> Self { - CmpOp::Eq - } -} - -impl std::cmp::PartialEq for CmpOpEq { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::Eq) - } -} - -pub struct CmpOpNotEq; -impl From for CmpOp { - fn from(_: CmpOpNotEq) -> Self { - CmpOp::NotEq - } -} - -impl std::cmp::PartialEq for CmpOpNotEq { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::NotEq) - } -} - -pub struct CmpOpLt; -impl From for CmpOp { - fn from(_: CmpOpLt) -> Self { - CmpOp::Lt - } -} - -impl std::cmp::PartialEq for CmpOpLt { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::Lt) - } -} - -pub struct CmpOpLtE; -impl From for CmpOp { - fn from(_: CmpOpLtE) -> Self { - CmpOp::LtE - } -} - -impl std::cmp::PartialEq for CmpOpLtE { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::LtE) - } -} - -pub struct CmpOpGt; -impl From for CmpOp { - fn from(_: CmpOpGt) -> Self { - CmpOp::Gt - } -} - -impl std::cmp::PartialEq for CmpOpGt { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::Gt) - } -} - -pub struct CmpOpGtE; -impl From for CmpOp { - fn from(_: CmpOpGtE) -> Self { - CmpOp::GtE - } -} - -impl std::cmp::PartialEq for CmpOpGtE { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::GtE) - } -} - -pub struct CmpOpIs; -impl From for CmpOp { - fn from(_: CmpOpIs) -> Self { - CmpOp::Is - } -} - -impl std::cmp::PartialEq for CmpOpIs { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::Is) - } -} - -pub struct CmpOpIsNot; -impl From for CmpOp { - fn from(_: CmpOpIsNot) -> Self { - CmpOp::IsNot - } -} - -impl std::cmp::PartialEq for CmpOpIsNot { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::IsNot) - } -} - -pub struct CmpOpIn; -impl From for CmpOp { - fn from(_: CmpOpIn) -> Self { - CmpOp::In - } -} - -impl std::cmp::PartialEq for CmpOpIn { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::In) - } -} - -pub struct CmpOpNotIn; -impl From for CmpOp { - fn from(_: CmpOpNotIn) -> Self { - CmpOp::NotIn - } -} - -impl std::cmp::PartialEq for CmpOpNotIn { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::NotIn) - } -} /// See also [comprehension](https://docs.python.org/3/library/ast.html#ast.comprehension) #[derive(Clone, Debug, PartialEq)]