Skip to content

Commit

Permalink
librustc_mir: use bug!(), span_bug!()
Browse files Browse the repository at this point in the history
  • Loading branch information
ben0x539 committed Mar 31, 2016
1 parent cc8159b commit 8aaf6ee
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 72 deletions.
5 changes: 3 additions & 2 deletions src/librustc_mir/build/expr/as_constant.rs
Expand Up @@ -33,9 +33,10 @@ impl<'a,'tcx> Builder<'a,'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),
}
}
}
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_temp.rs
Expand Up @@ -38,7 +38,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
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);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/build/matches/mod.rs
Expand Up @@ -162,10 +162,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
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
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_mir/build/matches/test.rs
Expand Up @@ -521,8 +521,9 @@ impl<'a,'tcx> Builder<'a,'tcx> {
}

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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/build/mod.rs
Expand Up @@ -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
}));
Expand Down
16 changes: 7 additions & 9 deletions src/librustc_mir/build/scope.rs
Expand Up @@ -306,7 +306,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
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();
Expand Down Expand Up @@ -345,7 +345,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
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
Expand All @@ -358,7 +358,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
.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 {
Expand Down Expand Up @@ -410,8 +410,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
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.
Expand Down Expand Up @@ -444,8 +443,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
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
Expand Down Expand Up @@ -531,7 +529,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
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));
Expand Down Expand Up @@ -566,7 +564,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
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));
Expand Down
61 changes: 33 additions & 28 deletions src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -64,11 +64,11 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {

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);
Expand Down Expand Up @@ -128,7 +128,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
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,
Expand Down Expand Up @@ -297,16 +297,18 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
}
}
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);
}
}
}
Expand All @@ -316,9 +318,9 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
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| {
Expand Down Expand Up @@ -355,7 +357,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
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),
},
}
},
Expand Down Expand Up @@ -383,14 +385,16 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
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) }
}
Expand Down Expand Up @@ -474,8 +478,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
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 {
Expand Down Expand Up @@ -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
Expand All @@ -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) => {
Expand All @@ -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 }
Expand Down Expand Up @@ -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");
}
};

Expand Down Expand Up @@ -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 {
Expand All @@ -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"),
}
}

Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/librustc_mir/hair/cx/mod.rs
Expand Up @@ -24,7 +24,6 @@ use rustc::middle::def_id::DefId;
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};
Expand Down Expand Up @@ -57,7 +56,7 @@ impl<'a,'tcx:'a> Cx<'a, '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"),
}
}

Expand Down Expand Up @@ -124,7 +123,7 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> {
}
}

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 {
Expand All @@ -141,10 +140,6 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> {
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
}
Expand Down

0 comments on commit 8aaf6ee

Please sign in to comment.