Skip to content

Commit a85d920

Browse files
Oliver 'ker' Schneideroli-obk
Oliver 'ker' Schneider
authored andcommitted
---
yaml --- r: 273118 b: refs/heads/beta c: 0d13231 h: refs/heads/master
1 parent 930c649 commit a85d920

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 7bde56e14941924c17daeaa1996d61d0ffdb6bd1
26+
refs/heads/beta: 0d13231a4cfb1f24c7cfc8168d15d19c63bdbdba
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/middle/const_eval.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ pub enum ConstVal {
267267
Array(ast::NodeId, u64),
268268
Repeat(ast::NodeId, u64),
269269
Char(char),
270+
/// A value that only occurs in case `eval_const_expr` reported an error. You should never
271+
/// handle this case. Its sole purpose is to allow more errors to be reported instead of
272+
/// causing a fatal error.
273+
Dummy,
270274
}
271275

272276
impl hash::Hash for ConstVal {
@@ -283,6 +287,7 @@ impl hash::Hash for ConstVal {
283287
Array(a, n) => { a.hash(state); n.hash(state) },
284288
Repeat(a, n) => { a.hash(state); n.hash(state) },
285289
Char(c) => c.hash(state),
290+
Dummy => ().hash(state),
286291
}
287292
}
288293
}
@@ -305,6 +310,7 @@ impl PartialEq for ConstVal {
305310
(&Array(a, an), &Array(b, bn)) => (a == b) && (an == bn),
306311
(&Repeat(a, an), &Repeat(b, bn)) => (a == b) && (an == bn),
307312
(&Char(a), &Char(b)) => a == b,
313+
(&Dummy, &Dummy) => true, // FIXME: should this be false?
308314
_ => false,
309315
}
310316
}
@@ -326,6 +332,7 @@ impl ConstVal {
326332
Array(..) => "array",
327333
Repeat(..) => "repeat",
328334
Char(..) => "char",
335+
Dummy => "dummy value",
329336
}
330337
}
331338
}
@@ -393,7 +400,12 @@ pub fn const_expr_to_pat(tcx: &TyCtxt, expr: &Expr, span: Span) -> P<hir::Pat> {
393400
pub fn eval_const_expr(tcx: &TyCtxt, e: &Expr) -> ConstVal {
394401
match eval_const_expr_partial(tcx, e, ExprTypeChecked, None) {
395402
Ok(r) => r,
396-
Err(s) => tcx.sess.span_fatal(s.span, &s.description())
403+
// non-const path still needs to be a fatal error, because enums are funky
404+
Err(ref s) if s.kind == NonConstPath => tcx.sess.span_fatal(s.span, &s.description()),
405+
Err(s) => {
406+
tcx.sess.span_err(s.span, &s.description());
407+
Dummy
408+
},
397409
}
398410
}
399411

@@ -405,7 +417,7 @@ pub struct ConstEvalErr {
405417
pub kind: ErrKind,
406418
}
407419

408-
#[derive(Clone)]
420+
#[derive(Clone, PartialEq)]
409421
pub enum ErrKind {
410422
CannotCast,
411423
CannotCastTo(&'static str),

branches/beta/src/librustc/middle/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ impl<'tcx, 'container> AdtDefData<'tcx, 'container> {
15461546
/// Asserts this is a struct and returns the struct's unique
15471547
/// variant.
15481548
pub fn struct_variant(&self) -> &VariantDefData<'tcx, 'container> {
1549-
assert!(self.adt_kind() == AdtKind::Struct);
1549+
assert_eq!(self.adt_kind(), AdtKind::Struct);
15501550
&self.variants[0]
15511551
}
15521552

branches/beta/src/librustc_trans/trans/mir/constant.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
9393
})
9494
},
9595
ConstVal::Char(c) => C_integral(Type::char(ccx), c as u64, false),
96+
ConstVal::Dummy => unreachable!(),
9697
ConstVal::Function(_) => C_nil(ccx)
9798
}
9899
}

0 commit comments

Comments
 (0)