librustc: replace span_bug calls with span_bug!()

This commit is contained in:
Benjamin Herr 2016-03-25 18:31:27 +01:00
parent 859b5a141c
commit bcdaccfbbe
21 changed files with 162 additions and 176 deletions

View File

@ -583,13 +583,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
return *l; return *l;
} }
} }
self.tcx.sess.span_bug(expr.span, span_bug!(expr.span, "no loop scope for id {}", loop_id);
&format!("no loop scope for id {}", loop_id));
} }
r => { r => {
self.tcx.sess.span_bug(expr.span, span_bug!(expr.span, "bad entry `{:?}` in def_map for label", r);
&format!("bad entry `{:?}` in def_map for label", r));
} }
} }
} }

View File

@ -339,10 +339,10 @@ impl<'cx, 'tcx> ty::fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
// Early-bound regions should really have been substituted away before // Early-bound regions should really have been substituted away before
// we get to this point. // we get to this point.
ty::ReEarlyBound(..) => { ty::ReEarlyBound(..) => {
self.tcx().sess.span_bug( span_bug!(
self.span, self.span,
&format!("Encountered early bound region when generalizing: {:?}", "Encountered early bound region when generalizing: {:?}",
r)); r);
} }
// Always make a fresh region variable for skolemized regions; // Always make a fresh region variable for skolemized regions;

View File

@ -183,11 +183,10 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
} }
} }
infcx.tcx.sess.span_bug( span_bug!(
span, span,
&format!("region {:?} is not associated with \ "region {:?} is not associated with any bound region from A!",
any bound region from A!", r0)
r0))
} }
} }
@ -297,7 +296,7 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
if a_r.is_some() && b_r.is_some() && only_new_vars { if a_r.is_some() && b_r.is_some() && only_new_vars {
// Related to exactly one bound variable from each fn: // Related to exactly one bound variable from each fn:
return rev_lookup(infcx, span, a_map, a_r.unwrap()); return rev_lookup(span, a_map, a_r.unwrap());
} else if a_r.is_none() && b_r.is_none() { } else if a_r.is_none() && b_r.is_none() {
// Not related to bound variables from either fn: // Not related to bound variables from either fn:
assert!(!r0.is_bound()); assert!(!r0.is_bound());
@ -308,8 +307,7 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
} }
} }
fn rev_lookup(infcx: &InferCtxt, fn rev_lookup(span: Span,
span: Span,
a_map: &FnvHashMap<ty::BoundRegion, ty::Region>, a_map: &FnvHashMap<ty::BoundRegion, ty::Region>,
r: ty::Region) -> ty::Region r: ty::Region) -> ty::Region
{ {
@ -318,9 +316,10 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
return ty::ReLateBound(ty::DebruijnIndex::new(1), *a_br); return ty::ReLateBound(ty::DebruijnIndex::new(1), *a_br);
} }
} }
infcx.tcx.sess.span_bug( span_bug!(
span, span,
&format!("could not find original bound region for {:?}", r)); "could not find original bound region for {:?}",
r);
} }
fn fresh_bound_variable(infcx: &InferCtxt, debruijn: ty::DebruijnIndex) -> ty::Region { fn fresh_bound_variable(infcx: &InferCtxt, debruijn: ty::DebruijnIndex) -> ty::Region {
@ -336,9 +335,10 @@ fn var_ids<'a, 'tcx>(fields: &CombineFields<'a, 'tcx>,
.map(|(_, r)| match *r { .map(|(_, r)| match *r {
ty::ReVar(r) => { r } ty::ReVar(r) => { r }
r => { r => {
fields.tcx().sess.span_bug( span_bug!(
fields.trace.origin.span(), fields.trace.origin.span(),
&format!("found non-region-vid: {:?}", r)); "found non-region-vid: {:?}",
r);
} }
}) })
.collect() .collect()

View File

@ -536,10 +536,10 @@ pub fn drain_fulfillment_cx_or_panic<'a,'tcx,T>(span: Span,
match drain_fulfillment_cx(infcx, fulfill_cx, result) { match drain_fulfillment_cx(infcx, fulfill_cx, result) {
Ok(v) => v, Ok(v) => v,
Err(errors) => { Err(errors) => {
infcx.tcx.sess.span_bug( span_bug!(
span, span,
&format!("Encountered errors `{:?}` fulfilling during trans", "Encountered errors `{:?}` fulfilling during trans",
errors)); errors);
} }
} }
} }

View File

@ -497,10 +497,10 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
(ReLateBound(..), _) | (ReLateBound(..), _) |
(_, ReEarlyBound(..)) | (_, ReEarlyBound(..)) |
(_, ReLateBound(..)) => { (_, ReLateBound(..)) => {
self.tcx.sess.span_bug(origin.span(), span_bug!(origin.span(),
&format!("cannot relate bound region: {:?} <= {:?}", "cannot relate bound region: {:?} <= {:?}",
sub, sub,
sup)); sup);
} }
(_, ReStatic) => { (_, ReStatic) => {
// all regions are subregions of static, so we can ignore this // all regions are subregions of static, so we can ignore this
@ -570,9 +570,9 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
pub fn resolve_var(&self, rid: RegionVid) -> ty::Region { pub fn resolve_var(&self, rid: RegionVid) -> ty::Region {
match *self.values.borrow() { match *self.values.borrow() {
None => { None => {
self.tcx.sess.span_bug((*self.var_origins.borrow())[rid.index as usize].span(), span_bug!((*self.var_origins.borrow())[rid.index as usize].span(),
"attempt to resolve region variable before values have \ "attempt to resolve region variable before values have \
been computed!") been computed!")
} }
Some(ref values) => { Some(ref values) => {
let r = lookup(values, rid); let r = lookup(values, rid);
@ -745,11 +745,11 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
} }
(ReVar(v_id), _) | (_, ReVar(v_id)) => { (ReVar(v_id), _) | (_, ReVar(v_id)) => {
self.tcx.sess.span_bug((*self.var_origins.borrow())[v_id.index as usize].span(), span_bug!((*self.var_origins.borrow())[v_id.index as usize].span(),
&format!("lub_concrete_regions invoked with non-concrete \ "lub_concrete_regions invoked with non-concrete \
regions: {:?}, {:?}", regions: {:?}, {:?}",
a, a,
b)); b);
} }
(ReFree(ref fr), ReScope(s_id)) | (ReFree(ref fr), ReScope(s_id)) |
@ -1193,13 +1193,13 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
} }
} }
self.tcx.sess.span_bug((*self.var_origins.borrow())[node_idx.index as usize].span(), span_bug!((*self.var_origins.borrow())[node_idx.index as usize].span(),
&format!("collect_error_for_expanding_node() could not find \ "collect_error_for_expanding_node() could not find \
error for var {:?}, lower_bounds={:?}, \ error for var {:?}, lower_bounds={:?}, \
upper_bounds={:?}", upper_bounds={:?}",
node_idx, node_idx,
lower_bounds, lower_bounds,
upper_bounds)); upper_bounds);
} }
fn collect_concrete_regions(&self, fn collect_concrete_regions(&self,

View File

@ -1275,9 +1275,9 @@ pub fn check_crate(tcx: &TyCtxt, access_levels: &AccessLevels) {
// in the iteration code. // in the iteration code.
for (id, v) in tcx.sess.lints.borrow().iter() { for (id, v) in tcx.sess.lints.borrow().iter() {
for &(lint, span, ref msg) in v { for &(lint, span, ref msg) in v {
tcx.sess.span_bug(span, span_bug!(span,
&format!("unprocessed lint {} at {}: {}", "unprocessed lint {} at {}: {}",
lint.as_str(), tcx.map.node_to_string(*id), *msg)) lint.as_str(), tcx.map.node_to_string(*id), *msg)
} }
} }
@ -1314,9 +1314,7 @@ pub fn check_ast_crate(sess: &Session, krate: &ast::Crate) {
// in the iteration code. // in the iteration code.
for (_, v) in sess.lints.borrow().iter() { for (_, v) in sess.lints.borrow().iter() {
for &(lint, span, ref msg) in v { for &(lint, span, ref msg) in v {
sess.span_bug(span, span_bug!(span, "unprocessed lint {}: {}", lint.as_str(), *msg)
&format!("unprocessed lint {}: {}",
lint.as_str(), *msg))
} }
} }
} }

View File

@ -67,8 +67,7 @@ pub fn ast_ty_to_prim_ty<'tcx>(tcx: &TyCtxt<'tcx>, ast_ty: &ast::Ty)
if let ast::TyPath(None, ref path) = ast_ty.node { if let ast::TyPath(None, ref path) = ast_ty.node {
let def = match tcx.def_map.borrow().get(&ast_ty.id) { let def = match tcx.def_map.borrow().get(&ast_ty.id) {
None => { None => {
tcx.sess.span_bug(ast_ty.span, span_bug!(ast_ty.span, "unbound path {:?}", path)
&format!("unbound path {:?}", path))
} }
Some(d) => d.full_def() Some(d) => d.full_def()
}; };

View File

@ -125,7 +125,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
if let ty::TyStruct(def, _) = self.tcx.expr_ty_adjusted(lhs).sty { if let ty::TyStruct(def, _) = self.tcx.expr_ty_adjusted(lhs).sty {
self.insert_def_id(def.struct_variant().field_named(name).did); self.insert_def_id(def.struct_variant().field_named(name).did);
} else { } else {
self.tcx.sess.span_bug(lhs.span, "named field access on non-struct") span_bug!(lhs.span, "named field access on non-struct")
} }
} }
@ -141,7 +141,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
let pat_ty = self.tcx.node_id_to_type(lhs.id); let pat_ty = self.tcx.node_id_to_type(lhs.id);
let variant = match pat_ty.sty { let variant = match pat_ty.sty {
ty::TyStruct(adt, _) | ty::TyEnum(adt, _) => adt.variant_of_def(def), ty::TyStruct(adt, _) | ty::TyEnum(adt, _) => adt.variant_of_def(def),
_ => self.tcx.sess.span_bug(lhs.span, "non-ADT in struct pattern") _ => span_bug!(lhs.span, "non-ADT in struct pattern")
}; };
for pat in pats { for pat in pats {
if let PatKind::Wild = pat.node.pat.node { if let PatKind::Wild = pat.node.pat.node {

View File

@ -564,9 +564,10 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
OverloadedCallType::from_method_id(self.tcx(), method_id) OverloadedCallType::from_method_id(self.tcx(), method_id)
} }
None => { None => {
self.tcx().sess.span_bug( span_bug!(
callee.span, callee.span,
&format!("unexpected callee type {}", callee_ty)) "unexpected callee type {}",
callee_ty)
} }
}; };
match overloaded_call_type { match overloaded_call_type {
@ -683,7 +684,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
// may not. This will generate an error earlier in typeck, // may not. This will generate an error earlier in typeck,
// so we can just ignore it. // so we can just ignore it.
if !self.tcx().sess.has_errors() { if !self.tcx().sess.has_errors() {
self.tcx().sess.span_bug( span_bug!(
with_expr.span, with_expr.span,
"with expression doesn't evaluate to a struct"); "with expression doesn't evaluate to a struct");
} }
@ -750,9 +751,9 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
let (m, r) = match self_ty.sty { let (m, r) = match self_ty.sty {
ty::TyRef(r, ref m) => (m.mutbl, r), ty::TyRef(r, ref m) => (m.mutbl, r),
_ => self.tcx().sess.span_bug(expr.span, _ => span_bug!(expr.span,
&format!("bad overloaded deref type {:?}", "bad overloaded deref type {:?}",
method_ty)) method_ty)
}; };
let bk = ty::BorrowKind::from_mutbl(m); let bk = ty::BorrowKind::from_mutbl(m);
self.delegate.borrow(expr.id, expr.span, cmt, self.delegate.borrow(expr.id, expr.span, cmt,
@ -934,7 +935,6 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
debug!("determine_pat_move_mode cmt_discr={:?} pat={:?}", cmt_discr, debug!("determine_pat_move_mode cmt_discr={:?} pat={:?}", cmt_discr,
pat); pat);
return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |_mc, cmt_pat, pat| { return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |_mc, cmt_pat, pat| {
let tcx = self.tcx();
let def_map = &self.tcx().def_map; let def_map = &self.tcx().def_map;
if pat_util::pat_is_binding(&def_map.borrow(), pat) { if pat_util::pat_is_binding(&def_map.borrow(), pat) {
match pat.node { match pat.node {
@ -947,7 +947,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
} }
} }
_ => { _ => {
tcx.sess.span_bug( span_bug!(
pat.span, pat.span,
"binding pattern not an identifier"); "binding pattern not an identifier");
} }
@ -972,8 +972,6 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
let delegate = &mut self.delegate; let delegate = &mut self.delegate;
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| { return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| {
if pat_util::pat_is_binding(&def_map.borrow(), pat) { if pat_util::pat_is_binding(&def_map.borrow(), pat) {
let tcx = typer.tcx;
debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}", debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}",
cmt_pat, cmt_pat,
pat, pat,
@ -1007,7 +1005,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
delegate.consume_pat(pat, cmt_pat, mode); delegate.consume_pat(pat, cmt_pat, mode);
} }
_ => { _ => {
tcx.sess.span_bug( span_bug!(
pat.span, pat.span,
"binding pattern not an identifier"); "binding pattern not an identifier");
} }
@ -1117,10 +1115,10 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
// reported. // reported.
if !tcx.sess.has_errors() { if !tcx.sess.has_errors() {
let msg = format!("Pattern has unexpected def: {:?} and type {:?}", span_bug!(pat.span,
def, "Pattern has unexpected def: {:?} and type {:?}",
cmt_pat.ty); def,
tcx.sess.span_bug(pat.span, &msg[..]) cmt_pat.ty);
} }
} }
} }

View File

@ -66,7 +66,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
let param_env = match self.param_envs.last() { let param_env = match self.param_envs.last() {
Some(p) => p, Some(p) => p,
None => { None => {
self.tcx.sess.span_bug( span_bug!(
span, span,
"transmute encountered outside of any fn"); "transmute encountered outside of any fn");
} }
@ -245,9 +245,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
} }
} }
_ => { _ => {
self.tcx span_bug!(expr.span, "transmute wasn't a bare fn?!");
.sess
.span_bug(expr.span, "transmute wasn't a bare fn?!");
} }
} }
} }

View File

@ -325,13 +325,10 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
fn variable(&self, node_id: NodeId, span: Span) -> Variable { fn variable(&self, node_id: NodeId, span: Span) -> Variable {
match self.variable_map.get(&node_id) { match self.variable_map.get(&node_id) {
Some(&var) => var, Some(&var) => var,
None => { None => {
self.tcx span_bug!(span, "no variable registered for id {}", node_id);
.sess }
.span_bug(span, &format!("no variable registered for id {}",
node_id));
}
} }
} }
@ -578,10 +575,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// above and the propagation code below; the two sets of // above and the propagation code below; the two sets of
// code have to agree about which AST nodes are worth // code have to agree about which AST nodes are worth
// creating liveness nodes for. // creating liveness nodes for.
self.ir.tcx.sess.span_bug( span_bug!(
span, span,
&format!("no live node registered for node {}", "no live node registered for node {}",
node_id)); node_id);
} }
} }
} }
@ -703,15 +700,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// to find with one // to find with one
match self.ir.tcx.def_map.borrow().get(&id).map(|d| d.full_def()) { match self.ir.tcx.def_map.borrow().get(&id).map(|d| d.full_def()) {
Some(Def::Label(loop_id)) => loop_id, Some(Def::Label(loop_id)) => loop_id,
_ => self.ir.tcx.sess.span_bug(sp, "label on break/loop \ _ => span_bug!(sp, "label on break/loop \
doesn't refer to a loop") doesn't refer to a loop")
} }
} }
None => { None => {
// Vanilla 'break' or 'loop', so use the enclosing // Vanilla 'break' or 'loop', so use the enclosing
// loop scope // loop scope
if self.loop_scope.is_empty() { if self.loop_scope.is_empty() {
self.ir.tcx.sess.span_bug(sp, "break outside loop"); span_bug!(sp, "break outside loop");
} else { } else {
*self.loop_scope.last().unwrap() *self.loop_scope.last().unwrap()
} }
@ -967,7 +964,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
let caps = match this.ir.capture_info_map.get(&expr.id) { let caps = match this.ir.capture_info_map.get(&expr.id) {
Some(caps) => caps.clone(), Some(caps) => caps.clone(),
None => { None => {
this.ir.tcx.sess.span_bug(expr.span, "no registered caps"); span_bug!(expr.span, "no registered caps");
} }
}; };
caps.iter().rev().fold(succ, |succ, cap| { caps.iter().rev().fold(succ, |succ, cap| {
@ -1061,8 +1058,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
match self.break_ln.get(&sc) { match self.break_ln.get(&sc) {
Some(&b) => b, Some(&b) => b,
None => self.ir.tcx.sess.span_bug(expr.span, None => span_bug!(expr.span, "break to unknown label")
"break to unknown label")
} }
} }
@ -1075,8 +1071,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
match self.cont_ln.get(&sc) { match self.cont_ln.get(&sc) {
Some(&b) => b, Some(&b) => b,
None => self.ir.tcx.sess.span_bug(expr.span, None => span_bug!(expr.span, "loop to unknown label")
"loop to unknown label")
} }
} }

View File

@ -312,9 +312,9 @@ impl MutabilityCategory {
McImmutable McImmutable
} }
} }
_ => tcx.sess.span_bug(p.span, "expected identifier pattern") _ => span_bug!(p.span, "expected identifier pattern")
}, },
_ => tcx.sess.span_bug(tcx.map.span(id), "expected identifier pattern") _ => span_bug!(tcx.map.span(id), "expected identifier pattern")
}; };
debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}", debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}",
"from_local", id, ret); "from_local", id, ret);
@ -559,8 +559,8 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
Def::TyParam(..) | Def::TyParam(..) |
Def::Label(_) | Def::SelfTy(..) | Def::Label(_) | Def::SelfTy(..) |
Def::AssociatedTy(..) => { Def::AssociatedTy(..) => {
self.tcx().sess.span_bug(span, &format!("Unexpected definition in \ span_bug!(span, "Unexpected definition in \
memory categorization: {:?}", def)); memory categorization: {:?}", def);
} }
Def::Static(_, mutbl) => { Def::Static(_, mutbl) => {
@ -583,18 +583,19 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
self.cat_upvar(id, span, var_id, fn_node_id, kind) self.cat_upvar(id, span, var_id, fn_node_id, kind)
} }
None => { None => {
self.tcx().sess.span_bug( span_bug!(
span, span,
&format!("No closure kind for {:?}", closure_id)); "No closure kind for {:?}",
closure_id);
} }
} }
} }
_ => { _ => {
self.tcx().sess.span_bug( span_bug!(
span, span,
&format!("Upvar of non-closure {} - {:?}", "Upvar of non-closure {} - {:?}",
fn_node_id, fn_node_id,
ty)); ty);
} }
} }
} }
@ -926,7 +927,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
let ptr = if implicit { let ptr = if implicit {
match ptr { match ptr {
BorrowedPtr(bk, r) => Implicit(bk, r), BorrowedPtr(bk, r) => Implicit(bk, r),
_ => self.tcx().sess.span_bug(node.span(), _ => span_bug!(node.span(),
"Implicit deref of non-borrowed pointer") "Implicit deref of non-borrowed pointer")
} }
} else { } else {
@ -1092,8 +1093,8 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
}, },
_ => { _ => {
tcx.sess.span_bug(pat.span, span_bug!(pat.span,
"type of slice pattern is not a slice"); "type of slice pattern is not a slice");
} }
} }
} }
@ -1261,9 +1262,10 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
} }
} }
_ => { _ => {
self.tcx().sess.span_bug( span_bug!(
pat.span, pat.span,
&format!("enum pattern didn't resolve to enum or struct {:?}", opt_def)); "enum pattern didn't resolve to enum or struct {:?}",
opt_def);
} }
} }
} }

View File

@ -67,10 +67,10 @@ fn method_might_be_inlined(tcx: &TyCtxt, sig: &hir::MethodSig,
Some(ast_map::NodeItem(item)) => Some(ast_map::NodeItem(item)) =>
item_might_be_inlined(&item), item_might_be_inlined(&item),
Some(..) | None => Some(..) | None =>
tcx.sess.span_bug(impl_item.span, "impl did is not an item") span_bug!(impl_item.span, "impl did is not an item")
} }
} else { } else {
tcx.sess.span_bug(impl_item.span, "found a foreign impl as a parent of a local method") span_bug!(impl_item.span, "found a foreign impl as a parent of a local method")
} }
} }
@ -94,8 +94,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> {
let def = match self.tcx.def_map.borrow().get(&expr.id) { let def = match self.tcx.def_map.borrow().get(&expr.id) {
Some(d) => d.full_def(), Some(d) => d.full_def(),
None => { None => {
self.tcx.sess.span_bug(expr.span, span_bug!(expr.span, "def ID not in def map?!")
"def ID not in def map?!")
} }
}; };

View File

@ -747,9 +747,9 @@ impl<'a> LifetimeContext<'a> {
lifetime_ref: &hir::Lifetime, lifetime_ref: &hir::Lifetime,
def: DefRegion) { def: DefRegion) {
if lifetime_ref.id == ast::DUMMY_NODE_ID { if lifetime_ref.id == ast::DUMMY_NODE_ID {
self.sess.span_bug(lifetime_ref.span, span_bug!(lifetime_ref.span,
"lifetime reference not renumbered, \ "lifetime reference not renumbered, \
probably a bug in syntax::fold"); probably a bug in syntax::fold");
} }
debug!("lifetime_ref={:?} id={:?} resolved to {:?}", debug!("lifetime_ref={:?} id={:?} resolved to {:?}",

View File

@ -516,8 +516,8 @@ pub fn check_expr(tcx: &TyCtxt, e: &hir::Expr,
span = field.span; span = field.span;
match tcx.expr_ty_adjusted(base_e).sty { match tcx.expr_ty_adjusted(base_e).sty {
ty::TyStruct(def, _) => def.struct_variant().field_named(field.node).did, ty::TyStruct(def, _) => def.struct_variant().field_named(field.node).did,
_ => tcx.sess.span_bug(e.span, _ => span_bug!(e.span,
"stability::check_expr: named field access on non-struct") "stability::check_expr: named field access on non-struct")
} }
} }
hir::ExprTupField(ref base_e, ref field) => { hir::ExprTupField(ref base_e, ref field) => {
@ -525,9 +525,9 @@ pub fn check_expr(tcx: &TyCtxt, e: &hir::Expr,
match tcx.expr_ty_adjusted(base_e).sty { match tcx.expr_ty_adjusted(base_e).sty {
ty::TyStruct(def, _) => def.struct_variant().fields[field.node].did, ty::TyStruct(def, _) => def.struct_variant().fields[field.node].did,
ty::TyTuple(..) => return, ty::TyTuple(..) => return,
_ => tcx.sess.span_bug(e.span, _ => span_bug!(e.span,
"stability::check_expr: unnamed field access on \ "stability::check_expr: unnamed field access on \
something other than a tuple or struct") something other than a tuple or struct")
} }
} }
hir::ExprStruct(_, ref expr_fields, _) => { hir::ExprStruct(_, ref expr_fields, _) => {
@ -551,10 +551,10 @@ pub fn check_expr(tcx: &TyCtxt, e: &hir::Expr,
// a bug to have construct one. // a bug to have construct one.
ty::TyEnum(..) => return, ty::TyEnum(..) => return,
_ => { _ => {
tcx.sess.span_bug(e.span, span_bug!(e.span,
&format!("stability::check_expr: struct construction \ "stability::check_expr: struct construction \
of non-struct, type {:?}", of non-struct, type {:?}",
type_)); type_);
} }
} }
} }

View File

@ -268,9 +268,9 @@ pub fn try_report_overflow_error_type_of_infinite_size<'a, 'tcx>(
} }
} }
_ => { _ => {
infcx.tcx.sess.span_bug(obligation.cause.span, span_bug!(obligation.cause.span,
&format!("Sized cycle involving non-trait-ref: {:?}", "Sized cycle involving non-trait-ref: {:?}",
obligation.predicate)); obligation.predicate);
} }
}) })
.collect(); .collect();
@ -472,9 +472,10 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
// ambiguity; otherwise, they always // ambiguity; otherwise, they always
// degenerate into other obligations // degenerate into other obligations
// (which may fail). // (which may fail).
infcx.tcx.sess.span_bug( span_bug!(
obligation.cause.span, obligation.cause.span,
&format!("WF predicate not satisfied for {:?}", ty)); "WF predicate not satisfied for {:?}",
ty);
} }
} }
} }

View File

@ -858,10 +858,10 @@ fn assemble_candidates_from_object_type<'cx,'tcx>(
let data = match object_ty.sty { let data = match object_ty.sty {
ty::TyTrait(ref data) => data, ty::TyTrait(ref data) => data,
_ => { _ => {
selcx.tcx().sess.span_bug( span_bug!(
obligation.cause.span, obligation.cause.span,
&format!("assemble_candidates_from_object_type called with non-object: {:?}", "assemble_candidates_from_object_type called with non-object: {:?}",
object_ty)); object_ty);
} }
}; };
let projection_bounds = data.projection_bounds_with_self_ty(selcx.tcx(), object_ty); let projection_bounds = data.projection_bounds_with_self_ty(selcx.tcx(), object_ty);
@ -951,10 +951,10 @@ fn assemble_candidates_from_impls<'cx,'tcx>(
super::VtableDefaultImpl(..) | super::VtableDefaultImpl(..) |
super::VtableBuiltin(..) => { super::VtableBuiltin(..) => {
// These traits have no associated types. // These traits have no associated types.
selcx.tcx().sess.span_bug( span_bug!(
obligation.cause.span, obligation.cause.span,
&format!("Cannot project an associated type from `{:?}`", "Cannot project an associated type from `{:?}`",
vtable)); vtable);
} }
} }
@ -1084,12 +1084,12 @@ fn confirm_param_env_candidate<'cx,'tcx>(
projection.projection_ty.trait_ref.clone()) { projection.projection_ty.trait_ref.clone()) {
Ok(()) => { } Ok(()) => { }
Err(e) => { Err(e) => {
selcx.tcx().sess.span_bug( span_bug!(
obligation.cause.span, obligation.cause.span,
&format!("Failed to unify `{:?}` and `{:?}` in projection: {}", "Failed to unify `{:?}` and `{:?}` in projection: {}",
obligation, obligation,
projection, projection,
e)); e);
} }
} }
@ -1124,8 +1124,9 @@ fn confirm_impl_candidate<'cx,'tcx>(
(ty.subst(tcx, substs), nested) (ty.subst(tcx, substs), nested)
} }
None => { None => {
tcx.sess.span_bug(obligation.cause.span, span_bug!(obligation.cause.span,
&format!("No associated type for {:?}", trait_ref)); "No associated type for {:?}",
trait_ref);
} }
} }
} }

View File

@ -1088,7 +1088,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let trait_def_id = match obligation.predicate.0.trait_ref.self_ty().sty { let trait_def_id = match obligation.predicate.0.trait_ref.self_ty().sty {
ty::TyProjection(ref data) => data.trait_ref.def_id, ty::TyProjection(ref data) => data.trait_ref.def_id,
ty::TyInfer(ty::TyVar(_)) => { ty::TyInfer(ty::TyVar(_)) => {
self.tcx().sess.span_bug(obligation.cause.span, span_bug!(obligation.cause.span,
"Self=_ should have been handled by assemble_candidates"); "Self=_ should have been handled by assemble_candidates");
} }
_ => { return; } _ => { return; }
@ -1125,11 +1125,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let projection_trait_ref = match skol_trait_predicate.trait_ref.self_ty().sty { let projection_trait_ref = match skol_trait_predicate.trait_ref.self_ty().sty {
ty::TyProjection(ref data) => &data.trait_ref, ty::TyProjection(ref data) => &data.trait_ref,
_ => { _ => {
self.tcx().sess.span_bug( span_bug!(
obligation.cause.span, obligation.cause.span,
&format!("match_projection_obligation_against_bounds_from_trait() called \ "match_projection_obligation_against_bounds_from_trait() called \
but self-ty not a projection: {:?}", but self-ty not a projection: {:?}",
skol_trait_predicate.trait_ref.self_ty())); skol_trait_predicate.trait_ref.self_ty());
} }
}; };
debug!("match_projection_obligation_against_bounds_from_trait: \ debug!("match_projection_obligation_against_bounds_from_trait: \
@ -2150,10 +2150,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
match self.builtin_bound(bound, obligation)? { match self.builtin_bound(bound, obligation)? {
If(nested) => Ok(self.vtable_builtin_data(obligation, bound, nested)), If(nested) => Ok(self.vtable_builtin_data(obligation, bound, nested)),
AmbiguousBuiltin | ParameterBuiltin => { AmbiguousBuiltin | ParameterBuiltin => {
self.tcx().sess.span_bug( span_bug!(
obligation.cause.span, obligation.cause.span,
&format!("builtin bound for {:?} was ambig", "builtin bound for {:?} was ambig",
obligation)); obligation);
} }
} }
} }
@ -2353,8 +2353,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
data.principal_trait_ref_with_self_ty(self.tcx(), self_ty) data.principal_trait_ref_with_self_ty(self.tcx(), self_ty)
} }
_ => { _ => {
self.tcx().sess.span_bug(obligation.cause.span, span_bug!(obligation.cause.span,
"object candidate with non-object"); "object candidate with non-object");
} }
}; };

View File

@ -234,12 +234,11 @@ impl<'tcx> ty::TyS<'tcx> {
match adjusted_ty.builtin_deref(true, NoPreference) { match adjusted_ty.builtin_deref(true, NoPreference) {
Some(mt) => mt.ty, Some(mt) => mt.ty,
None => { None => {
cx.sess.span_bug( span_bug!(
expr_span, expr_span,
&format!("the {}th autoderef failed: {}", "the {}th autoderef failed: {}",
autoderef, autoderef,
adjusted_ty) adjusted_ty);
);
} }
} }
} }

View File

@ -1339,10 +1339,10 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
cx.region_maps.item_extent(id)) cx.region_maps.item_extent(id))
} }
_ => { _ => {
cx.sess.span_bug(item.span, span_bug!(item.span,
"ParameterEnvironment::for_item(): "ParameterEnvironment::for_item():
can't create a parameter \ can't create a parameter \
environment for this kind of item") environment for this kind of item")
} }
} }
} }
@ -2003,8 +2003,7 @@ impl<'tcx> TyCtxt<'tcx> {
match self.def_map.borrow().get(&expr.id) { match self.def_map.borrow().get(&expr.id) {
Some(def) => def.full_def(), Some(def) => def.full_def(),
None => { None => {
self.sess.span_bug(expr.span, &format!( span_bug!(expr.span, "no def-map entry for expr {}", expr.id);
"no def-map entry for expr {}", expr.id));
} }
} }
} }
@ -2027,8 +2026,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
Some(&def::PathResolution { base_def: Def::Err, .. })=> true, Some(&def::PathResolution { base_def: Def::Err, .. })=> true,
Some(..) => false, Some(..) => false,
None => self.sess.span_bug(expr.span, &format!( None => span_bug!(expr.span, "no def for path {}", expr.id)
"no def for path {}", expr.id))
} }
} }

View File

@ -604,15 +604,15 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
} }
None => { None => {
let span = self.span.unwrap_or(DUMMY_SP); let span = self.span.unwrap_or(DUMMY_SP);
self.tcx().sess.span_bug( span_bug!(
span, span,
&format!("Region parameter out of range \ "Region parameter out of range \
when substituting in region {} (root type={:?}) \ when substituting in region {} (root type={:?}) \
(space={:?}, index={})", (space={:?}, index={})",
data.name, data.name,
self.root_ty, self.root_ty,
data.space, data.space,
data.index)); data.index);
} }
} }
} }
@ -659,16 +659,16 @@ impl<'a,'tcx> SubstFolder<'a,'tcx> {
Some(t) => *t, Some(t) => *t,
None => { None => {
let span = self.span.unwrap_or(DUMMY_SP); let span = self.span.unwrap_or(DUMMY_SP);
self.tcx().sess.span_bug( span_bug!(
span, span,
&format!("Type parameter `{:?}` ({:?}/{:?}/{}) out of range \ "Type parameter `{:?}` ({:?}/{:?}/{}) out of range \
when substituting (root type={:?}) substs={:?}", when substituting (root type={:?}) substs={:?}",
p, p,
source_ty, source_ty,
p.space, p.space,
p.idx, p.idx,
self.root_ty, self.root_ty,
self.substs)); self.substs);
} }
}; };