Skip to content

Commit 8aaf6ee

Browse files
committed
librustc_mir: use bug!(), span_bug!()
1 parent cc8159b commit 8aaf6ee

File tree

11 files changed

+75
-72
lines changed

11 files changed

+75
-72
lines changed

src/librustc_mir/build/expr/as_constant.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
3333
ExprKind::Literal { literal } =>
3434
Constant { span: span, ty: ty, literal: literal },
3535
_ =>
36-
this.hir.span_bug(
36+
span_bug!(
3737
span,
38-
&format!("expression is not a valid constant {:?}", kind)),
38+
"expression is not a valid constant {:?}",
39+
kind),
3940
}
4041
}
4142
}

src/librustc_mir/build/expr/as_temp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
3838
let temp_lifetime = match expr.temp_lifetime {
3939
Some(t) => t,
4040
None => {
41-
this.hir.span_bug(expr.span, "no temp_lifetime for expr");
41+
span_bug!(expr.span, "no temp_lifetime for expr");
4242
}
4343
};
4444
this.schedule_drop(expr.span, temp_lifetime, &temp, expr_ty);

src/librustc_mir/build/matches/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
162162
unpack!(block = self.simplify_candidate(block, &mut candidate));
163163

164164
if !candidate.match_pairs.is_empty() {
165-
self.hir.span_bug(candidate.match_pairs[0].pattern.span,
166-
&format!("match pairs {:?} remaining after simplifying \
167-
irrefutable pattern",
168-
candidate.match_pairs));
165+
span_bug!(candidate.match_pairs[0].pattern.span,
166+
"match pairs {:?} remaining after simplifying \
167+
irrefutable pattern",
168+
candidate.match_pairs);
169169
}
170170

171171
// now apply the bindings, which will also declare the variables

src/librustc_mir/build/matches/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,9 @@ impl<'a,'tcx> Builder<'a,'tcx> {
521521
}
522522

523523
fn error_simplifyable<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> ! {
524-
self.hir.span_bug(match_pair.pattern.span,
525-
&format!("simplifyable pattern found: {:?}", match_pair.pattern))
524+
span_bug!(match_pair.pattern.span,
525+
"simplifyable pattern found: {:?}",
526+
match_pair.pattern)
526527
}
527528
}
528529

src/librustc_mir/build/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>,
218218
.enumerate()
219219
.all(|(index, block)| {
220220
if block.terminator.is_none() {
221-
panic!("no terminator on block {:?} in fn {:?}",
222-
index, fn_id)
221+
bug!("no terminator on block {:?} in fn {:?}",
222+
index, fn_id)
223223
}
224224
true
225225
}));

src/librustc_mir/build/scope.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
306306
debug!("exit_scope(extent={:?}, block={:?}, target={:?})", extent, block, target);
307307
let scope_count = 1 + self.scopes.iter().rev().position(|scope| scope.extent == extent)
308308
.unwrap_or_else(||{
309-
self.hir.span_bug(span, &format!("extent {:?} does not enclose", extent))
309+
span_bug!(span, "extent {:?} does not enclose", extent)
310310
});
311311

312312
let tmp = self.get_unit_temp();
@@ -345,7 +345,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
345345
span: Span,
346346
label: Option<CodeExtent>)
347347
-> &mut LoopScope {
348-
let Builder { ref mut loop_scopes, ref mut hir, .. } = *self;
348+
let loop_scopes = &mut self.loop_scopes;
349349
match label {
350350
None => {
351351
// no label? return the innermost loop scope
@@ -358,7 +358,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
358358
.filter(|loop_scope| loop_scope.extent == label)
359359
.next()
360360
}
361-
}.unwrap_or_else(|| hir.span_bug(span, "no enclosing loop scope found?"))
361+
}.unwrap_or_else(|| span_bug!(span, "no enclosing loop scope found?"))
362362
}
363363

364364
pub fn innermost_scope_id(&self) -> ScopeId {
@@ -410,8 +410,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
410410
scope.invalidate_cache()
411411
}
412412
}
413-
self.hir.span_bug(span,
414-
&format!("extent {:?} not in scope to drop {:?}", extent, lvalue));
413+
span_bug!(span, "extent {:?} not in scope to drop {:?}", extent, lvalue);
415414
}
416415

417416
/// Schedule dropping of a not-yet-fully-initialised box.
@@ -444,8 +443,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
444443
scope.invalidate_cache();
445444
}
446445
}
447-
self.hir.span_bug(span,
448-
&format!("extent {:?} not in scope to free {:?}", extent, value));
446+
span_bug!(span, "extent {:?} not in scope to free {:?}", extent, value);
449447
}
450448

451449
// Other
@@ -531,7 +529,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
531529
let tup_ty = if let ty::TyRef(_, tyandmut) = ref_ty.sty {
532530
tyandmut.ty
533531
} else {
534-
self.hir.span_bug(span, &format!("unexpected panic_bound_check type: {:?}", func.ty));
532+
span_bug!(span, "unexpected panic_bound_check type: {:?}", func.ty);
535533
};
536534

537535
let (tuple, tuple_ref) = (self.temp(tup_ty), self.temp(ref_ty));
@@ -566,7 +564,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
566564
let tup_ty = if let ty::TyRef(_, tyandmut) = ref_ty.sty {
567565
tyandmut.ty
568566
} else {
569-
self.hir.span_bug(span, &format!("unexpected panic type: {:?}", func.ty));
567+
span_bug!(span, "unexpected panic type: {:?}", func.ty);
570568
};
571569

572570
let (tuple, tuple_ref) = (self.temp(tup_ty), self.temp(ref_ty));

src/librustc_mir/hair/cx/expr.rs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
6464

6565
let sig = match method.ty.sty {
6666
ty::TyFnDef(_, _, fn_ty) => &fn_ty.sig,
67-
_ => cx.tcx.sess.span_bug(self.span, "type of method is not an fn")
67+
_ => span_bug!(self.span, "type of method is not an fn")
6868
};
6969

7070
let sig = cx.tcx.no_late_bound_regions(sig).unwrap_or_else(|| {
71-
cx.tcx.sess.span_bug(self.span, "method call has late-bound regions")
71+
span_bug!(self.span, "method call has late-bound regions")
7272
});
7373

7474
assert_eq!(sig.inputs.len(), 2);
@@ -128,7 +128,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
128128
hir::ExprAddrOf(mutbl, ref expr) => {
129129
let region = match expr_ty.sty {
130130
ty::TyRef(r, _) => r,
131-
_ => cx.tcx.sess.span_bug(expr.span, "type of & not region"),
131+
_ => span_bug!(expr.span, "type of & not region"),
132132
};
133133
ExprKind::Borrow {
134134
region: *region,
@@ -297,16 +297,18 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
297297
}
298298
}
299299
ref def => {
300-
cx.tcx.sess.span_bug(
300+
span_bug!(
301301
self.span,
302-
&format!("unexpected def: {:?}", def));
302+
"unexpected def: {:?}",
303+
def);
303304
}
304305
}
305306
}
306307
_ => {
307-
cx.tcx.sess.span_bug(
308+
span_bug!(
308309
self.span,
309-
&format!("unexpected type for struct literal: {:?}", expr_ty));
310+
"unexpected type for struct literal: {:?}",
311+
expr_ty);
310312
}
311313
}
312314
}
@@ -316,9 +318,9 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
316318
let (def_id, substs) = match closure_ty.sty {
317319
ty::TyClosure(def_id, ref substs) => (def_id, substs),
318320
_ => {
319-
cx.tcx.sess.span_bug(self.span,
320-
&format!("closure expr w/o closure type: {:?}",
321-
closure_ty));
321+
span_bug!(self.span,
322+
"closure expr w/o closure type: {:?}",
323+
closure_ty);
322324
}
323325
};
324326
let upvars = cx.tcx.with_freevars(self.id, |freevars| {
@@ -355,7 +357,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
355357
span: c.span,
356358
value: match const_eval::eval_const_expr(cx.tcx, c) {
357359
ConstVal::Integral(ConstInt::Usize(u)) => u,
358-
other => panic!("constant evaluation of repeat count yielded {:?}", other),
360+
other => bug!("constant evaluation of repeat count yielded {:?}", other),
359361
},
360362
}
361363
},
@@ -383,14 +385,16 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
383385
ty::TyStruct(adt_def, _) =>
384386
adt_def.variants[0].index_of_field_named(name.node),
385387
ref ty =>
386-
cx.tcx.sess.span_bug(
388+
span_bug!(
387389
self.span,
388-
&format!("field of non-struct: {:?}", ty)),
390+
"field of non-struct: {:?}",
391+
ty),
389392
};
390393
let index = index.unwrap_or_else(|| {
391-
cx.tcx.sess.span_bug(
394+
span_bug!(
392395
self.span,
393-
&format!("no index found for field `{}`", name.node));
396+
"no index found for field `{}`",
397+
name.node)
394398
});
395399
ExprKind::Field { lhs: source.to_ref(), name: Field::new(index) }
396400
}
@@ -474,8 +478,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
474478
Some(ty::FnConverging(&ty::TyS {
475479
sty: ty::TyRef(region, mt), ..
476480
})) => (region, mt.mutbl),
477-
_ => cx.tcx.sess.span_bug(
478-
expr.span, "autoderef returned bad type")
481+
_ => span_bug!(expr.span, "autoderef returned bad type")
479482
};
480483

481484
expr = Expr {
@@ -651,7 +654,7 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
651654
fields: vec![],
652655
base: None
653656
},
654-
ref sty => panic!("unexpected sty: {:?}", sty)
657+
ref sty => bug!("unexpected sty: {:?}", sty)
655658
},
656659
Def::Variant(enum_id, variant_id) => match cx.tcx.node_id_to_type(expr.id).sty {
657660
// 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)
669672
base: None
670673
};
671674
},
672-
ref sty => panic!("unexpected sty: {:?}", sty)
675+
ref sty => bug!("unexpected sty: {:?}", sty)
673676
},
674677
Def::Const(def_id) |
675678
Def::AssociatedConst(def_id) => {
@@ -693,9 +696,10 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
693696
def @ Def::Upvar(..) => return convert_var(cx, expr, def),
694697

695698
def =>
696-
cx.tcx.sess.span_bug(
699+
span_bug!(
697700
expr.span,
698-
&format!("def `{:?}` not yet implemented", def)),
701+
"def `{:?}` not yet implemented",
702+
def),
699703
};
700704
ExprKind::Literal {
701705
literal: Literal::Item { def_id: def_id, substs: substs }
@@ -724,12 +728,12 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
724728
match expr.node {
725729
hir::ExprClosure(_, _, ref body) => body.id,
726730
_ => {
727-
cx.tcx.sess.span_bug(expr.span, "closure expr is not a closure expr");
731+
span_bug!(expr.span, "closure expr is not a closure expr");
728732
}
729733
}
730734
}
731735
_ => {
732-
cx.tcx.sess.span_bug(expr.span, "ast-map has garbage for closure expr");
736+
span_bug!(expr.span, "ast-map has garbage for closure expr");
733737
}
734738
};
735739

@@ -809,9 +813,10 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
809813
let upvar_capture = match cx.tcx.upvar_capture(upvar_id) {
810814
Some(c) => c,
811815
None => {
812-
cx.tcx.sess.span_bug(
816+
span_bug!(
813817
expr.span,
814-
&format!("no upvar_capture for {:?}", upvar_id));
818+
"no upvar_capture for {:?}",
819+
upvar_id);
815820
}
816821
};
817822
match upvar_capture {
@@ -834,7 +839,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
834839
}
835840
}
836841

837-
_ => cx.tcx.sess.span_bug(expr.span, "type of & not region"),
842+
_ => span_bug!(expr.span, "type of & not region"),
838843
}
839844
}
840845

@@ -857,7 +862,7 @@ fn bin_op(op: hir::BinOp_) -> BinOp {
857862
hir::BinOp_::BiNe => BinOp::Ne,
858863
hir::BinOp_::BiGe => BinOp::Ge,
859864
hir::BinOp_::BiGt => BinOp::Gt,
860-
_ => panic!("no equivalent for ast binop {:?}", op),
865+
_ => bug!("no equivalent for ast binop {:?}", op),
861866
}
862867
}
863868

@@ -997,7 +1002,7 @@ fn loop_label<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr) -> Cod
9971002
match cx.tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def()) {
9981003
Some(Def::Label(loop_id)) => cx.tcx.region_maps.node_extent(loop_id),
9991004
d => {
1000-
cx.tcx.sess.span_bug(expr.span, &format!("loop scope resolved to {:?}", d));
1005+
span_bug!(expr.span, "loop scope resolved to {:?}", d);
10011006
}
10021007
}
10031008
}

src/librustc_mir/hair/cx/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc::middle::def_id::DefId;
2424
use rustc::infer::InferCtxt;
2525
use rustc::ty::subst::{Subst, Substs};
2626
use rustc::ty::{self, Ty, TyCtxt};
27-
use syntax::codemap::Span;
2827
use syntax::parse::token;
2928
use rustc_front::hir;
3029
use rustc_const_math::{ConstInt, ConstUsize};
@@ -57,7 +56,7 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> {
5756
pub fn usize_literal(&mut self, value: u64) -> Literal<'tcx> {
5857
match ConstUsize::new(value, self.tcx.sess.target.uint_type) {
5958
Ok(val) => Literal::Value { value: ConstVal::Integral(ConstInt::Usize(val))},
60-
Err(_) => panic!("usize literal out of range for target"),
59+
Err(_) => bug!("usize literal out of range for target"),
6160
}
6261
}
6362

@@ -124,7 +123,7 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> {
124123
}
125124
}
126125

127-
self.tcx.sess.bug(&format!("found no method `{}` in `{:?}`", method_name, trait_def_id));
126+
bug!("found no method `{}` in `{:?}`", method_name, trait_def_id);
128127
}
129128

130129
pub fn num_variants(&mut self, adt_def: ty::AdtDef<'tcx>) -> usize {
@@ -141,10 +140,6 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> {
141140
self.tcx.type_needs_drop_given_env(ty, &self.infcx.parameter_environment)
142141
}
143142

144-
pub fn span_bug(&mut self, span: Span, message: &str) -> ! {
145-
self.tcx.sess.span_bug(span, message)
146-
}
147-
148143
pub fn tcx(&self) -> &'a TyCtxt<'tcx> {
149144
self.tcx
150145
}

0 commit comments

Comments
 (0)