From 065dcd0702769de9bd95d0e9887713c6778ed67f Mon Sep 17 00:00:00 2001 From: Benjamin Herr Date: Mon, 28 Mar 2016 21:19:32 +0200 Subject: [PATCH] librustc_borrowck: use bug!(), span_bug!() --- src/librustc_borrowck/borrowck/fragments.rs | 13 +++++----- .../borrowck/gather_loans/gather_moves.rs | 4 +-- .../borrowck/gather_loans/mod.rs | 6 ++--- .../borrowck/gather_loans/move_error.rs | 9 +++---- .../borrowck/mir/gather_moves.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 26 +++++++------------ src/librustc_borrowck/borrowck/move_data.rs | 2 +- src/librustc_borrowck/lib.rs | 1 + 8 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/librustc_borrowck/borrowck/fragments.rs b/src/librustc_borrowck/borrowck/fragments.rs index 2d38b665cf9..d1b30bb2746 100644 --- a/src/librustc_borrowck/borrowck/fragments.rs +++ b/src/librustc_borrowck/borrowck/fragments.rs @@ -27,7 +27,7 @@ use rustc::middle::mem_categorization as mc; use std::mem; use std::rc::Rc; use syntax::ast; -use syntax::codemap::Span; +use syntax::codemap::{Span, DUMMY_SP}; use syntax::attr::AttrMetaMethods; #[derive(PartialEq, Eq, PartialOrd, Ord)] @@ -428,8 +428,8 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>, let tuple_idx = match *origin_field_name { mc::PositionalField(tuple_idx) => tuple_idx, mc::NamedField(_) => - panic!("tuple type {:?} should not have named fields.", - parent_ty), + bug!("tuple type {:?} should not have named fields.", + parent_ty), }; let tuple_len = v.len(); for i in 0..tuple_len { @@ -493,10 +493,11 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>, } ref sty_and_variant_info => { - let msg = format!("type {:?} ({:?}) is not fragmentable", - parent_ty, sty_and_variant_info); let opt_span = origin_id.and_then(|id|tcx.map.opt_span(id)); - tcx.sess.opt_span_bug(opt_span, &msg[..]) + span_bug!(opt_span.unwrap_or(DUMMY_SP), + "type {:?} ({:?}) is not fragmentable", + parent_ty, + sty_and_variant_info); } } } diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index 107109c9115..489c8be4e38 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -78,8 +78,8 @@ pub fn gather_match_variant<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, LpDowncast(ref base_lp, _) => move_data.add_variant_match( tcx, lp.clone(), move_pat.id, base_lp.clone(), mode), - _ => panic!("should only call gather_match_variant \ - for cat_downcast cmt"), + _ => bug!("should only call gather_match_variant \ + for cat_downcast cmt"), } } None => { diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index 247f8121de7..c759722c24b 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -378,10 +378,10 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { ty::ReEarlyBound(..) | ty::ReVar(..) | ty::ReSkolemized(..) => { - self.tcx().sess.span_bug( + span_bug!( cmt.span, - &format!("invalid borrow lifetime: {:?}", - loan_region)); + "invalid borrow lifetime: {:?}", + loan_region); } }; debug!("loan_scope = {:?}", loan_scope); diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index f49554289b3..f5e3bc4f6fb 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -134,8 +134,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, a non-copy fixed-size array", b.ty) } else { - bccx.span_bug(move_from.span, "this path should not cause illegal move"); - unreachable!(); + span_bug!(move_from.span, "this path should not cause illegal move"); } } @@ -150,14 +149,12 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, b.ty) }, _ => { - bccx.span_bug(move_from.span, "this path should not cause illegal move"); - unreachable!(); + span_bug!(move_from.span, "this path should not cause illegal move"); } } } _ => { - bccx.span_bug(move_from.span, "this path should not cause illegal move"); - unreachable!(); + span_bug!(move_from.span, "this path should not cause illegal move"); } } } diff --git a/src/librustc_borrowck/borrowck/mir/gather_moves.rs b/src/librustc_borrowck/borrowck/mir/gather_moves.rs index dbe58799341..2b1b743afe9 100644 --- a/src/librustc_borrowck/borrowck/mir/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/mir/gather_moves.rs @@ -569,7 +569,7 @@ fn gather_moves<'tcx>(mir: &Mir<'tcx>, tcx: &TyCtxt<'tcx>) -> MoveData<'tcx> { Rvalue::InlineAsm { .. } => {} Rvalue::Slice {..} => { - bb_ctxt.tcx.sess.bug("cannot move out of slice"); + bug!("cannot move out of slice"); } } } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index d985359a3dd..1dfa4da46aa 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -420,10 +420,10 @@ pub fn closure_to_block(closure_id: ast::NodeId, block.id } _ => { - panic!("encountered non-closure id: {}", closure_id) + bug!("encountered non-closure id: {}", closure_id) } }, - _ => panic!("encountered non-expr id: {}", closure_id) + _ => bug!("encountered non-expr id: {}", closure_id) } } @@ -704,10 +704,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { (self.tcx.expr_ty_adjusted(&expr), expr.span) } r => { - self.tcx.sess.bug(&format!("MoveExpr({}) maps to \ - {:?}, not Expr", - the_move.id, - r)) + bug!("MoveExpr({}) maps to {:?}, not Expr", + the_move.id, + r) } }; let (suggestion, _) = @@ -766,10 +765,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { (self.tcx.expr_ty_adjusted(&expr), expr.span) } r => { - self.tcx.sess.bug(&format!("Captured({}) maps to \ - {:?}, not Expr", - the_move.id, - r)) + bug!("Captured({}) maps to {:?}, not Expr", + the_move.id, + r) } }; let (suggestion, help) = @@ -852,10 +850,6 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { self.tcx.sess.span_err_with_code(s, msg, code); } - pub fn span_bug(&self, s: Span, m: &str) { - self.tcx.sess.span_bug(s, m); - } - pub fn bckerr_to_string(&self, err: &BckError<'tcx>) -> String { match err.code { err_mutbl => { @@ -895,7 +889,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { format!("cannot borrow {} as mutable", descr) } BorrowViolation(euv::ClosureInvocation) => { - self.tcx.sess.span_bug(err.span, + span_bug!(err.span, "err_mutbl with a closure invocation"); } } @@ -1035,7 +1029,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { // We need to determine which is the case here. let kind = match err.cmt.upvar().unwrap().cat { Categorization::Upvar(mc::Upvar { kind, .. }) => kind, - _ => unreachable!() + _ => bug!() }; if kind == ty::ClosureKind::Fn { db.span_help( diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs index 00274fe1a04..b31f74c6476 100644 --- a/src/librustc_borrowck/borrowck/move_data.rs +++ b/src/librustc_borrowck/borrowck/move_data.rs @@ -515,7 +515,7 @@ impl<'tcx> MoveData<'tcx> { assignment_index); } LpExtend(..) => { - tcx.sess.bug("var assignment for non var path"); + bug!("var assignment for non var path"); } } } diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index 1aa27f8b32b..6f21fcd9230 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -32,6 +32,7 @@ // for "clarity", rename the graphviz crate to dot; graphviz within `borrowck` // refers to the borrowck-specific graphviz adapter traits. extern crate graphviz as dot; +#[macro_use] extern crate rustc; extern crate rustc_front; extern crate rustc_mir;