Skip to content

Commit

Permalink
Remove the UnequalTypes error variant
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 30, 2018
1 parent 7d982fd commit 0aa6e03
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/librustc/ich/impls_const_math.rs
Expand Up @@ -17,7 +17,6 @@ impl_stable_hash_for!(struct ::rustc_const_math::ConstFloat {
});

impl_stable_hash_for!(enum ::rustc_const_math::ConstMathErr {
UnequalTypes(op),
Overflow(op),
DivisionByZero,
RemainderByZero,
Expand Down
12 changes: 0 additions & 12 deletions src/librustc_const_math/err.rs
Expand Up @@ -10,7 +10,6 @@

#[derive(Debug, PartialEq, Eq, Clone, RustcEncodable, RustcDecodable)]
pub enum ConstMathErr {
UnequalTypes(Op),
Overflow(Op),
DivisionByZero,
RemainderByZero,
Expand All @@ -36,17 +35,6 @@ impl ConstMathErr {
pub fn description(&self) -> &'static str {
use self::Op::*;
match *self {
UnequalTypes(Add) => "tried to add two values of different types",
UnequalTypes(Sub) => "tried to subtract two values of different types",
UnequalTypes(Mul) => "tried to multiply two values of different types",
UnequalTypes(Div) => "tried to divide two values of different types",
UnequalTypes(Rem) => {
"tried to calculate the remainder of two values of different types"
},
UnequalTypes(BitAnd) => "tried to bitand two values of different types",
UnequalTypes(BitOr) => "tried to bitor two values of different types",
UnequalTypes(BitXor) => "tried to xor two values of different types",
UnequalTypes(_) => unreachable!(),
Overflow(Add) => "attempt to add with overflow",
Overflow(Sub) => "attempt to subtract with overflow",
Overflow(Mul) => "attempt to multiply with overflow",
Expand Down
10 changes: 4 additions & 6 deletions src/librustc_const_math/float.rs
Expand Up @@ -16,8 +16,6 @@ use syntax::ast;
use rustc_apfloat::{Float, FloatConvert, Status};
use rustc_apfloat::ieee::{Single, Double};

use super::err::*;

// Note that equality for `ConstFloat` means that the it is the same
// constant, not that the rust values are equal. In particular, `NaN
// == NaN` (at least if it's the same NaN; distinct encodings for NaN
Expand Down Expand Up @@ -172,8 +170,8 @@ impl ::std::fmt::Debug for ConstFloat {
macro_rules! derive_binop {
($op:ident, $func:ident) => {
impl ::std::ops::$op for ConstFloat {
type Output = Result<Self, ConstMathErr>;
fn $func(self, rhs: Self) -> Result<Self, ConstMathErr> {
type Output = Option<Self>;
fn $func(self, rhs: Self) -> Option<Self> {
let bits = match (self.ty, rhs.ty) {
(ast::FloatTy::F32, ast::FloatTy::F32) =>{
let a = Single::from_bits(self.bits);
Expand All @@ -185,9 +183,9 @@ macro_rules! derive_binop {
let b = Double::from_bits(rhs.bits);
a.$func(b).value.to_bits()
}
_ => return Err(UnequalTypes(Op::$op)),
_ => return None,
};
Ok(ConstFloat { bits, ty: self.ty })
Some(ConstFloat { bits, ty: self.ty })
}
}
}
Expand Down

0 comments on commit 0aa6e03

Please sign in to comment.