librustc_mir: use bug!(), span_bug!()
This commit is contained in:
parent
cc8159b0ed
commit
8aaf6eee2f
@ -33,9 +33,10 @@ fn expr_as_constant(&mut self, expr: Expr<'tcx>) -> Constant<'tcx> {
|
||||
ExprKind::Literal { literal } =>
|
||||
Constant { span: span, ty: ty, literal: literal },
|
||||
_ =>
|
||||
this.hir.span_bug(
|
||||
span_bug!(
|
||||
span,
|
||||
&format!("expression is not a valid constant {:?}", kind)),
|
||||
"expression is not a valid constant {:?}",
|
||||
kind),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ fn expr_as_temp(&mut self, mut block: BasicBlock, expr: Expr<'tcx>) -> BlockAnd<
|
||||
let temp_lifetime = match expr.temp_lifetime {
|
||||
Some(t) => t,
|
||||
None => {
|
||||
this.hir.span_bug(expr.span, "no temp_lifetime for expr");
|
||||
span_bug!(expr.span, "no temp_lifetime for expr");
|
||||
}
|
||||
};
|
||||
this.schedule_drop(expr.span, temp_lifetime, &temp, expr_ty);
|
||||
|
@ -162,10 +162,10 @@ pub fn lvalue_into_pattern(&mut self,
|
||||
unpack!(block = self.simplify_candidate(block, &mut candidate));
|
||||
|
||||
if !candidate.match_pairs.is_empty() {
|
||||
self.hir.span_bug(candidate.match_pairs[0].pattern.span,
|
||||
&format!("match pairs {:?} remaining after simplifying \
|
||||
irrefutable pattern",
|
||||
candidate.match_pairs));
|
||||
span_bug!(candidate.match_pairs[0].pattern.span,
|
||||
"match pairs {:?} remaining after simplifying \
|
||||
irrefutable pattern",
|
||||
candidate.match_pairs);
|
||||
}
|
||||
|
||||
// now apply the bindings, which will also declare the variables
|
||||
|
@ -521,8 +521,9 @@ fn candidate_after_variant_switch<'pat>(&mut self,
|
||||
}
|
||||
|
||||
fn error_simplifyable<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> ! {
|
||||
self.hir.span_bug(match_pair.pattern.span,
|
||||
&format!("simplifyable pattern found: {:?}", match_pair.pattern))
|
||||
span_bug!(match_pair.pattern.span,
|
||||
"simplifyable pattern found: {:?}",
|
||||
match_pair.pattern)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,8 +218,8 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>,
|
||||
.enumerate()
|
||||
.all(|(index, block)| {
|
||||
if block.terminator.is_none() {
|
||||
panic!("no terminator on block {:?} in fn {:?}",
|
||||
index, fn_id)
|
||||
bug!("no terminator on block {:?} in fn {:?}",
|
||||
index, fn_id)
|
||||
}
|
||||
true
|
||||
}));
|
||||
|
@ -306,7 +306,7 @@ pub fn exit_scope(&mut self,
|
||||
debug!("exit_scope(extent={:?}, block={:?}, target={:?})", extent, block, target);
|
||||
let scope_count = 1 + self.scopes.iter().rev().position(|scope| scope.extent == extent)
|
||||
.unwrap_or_else(||{
|
||||
self.hir.span_bug(span, &format!("extent {:?} does not enclose", extent))
|
||||
span_bug!(span, "extent {:?} does not enclose", extent)
|
||||
});
|
||||
|
||||
let tmp = self.get_unit_temp();
|
||||
@ -345,7 +345,7 @@ pub fn find_loop_scope(&mut self,
|
||||
span: Span,
|
||||
label: Option<CodeExtent>)
|
||||
-> &mut LoopScope {
|
||||
let Builder { ref mut loop_scopes, ref mut hir, .. } = *self;
|
||||
let loop_scopes = &mut self.loop_scopes;
|
||||
match label {
|
||||
None => {
|
||||
// no label? return the innermost loop scope
|
||||
@ -358,7 +358,7 @@ pub fn find_loop_scope(&mut self,
|
||||
.filter(|loop_scope| loop_scope.extent == label)
|
||||
.next()
|
||||
}
|
||||
}.unwrap_or_else(|| hir.span_bug(span, "no enclosing loop scope found?"))
|
||||
}.unwrap_or_else(|| span_bug!(span, "no enclosing loop scope found?"))
|
||||
}
|
||||
|
||||
pub fn innermost_scope_id(&self) -> ScopeId {
|
||||
@ -410,8 +410,7 @@ pub fn schedule_drop(&mut self,
|
||||
scope.invalidate_cache()
|
||||
}
|
||||
}
|
||||
self.hir.span_bug(span,
|
||||
&format!("extent {:?} not in scope to drop {:?}", extent, lvalue));
|
||||
span_bug!(span, "extent {:?} not in scope to drop {:?}", extent, lvalue);
|
||||
}
|
||||
|
||||
/// Schedule dropping of a not-yet-fully-initialised box.
|
||||
@ -444,8 +443,7 @@ pub fn schedule_box_free(&mut self,
|
||||
scope.invalidate_cache();
|
||||
}
|
||||
}
|
||||
self.hir.span_bug(span,
|
||||
&format!("extent {:?} not in scope to free {:?}", extent, value));
|
||||
span_bug!(span, "extent {:?} not in scope to free {:?}", extent, value);
|
||||
}
|
||||
|
||||
// Other
|
||||
@ -531,7 +529,7 @@ pub fn panic_bounds_check(&mut self,
|
||||
let tup_ty = if let ty::TyRef(_, tyandmut) = ref_ty.sty {
|
||||
tyandmut.ty
|
||||
} else {
|
||||
self.hir.span_bug(span, &format!("unexpected panic_bound_check type: {:?}", func.ty));
|
||||
span_bug!(span, "unexpected panic_bound_check type: {:?}", func.ty);
|
||||
};
|
||||
|
||||
let (tuple, tuple_ref) = (self.temp(tup_ty), self.temp(ref_ty));
|
||||
@ -566,7 +564,7 @@ pub fn panic(&mut self, block: BasicBlock, msg: &'static str, span: Span) {
|
||||
let tup_ty = if let ty::TyRef(_, tyandmut) = ref_ty.sty {
|
||||
tyandmut.ty
|
||||
} else {
|
||||
self.hir.span_bug(span, &format!("unexpected panic type: {:?}", func.ty));
|
||||
span_bug!(span, "unexpected panic type: {:?}", func.ty);
|
||||
};
|
||||
|
||||
let (tuple, tuple_ref) = (self.temp(tup_ty), self.temp(ref_ty));
|
||||
|
@ -64,11 +64,11 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
|
||||
let sig = match method.ty.sty {
|
||||
ty::TyFnDef(_, _, fn_ty) => &fn_ty.sig,
|
||||
_ => cx.tcx.sess.span_bug(self.span, "type of method is not an fn")
|
||||
_ => span_bug!(self.span, "type of method is not an fn")
|
||||
};
|
||||
|
||||
let sig = cx.tcx.no_late_bound_regions(sig).unwrap_or_else(|| {
|
||||
cx.tcx.sess.span_bug(self.span, "method call has late-bound regions")
|
||||
span_bug!(self.span, "method call has late-bound regions")
|
||||
});
|
||||
|
||||
assert_eq!(sig.inputs.len(), 2);
|
||||
@ -128,7 +128,7 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
hir::ExprAddrOf(mutbl, ref expr) => {
|
||||
let region = match expr_ty.sty {
|
||||
ty::TyRef(r, _) => r,
|
||||
_ => cx.tcx.sess.span_bug(expr.span, "type of & not region"),
|
||||
_ => span_bug!(expr.span, "type of & not region"),
|
||||
};
|
||||
ExprKind::Borrow {
|
||||
region: *region,
|
||||
@ -297,16 +297,18 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
}
|
||||
}
|
||||
ref def => {
|
||||
cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
self.span,
|
||||
&format!("unexpected def: {:?}", def));
|
||||
"unexpected def: {:?}",
|
||||
def);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
self.span,
|
||||
&format!("unexpected type for struct literal: {:?}", expr_ty));
|
||||
"unexpected type for struct literal: {:?}",
|
||||
expr_ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,9 +318,9 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
let (def_id, substs) = match closure_ty.sty {
|
||||
ty::TyClosure(def_id, ref substs) => (def_id, substs),
|
||||
_ => {
|
||||
cx.tcx.sess.span_bug(self.span,
|
||||
&format!("closure expr w/o closure type: {:?}",
|
||||
closure_ty));
|
||||
span_bug!(self.span,
|
||||
"closure expr w/o closure type: {:?}",
|
||||
closure_ty);
|
||||
}
|
||||
};
|
||||
let upvars = cx.tcx.with_freevars(self.id, |freevars| {
|
||||
@ -355,7 +357,7 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
span: c.span,
|
||||
value: match const_eval::eval_const_expr(cx.tcx, c) {
|
||||
ConstVal::Integral(ConstInt::Usize(u)) => u,
|
||||
other => panic!("constant evaluation of repeat count yielded {:?}", other),
|
||||
other => bug!("constant evaluation of repeat count yielded {:?}", other),
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -383,14 +385,16 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
ty::TyStruct(adt_def, _) =>
|
||||
adt_def.variants[0].index_of_field_named(name.node),
|
||||
ref ty =>
|
||||
cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
self.span,
|
||||
&format!("field of non-struct: {:?}", ty)),
|
||||
"field of non-struct: {:?}",
|
||||
ty),
|
||||
};
|
||||
let index = index.unwrap_or_else(|| {
|
||||
cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
self.span,
|
||||
&format!("no index found for field `{}`", name.node));
|
||||
"no index found for field `{}`",
|
||||
name.node)
|
||||
});
|
||||
ExprKind::Field { lhs: source.to_ref(), name: Field::new(index) }
|
||||
}
|
||||
@ -474,8 +478,7 @@ fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Expr<'tcx> {
|
||||
Some(ty::FnConverging(&ty::TyS {
|
||||
sty: ty::TyRef(region, mt), ..
|
||||
})) => (region, mt.mutbl),
|
||||
_ => cx.tcx.sess.span_bug(
|
||||
expr.span, "autoderef returned bad type")
|
||||
_ => span_bug!(expr.span, "autoderef returned bad type")
|
||||
};
|
||||
|
||||
expr = Expr {
|
||||
@ -651,7 +654,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
|
||||
fields: vec![],
|
||||
base: None
|
||||
},
|
||||
ref sty => panic!("unexpected sty: {:?}", sty)
|
||||
ref sty => bug!("unexpected sty: {:?}", sty)
|
||||
},
|
||||
Def::Variant(enum_id, variant_id) => match cx.tcx.node_id_to_type(expr.id).sty {
|
||||
// A variant constructor. Should only be reached if not called in the same
|
||||
@ -669,7 +672,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
|
||||
base: None
|
||||
};
|
||||
},
|
||||
ref sty => panic!("unexpected sty: {:?}", sty)
|
||||
ref sty => bug!("unexpected sty: {:?}", sty)
|
||||
},
|
||||
Def::Const(def_id) |
|
||||
Def::AssociatedConst(def_id) => {
|
||||
@ -693,9 +696,10 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
|
||||
def @ Def::Upvar(..) => return convert_var(cx, expr, def),
|
||||
|
||||
def =>
|
||||
cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
expr.span,
|
||||
&format!("def `{:?}` not yet implemented", def)),
|
||||
"def `{:?}` not yet implemented",
|
||||
def),
|
||||
};
|
||||
ExprKind::Literal {
|
||||
literal: Literal::Item { def_id: def_id, substs: substs }
|
||||
@ -724,12 +728,12 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
|
||||
match expr.node {
|
||||
hir::ExprClosure(_, _, ref body) => body.id,
|
||||
_ => {
|
||||
cx.tcx.sess.span_bug(expr.span, "closure expr is not a closure expr");
|
||||
span_bug!(expr.span, "closure expr is not a closure expr");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
cx.tcx.sess.span_bug(expr.span, "ast-map has garbage for closure expr");
|
||||
span_bug!(expr.span, "ast-map has garbage for closure expr");
|
||||
}
|
||||
};
|
||||
|
||||
@ -809,9 +813,10 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
|
||||
let upvar_capture = match cx.tcx.upvar_capture(upvar_id) {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
expr.span,
|
||||
&format!("no upvar_capture for {:?}", upvar_id));
|
||||
"no upvar_capture for {:?}",
|
||||
upvar_id);
|
||||
}
|
||||
};
|
||||
match upvar_capture {
|
||||
@ -834,7 +839,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
|
||||
}
|
||||
}
|
||||
|
||||
_ => cx.tcx.sess.span_bug(expr.span, "type of & not region"),
|
||||
_ => span_bug!(expr.span, "type of & not region"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -857,7 +862,7 @@ fn bin_op(op: hir::BinOp_) -> BinOp {
|
||||
hir::BinOp_::BiNe => BinOp::Ne,
|
||||
hir::BinOp_::BiGe => BinOp::Ge,
|
||||
hir::BinOp_::BiGt => BinOp::Gt,
|
||||
_ => panic!("no equivalent for ast binop {:?}", op),
|
||||
_ => bug!("no equivalent for ast binop {:?}", op),
|
||||
}
|
||||
}
|
||||
|
||||
@ -997,7 +1002,7 @@ fn loop_label<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr) -> Cod
|
||||
match cx.tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def()) {
|
||||
Some(Def::Label(loop_id)) => cx.tcx.region_maps.node_extent(loop_id),
|
||||
d => {
|
||||
cx.tcx.sess.span_bug(expr.span, &format!("loop scope resolved to {:?}", d));
|
||||
span_bug!(expr.span, "loop scope resolved to {:?}", d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
use rustc::infer::InferCtxt;
|
||||
use rustc::ty::subst::{Subst, Substs};
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
use rustc_front::hir;
|
||||
use rustc_const_math::{ConstInt, ConstUsize};
|
||||
@ -57,7 +56,7 @@ pub fn usize_ty(&mut self) -> Ty<'tcx> {
|
||||
pub fn usize_literal(&mut self, value: u64) -> Literal<'tcx> {
|
||||
match ConstUsize::new(value, self.tcx.sess.target.uint_type) {
|
||||
Ok(val) => Literal::Value { value: ConstVal::Integral(ConstInt::Usize(val))},
|
||||
Err(_) => panic!("usize literal out of range for target"),
|
||||
Err(_) => bug!("usize literal out of range for target"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +123,7 @@ pub fn trait_method(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
self.tcx.sess.bug(&format!("found no method `{}` in `{:?}`", method_name, trait_def_id));
|
||||
bug!("found no method `{}` in `{:?}`", method_name, trait_def_id);
|
||||
}
|
||||
|
||||
pub fn num_variants(&mut self, adt_def: ty::AdtDef<'tcx>) -> usize {
|
||||
@ -141,10 +140,6 @@ pub fn needs_drop(&mut self, ty: Ty<'tcx>) -> bool {
|
||||
self.tcx.type_needs_drop_given_env(ty, &self.infcx.parameter_environment)
|
||||
}
|
||||
|
||||
pub fn span_bug(&mut self, span: Span, message: &str) -> ! {
|
||||
self.tcx.sess.span_bug(span, message)
|
||||
}
|
||||
|
||||
pub fn tcx(&self) -> &'a TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
@ -97,21 +97,23 @@ fn to_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
|
||||
Ok(pat) =>
|
||||
return self.to_pattern(&pat),
|
||||
Err(_) =>
|
||||
self.cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
pat.span, "illegal constant"),
|
||||
}
|
||||
}
|
||||
None => {
|
||||
self.cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
pat.span,
|
||||
&format!("cannot eval constant: {:?}", def_id))
|
||||
"cannot eval constant: {:?}",
|
||||
def_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ =>
|
||||
self.cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
pat.span,
|
||||
&format!("def not a constant: {:?}", def)),
|
||||
"def not a constant: {:?}",
|
||||
def),
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,9 +140,10 @@ fn to_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
|
||||
self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix),
|
||||
|
||||
ref sty =>
|
||||
self.cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
pat.span,
|
||||
&format!("unexpanded type for vector pattern: {:?}", sty)),
|
||||
"unexpanded type for vector pattern: {:?}",
|
||||
sty),
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +189,7 @@ fn to_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
|
||||
if let ty::TyRef(_, mt) = ty.sty {
|
||||
ty = mt.ty;
|
||||
} else {
|
||||
unreachable!("`ref {}` has wrong type {}", ident.node, ty);
|
||||
bug!("`ref {}` has wrong type {}", ident.node, ty);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +225,7 @@ fn to_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
|
||||
let adt_def = match pat_ty.sty {
|
||||
ty::TyStruct(adt_def, _) | ty::TyEnum(adt_def, _) => adt_def,
|
||||
_ => {
|
||||
self.cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
pat.span,
|
||||
"struct pattern not applied to struct or enum");
|
||||
}
|
||||
@ -236,9 +239,10 @@ fn to_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
|
||||
.map(|field| {
|
||||
let index = variant_def.index_of_field_named(field.node.name);
|
||||
let index = index.unwrap_or_else(|| {
|
||||
self.cx.tcx.sess.span_bug(
|
||||
span_bug!(
|
||||
pat.span,
|
||||
&format!("no field with name {:?}", field.node.name));
|
||||
"no field with name {:?}",
|
||||
field.node.name);
|
||||
});
|
||||
FieldPattern {
|
||||
field: Field::new(index),
|
||||
@ -251,7 +255,7 @@ fn to_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
|
||||
}
|
||||
|
||||
PatKind::QPath(..) => {
|
||||
self.cx.tcx.sess.span_bug(pat.span, "unexpanded macro or bad constant etc");
|
||||
span_bug!(pat.span, "unexpanded macro or bad constant etc");
|
||||
}
|
||||
};
|
||||
|
||||
@ -298,7 +302,7 @@ fn slice_or_array_pattern(&mut self,
|
||||
}
|
||||
|
||||
_ => {
|
||||
self.cx.tcx.sess.span_bug(span, "unexpanded macro or bad constant etc");
|
||||
span_bug!(span, "unexpanded macro or bad constant etc");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -327,8 +331,7 @@ fn variant_or_leaf(&mut self,
|
||||
}
|
||||
|
||||
_ => {
|
||||
self.cx.tcx.sess.span_bug(pat.span,
|
||||
&format!("inappropriate def for pattern: {:?}", def));
|
||||
span_bug!(pat.span, "inappropriate def for pattern: {:?}", def);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
extern crate graphviz as dot;
|
||||
#[macro_use]
|
||||
extern crate rustc;
|
||||
extern crate rustc_data_structures;
|
||||
extern crate rustc_front;
|
||||
|
@ -165,8 +165,7 @@ fn build_mir<'a,'tcx:'a>(cx: Cx<'a,'tcx>,
|
||||
let fn_sig = match cx.tcx().tables.borrow().liberated_fn_sigs.get(&fn_id) {
|
||||
Some(f) => f.clone(),
|
||||
None => {
|
||||
cx.tcx().sess.span_bug(span,
|
||||
&format!("no liberated fn sig for {:?}", fn_id));
|
||||
span_bug!(span, "no liberated fn sig for {:?}", fn_id);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user