diff options
| author | Benjamin Herr <ben@0x539.de> | 2016-03-28 22:22:14 +0200 |
|---|---|---|
| committer | Benjamin Herr <ben@0x539.de> | 2016-03-31 22:04:23 +0200 |
| commit | 8aaf6eee2fee2ffd6d8eeba1542916fcbd7c6dad (patch) | |
| tree | a79163b62e32162e18c6ae9d36a3cf9246c6e0c3 /src | |
| parent | cc8159b0ed63eb29254528fe9f078e3cec087b72 (diff) | |
| download | rust-8aaf6eee2fee2ffd6d8eeba1542916fcbd7c6dad.tar.gz rust-8aaf6eee2fee2ffd6d8eeba1542916fcbd7c6dad.zip | |
librustc_mir: use bug!(), span_bug!()
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/build/expr/as_constant.rs | 5 | ||||
| -rw-r--r-- | src/librustc_mir/build/expr/as_temp.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/build/matches/mod.rs | 8 | ||||
| -rw-r--r-- | src/librustc_mir/build/matches/test.rs | 5 | ||||
| -rw-r--r-- | src/librustc_mir/build/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/build/scope.rs | 16 | ||||
| -rw-r--r-- | src/librustc_mir/hair/cx/expr.rs | 61 | ||||
| -rw-r--r-- | src/librustc_mir/hair/cx/mod.rs | 9 | ||||
| -rw-r--r-- | src/librustc_mir/hair/cx/pattern.rs | 33 | ||||
| -rw-r--r-- | src/librustc_mir/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_mir/mir_map.rs | 3 |
11 files changed, 75 insertions, 72 deletions
diff --git a/src/librustc_mir/build/expr/as_constant.rs b/src/librustc_mir/build/expr/as_constant.rs index 6f186b8ada4..d97245a5fc2 100644 --- a/src/librustc_mir/build/expr/as_constant.rs +++ b/src/librustc_mir/build/expr/as_constant.rs @@ -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), } } } diff --git a/src/librustc_mir/build/expr/as_temp.rs b/src/librustc_mir/build/expr/as_temp.rs index 30a42bcd709..a2f7d2c9d72 100644 --- a/src/librustc_mir/build/expr/as_temp.rs +++ b/src/librustc_mir/build/expr/as_temp.rs @@ -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); diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 68563197014..cabf5c95546 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -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 diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index dc70cf4ffb9..f70d4321a49 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -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) } } diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 82f7ddebf0b..51069c38857 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -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 })); diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index e3093eab22b..bda9cf058f6 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -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(); @@ -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 @@ -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 { @@ -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. @@ -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 @@ -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)); @@ -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)); diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 451cdea35a7..7e16883e754 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -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); @@ -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, @@ -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); } } } @@ -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| { @@ -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), }, } }, @@ -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) } } @@ -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 { @@ -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); } } } diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index e4a8363051b..05448a7deab 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -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}; @@ -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"), } } @@ -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 { @@ -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 } diff --git a/src/librustc_mir/hair/cx/pattern.rs b/src/librustc_mir/hair/cx/pattern.rs index c6132a71eef..8ec8cd4bf81 100644 --- a/src/librustc_mir/hair/cx/pattern.rs +++ b/src/librustc_mir/hair/cx/pattern.rs @@ -97,21 +97,23 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, '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 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, '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 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, '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 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, '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 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, '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 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, '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 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> { } _ => { - 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 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> { } _ => { - self.cx.tcx.sess.span_bug(pat.span, - &format!("inappropriate def for pattern: {:?}", def)); + span_bug!(pat.span, "inappropriate def for pattern: {:?}", def); } } } diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index e024fa94fb7..e7c0a3d9cae 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -27,6 +27,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #[macro_use] extern crate log; extern crate graphviz as dot; +#[macro_use] extern crate rustc; extern crate rustc_data_structures; extern crate rustc_front; diff --git a/src/librustc_mir/mir_map.rs b/src/librustc_mir/mir_map.rs index 21cc8d35320..9ec88c1b59a 100644 --- a/src/librustc_mir/mir_map.rs +++ b/src/librustc_mir/mir_map.rs @@ -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); } }; |
