Remove unused operator methods and impl (#10690)

## Summary

This PR removes unused operator methods and impl traits. There is
already the `is_macro::Is` implementation for all the operators and this
seems unnecessary.
This commit is contained in:
Dhruv Manilawala 2024-04-02 15:53:20 +05:30 committed by GitHub
parent 159bad73d5
commit eee2d5b915
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2727,73 +2727,6 @@ pub enum ExprContext {
Store,
Del,
}
impl ExprContext {
#[inline]
pub const fn load(&self) -> Option<ExprContextLoad> {
match self {
ExprContext::Load => Some(ExprContextLoad),
_ => None,
}
}
#[inline]
pub const fn store(&self) -> Option<ExprContextStore> {
match self {
ExprContext::Store => Some(ExprContextStore),
_ => None,
}
}
#[inline]
pub const fn del(&self) -> Option<ExprContextDel> {
match self {
ExprContext::Del => Some(ExprContextDel),
_ => None,
}
}
}
pub struct ExprContextLoad;
impl From<ExprContextLoad> for ExprContext {
fn from(_: ExprContextLoad) -> Self {
ExprContext::Load
}
}
impl std::cmp::PartialEq<ExprContext> for ExprContextLoad {
#[inline]
fn eq(&self, other: &ExprContext) -> bool {
matches!(other, ExprContext::Load)
}
}
pub struct ExprContextStore;
impl From<ExprContextStore> for ExprContext {
fn from(_: ExprContextStore) -> Self {
ExprContext::Store
}
}
impl std::cmp::PartialEq<ExprContext> for ExprContextStore {
#[inline]
fn eq(&self, other: &ExprContext) -> bool {
matches!(other, ExprContext::Store)
}
}
pub struct ExprContextDel;
impl From<ExprContextDel> for ExprContext {
fn from(_: ExprContextDel) -> Self {
ExprContext::Del
}
}
impl std::cmp::PartialEq<ExprContext> 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<BoolOpAnd> {
match self {
BoolOp::And => Some(BoolOpAnd),
BoolOp::Or => None,
}
}
#[inline]
pub const fn or(&self) -> Option<BoolOpOr> {
match self {
BoolOp::Or => Some(BoolOpOr),
BoolOp::And => None,
}
}
}
pub struct BoolOpAnd;
impl From<BoolOpAnd> for BoolOp {
fn from(_: BoolOpAnd) -> Self {
BoolOp::And
}
}
impl std::cmp::PartialEq<BoolOp> for BoolOpAnd {
#[inline]
fn eq(&self, other: &BoolOp) -> bool {
matches!(other, BoolOp::And)
}
}
pub struct BoolOpOr;
impl From<BoolOpOr> for BoolOp {
fn from(_: BoolOpOr) -> Self {
BoolOp::Or
}
}
impl std::cmp::PartialEq<BoolOp> 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<OperatorAdd> {
match self {
Operator::Add => Some(OperatorAdd),
_ => None,
}
}
#[inline]
pub const fn operator_sub(&self) -> Option<OperatorSub> {
match self {
Operator::Sub => Some(OperatorSub),
_ => None,
}
}
#[inline]
pub const fn operator_mult(&self) -> Option<OperatorMult> {
match self {
Operator::Mult => Some(OperatorMult),
_ => None,
}
}
#[inline]
pub const fn operator_mat_mult(&self) -> Option<OperatorMatMult> {
match self {
Operator::MatMult => Some(OperatorMatMult),
_ => None,
}
}
#[inline]
pub const fn operator_div(&self) -> Option<OperatorDiv> {
match self {
Operator::Div => Some(OperatorDiv),
_ => None,
}
}
#[inline]
pub const fn operator_mod(&self) -> Option<OperatorMod> {
match self {
Operator::Mod => Some(OperatorMod),
_ => None,
}
}
#[inline]
pub const fn operator_pow(&self) -> Option<OperatorPow> {
match self {
Operator::Pow => Some(OperatorPow),
_ => None,
}
}
#[inline]
pub const fn operator_l_shift(&self) -> Option<OperatorLShift> {
match self {
Operator::LShift => Some(OperatorLShift),
_ => None,
}
}
#[inline]
pub const fn operator_r_shift(&self) -> Option<OperatorRShift> {
match self {
Operator::RShift => Some(OperatorRShift),
_ => None,
}
}
#[inline]
pub const fn operator_bit_or(&self) -> Option<OperatorBitOr> {
match self {
Operator::BitOr => Some(OperatorBitOr),
_ => None,
}
}
#[inline]
pub const fn operator_bit_xor(&self) -> Option<OperatorBitXor> {
match self {
Operator::BitXor => Some(OperatorBitXor),
_ => None,
}
}
#[inline]
pub const fn operator_bit_and(&self) -> Option<OperatorBitAnd> {
match self {
Operator::BitAnd => Some(OperatorBitAnd),
_ => None,
}
}
#[inline]
pub const fn operator_floor_div(&self) -> Option<OperatorFloorDiv> {
match self {
Operator::FloorDiv => Some(OperatorFloorDiv),
_ => None,
}
}
}
pub struct OperatorAdd;
impl From<OperatorAdd> for Operator {
fn from(_: OperatorAdd) -> Self {
Operator::Add
}
}
impl std::cmp::PartialEq<Operator> for OperatorAdd {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::Add)
}
}
pub struct OperatorSub;
impl From<OperatorSub> for Operator {
fn from(_: OperatorSub) -> Self {
Operator::Sub
}
}
impl std::cmp::PartialEq<Operator> for OperatorSub {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::Sub)
}
}
pub struct OperatorMult;
impl From<OperatorMult> for Operator {
fn from(_: OperatorMult) -> Self {
Operator::Mult
}
}
impl std::cmp::PartialEq<Operator> for OperatorMult {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::Mult)
}
}
pub struct OperatorMatMult;
impl From<OperatorMatMult> for Operator {
fn from(_: OperatorMatMult) -> Self {
Operator::MatMult
}
}
impl std::cmp::PartialEq<Operator> for OperatorMatMult {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::MatMult)
}
}
pub struct OperatorDiv;
impl From<OperatorDiv> for Operator {
fn from(_: OperatorDiv) -> Self {
Operator::Div
}
}
impl std::cmp::PartialEq<Operator> for OperatorDiv {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::Div)
}
}
pub struct OperatorMod;
impl From<OperatorMod> for Operator {
fn from(_: OperatorMod) -> Self {
Operator::Mod
}
}
impl std::cmp::PartialEq<Operator> for OperatorMod {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::Mod)
}
}
pub struct OperatorPow;
impl From<OperatorPow> for Operator {
fn from(_: OperatorPow) -> Self {
Operator::Pow
}
}
impl std::cmp::PartialEq<Operator> for OperatorPow {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::Pow)
}
}
pub struct OperatorLShift;
impl From<OperatorLShift> for Operator {
fn from(_: OperatorLShift) -> Self {
Operator::LShift
}
}
impl std::cmp::PartialEq<Operator> for OperatorLShift {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::LShift)
}
}
pub struct OperatorRShift;
impl From<OperatorRShift> for Operator {
fn from(_: OperatorRShift) -> Self {
Operator::RShift
}
}
impl std::cmp::PartialEq<Operator> for OperatorRShift {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::RShift)
}
}
pub struct OperatorBitOr;
impl From<OperatorBitOr> for Operator {
fn from(_: OperatorBitOr) -> Self {
Operator::BitOr
}
}
impl std::cmp::PartialEq<Operator> for OperatorBitOr {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::BitOr)
}
}
pub struct OperatorBitXor;
impl From<OperatorBitXor> for Operator {
fn from(_: OperatorBitXor) -> Self {
Operator::BitXor
}
}
impl std::cmp::PartialEq<Operator> for OperatorBitXor {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::BitXor)
}
}
pub struct OperatorBitAnd;
impl From<OperatorBitAnd> for Operator {
fn from(_: OperatorBitAnd) -> Self {
Operator::BitAnd
}
}
impl std::cmp::PartialEq<Operator> for OperatorBitAnd {
#[inline]
fn eq(&self, other: &Operator) -> bool {
matches!(other, Operator::BitAnd)
}
}
pub struct OperatorFloorDiv;
impl From<OperatorFloorDiv> for Operator {
fn from(_: OperatorFloorDiv) -> Self {
Operator::FloorDiv
}
}
impl std::cmp::PartialEq<Operator> 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<UnaryOpInvert> {
match self {
UnaryOp::Invert => Some(UnaryOpInvert),
_ => None,
}
}
#[inline]
pub const fn not(&self) -> Option<UnaryOpNot> {
match self {
UnaryOp::Not => Some(UnaryOpNot),
_ => None,
}
}
#[inline]
pub const fn u_add(&self) -> Option<UnaryOpUAdd> {
match self {
UnaryOp::UAdd => Some(UnaryOpUAdd),
_ => None,
}
}
#[inline]
pub const fn u_sub(&self) -> Option<UnaryOpUSub> {
match self {
UnaryOp::USub => Some(UnaryOpUSub),
_ => None,
}
}
}
pub struct UnaryOpInvert;
impl From<UnaryOpInvert> for UnaryOp {
fn from(_: UnaryOpInvert) -> Self {
UnaryOp::Invert
}
}
impl std::cmp::PartialEq<UnaryOp> for UnaryOpInvert {
#[inline]
fn eq(&self, other: &UnaryOp) -> bool {
matches!(other, UnaryOp::Invert)
}
}
pub struct UnaryOpNot;
impl From<UnaryOpNot> for UnaryOp {
fn from(_: UnaryOpNot) -> Self {
UnaryOp::Not
}
}
impl std::cmp::PartialEq<UnaryOp> for UnaryOpNot {
#[inline]
fn eq(&self, other: &UnaryOp) -> bool {
matches!(other, UnaryOp::Not)
}
}
pub struct UnaryOpUAdd;
impl From<UnaryOpUAdd> for UnaryOp {
fn from(_: UnaryOpUAdd) -> Self {
UnaryOp::UAdd
}
}
impl std::cmp::PartialEq<UnaryOp> for UnaryOpUAdd {
#[inline]
fn eq(&self, other: &UnaryOp) -> bool {
matches!(other, UnaryOp::UAdd)
}
}
pub struct UnaryOpUSub;
impl From<UnaryOpUSub> for UnaryOp {
fn from(_: UnaryOpUSub) -> Self {
UnaryOp::USub
}
}
impl std::cmp::PartialEq<UnaryOp> 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<CmpOpEq> {
match self {
CmpOp::Eq => Some(CmpOpEq),
_ => None,
}
}
#[inline]
pub const fn cmp_op_not_eq(&self) -> Option<CmpOpNotEq> {
match self {
CmpOp::NotEq => Some(CmpOpNotEq),
_ => None,
}
}
#[inline]
pub const fn cmp_op_lt(&self) -> Option<CmpOpLt> {
match self {
CmpOp::Lt => Some(CmpOpLt),
_ => None,
}
}
#[inline]
pub const fn cmp_op_lt_e(&self) -> Option<CmpOpLtE> {
match self {
CmpOp::LtE => Some(CmpOpLtE),
_ => None,
}
}
#[inline]
pub const fn cmp_op_gt(&self) -> Option<CmpOpGt> {
match self {
CmpOp::Gt => Some(CmpOpGt),
_ => None,
}
}
#[inline]
pub const fn cmp_op_gt_e(&self) -> Option<CmpOpGtE> {
match self {
CmpOp::GtE => Some(CmpOpGtE),
_ => None,
}
}
#[inline]
pub const fn cmp_op_is(&self) -> Option<CmpOpIs> {
match self {
CmpOp::Is => Some(CmpOpIs),
_ => None,
}
}
#[inline]
pub const fn cmp_op_is_not(&self) -> Option<CmpOpIsNot> {
match self {
CmpOp::IsNot => Some(CmpOpIsNot),
_ => None,
}
}
#[inline]
pub const fn cmp_op_in(&self) -> Option<CmpOpIn> {
match self {
CmpOp::In => Some(CmpOpIn),
_ => None,
}
}
#[inline]
pub const fn cmp_op_not_in(&self) -> Option<CmpOpNotIn> {
match self {
CmpOp::NotIn => Some(CmpOpNotIn),
_ => None,
}
}
}
pub struct CmpOpEq;
impl From<CmpOpEq> for CmpOp {
fn from(_: CmpOpEq) -> Self {
CmpOp::Eq
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpEq {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::Eq)
}
}
pub struct CmpOpNotEq;
impl From<CmpOpNotEq> for CmpOp {
fn from(_: CmpOpNotEq) -> Self {
CmpOp::NotEq
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpNotEq {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::NotEq)
}
}
pub struct CmpOpLt;
impl From<CmpOpLt> for CmpOp {
fn from(_: CmpOpLt) -> Self {
CmpOp::Lt
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpLt {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::Lt)
}
}
pub struct CmpOpLtE;
impl From<CmpOpLtE> for CmpOp {
fn from(_: CmpOpLtE) -> Self {
CmpOp::LtE
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpLtE {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::LtE)
}
}
pub struct CmpOpGt;
impl From<CmpOpGt> for CmpOp {
fn from(_: CmpOpGt) -> Self {
CmpOp::Gt
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpGt {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::Gt)
}
}
pub struct CmpOpGtE;
impl From<CmpOpGtE> for CmpOp {
fn from(_: CmpOpGtE) -> Self {
CmpOp::GtE
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpGtE {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::GtE)
}
}
pub struct CmpOpIs;
impl From<CmpOpIs> for CmpOp {
fn from(_: CmpOpIs) -> Self {
CmpOp::Is
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpIs {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::Is)
}
}
pub struct CmpOpIsNot;
impl From<CmpOpIsNot> for CmpOp {
fn from(_: CmpOpIsNot) -> Self {
CmpOp::IsNot
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpIsNot {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::IsNot)
}
}
pub struct CmpOpIn;
impl From<CmpOpIn> for CmpOp {
fn from(_: CmpOpIn) -> Self {
CmpOp::In
}
}
impl std::cmp::PartialEq<CmpOp> for CmpOpIn {
#[inline]
fn eq(&self, other: &CmpOp) -> bool {
matches!(other, CmpOp::In)
}
}
pub struct CmpOpNotIn;
impl From<CmpOpNotIn> for CmpOp {
fn from(_: CmpOpNotIn) -> Self {
CmpOp::NotIn
}
}
impl std::cmp::PartialEq<CmpOp> 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)]