Skip to content

Commit

Permalink
librustc_borrowck: 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 e3a7a66 commit 065dcd0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 35 deletions.
13 changes: 7 additions & 6 deletions src/librustc_borrowck/borrowck/fragments.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
Expand Up @@ -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 => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_borrowck/borrowck/gather_loans/mod.rs
Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Expand Up @@ -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");
}
}

Expand All @@ -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");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mir/gather_moves.rs
Expand Up @@ -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");
}
}
}
Expand Down
26 changes: 10 additions & 16 deletions src/librustc_borrowck/borrowck/mod.rs
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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, _) =
Expand Down Expand Up @@ -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) =
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/move_data.rs
Expand Up @@ -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");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_borrowck/lib.rs
Expand Up @@ -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;
Expand Down

0 comments on commit 065dcd0

Please sign in to comment.