Skip to content

Commit

Permalink
rustc: remove obsolete const_val::ErrKind::{Negate,Not}On.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Sep 11, 2017
1 parent 8a9b78f commit 8821761
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
24 changes: 0 additions & 24 deletions src/librustc/middle/const_val.rs
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use self::ConstVal::*;
use self::ConstAggregate::*;
pub use rustc_const_math::ConstInt;

use hir;
Expand Down Expand Up @@ -73,23 +71,6 @@ impl<'tcx> Decodable for ConstAggregate<'tcx> {
}

impl<'tcx> ConstVal<'tcx> {
pub fn description(&self) -> &'static str {
match *self {
Float(f) => f.description(),
Integral(i) => i.description(),
Str(_) => "string literal",
ByteStr(_) => "byte string literal",
Bool(_) => "boolean",
Char(..) => "char",
Variant(_) => "enum variant",
Aggregate(Struct(_)) => "struct",
Aggregate(Tuple(_)) => "tuple",
Function(..) => "function definition",
Aggregate(Array(..)) => "array",
Aggregate(Repeat(..)) => "repeat",
}
}

pub fn to_const_int(&self) -> Option<ConstInt> {
match *self {
ConstVal::Integral(i) => Some(i),
Expand All @@ -110,8 +91,6 @@ pub struct ConstEvalErr<'tcx> {
pub enum ErrKind<'tcx> {
CannotCast,
MissingStructField,
NegateOn(ConstVal<'tcx>),
NotOn(ConstVal<'tcx>),

NonConstPath,
UnimplementedConstVal(&'static str),
Expand Down Expand Up @@ -170,9 +149,6 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {

match self.kind {
CannotCast => simple!("can't cast this type"),
NegateOn(ref const_val) => simple!("negate on {}", const_val.description()),
NotOn(ref const_val) => simple!("not on {}", const_val.description()),

MissingStructField => simple!("nonexistent struct field"),
NonConstPath => simple!("non-constant path in constant expression"),
UnimplementedConstVal(what) =>
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_const_eval/diagnostics.rs
Expand Up @@ -565,7 +565,7 @@ See also https://github.com/rust-lang/rust/issues/14587


register_diagnostics! {
E0298, // cannot compare constants
// E0298, // cannot compare constants
// E0299, // mismatched types between arms
// E0471, // constant evaluation error (in pattern)
}
10 changes: 4 additions & 6 deletions src/librustc_const_eval/eval.rs
Expand Up @@ -186,14 +186,14 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
mk_const(match cx.eval(inner)?.val {
Float(f) => Float(-f),
Integral(i) => Integral(math!(e, -i)),
const_val => signal!(e, NegateOn(const_val)),
_ => signal!(e, TypeckError)
})
}
hir::ExprUnary(hir::UnNot, ref inner) => {
mk_const(match cx.eval(inner)?.val {
Integral(i) => Integral(math!(e, !i)),
Bool(b) => Bool(!b),
const_val => signal!(e, NotOn(const_val)),
_ => signal!(e, TypeckError)
})
}
hir::ExprUnary(hir::UnDeref, _) => signal!(e, UnimplementedConstVal("deref operation")),
Expand Down Expand Up @@ -734,10 +734,8 @@ pub fn compare_const_vals(tcx: TyCtxt, span: Span, a: &ConstVal, b: &ConstVal)
Some(result) => Ok(result),
None => {
// FIXME: can this ever be reached?
span_err!(tcx.sess, span, E0298,
"type mismatch comparing {} and {}",
a.description(),
b.description());
tcx.sess.delay_span_bug(span,
&format!("type mismatch comparing {:?} and {:?}", a, b));
Err(ErrorReported)
}
}
Expand Down

0 comments on commit 8821761

Please sign in to comment.