librustc_typeck: use bug!(), span_bug!()

This commit is contained in:
Benjamin Herr 2016-03-29 00:06:35 +02:00
parent 4bb767965c
commit 35e160364d
18 changed files with 129 additions and 151 deletions

View File

@ -161,7 +161,7 @@ pub fn ast_region_to_region(tcx: &TyCtxt, lifetime: &hir::Lifetime)
let r = match tcx.named_region_map.get(&lifetime.id) { let r = match tcx.named_region_map.get(&lifetime.id) {
None => { None => {
// should have been recorded by the `resolve_lifetime` pass // should have been recorded by the `resolve_lifetime` pass
tcx.sess.span_bug(lifetime.span, "unresolved lifetime"); span_bug!(lifetime.span, "unresolved lifetime");
} }
Some(&rl::DefStaticRegion) => { Some(&rl::DefStaticRegion) => {
@ -485,7 +485,7 @@ fn create_substs_for_ast_path<'tcx>(
substs.types.push(TypeSpace, default); substs.types.push(TypeSpace, default);
} }
} else { } else {
tcx.sess.span_bug(span, "extra parameter without default"); span_bug!(span, "extra parameter without default");
} }
} }
@ -839,7 +839,7 @@ fn create_substs_for_ast_trait_ref<'a,'tcx>(this: &AstConv<'tcx>,
Err(ErrorReported) => { Err(ErrorReported) => {
// No convenient way to recover from a cycle here. Just bail. Sorry! // No convenient way to recover from a cycle here. Just bail. Sorry!
this.tcx().sess.abort_if_errors(); this.tcx().sess.abort_if_errors();
this.tcx().sess.bug("ErrorReported returned, but no errors reports?") bug!("ErrorReported returned, but no errors reports?")
} }
}; };
@ -1353,7 +1353,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
.expect("missing associated type"); .expect("missing associated type");
tcx.map.local_def_id(item.id) tcx.map.local_def_id(item.id)
} }
_ => unreachable!() _ => bug!()
} }
} else { } else {
let trait_items = tcx.trait_items(trait_did); let trait_items = tcx.trait_items(trait_did);
@ -1496,7 +1496,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
ty ty
} }
} else { } else {
tcx.sess.span_bug(span, "self type has not been fully resolved") span_bug!(span, "self type has not been fully resolved")
} }
} }
Def::SelfTy(Some(_), None) => { Def::SelfTy(Some(_), None) => {
@ -1654,7 +1654,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
depth: path.segments.len() depth: path.segments.len()
} }
} else { } else {
tcx.sess.span_bug(ast_ty.span, &format!("unbound path {:?}", ast_ty)) span_bug!(ast_ty.span, "unbound path {:?}", ast_ty)
}; };
let def = path_res.base_def; let def = path_res.base_def;
let base_ty_end = path.segments.len() - path_res.depth; let base_ty_end = path.segments.len() - path_res.depth;
@ -1961,7 +1961,7 @@ pub fn ty_of_closure<'tcx>(
ty::FnConverging(this.ty_infer(None, None, None, decl.output.span())), ty::FnConverging(this.ty_infer(None, None, None, decl.output.span())),
hir::Return(ref output) => hir::Return(ref output) =>
ty::FnConverging(ast_ty_to_ty(this, &rb, &output)), ty::FnConverging(ast_ty_to_ty(this, &rb, &output)),
hir::DefaultReturn(..) => unreachable!(), hir::DefaultReturn(..) => bug!(),
hir::NoReturn(..) => ty::FnDiverging hir::NoReturn(..) => ty::FnDiverging
}; };

View File

@ -413,8 +413,7 @@ fn check_assoc_item_is_const(pcx: &pat_ctxt, def: Def, span: Span) -> bool {
false false
} }
_ => { _ => {
pcx.fcx.ccx.tcx.sess.span_bug(span, "non-associated item in span_bug!(span, "non-associated item in check_assoc_item_is_const");
check_assoc_item_is_const");
} }
} }
} }
@ -588,7 +587,7 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx hir::Pat,
let pat_ty = pcx.fcx.instantiate_type(def.def_id(), path); let pat_ty = pcx.fcx.instantiate_type(def.def_id(), path);
let item_substs = match pat_ty.sty { let item_substs = match pat_ty.sty {
ty::TyStruct(_, substs) | ty::TyEnum(_, substs) => substs, ty::TyStruct(_, substs) | ty::TyEnum(_, substs) => substs,
_ => tcx.sess.span_bug(pat.span, "struct variant is not an ADT") _ => span_bug!(pat.span, "struct variant is not an ADT")
}; };
demand::eqtype(fcx, pat.span, expected, pat_ty); demand::eqtype(fcx, pat.span, expected, pat_ty);
check_struct_pat_fields(pcx, pat.span, fields, variant, &item_substs, etc); check_struct_pat_fields(pcx, pat.span, fields, variant, &item_substs, etc);

View File

@ -397,7 +397,7 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
write_overloaded_call_method_map(fcx, self.call_expr, method_callee); write_overloaded_call_method_map(fcx, self.call_expr, method_callee);
} }
None => { None => {
fcx.tcx().sess.span_bug( span_bug!(
self.call_expr.span, self.call_expr.span,
"failed to find an overloaded call trait for closure call"); "failed to find an overloaded call trait for closure call");
} }

View File

@ -139,7 +139,7 @@ impl<'tcx> CastCheck<'tcx> {
CastError::NeedViaThinPtr => "a thin pointer", CastError::NeedViaThinPtr => "a thin pointer",
CastError::NeedViaInt => "an integer", CastError::NeedViaInt => "an integer",
CastError::NeedViaUsize => "a usize", CastError::NeedViaUsize => "a usize",
_ => unreachable!() _ => bug!()
})) }))
.emit(); .emit();
} }

View File

@ -372,8 +372,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
} }
let r_borrow = match ty.sty { let r_borrow = match ty.sty {
ty::TyRef(r_borrow, _) => r_borrow, ty::TyRef(r_borrow, _) => r_borrow,
_ => self.tcx().sess.span_bug(span, _ => span_bug!(span, "expected a ref type, got {:?}", ty)
&format!("expected a ref type, got {:?}", ty))
}; };
let autoref = Some(AutoPtr(r_borrow, mt_b.mutbl)); let autoref = Some(AutoPtr(r_borrow, mt_b.mutbl));
debug!("coerce_borrowed_pointer: succeeded ty={:?} autoderefs={:?} autoref={:?}", debug!("coerce_borrowed_pointer: succeeded ty={:?} autoderefs={:?} autoref={:?}",

View File

@ -62,9 +62,9 @@ pub fn check_drop_impl(tcx: &TyCtxt, drop_impl_did: DefId) -> Result<(), ()> {
// Destructors only work on nominal types. This was // Destructors only work on nominal types. This was
// already checked by coherence, so we can panic here. // already checked by coherence, so we can panic here.
let span = tcx.map.def_id_span(drop_impl_did, codemap::DUMMY_SP); let span = tcx.map.def_id_span(drop_impl_did, codemap::DUMMY_SP);
tcx.sess.span_bug( span_bug!(span,
span, &format!("should have been rejected by coherence check: {}", "should have been rejected by coherence check: {}",
dtor_self_type)); dtor_self_type);
} }
} }
} }
@ -276,8 +276,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>
typ, scope); typ, scope);
let parent_scope = rcx.tcx().region_maps.opt_encl_scope(scope).unwrap_or_else(|| { let parent_scope = rcx.tcx().region_maps.opt_encl_scope(scope).unwrap_or_else(|| {
rcx.tcx().sess.span_bug( span_bug!(span, "no enclosing scope found for scope: {:?}", scope)
span, &format!("no enclosing scope found for scope: {:?}", scope))
}); });
let result = iterate_over_potentially_unsafe_regions_in_type( let result = iterate_over_potentially_unsafe_regions_in_type(
@ -493,7 +492,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'b, 'tcx>(
} }
// these are always dtorck // these are always dtorck
ty::TyTrait(..) | ty::TyProjection(_) => unreachable!(), ty::TyTrait(..) | ty::TyProjection(_) => bug!(),
} }
} }

View File

@ -300,10 +300,10 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
match result { match result {
Some(r) => r, Some(r) => r,
None => { None => {
self.tcx().sess.span_bug( span_bug!(
self.span, self.span,
&format!("self-type `{}` for ObjectPick never dereferenced to an object", "self-type `{}` for ObjectPick never dereferenced to an object",
self_ty)) self_ty)
} }
} }
} }
@ -372,10 +372,10 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
match self.fcx.mk_subty(false, TypeOrigin::Misc(self.span), self_ty, method_self_ty) { match self.fcx.mk_subty(false, TypeOrigin::Misc(self.span), self_ty, method_self_ty) {
Ok(_) => {} Ok(_) => {}
Err(_) => { Err(_) => {
self.tcx().sess.span_bug( span_bug!(
self.span, self.span,
&format!("{} was a subtype of {} but now is not?", "{} was a subtype of {} but now is not?",
self_ty, method_self_ty)); self_ty, method_self_ty);
} }
} }
} }
@ -550,15 +550,15 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
})) }))
} }
Some(_) => { Some(_) => {
self.tcx().sess.span_bug( span_bug!(
base_expr.span, base_expr.span,
&format!("unexpected adjustment autoref {:?}", "unexpected adjustment autoref {:?}",
adr)); adr);
} }
}, },
None => (0, None), None => (0, None),
Some(_) => { Some(_) => {
self.tcx().sess.span_bug( span_bug!(
base_expr.span, base_expr.span,
"unexpected adjustment type"); "unexpected adjustment type");
} }
@ -646,12 +646,12 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
// must be exactly one trait ref or we'd get an ambig error etc // must be exactly one trait ref or we'd get an ambig error etc
if upcast_trait_refs.len() != 1 { if upcast_trait_refs.len() != 1 {
self.tcx().sess.span_bug( span_bug!(
self.span, self.span,
&format!("cannot uniquely upcast `{:?}` to `{:?}`: `{:?}`", "cannot uniquely upcast `{:?}` to `{:?}`: `{:?}`",
source_trait_ref, source_trait_ref,
target_trait_def_id, target_trait_def_id,
upcast_trait_refs)); upcast_trait_refs);
} }
upcast_trait_refs.into_iter().next().unwrap() upcast_trait_refs.into_iter().next().unwrap()

View File

@ -302,21 +302,19 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
} }
_ => { _ => {
fcx.tcx().sess.span_bug( span_bug!(
span, span,
&format!( "trait method is &self but first arg is: {}",
"trait method is &self but first arg is: {}", transformed_self_ty);
transformed_self_ty));
} }
} }
} }
_ => { _ => {
fcx.tcx().sess.span_bug( span_bug!(
span, span,
&format!( "unexpected explicit self type in operator method: {:?}",
"unexpected explicit self type in operator method: {:?}", method_ty.explicit_self);
method_ty.explicit_self));
} }
} }
} }

View File

@ -877,8 +877,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
match tcx.trait_id_of_impl(impl_id) { match tcx.trait_id_of_impl(impl_id) {
Some(id) => id, Some(id) => id,
None => None =>
tcx.sess.span_bug(span, span_bug!(span,
"found inherent method when looking at traits") "found inherent method when looking at traits")
} }
} }
} }
@ -889,7 +889,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
} }
Some(Err(MethodError::ClosureAmbiguity(..))) => { Some(Err(MethodError::ClosureAmbiguity(..))) => {
// this error only occurs when assembling candidates // this error only occurs when assembling candidates
tcx.sess.span_bug(span, "encountered ClosureAmbiguity from pick_core"); span_bug!(span, "encountered ClosureAmbiguity from pick_core");
} }
_ => vec![], _ => vec![],
}; };

View File

@ -463,8 +463,7 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
regionck::regionck_fn(&fcx, fn_id, fn_span, decl, body); regionck::regionck_fn(&fcx, fn_id, fn_span, decl, body);
writeback::resolve_type_vars_in_fn(&fcx, decl, body); writeback::resolve_type_vars_in_fn(&fcx, decl, body);
} }
_ => ccx.tcx.sess.impossible_case(body.span, _ => span_bug!(body.span, "check_bare_fn: function type expected")
"check_bare_fn: function type expected")
} }
} }
@ -946,7 +945,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
hir::ImplItemKind::Const(..) => { hir::ImplItemKind::Const(..) => {
let impl_const = match ty_impl_item { let impl_const = match ty_impl_item {
ty::ConstTraitItem(ref cti) => cti, ty::ConstTraitItem(ref cti) => cti,
_ => tcx.sess.span_bug(impl_item.span, "non-const impl-item for const") _ => span_bug!(impl_item.span, "non-const impl-item for const")
}; };
// Find associated const definition. // Find associated const definition.
@ -969,7 +968,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let impl_method = match ty_impl_item { let impl_method = match ty_impl_item {
ty::MethodTraitItem(ref mti) => mti, ty::MethodTraitItem(ref mti) => mti,
_ => tcx.sess.span_bug(impl_item.span, "non-method impl-item for method") _ => span_bug!(impl_item.span, "non-method impl-item for method")
}; };
if let &ty::MethodTraitItem(ref trait_method) = ty_trait_item { if let &ty::MethodTraitItem(ref trait_method) = ty_trait_item {
@ -990,7 +989,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
hir::ImplItemKind::Type(_) => { hir::ImplItemKind::Type(_) => {
let impl_type = match ty_impl_item { let impl_type = match ty_impl_item {
ty::TypeTraitItem(ref tti) => tti, ty::TypeTraitItem(ref tti) => tti,
_ => tcx.sess.span_bug(impl_item.span, "non-type impl-item for type") _ => span_bug!(impl_item.span, "non-type impl-item for type")
}; };
if let &ty::TypeTraitItem(ref at) = ty_trait_item { if let &ty::TypeTraitItem(ref at) = ty_trait_item {
@ -1567,8 +1566,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match self.inh.tables.borrow().node_types.get(&ex.id) { match self.inh.tables.borrow().node_types.get(&ex.id) {
Some(&t) => t, Some(&t) => t,
None => { None => {
self.tcx().sess.bug(&format!("no type for expr in fcx {}", bug!("no type for expr in fcx {}", self.tag());
self.tag()));
} }
} }
} }
@ -1593,10 +1591,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(&t) => t, Some(&t) => t,
None if self.err_count_since_creation() != 0 => self.tcx().types.err, None if self.err_count_since_creation() != 0 => self.tcx().types.err,
None => { None => {
self.tcx().sess.bug( bug!("no type for node {}: {} in fcx {}",
&format!("no type for node {}: {} in fcx {}", id, self.tcx().map.node_to_string(id),
id, self.tcx().map.node_to_string(id), self.tag());
self.tag()));
} }
} }
} }
@ -2386,8 +2383,7 @@ fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
fty.sig.0.output fty.sig.0.output
} }
_ => { _ => {
fcx.tcx().sess.span_bug(callee_expr.span, span_bug!(callee_expr.span, "method without bare fn type");
"method without bare fn type");
} }
} }
} }
@ -3139,7 +3135,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
let substs = match adt_ty.sty { let substs = match adt_ty.sty {
ty::TyStruct(_, substs) | ty::TyEnum(_, substs) => substs, ty::TyStruct(_, substs) | ty::TyEnum(_, substs) => substs,
_ => tcx.sess.span_bug(span, "non-ADT passed to check_expr_struct_fields") _ => span_bug!(span, "non-ADT passed to check_expr_struct_fields")
}; };
let mut remaining_fields = FnvHashMap(); let mut remaining_fields = FnvHashMap();
@ -3400,8 +3396,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
depth: path.segments.len() depth: path.segments.len()
} }
} else { } else {
tcx.sess.span_bug(expr.span, span_bug!(expr.span, "unbound path {:?}", expr)
&format!("unbound path {:?}", expr))
}; };
if let Some((opt_ty, segments, def)) = if let Some((opt_ty, segments, def)) =
@ -4224,7 +4219,7 @@ fn type_scheme_and_predicates_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
Def::Label(..) | Def::Label(..) |
Def::SelfTy(..) | Def::SelfTy(..) |
Def::Err => { Def::Err => {
fcx.ccx.tcx.sess.span_bug(sp, &format!("expected value, found {:?}", defn)); span_bug!(sp, "expected value, found {:?}", defn);
} }
} }
} }
@ -4485,11 +4480,10 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let impl_ty = fcx.instantiate_type_scheme(span, &substs, &impl_scheme.ty); let impl_ty = fcx.instantiate_type_scheme(span, &substs, &impl_scheme.ty);
if fcx.mk_subty(false, TypeOrigin::Misc(span), self_ty, impl_ty).is_err() { if fcx.mk_subty(false, TypeOrigin::Misc(span), self_ty, impl_ty).is_err() {
fcx.tcx().sess.span_bug(span, span_bug!(span,
&format!(
"instantiate_path: (UFCS) {:?} was a subtype of {:?} but now is not?", "instantiate_path: (UFCS) {:?} was a subtype of {:?} but now is not?",
self_ty, self_ty,
impl_ty)); impl_ty);
} }
} }

View File

@ -270,8 +270,9 @@ fn name_and_trait_def_id(fcx: &FnCtxt,
hir::BiShr => ("shr_assign", lang.shr_assign_trait()), hir::BiShr => ("shr_assign", lang.shr_assign_trait()),
hir::BiLt | hir::BiLe | hir::BiGe | hir::BiGt | hir::BiEq | hir::BiNe | hir::BiAnd | hir::BiLt | hir::BiLe | hir::BiGe | hir::BiGt | hir::BiEq | hir::BiNe | hir::BiAnd |
hir::BiOr => { hir::BiOr => {
fcx.tcx().sess.span_bug(op.span, &format!("impossible assignment operation: {}=", span_bug!(op.span,
hir_util::binop_to_string(op.node))) "impossible assignment operation: {}=",
hir_util::binop_to_string(op.node))
} }
} }
} else { } else {
@ -293,7 +294,7 @@ fn name_and_trait_def_id(fcx: &FnCtxt,
hir::BiEq => ("eq", lang.eq_trait()), hir::BiEq => ("eq", lang.eq_trait()),
hir::BiNe => ("ne", lang.eq_trait()), hir::BiNe => ("ne", lang.eq_trait()),
hir::BiAnd | hir::BiOr => { hir::BiAnd | hir::BiOr => {
fcx.tcx().sess.span_bug(op.span, "&& and || are not overloadable") span_bug!(op.span, "&& and || are not overloadable")
} }
} }
} }

View File

@ -298,8 +298,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
match fn_sig_map.get(&id) { match fn_sig_map.get(&id) {
Some(f) => f.clone(), Some(f) => f.clone(),
None => { None => {
self.tcx().sess.bug( bug!("No fn-sig entry for id={}", id);
&format!("No fn-sig entry for id={}", id));
} }
} }
}; };
@ -446,8 +445,8 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
let subject_node_id = match self.subject { let subject_node_id = match self.subject {
Subject(s) => s, Subject(s) => s,
SubjectNode::None => { SubjectNode::None => {
self.tcx().sess.bug("cannot resolve_regions_and_report_errors \ bug!("cannot resolve_regions_and_report_errors \
without subject node"); without subject node");
} }
}; };
@ -886,9 +885,10 @@ fn constrain_callee(rcx: &mut Rcx,
// this should not happen, but it does if the program is // this should not happen, but it does if the program is
// erroneous // erroneous
// //
// tcx.sess.span_bug( // bug!(
// callee_expr.span, // callee_expr.span,
// format!("Calling non-function: {}", callee_ty)); // "Calling non-function: {}",
// callee_ty);
} }
} }
} }
@ -986,10 +986,10 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'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),
_ => { _ => {
rcx.tcx().sess.span_bug( span_bug!(
deref_expr.span, deref_expr.span,
&format!("bad overloaded deref type {:?}", "bad overloaded deref type {:?}",
method.ty)) method.ty)
} }
}; };
@ -1014,7 +1014,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
return_type, r_deref_expr); return_type, r_deref_expr);
return_type return_type
} }
ty::FnDiverging => unreachable!() ty::FnDiverging => bug!()
} }
} }
None => derefd_ty None => derefd_ty
@ -1057,12 +1057,10 @@ fn check_safety_of_rvalue_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 't
} }
ty::ReStatic => {} ty::ReStatic => {}
region => { region => {
rcx.tcx() span_bug!(span,
.sess "unexpected rvalue region in rvalue \
.span_bug(span, destructor safety checking: `{:?}`",
&format!("unexpected rvalue region in rvalue \ region);
destructor safety checking: `{:?}`",
region));
} }
} }
} }
@ -1394,10 +1392,7 @@ fn link_reborrowed_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
infer::ReborrowUpvar(span, *upvar_id) infer::ReborrowUpvar(span, *upvar_id)
} }
_ => { _ => {
rcx.tcx().sess.span_bug( span_bug!( span, "Illegal upvar id: {:?}", upvar_id);
span,
&format!("Illegal upvar id: {:?}",
upvar_id));
} }
} }
} }

View File

@ -209,10 +209,10 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
let closure_substs = match self.fcx.node_ty(id).sty { let closure_substs = match self.fcx.node_ty(id).sty {
ty::TyClosure(_, ref substs) => substs, ty::TyClosure(_, ref substs) => substs,
ref t => { ref t => {
self.fcx.tcx().sess.span_bug( span_bug!(
span, span,
&format!("type of closure expr {:?} is not a closure {:?}", "type of closure expr {:?} is not a closure {:?}",
id, t)); id, t);
} }
}; };

View File

@ -257,7 +257,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
let bare_fn_ty = match item_ty.sty { let bare_fn_ty = match item_ty.sty {
ty::TyFnDef(_, _, ref bare_fn_ty) => bare_fn_ty, ty::TyFnDef(_, _, ref bare_fn_ty) => bare_fn_ty,
_ => { _ => {
this.tcx().sess.span_bug(item.span, "Fn item without fn type"); span_bug!(item.span, "Fn item without fn type");
} }
}; };
@ -473,7 +473,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
let name = match space { let name = match space {
TypeSpace => ast_generics.ty_params[index].name, TypeSpace => ast_generics.ty_params[index].name,
SelfSpace => special_idents::type_self.name, SelfSpace => special_idents::type_self.name,
FnSpace => self.tcx().sess.bug("Fn space occupied?"), FnSpace => bug!("Fn space occupied?"),
}; };
ty::ParamTy { space: space, idx: index as u32, name: name } ty::ParamTy { space: space, idx: index as u32, name: name }
@ -489,7 +489,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
match space { match space {
TypeSpace => ast_generics.ty_params[index].span, TypeSpace => ast_generics.ty_params[index].span,
SelfSpace => item.span, SelfSpace => item.span,
FnSpace => self.tcx().sess.span_bug(item.span, "Fn space occupied?"), FnSpace => span_bug!(item.span, "Fn space occupied?"),
} }
} }

View File

@ -77,10 +77,10 @@ fn get_base_type_def_id<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>,
TyInfer(..) | TyClosure(..) => { TyInfer(..) | TyClosure(..) => {
// `ty` comes from a user declaration so we should only expect types // `ty` comes from a user declaration so we should only expect types
// that the user can type // that the user can type
inference_context.tcx.sess.span_bug( span_bug!(
span, span,
&format!("coherence encountered unexpected type searching for base type: {}", "coherence encountered unexpected type searching for base type: {}",
ty)); ty);
} }
} }
} }
@ -219,9 +219,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
}).collect() }).collect()
} }
_ => { _ => {
self.crate_context.tcx.sess.span_bug(item.span, span_bug!(item.span, "can't convert a non-impl to an impl");
"can't convert a non-impl \
to an impl");
} }
} }
} }
@ -263,13 +261,12 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
"the Drop trait may only be implemented on structures"); "the Drop trait may only be implemented on structures");
} }
_ => { _ => {
tcx.sess.bug("didn't find impl in ast \ bug!("didn't find impl in ast map");
map");
} }
} }
} else { } else {
tcx.sess.bug("found external impl of Drop trait on \ bug!("found external impl of Drop trait on \
something other than a struct"); :omething other than a struct");
} }
} }
} }

View File

@ -274,7 +274,7 @@ impl<'a,'tcx> CrateCtxt<'a,'tcx> {
if let Some(trait_id) = tcx.map.as_local_node_id(trait_id) { if let Some(trait_id) = tcx.map.as_local_node_id(trait_id) {
let item = match tcx.map.get(trait_id) { let item = match tcx.map.get(trait_id) {
hir_map::NodeItem(item) => item, hir_map::NodeItem(item) => item,
_ => tcx.sess.bug(&format!("get_trait_def({:?}): not an item", trait_id)) _ => bug!("get_trait_def({:?}): not an item", trait_id)
}; };
trait_def_of_item(self, &item) trait_def_of_item(self, &item)
@ -1165,13 +1165,13 @@ fn ensure_super_predicates_step(ccx: &CrateCtxt,
let superpredicates = superpredicates.unwrap_or_else(|| { let superpredicates = superpredicates.unwrap_or_else(|| {
let item = match ccx.tcx.map.get(trait_node_id) { let item = match ccx.tcx.map.get(trait_node_id) {
hir_map::NodeItem(item) => item, hir_map::NodeItem(item) => item,
_ => ccx.tcx.sess.bug(&format!("trait_node_id {} is not an item", trait_node_id)) _ => bug!("trait_node_id {} is not an item", trait_node_id)
}; };
let (generics, bounds) = match item.node { let (generics, bounds) = match item.node {
hir::ItemTrait(_, ref generics, ref supertraits, _) => (generics, supertraits), hir::ItemTrait(_, ref generics, ref supertraits, _) => (generics, supertraits),
_ => tcx.sess.span_bug(item.span, _ => span_bug!(item.span,
"ensure_super_predicates_step invoked on non-trait"), "ensure_super_predicates_step invoked on non-trait"),
}; };
// In-scope when converting the superbounds for `Trait` are // In-scope when converting the superbounds for `Trait` are
@ -1237,7 +1237,7 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let (unsafety, generics, items) = match it.node { let (unsafety, generics, items) = match it.node {
hir::ItemTrait(unsafety, ref generics, _, ref items) => (unsafety, generics, items), hir::ItemTrait(unsafety, ref generics, _, ref items) => (unsafety, generics, items),
_ => tcx.sess.span_bug(it.span, "trait_def_of_item invoked on non-trait"), _ => span_bug!(it.span, "trait_def_of_item invoked on non-trait"),
}; };
let paren_sugar = tcx.has_attr(def_id, "rustc_paren_sugar"); let paren_sugar = tcx.has_attr(def_id, "rustc_paren_sugar");
@ -1317,12 +1317,12 @@ fn trait_defines_associated_type_named(ccx: &CrateCtxt,
{ {
let item = match ccx.tcx.map.get(trait_node_id) { let item = match ccx.tcx.map.get(trait_node_id) {
hir_map::NodeItem(item) => item, hir_map::NodeItem(item) => item,
_ => ccx.tcx.sess.bug(&format!("trait_node_id {} is not an item", trait_node_id)) _ => bug!("trait_node_id {} is not an item", trait_node_id)
}; };
let trait_items = match item.node { let trait_items = match item.node {
hir::ItemTrait(_, _, _, ref trait_items) => trait_items, hir::ItemTrait(_, _, _, ref trait_items) => trait_items,
_ => ccx.tcx.sess.bug(&format!("trait_node_id {} is not a trait", trait_node_id)) _ => bug!("trait_node_id {} is not a trait", trait_node_id)
}; };
trait_items.iter().any(|trait_item| { trait_items.iter().any(|trait_item| {
@ -1342,9 +1342,10 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item)
let (generics, items) = match it.node { let (generics, items) = match it.node {
hir::ItemTrait(_, ref generics, _, ref items) => (generics, items), hir::ItemTrait(_, ref generics, _, ref items) => (generics, items),
ref s => { ref s => {
tcx.sess.span_bug( span_bug!(
it.span, it.span,
&format!("trait_def_of_item invoked on {:?}", s)); "trait_def_of_item invoked on {:?}",
s);
} }
}; };
@ -1421,9 +1422,8 @@ fn type_scheme_of_def_id<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
type_scheme_of_foreign_item(ccx, &foreign_item, abi) type_scheme_of_foreign_item(ccx, &foreign_item, abi)
} }
x => { x => {
ccx.tcx.sess.bug(&format!("unexpected sort of node \ bug!("unexpected sort of node in get_item_type_scheme(): {:?}",
in get_item_type_scheme(): {:?}", x);
x));
} }
} }
} else { } else {
@ -1489,10 +1489,10 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
hir::ItemForeignMod(..) | hir::ItemForeignMod(..) |
hir::ItemExternCrate(..) | hir::ItemExternCrate(..) |
hir::ItemUse(..) => { hir::ItemUse(..) => {
tcx.sess.span_bug( span_bug!(
it.span, it.span,
&format!("compute_type_scheme_of_item: unexpected item type: {:?}", "compute_type_scheme_of_item: unexpected item type: {:?}",
it.node)); it.node);
} }
} }
} }
@ -1528,10 +1528,10 @@ fn convert_typed_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
hir::ItemImpl(..) | hir::ItemImpl(..) |
hir::ItemMod(..) | hir::ItemMod(..) |
hir::ItemForeignMod(..) => { hir::ItemForeignMod(..) => {
tcx.sess.span_bug( span_bug!(
it.span, it.span,
&format!("compute_type_scheme_of_item: unexpected item type: {:?}", "compute_type_scheme_of_item: unexpected item type: {:?}",
it.node)); it.node);
} }
}; };
@ -1836,9 +1836,9 @@ fn ty_generic_predicates<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
&hir::WherePredicate::EqPredicate(ref eq_pred) => { &hir::WherePredicate::EqPredicate(ref eq_pred) => {
// FIXME(#20041) // FIXME(#20041)
tcx.sess.span_bug(eq_pred.span, span_bug!(eq_pred.span,
"Equality constraints are not yet \ "Equality constraints are not yet \
implemented (#20041)") implemented (#20041)")
} }
} }
} }

View File

@ -88,7 +88,7 @@ This API is completely unstable and subject to change.
extern crate arena; extern crate arena;
extern crate fmt_macros; extern crate fmt_macros;
extern crate rustc; #[macro_use] extern crate rustc;
extern crate rustc_platform_intrinsics as intrinsics; extern crate rustc_platform_intrinsics as intrinsics;
extern crate rustc_front; extern crate rustc_front;
extern crate rustc_back; extern crate rustc_back;
@ -258,9 +258,9 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
}); });
} }
_ => { _ => {
tcx.sess.span_bug(main_span, span_bug!(main_span,
&format!("main has a non-function type: found `{}`", "main has a non-function type: found `{}`",
main_t)); main_t);
} }
} }
} }
@ -310,9 +310,9 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
} }
_ => { _ => {
tcx.sess.span_bug(start_span, span_bug!(start_span,
&format!("start has a non-function type: found `{}`", "start has a non-function type: found `{}`",
start_t)); start_t);
} }
} }
} }
@ -325,7 +325,7 @@ fn check_for_entry_fn(ccx: &CrateCtxt) {
Some(config::EntryMain) => check_main_fn_ty(ccx, id, sp), Some(config::EntryMain) => check_main_fn_ty(ccx, id, sp),
Some(config::EntryStart) => check_start_fn_ty(ccx, id, sp), Some(config::EntryStart) => check_start_fn_ty(ccx, id, sp),
Some(config::EntryNone) => {} Some(config::EntryNone) => {}
None => tcx.sess.bug("entry function without a type") None => bug!("entry function without a type")
}, },
None => {} None => {}
} }

View File

@ -135,9 +135,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
match self.terms_cx.inferred_map.get(&param_id) { match self.terms_cx.inferred_map.get(&param_id) {
Some(&index) => index, Some(&index) => index,
None => { None => {
self.tcx().sess.bug(&format!( bug!("no inferred index entry for {}",
"no inferred index entry for {}", self.tcx().map.node_to_string(param_id));
self.tcx().map.node_to_string(param_id)));
} }
} }
} }
@ -148,7 +147,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
match tcx.named_region_map.get(&param_id) { match tcx.named_region_map.get(&param_id) {
Some(&rl::DefEarlyBoundRegion(_, _, lifetime_decl_id)) Some(&rl::DefEarlyBoundRegion(_, _, lifetime_decl_id))
=> lifetime_decl_id, => lifetime_decl_id,
Some(_) => panic!("should not encounter non early-bound cases"), Some(_) => bug!("should not encounter non early-bound cases"),
// The lookup should only fail when `param_id` is // The lookup should only fail when `param_id` is
// itself a lifetime binding: use it as the decl_id. // itself a lifetime binding: use it as the decl_id.
@ -173,13 +172,13 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
assert!(is_lifetime(&tcx.map, param_id)); assert!(is_lifetime(&tcx.map, param_id));
let parent_id = tcx.map.get_parent(decl_id); let parent_id = tcx.map.get_parent(decl_id);
let parent = tcx.map.find(parent_id).unwrap_or_else( let parent = tcx.map.find(parent_id).unwrap_or_else(
|| panic!("tcx.map missing entry for id: {}", parent_id)); || bug!("tcx.map missing entry for id: {}", parent_id));
let is_inferred; let is_inferred;
macro_rules! cannot_happen { () => { { macro_rules! cannot_happen { () => { {
panic!("invalid parent: {} for {}", bug!("invalid parent: {} for {}",
tcx.map.node_to_string(parent_id), tcx.map.node_to_string(parent_id),
tcx.map.node_to_string(param_id)); tcx.map.node_to_string(param_id));
} } } } } }
match parent { match parent {
@ -328,7 +327,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
} }
ty::TyClosure(..) => { ty::TyClosure(..) => {
self.tcx().sess.bug("Unexpected closure type in variance computation"); bug!("Unexpected closure type in variance computation");
} }
ty::TyRef(region, ref mt) => { ty::TyRef(region, ref mt) => {
@ -440,9 +439,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
} }
ty::TyInfer(..) => { ty::TyInfer(..) => {
self.tcx().sess.bug( bug!("unexpected type encountered in \
&format!("unexpected type encountered in \ variance inference: {}", ty);
variance inference: {}", ty));
} }
} }
} }
@ -525,11 +523,9 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
ty::ReSkolemized(..) | ty::ReEmpty => { ty::ReSkolemized(..) | ty::ReEmpty => {
// We don't expect to see anything but 'static or bound // We don't expect to see anything but 'static or bound
// regions when visiting member types or method types. // regions when visiting member types or method types.
self.tcx() bug!("unexpected region encountered in variance \
.sess inference: {:?}",
.bug(&format!("unexpected region encountered in variance \ region);
inference: {:?}",
region));
} }
} }
} }