Skip to content

Commit 89fcc00

Browse files
committed
librustc_const_eval: use bug!(), span_bug!()
1 parent c59ea49 commit 89fcc00

File tree

3 files changed

+43
-46
lines changed

3 files changed

+43
-46
lines changed

src/librustc_const_eval/check_match.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -339,20 +339,20 @@ fn check_arms(cx: &MatchCheckCtxt,
339339
// `Some(<head>)` and `None`. It's impossible to have an unreachable
340340
// pattern
341341
// (see libsyntax/ext/expand.rs for the full expansion of a for loop)
342-
cx.tcx.sess.span_bug(pat.span, "unreachable for-loop pattern")
342+
span_bug!(pat.span, "unreachable for-loop pattern")
343343
},
344344

345345
hir::MatchSource::Normal => {
346346
span_err!(cx.tcx.sess, pat.span, E0001, "unreachable pattern")
347347
},
348348

349349
hir::MatchSource::TryDesugar => {
350-
cx.tcx.sess.span_bug(pat.span, "unreachable try pattern")
350+
span_bug!(pat.span, "unreachable try pattern")
351351
},
352352
}
353353
}
354354
Useful => (),
355-
UsefulWithWitness(_) => unreachable!()
355+
UsefulWithWitness(_) => bug!()
356356
}
357357
if guard.is_none() {
358358
let Matrix(mut rows) = seen;
@@ -384,9 +384,9 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
384384
let witness = match witnesses[0].node {
385385
PatKind::TupleStruct(_, Some(ref pats)) => match &pats[..] {
386386
[ref pat] => &**pat,
387-
_ => unreachable!(),
387+
_ => bug!(),
388388
},
389-
_ => unreachable!(),
389+
_ => bug!(),
390390
};
391391
span_err!(cx.tcx.sess, sp, E0297,
392392
"refutable pattern in `for` loop binding: \
@@ -399,7 +399,7 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
399399
}).collect();
400400
const LIMIT: usize = 3;
401401
let joined_patterns = match pattern_strings.len() {
402-
0 => unreachable!(),
402+
0 => bug!(),
403403
1 => format!("`{}`", pattern_strings[0]),
404404
2...LIMIT => {
405405
let (tail, head) = pattern_strings.split_last().unwrap();
@@ -420,14 +420,14 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
420420
NotUseful => {
421421
// This is good, wildcard pattern isn't reachable
422422
},
423-
_ => unreachable!()
423+
_ => bug!()
424424
}
425425
}
426426

427427
fn const_val_to_expr(value: &ConstVal) -> P<hir::Expr> {
428428
let node = match value {
429429
&ConstVal::Bool(b) => ast::LitKind::Bool(b),
430-
_ => unreachable!()
430+
_ => bug!()
431431
};
432432
P(hir::Expr {
433433
id: 0,
@@ -579,14 +579,14 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
579579
assert_eq!(pats_len, n);
580580
PatKind::Vec(pats.collect(), None, hir::HirVec::new())
581581
},
582-
_ => unreachable!()
582+
_ => bug!()
583583
},
584584
ty::TySlice(_) => match ctor {
585585
&Slice(n) => {
586586
assert_eq!(pats_len, n);
587587
PatKind::Vec(pats.collect(), None, hir::HirVec::new())
588588
},
589-
_ => unreachable!()
589+
_ => bug!()
590590
},
591591
ty::TyStr => PatKind::Wild,
592592

@@ -791,17 +791,16 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
791791
PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..) | PatKind::Ident(..) =>
792792
match cx.tcx.def_map.borrow().get(&pat.id).unwrap().full_def() {
793793
Def::Const(..) | Def::AssociatedConst(..) =>
794-
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
795-
been rewritten"),
794+
span_bug!(pat.span, "const pattern should've \
795+
been rewritten"),
796796
Def::Struct(..) | Def::TyAlias(..) => vec![Single],
797797
Def::Variant(_, id) => vec![Variant(id)],
798798
Def::Local(..) => vec![],
799-
def => cx.tcx.sess.span_bug(pat.span, &format!("pat_constructors: unexpected \
800-
definition {:?}", def)),
799+
def => span_bug!(pat.span, "pat_constructors: unexpected \
800+
definition {:?}", def),
801801
},
802802
PatKind::QPath(..) =>
803-
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
804-
been rewritten"),
803+
span_bug!(pat.span, "const pattern should've been rewritten"),
805804
PatKind::Lit(ref expr) =>
806805
vec!(ConstantValue(eval_const_expr(cx.tcx, &expr))),
807806
PatKind::Range(ref lo, ref hi) =>
@@ -837,7 +836,7 @@ pub fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> us
837836
ty::TySlice(_) => match *ctor {
838837
Slice(length) => length,
839838
ConstantValue(_) => 0,
840-
_ => unreachable!()
839+
_ => bug!()
841840
},
842841
ty::TyStr => 0,
843842
_ => 1
@@ -856,7 +855,7 @@ fn range_covered_by_constructor(ctor: &Constructor,
856855
ConstantValue(ref value) => (value, value),
857856
ConstantRange(ref from, ref to) => (from, to),
858857
Single => return Some(true),
859-
_ => unreachable!()
858+
_ => bug!()
860859
};
861860
let cmp_from = compare_const_vals(c_from, from);
862861
let cmp_to = compare_const_vals(c_to, to);
@@ -889,22 +888,22 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
889888
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
890889
match def {
891890
Def::Const(..) | Def::AssociatedConst(..) =>
892-
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
893-
been rewritten"),
891+
span_bug!(pat_span, "const pattern should've \
892+
been rewritten"),
894893
Def::Variant(_, id) if *constructor != Variant(id) => None,
895894
Def::Variant(..) | Def::Struct(..) => Some(Vec::new()),
896895
Def::Local(..) => Some(vec![DUMMY_WILD_PAT; arity]),
897-
_ => cx.tcx.sess.span_bug(pat_span, &format!("specialize: unexpected \
898-
definition {:?}", def)),
896+
_ => span_bug!(pat_span, "specialize: unexpected \
897+
definition {:?}", def),
899898
}
900899
}
901900

902901
PatKind::TupleStruct(_, ref args) => {
903902
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
904903
match def {
905904
Def::Const(..) | Def::AssociatedConst(..) =>
906-
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
907-
been rewritten"),
905+
span_bug!(pat_span, "const pattern should've \
906+
been rewritten"),
908907
Def::Variant(_, id) if *constructor != Variant(id) => None,
909908
Def::Variant(..) | Def::Struct(..) => {
910909
Some(match args {
@@ -917,8 +916,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
917916
}
918917

919918
PatKind::QPath(_, _) => {
920-
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
921-
been rewritten")
919+
span_bug!(pat_span, "const pattern should've been rewritten")
922920
}
923921

924922
PatKind::Struct(_, ref pattern_fields, _) => {
@@ -1062,7 +1060,7 @@ fn is_refutable<A, F>(cx: &MatchCheckCtxt, pat: &Pat, refutable: F) -> Option<A>
10621060
match is_useful(cx, &pats, &[DUMMY_WILD_PAT], ConstructWitness) {
10631061
UsefulWithWitness(pats) => Some(refutable(&pats[0])),
10641062
NotUseful => None,
1065-
Useful => unreachable!()
1063+
Useful => bug!()
10661064
}
10671065
}
10681066

@@ -1119,12 +1117,11 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
11191117
PatKind::Ident(hir::BindByRef(_), _, _) => {
11201118
}
11211119
_ => {
1122-
cx.tcx.sess.span_bug(
1120+
span_bug!(
11231121
p.span,
1124-
&format!("binding pattern {} is not an \
1125-
identifier: {:?}",
1126-
p.id,
1127-
p.node));
1122+
"binding pattern {} is not an identifier: {:?}",
1123+
p.id,
1124+
p.node);
11281125
}
11291126
}
11301127
}

src/librustc_const_eval/eval.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub fn const_expr_to_pat(tcx: &ty::TyCtxt, expr: &Expr, pat_id: ast::NodeId, spa
286286
node: PatKind::Lit(P(expr.clone())),
287287
span: span,
288288
})),
289-
_ => unreachable!()
289+
_ => bug!()
290290
};
291291
let pats = try!(args.iter()
292292
.map(|expr| const_expr_to_pat(tcx, &**expr,
@@ -330,7 +330,7 @@ pub fn const_expr_to_pat(tcx: &ty::TyCtxt, expr: &Expr, pat_id: ast::NodeId, spa
330330
let (expr, _ty) = lookup_const_by_id(tcx, def_id, substs).unwrap();
331331
return const_expr_to_pat(tcx, expr, pat_id, span);
332332
},
333-
_ => unreachable!(),
333+
_ => bug!(),
334334
}
335335
}
336336

@@ -588,7 +588,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
588588
IntTy::I64 => if n == I64_OVERFLOW {
589589
return Ok(Integral(Isize(Is64(::std::i64::MIN))));
590590
},
591-
_ => unreachable!(),
591+
_ => bug!(),
592592
}
593593
},
594594
_ => {},
@@ -697,7 +697,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
697697
Some(IntType::UnsignedInt(ty)) => ty_hint.checked_or(tcx.mk_mach_uint(ty)),
698698
Some(IntType::SignedInt(ty)) => ty_hint.checked_or(tcx.mk_mach_int(ty)),
699699
// we had a type hint, so we can't have an unknown type
700-
None => unreachable!(),
700+
None => bug!(),
701701
};
702702
eval_const_expr_partial(tcx, &base, hint, fn_args)?
703703
},
@@ -798,7 +798,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
798798
hir::ExprBlock(ref block) => {
799799
match block.expr {
800800
Some(ref expr) => eval_const_expr_partial(tcx, &expr, ty_hint, fn_args)?,
801-
None => unreachable!(),
801+
None => bug!(),
802802
}
803803
}
804804
hir::ExprType(ref e, _) => eval_const_expr_partial(tcx, &e, ty_hint, fn_args)?,
@@ -813,7 +813,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
813813
let idx_hint = ty_hint.checked_or(tcx.types.usize);
814814
let idx = match eval_const_expr_partial(tcx, idx, idx_hint, fn_args)? {
815815
Integral(Usize(i)) => i.as_u64(tcx.sess.target.uint_type),
816-
Integral(_) => unreachable!(),
816+
Integral(_) => bug!(),
817817
_ => signal!(idx, IndexNotInt),
818818
};
819819
assert_eq!(idx as usize as u64, idx);
@@ -823,7 +823,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
823823
assert_eq!(n as usize as u64, n);
824824
eval_const_expr_partial(tcx, &v[idx as usize], ty_hint, fn_args)?
825825
} else {
826-
unreachable!()
826+
bug!()
827827
},
828828

829829
Repeat(_, n) if idx >= n => signal!(e, IndexOutOfBounds),
@@ -840,7 +840,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
840840
},
841841

842842
Str(ref s) if idx as usize >= s.len() => signal!(e, IndexOutOfBounds),
843-
Str(_) => unimplemented!(), // FIXME: return a const char
843+
Str(_) => bug!("unimplemented"), // FIXME: return a const char
844844
_ => signal!(e, IndexedNonVec),
845845
}
846846
}
@@ -867,7 +867,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
867867
signal!(e, TupleIndexOutOfBounds);
868868
}
869869
} else {
870-
unreachable!()
870+
bug!()
871871
}
872872
} else {
873873
signal!(base, ExpectedConstTuple);
@@ -888,7 +888,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
888888
signal!(e, MissingStructField);
889889
}
890890
} else {
891-
unreachable!()
891+
bug!()
892892
}
893893
} else {
894894
signal!(base, ExpectedConstStruct);
@@ -1025,7 +1025,7 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: &'a TyCtxt<'tcx>,
10251025
}
10261026
}
10271027
_ => {
1028-
tcx.sess.span_bug(
1028+
span_bug!(
10291029
ti.span,
10301030
"resolve_trait_associated_const: unexpected vtable type")
10311031
}
@@ -1127,7 +1127,7 @@ fn lit_to_const<'tcx>(lit: &ast::LitKind,
11271127
let int_ty = tcx.enum_repr_type(hints.iter().next());
11281128
infer(Infer(n), tcx, &int_ty.to_ty(tcx).sty, span).map(Integral)
11291129
},
1130-
Some(ty_hint) => panic!("bad ty_hint: {:?}, {:?}", ty_hint, lit),
1130+
Some(ty_hint) => bug!("bad ty_hint: {:?}, {:?}", ty_hint, lit),
11311131
}
11321132
},
11331133
LitKind::Int(n, Unsigned(ity)) => {
@@ -1140,7 +1140,7 @@ fn lit_to_const<'tcx>(lit: &ast::LitKind,
11401140
Ok(Float(x))
11411141
} else {
11421142
// FIXME(#31407) this is only necessary because float parsing is buggy
1143-
tcx.sess.span_bug(span, "could not evaluate float literal (see issue #31407)");
1143+
span_bug!(span, "could not evaluate float literal (see issue #31407)");
11441144
}
11451145
}
11461146
LitKind::Bool(b) => Ok(Bool(b)),

src/librustc_const_eval/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#[macro_use] extern crate syntax;
3434
#[macro_use] extern crate log;
35-
extern crate rustc;
35+
#[macro_use] extern crate rustc;
3636
extern crate rustc_front;
3737
extern crate rustc_back;
3838
extern crate rustc_const_math;

0 commit comments

Comments
 (0)