Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paholg committed Jun 20, 2018
1 parent eabd122 commit 1f4bfb3
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 108 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
language: rust
cache: cargo
sudo: false
rust:
- stable
- beta
- nightly
cache: cargo

notifications:
email:
recipients: paho@paholg.com

matrix:
include:
- rust: nightly-2018-03-06
- rust: nightly-2018-06-19
env:
- CLIPPY_VERSION=0.0.187
- CLIPPY_VERSION=0.0.209
before_script:
- rustup component add rustfmt-preview
- cargo install clippy --version $CLIPPY_VERSION || echo "Clippy already installed"
- cargo clippy --version
script:
cargo fmt -- --write-mode=diff &&
cargo fmt --all -- --check &&
cargo clippy --all-features -- -D clippy

script: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This project follows semantic versioning.

### unreleased
- [changed] Removed `feature(i128_type)` when running with the `i128` feature. Kept the feature flag
for typenum to maintain compatibility with old Rust versions.
- [added] Integer `sqrt` to the `op!` macro.
- [added] Integer square root operator `SquareRoot` with alias `Sqrt`.

Expand Down
14 changes: 9 additions & 5 deletions build/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::env;
use std::fmt;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::fmt;

mod op;
#[cfg(tests)]
mod tests;
mod op;

pub enum UIntCode {
Term,
Expand Down Expand Up @@ -67,9 +67,13 @@ pub fn gen_int(i: i64) -> IntCode {
}
}

#[cfg_attr(feature="no_std", deprecated(
since="1.3.0",
note="the `no_std` flag is no longer necessary and will be removed in the future"))]
#[cfg_attr(
feature = "no_std",
deprecated(
since = "1.3.0",
note = "the `no_std` flag is no longer necessary and will be removed in the future"
)
)]
pub fn no_std() {}

// fixme: get a warning when testing without this
Expand Down
3 changes: 2 additions & 1 deletion build/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ macro_rules! op {{
for o1 in ops.iter().filter(|op| op.op_type == Operator) {
// If top of stack is operator o2 with o1.precedence <= o2.precedence,
// Then pop o2 off stack onto queue:
for o2 in ops.iter()
for o2 in ops
.iter()
.filter(|op| op.op_type == Operator)
.filter(|o2| o1.precedence <= o2.precedence)
{
Expand Down
20 changes: 8 additions & 12 deletions src/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,14 @@ mod tests {
// macro for testing operation results. Uses `Same` to ensure the types are equal and
// not just the values they evaluate to.
macro_rules! test_bit_op {
($op:ident $Lhs:ident = $Answer:ident) => (
{
type Test = <<$Lhs as $op>::Output as ::Same<$Answer>>::Output;
assert_eq!(<$Answer as Bit>::to_u8(), <Test as Bit>::to_u8());
}
);
($Lhs:ident $op:ident $Rhs:ident = $Answer:ident) => (
{
type Test = <<$Lhs as $op<$Rhs>>::Output as ::Same<$Answer>>::Output;
assert_eq!(<$Answer as Bit>::to_u8(), <Test as Bit>::to_u8());
}
);
($op:ident $Lhs:ident = $Answer:ident) => {{
type Test = <<$Lhs as $op>::Output as ::Same<$Answer>>::Output;
assert_eq!(<$Answer as Bit>::to_u8(), <Test as Bit>::to_u8());
}};
($Lhs:ident $op:ident $Rhs:ident = $Answer:ident) => {{
type Test = <<$Lhs as $op<$Rhs>>::Output as ::Same<$Answer>>::Output;
assert_eq!(<$Answer as Bit>::to_u8(), <Test as Bit>::to_u8());
}};
}

#[test]
Expand Down
55 changes: 31 additions & 24 deletions src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
//! ```
//!

use core::ops::{Add, Div, Mul, Neg, Rem, Sub};
use core::marker::PhantomData;
use core::ops::{Add, Div, Mul, Neg, Rem, Sub};

use {Cmp, Equal, Greater, Less, NonZero, Pow, PowerOfTwo};
use uint::{UInt, Unsigned};
use bit::{B0, B1, Bit};
use private::{PrivateDivInt, PrivateIntegerAdd, PrivateRem};
use consts::{N1, P1, U0, U1};
use private::{PrivateDivInt, PrivateIntegerAdd, PrivateRem};
use uint::{UInt, Unsigned};
use {Cmp, Equal, Greater, Less, NonZero, Pow, PowerOfTwo};

pub use marker_traits::Integer;

Expand Down Expand Up @@ -496,37 +496,41 @@ impl<I: Integer + NonZero> Div<I> for Z0 {
}

macro_rules! impl_int_div {
($A:ident, $B:ident, $R:ident) => (
($A:ident, $B:ident, $R:ident) => {
/// `$A<Ul> / $B<Ur> = $R<Ul / Ur>`
impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Div<$B<Ur>> for $A<Ul>
where Ul: Cmp<Ur>,
$A<Ul>: PrivateDivInt<<Ul as Cmp<Ur>>::Output, $B<Ur>>
where
Ul: Cmp<Ur>,
$A<Ul>: PrivateDivInt<<Ul as Cmp<Ur>>::Output, $B<Ur>>,
{
type Output = <$A<Ul> as PrivateDivInt<
<Ul as Cmp<Ur>>::Output,
$B<Ur>>>::Output;
type Output = <$A<Ul> as PrivateDivInt<<Ul as Cmp<Ur>>::Output, $B<Ur>>>::Output;
fn div(self, _: $B<Ur>) -> Self::Output {
unsafe { ::core::mem::uninitialized() }
}
}
impl<Ul, Ur> PrivateDivInt<Less, $B<Ur>> for $A<Ul>
where Ul: Unsigned + NonZero, Ur: Unsigned + NonZero,
where
Ul: Unsigned + NonZero,
Ur: Unsigned + NonZero,
{
type Output = Z0;
}
impl<Ul, Ur> PrivateDivInt<Equal, $B<Ur>> for $A<Ul>
where Ul: Unsigned + NonZero, Ur: Unsigned + NonZero,
where
Ul: Unsigned + NonZero,
Ur: Unsigned + NonZero,
{
type Output = $R<U1>;
}
impl<Ul, Ur> PrivateDivInt<Greater, $B<Ur>> for $A<Ul>
where Ul: Unsigned + NonZero + Div<Ur>,
Ur: Unsigned + NonZero,
<Ul as Div<Ur>>::Output: Unsigned + NonZero,
where
Ul: Unsigned + NonZero + Div<Ur>,
Ur: Unsigned + NonZero,
<Ul as Div<Ur>>::Output: Unsigned + NonZero,
{
type Output = $R<<Ul as Div<Ur>>::Output>;
}
);
};
}

impl_int_div!(PInt, PInt, PInt);
Expand Down Expand Up @@ -609,15 +613,14 @@ impl<I: Integer + NonZero> Rem<I> for Z0 {
}

macro_rules! impl_int_rem {
($A:ident, $B:ident, $R:ident) => (
($A:ident, $B:ident, $R:ident) => {
/// `$A<Ul> % $B<Ur> = $R<Ul % Ur>`
impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Rem<$B<Ur>> for $A<Ul>
where Ul: Rem<Ur>,
$A<Ul>: PrivateRem<<Ul as Rem<Ur>>::Output, $B<Ur>>
where
Ul: Rem<Ur>,
$A<Ul>: PrivateRem<<Ul as Rem<Ur>>::Output, $B<Ur>>,
{
type Output = <$A<Ul> as PrivateRem<
<Ul as Rem<Ur>>::Output,
$B<Ur>>>::Output;
type Output = <$A<Ul> as PrivateRem<<Ul as Rem<Ur>>::Output, $B<Ur>>>::Output;
fn rem(self, _: $B<Ur>) -> Self::Output {
unsafe { ::core::mem::uninitialized() }
}
Expand All @@ -626,11 +629,15 @@ macro_rules! impl_int_rem {
type Output = Z0;
}
impl<Ul, Ur, U, B> PrivateRem<UInt<U, B>, $B<Ur>> for $A<Ul>
where Ul: Unsigned + NonZero, Ur: Unsigned + NonZero, U: Unsigned, B: Bit,
where
Ul: Unsigned + NonZero,
Ur: Unsigned + NonZero,
U: Unsigned,
B: Bit,
{
type Output = $R<UInt<U, B>>;
}
);
};
}

impl_int_rem!(PInt, PInt, PInt);
Expand Down
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@

#![no_std]
#![warn(missing_docs)]
#![cfg_attr(feature = "i128", feature(i128_type))]
#![cfg_attr(feature = "strict", deny(missing_docs))]
#![cfg_attr(feature = "strict", deny(warnings))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy))]
#![cfg_attr(feature = "cargo-clippy",
allow(type_complexity, len_without_is_empty, new_without_default_derive))]
#![cfg_attr(
feature = "cargo-clippy",
allow(type_complexity, len_without_is_empty, new_without_default_derive)
)]

// For debugging macros:
// #![feature(trace_macros)]
Expand All @@ -61,23 +62,23 @@ use core::cmp::Ordering;
include!(concat!(env!("OUT_DIR"), "/consts.rs"));
include!(concat!(env!("OUT_DIR"), "/op.rs"));
pub mod bit;
pub mod uint;
pub mod int;
pub mod private;
pub mod marker_traits;
pub mod type_operators;
pub mod operator_aliases;
pub mod private;
pub mod type_operators;
pub mod uint;

pub mod array;

pub use consts::*;
pub use marker_traits::*;
pub use type_operators::*;
pub use operator_aliases::*;
pub use type_operators::*;

pub use uint::{UInt, UTerm};
pub use int::{NInt, PInt};
pub use array::{ATerm, TArr};
pub use int::{NInt, PInt};
pub use uint::{UInt, UTerm};

/// A potential output from `Cmp`, this is the type equivalent to the enum variant
/// `core::cmp::Ordering::Greater`.
Expand Down Expand Up @@ -121,15 +122,15 @@ impl Ord for Equal {
/// Asserts that two types are the same.
#[macro_export]
macro_rules! assert_type_eq {
($a:ty, $b:ty) => (
($a:ty, $b:ty) => {
let _: <$a as $crate::Same<$b>>::Output;
);
};
}

/// Asserts that a type is `True`, aka `B1`.
#[macro_export]
macro_rules! assert_type {
($a:ty) => (
($a:ty) => {
let _: <$a as $crate::Same<True>>::Output;
);
};
}
Loading

0 comments on commit 1f4bfb3

Please sign in to comment.