Skip to content

ran cargo clippy --fix -- -A clippy::all -W clippy::use_self #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 69 additions & 70 deletions src/bigint.rs

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions src/bigint/addition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ impl Add<BigInt> for &BigInt {
}
}

impl Add<&BigInt> for BigInt {
type Output = BigInt;
impl Add<&Self> for BigInt {
type Output = Self;

#[inline]
fn add(self, other: &BigInt) -> BigInt {
fn add(self, other: &Self) -> Self {
bigint_add!(self, self, self.data, other, other.clone(), &other.data)
}
}

impl Add<BigInt> for BigInt {
type Output = BigInt;
impl Add<Self> for BigInt {
type Output = Self;

#[inline]
fn add(self, other: BigInt) -> BigInt {
fn add(self, other: Self) -> Self {
bigint_add!(self, self, self.data, other, other, other.data)
}
}

impl AddAssign<&BigInt> for BigInt {
impl AddAssign<&Self> for BigInt {
#[inline]
fn add_assign(&mut self, other: &BigInt) {
fn add_assign(&mut self, other: &Self) {
let n = mem::replace(self, Self::ZERO);
*self = n + other;
}
Expand All @@ -89,17 +89,17 @@ forward_all_scalar_binop_to_val_val_commutative!(impl Add<u64> for BigInt, add);
forward_all_scalar_binop_to_val_val_commutative!(impl Add<u128> for BigInt, add);

impl Add<u32> for BigInt {
type Output = BigInt;
type Output = Self;

#[inline]
fn add(self, other: u32) -> BigInt {
fn add(self, other: u32) -> Self {
match self.sign {
NoSign => From::from(other),
Plus => BigInt::from(self.data + other),
Plus => Self::from(self.data + other),
Minus => match self.data.cmp(&From::from(other)) {
Equal => Self::ZERO,
Less => BigInt::from(other - self.data),
Greater => -BigInt::from(self.data - other),
Less => Self::from(other - self.data),
Greater => -Self::from(self.data - other),
},
}
}
Expand All @@ -114,17 +114,17 @@ impl AddAssign<u32> for BigInt {
}

impl Add<u64> for BigInt {
type Output = BigInt;
type Output = Self;

#[inline]
fn add(self, other: u64) -> BigInt {
fn add(self, other: u64) -> Self {
match self.sign {
NoSign => From::from(other),
Plus => BigInt::from(self.data + other),
Plus => Self::from(self.data + other),
Minus => match self.data.cmp(&From::from(other)) {
Equal => Self::ZERO,
Less => BigInt::from(other - self.data),
Greater => -BigInt::from(self.data - other),
Less => Self::from(other - self.data),
Greater => -Self::from(self.data - other),
},
}
}
Expand All @@ -139,17 +139,17 @@ impl AddAssign<u64> for BigInt {
}

impl Add<u128> for BigInt {
type Output = BigInt;
type Output = Self;

#[inline]
fn add(self, other: u128) -> BigInt {
fn add(self, other: u128) -> Self {
match self.sign {
NoSign => BigInt::from(other),
Plus => BigInt::from(self.data + other),
NoSign => Self::from(other),
Plus => Self::from(self.data + other),
Minus => match self.data.cmp(&From::from(other)) {
Equal => Self::ZERO,
Less => BigInt::from(other - self.data),
Greater => -BigInt::from(self.data - other),
Less => Self::from(other - self.data),
Greater => -Self::from(self.data - other),
},
}
}
Expand All @@ -167,10 +167,10 @@ forward_all_scalar_binop_to_val_val_commutative!(impl Add<i64> for BigInt, add);
forward_all_scalar_binop_to_val_val_commutative!(impl Add<i128> for BigInt, add);

impl Add<i32> for BigInt {
type Output = BigInt;
type Output = Self;

#[inline]
fn add(self, other: i32) -> BigInt {
fn add(self, other: i32) -> Self {
match other.checked_uabs() {
Positive(u) => self + u,
Negative(u) => self - u,
Expand All @@ -188,10 +188,10 @@ impl AddAssign<i32> for BigInt {
}

impl Add<i64> for BigInt {
type Output = BigInt;
type Output = Self;

#[inline]
fn add(self, other: i64) -> BigInt {
fn add(self, other: i64) -> Self {
match other.checked_uabs() {
Positive(u) => self + u,
Negative(u) => self - u,
Expand All @@ -209,10 +209,10 @@ impl AddAssign<i64> for BigInt {
}

impl Add<i128> for BigInt {
type Output = BigInt;
type Output = Self;

#[inline]
fn add(self, other: i128) -> BigInt {
fn add(self, other: i128) -> Self {
match other.checked_uabs() {
Positive(u) => self + u,
Negative(u) => self - u,
Expand All @@ -231,7 +231,7 @@ impl AddAssign<i128> for BigInt {

impl CheckedAdd for BigInt {
#[inline]
fn checked_add(&self, v: &BigInt) -> Option<BigInt> {
fn checked_add(&self, v: &Self) -> Option<Self> {
Some(self.add(v))
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/bigint/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,20 @@ impl BitAnd<&BigInt> for &BigInt {
}
}

impl BitAnd<&BigInt> for BigInt {
type Output = BigInt;
impl BitAnd<&Self> for BigInt {
type Output = Self;

#[inline]
fn bitand(mut self, other: &BigInt) -> BigInt {
fn bitand(mut self, other: &Self) -> Self {
self &= other;
self
}
}

forward_val_assign!(impl BitAndAssign for BigInt, bitand_assign);

impl BitAndAssign<&BigInt> for BigInt {
fn bitand_assign(&mut self, other: &BigInt) {
impl BitAndAssign<&Self> for BigInt {
fn bitand_assign(&mut self, other: &Self) {
match (self.sign, other.sign) {
(NoSign, _) => {}
(_, NoSign) => self.set_zero(),
Expand Down Expand Up @@ -270,20 +270,20 @@ impl BitOr<&BigInt> for &BigInt {
}
}

impl BitOr<&BigInt> for BigInt {
type Output = BigInt;
impl BitOr<&Self> for BigInt {
type Output = Self;

#[inline]
fn bitor(mut self, other: &BigInt) -> BigInt {
fn bitor(mut self, other: &Self) -> Self {
self |= other;
self
}
}

forward_val_assign!(impl BitOrAssign for BigInt, bitor_assign);

impl BitOrAssign<&BigInt> for BigInt {
fn bitor_assign(&mut self, other: &BigInt) {
impl BitOrAssign<&Self> for BigInt {
fn bitor_assign(&mut self, other: &Self) {
match (self.sign, other.sign) {
(_, NoSign) => {}
(NoSign, _) => self.clone_from(other),
Expand Down Expand Up @@ -408,20 +408,20 @@ fn bitxor_neg_neg(a: &mut Vec<BigDigit>, b: &[BigDigit]) {

forward_all_binop_to_val_ref_commutative!(impl BitXor for BigInt, bitxor);

impl BitXor<&BigInt> for BigInt {
type Output = BigInt;
impl BitXor<&Self> for BigInt {
type Output = Self;

#[inline]
fn bitxor(mut self, other: &BigInt) -> BigInt {
fn bitxor(mut self, other: &Self) -> Self {
self ^= other;
self
}
}

forward_val_assign!(impl BitXorAssign for BigInt, bitxor_assign);

impl BitXorAssign<&BigInt> for BigInt {
fn bitxor_assign(&mut self, other: &BigInt) {
impl BitXorAssign<&Self> for BigInt {
fn bitxor_assign(&mut self, other: &Self) {
match (self.sign, other.sign) {
(_, NoSign) => {}
(NoSign, _) => self.clone_from(other),
Expand Down
48 changes: 24 additions & 24 deletions src/bigint/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ impl FromStr for BigInt {
type Err = ParseBigIntError;

#[inline]
fn from_str(s: &str) -> Result<BigInt, ParseBigIntError> {
BigInt::from_str_radix(s, 10)
fn from_str(s: &str) -> Result<Self, ParseBigIntError> {
Self::from_str_radix(s, 10)
}
}

Expand All @@ -24,7 +24,7 @@ impl Num for BigInt {

/// Creates and initializes a [`BigInt`].
#[inline]
fn from_str_radix(mut s: &str, radix: u32) -> Result<BigInt, ParseBigIntError> {
fn from_str_radix(mut s: &str, radix: u32) -> Result<Self, ParseBigIntError> {
let sign = if let Some(tail) = s.strip_prefix('-') {
if !tail.starts_with('+') {
s = tail
Expand All @@ -34,7 +34,7 @@ impl Num for BigInt {
Plus
};
let bu = BigUint::from_str_radix(s, radix)?;
Ok(BigInt::from_biguint(sign, bu))
Ok(Self::from_biguint(sign, bu))
}
}

Expand Down Expand Up @@ -142,32 +142,32 @@ impl_try_from_bigint!(i128, ToPrimitive::to_i128);

impl FromPrimitive for BigInt {
#[inline]
fn from_i64(n: i64) -> Option<BigInt> {
Some(BigInt::from(n))
fn from_i64(n: i64) -> Option<Self> {
Some(Self::from(n))
}

#[inline]
fn from_i128(n: i128) -> Option<BigInt> {
Some(BigInt::from(n))
fn from_i128(n: i128) -> Option<Self> {
Some(Self::from(n))
}

#[inline]
fn from_u64(n: u64) -> Option<BigInt> {
Some(BigInt::from(n))
fn from_u64(n: u64) -> Option<Self> {
Some(Self::from(n))
}

#[inline]
fn from_u128(n: u128) -> Option<BigInt> {
Some(BigInt::from(n))
fn from_u128(n: u128) -> Option<Self> {
Some(Self::from(n))
}

#[inline]
fn from_f64(n: f64) -> Option<BigInt> {
fn from_f64(n: f64) -> Option<Self> {
if n >= 0.0 {
BigUint::from_f64(n).map(BigInt::from)
BigUint::from_f64(n).map(Self::from)
} else {
let x = BigUint::from_f64(-n)?;
Some(-BigInt::from(x))
Some(-Self::from(x))
}
}
}
Expand All @@ -176,10 +176,10 @@ impl From<i64> for BigInt {
#[inline]
fn from(n: i64) -> Self {
if n >= 0 {
BigInt::from(n as u64)
Self::from(n as u64)
} else {
let u = u64::MAX - (n as u64) + 1;
BigInt {
Self {
sign: Minus,
data: BigUint::from(u),
}
Expand All @@ -191,10 +191,10 @@ impl From<i128> for BigInt {
#[inline]
fn from(n: i128) -> Self {
if n >= 0 {
BigInt::from(n as u128)
Self::from(n as u128)
} else {
let u = u128::MAX - (n as u128) + 1;
BigInt {
Self {
sign: Minus,
data: BigUint::from(u),
}
Expand Down Expand Up @@ -222,7 +222,7 @@ impl From<u64> for BigInt {
#[inline]
fn from(n: u64) -> Self {
if n > 0 {
BigInt {
Self {
sign: Plus,
data: BigUint::from(n),
}
Expand All @@ -236,7 +236,7 @@ impl From<u128> for BigInt {
#[inline]
fn from(n: u128) -> Self {
if n > 0 {
BigInt {
Self {
sign: Plus,
data: BigUint::from(n),
}
Expand Down Expand Up @@ -268,7 +268,7 @@ impl From<BigUint> for BigInt {
if n.is_zero() {
Self::ZERO
} else {
BigInt {
Self {
sign: Plus,
data: n,
}
Expand Down Expand Up @@ -312,7 +312,7 @@ impl TryFrom<&BigInt> for BigUint {
type Error = TryFromBigIntError<()>;

#[inline]
fn try_from(value: &BigInt) -> Result<BigUint, TryFromBigIntError<()>> {
fn try_from(value: &BigInt) -> Result<Self, TryFromBigIntError<()>> {
value
.to_biguint()
.ok_or_else(|| TryFromBigIntError::new(()))
Expand All @@ -323,7 +323,7 @@ impl TryFrom<BigInt> for BigUint {
type Error = TryFromBigIntError<BigInt>;

#[inline]
fn try_from(value: BigInt) -> Result<BigUint, TryFromBigIntError<BigInt>> {
fn try_from(value: BigInt) -> Result<Self, TryFromBigIntError<BigInt>> {
if value.sign() == Sign::Minus {
Err(TryFromBigIntError::new(value))
} else {
Expand Down
Loading