1
Fork 0

Remove the UnequalTypes error variant

This commit is contained in:
Oliver Schneider 2018-04-24 14:55:34 +02:00 committed by Oliver Schneider
parent 7d982fdcf4
commit 0aa6e039d0
No known key found for this signature in database
GPG key ID: 1D5CB4FC597C3004
3 changed files with 4 additions and 19 deletions

View file

@ -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,

View file

@ -10,7 +10,6 @@
#[derive(Debug, PartialEq, Eq, Clone, RustcEncodable, RustcDecodable)]
pub enum ConstMathErr {
UnequalTypes(Op),
Overflow(Op),
DivisionByZero,
RemainderByZero,
@ -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",

View file

@ -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
@ -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);
@ -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 })
}
}
}