]> git.proxmox.com Git - rustc.git/blob - src/librustc_const_math/err.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc_const_math / err.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use syntax::ast;
12
13 #[derive(Debug, PartialEq, Eq, Clone)]
14 pub enum ConstMathErr {
15 NotInRange,
16 CmpBetweenUnequalTypes,
17 UnequalTypes(Op),
18 Overflow(Op),
19 ShiftNegative,
20 DivisionByZero,
21 RemainderByZero,
22 UnsignedNegation,
23 ULitOutOfRange(ast::UintTy),
24 LitOutOfRange(ast::IntTy),
25 }
26 pub use self::ConstMathErr::*;
27
28 #[derive(Debug, PartialEq, Eq, Clone)]
29 pub enum Op {
30 Add,
31 Sub,
32 Mul,
33 Div,
34 Rem,
35 Shr,
36 Shl,
37 Neg,
38 BitAnd,
39 BitOr,
40 BitXor,
41 }
42
43 impl ConstMathErr {
44 pub fn description(&self) -> &'static str {
45 use self::Op::*;
46 match *self {
47 NotInRange => "inferred value out of range",
48 CmpBetweenUnequalTypes => "compared two integrals of different types",
49 UnequalTypes(Add) => "tried to add two integrals of different types",
50 UnequalTypes(Sub) => "tried to subtract two integrals of different types",
51 UnequalTypes(Mul) => "tried to multiply two integrals of different types",
52 UnequalTypes(Div) => "tried to divide two integrals of different types",
53 UnequalTypes(Rem) => {
54 "tried to calculate the remainder of two integrals of different types"
55 },
56 UnequalTypes(BitAnd) => "tried to bitand two integrals of different types",
57 UnequalTypes(BitOr) => "tried to bitor two integrals of different types",
58 UnequalTypes(BitXor) => "tried to xor two integrals of different types",
59 UnequalTypes(_) => unreachable!(),
60 Overflow(Add) => "attempted to add with overflow",
61 Overflow(Sub) => "attempted to subtract with overflow",
62 Overflow(Mul) => "attempted to multiply with overflow",
63 Overflow(Div) => "attempted to divide with overflow",
64 Overflow(Rem) => "attempted to calculate the remainder with overflow",
65 Overflow(Neg) => "attempted to negate with overflow",
66 Overflow(Shr) => "attempted to shift right with overflow",
67 Overflow(Shl) => "attempted to shift left with overflow",
68 Overflow(_) => unreachable!(),
69 ShiftNegative => "attempted to shift by a negative amount",
70 DivisionByZero => "attempted to divide by zero",
71 RemainderByZero => "attempted to calculate the remainder with a divisor of zero",
72 UnsignedNegation => "unary negation of unsigned integer",
73 ULitOutOfRange(ast::UintTy::U8) => "literal out of range for u8",
74 ULitOutOfRange(ast::UintTy::U16) => "literal out of range for u16",
75 ULitOutOfRange(ast::UintTy::U32) => "literal out of range for u32",
76 ULitOutOfRange(ast::UintTy::U64) => "literal out of range for u64",
77 ULitOutOfRange(ast::UintTy::Us) => "literal out of range for usize",
78 LitOutOfRange(ast::IntTy::I8) => "literal out of range for i8",
79 LitOutOfRange(ast::IntTy::I16) => "literal out of range for i16",
80 LitOutOfRange(ast::IntTy::I32) => "literal out of range for i32",
81 LitOutOfRange(ast::IntTy::I64) => "literal out of range for i64",
82 LitOutOfRange(ast::IntTy::Is) => "literal out of range for isize",
83 }
84 }
85 }