From 35e160364df35104313ad0d6d884037e360bbd46 Mon Sep 17 00:00:00 2001 From: Benjamin Herr Date: Tue, 29 Mar 2016 00:06:35 +0200 Subject: [PATCH] librustc_typeck: use bug!(), span_bug!() --- src/librustc_typeck/astconv.rs | 14 +++---- src/librustc_typeck/check/_match.rs | 5 +-- src/librustc_typeck/check/callee.rs | 2 +- src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/check/coercion.rs | 3 +- src/librustc_typeck/check/dropck.rs | 11 +++--- src/librustc_typeck/check/method/confirm.rs | 30 +++++++-------- src/librustc_typeck/check/method/mod.rs | 14 +++---- src/librustc_typeck/check/method/probe.rs | 6 +-- src/librustc_typeck/check/mod.rs | 34 +++++++---------- src/librustc_typeck/check/op.rs | 7 ++-- src/librustc_typeck/check/regionck.rs | 35 ++++++++--------- src/librustc_typeck/check/upvar.rs | 6 +-- src/librustc_typeck/check/wfcheck.rs | 6 +-- src/librustc_typeck/coherence/mod.rs | 17 ++++----- src/librustc_typeck/collect.rs | 42 ++++++++++----------- src/librustc_typeck/lib.rs | 16 ++++---- src/librustc_typeck/variance/constraints.rs | 30 +++++++-------- 18 files changed, 129 insertions(+), 151 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index b7d00716f022..d925ff9fa3cf 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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) { None => { // 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) => { @@ -485,7 +485,7 @@ fn create_substs_for_ast_path<'tcx>( substs.types.push(TypeSpace, default); } } 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) => { // No convenient way to recover from a cycle here. Just bail. Sorry! 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"); tcx.map.local_def_id(item.id) } - _ => unreachable!() + _ => bug!() } } else { let trait_items = tcx.trait_items(trait_did); @@ -1496,7 +1496,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>, ty } } 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) => { @@ -1654,7 +1654,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>, depth: path.segments.len() } } 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 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())), hir::Return(ref output) => ty::FnConverging(ast_ty_to_ty(this, &rb, &output)), - hir::DefaultReturn(..) => unreachable!(), + hir::DefaultReturn(..) => bug!(), hir::NoReturn(..) => ty::FnDiverging }; diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index f8fa9c8e9b6c..6dad3ff850ba 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -413,8 +413,7 @@ fn check_assoc_item_is_const(pcx: &pat_ctxt, def: Def, span: Span) -> bool { false } _ => { - pcx.fcx.ccx.tcx.sess.span_bug(span, "non-associated item in - check_assoc_item_is_const"); + span_bug!(span, "non-associated item in 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 item_substs = match pat_ty.sty { 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); check_struct_pat_fields(pcx, pat.span, fields, variant, &item_substs, etc); diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 4e582033c8b6..bedf4753313f 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -397,7 +397,7 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> { write_overloaded_call_method_map(fcx, self.call_expr, method_callee); } None => { - fcx.tcx().sess.span_bug( + span_bug!( self.call_expr.span, "failed to find an overloaded call trait for closure call"); } diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 7ca4251e4c80..d743a036040d 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -139,7 +139,7 @@ impl<'tcx> CastCheck<'tcx> { CastError::NeedViaThinPtr => "a thin pointer", CastError::NeedViaInt => "an integer", CastError::NeedViaUsize => "a usize", - _ => unreachable!() + _ => bug!() })) .emit(); } diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index e36da1a568a7..70467e2d2dd9 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -372,8 +372,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } let r_borrow = match ty.sty { ty::TyRef(r_borrow, _) => r_borrow, - _ => self.tcx().sess.span_bug(span, - &format!("expected a ref type, got {:?}", ty)) + _ => span_bug!(span, "expected a ref type, got {:?}", ty) }; let autoref = Some(AutoPtr(r_borrow, mt_b.mutbl)); debug!("coerce_borrowed_pointer: succeeded ty={:?} autoderefs={:?} autoref={:?}", diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index bf2388ab7931..1f1bba509e01 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -62,9 +62,9 @@ pub fn check_drop_impl(tcx: &TyCtxt, drop_impl_did: DefId) -> Result<(), ()> { // Destructors only work on nominal types. This was // already checked by coherence, so we can panic here. let span = tcx.map.def_id_span(drop_impl_did, codemap::DUMMY_SP); - tcx.sess.span_bug( - span, &format!("should have been rejected by coherence check: {}", - dtor_self_type)); + span_bug!(span, + "should have been rejected by coherence check: {}", + dtor_self_type); } } } @@ -276,8 +276,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx> typ, scope); let parent_scope = rcx.tcx().region_maps.opt_encl_scope(scope).unwrap_or_else(|| { - rcx.tcx().sess.span_bug( - span, &format!("no enclosing scope found for scope: {:?}", scope)) + span_bug!(span, "no enclosing scope found for scope: {:?}", scope) }); 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 - ty::TyTrait(..) | ty::TyProjection(_) => unreachable!(), + ty::TyTrait(..) | ty::TyProjection(_) => bug!(), } } diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 310245f0a0e1..f90a56965397 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -300,10 +300,10 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { match result { Some(r) => r, None => { - self.tcx().sess.span_bug( + span_bug!( self.span, - &format!("self-type `{}` for ObjectPick never dereferenced to an object", - self_ty)) + "self-type `{}` for ObjectPick never dereferenced to an object", + 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) { Ok(_) => {} Err(_) => { - self.tcx().sess.span_bug( + span_bug!( self.span, - &format!("{} was a subtype of {} but now is not?", - self_ty, method_self_ty)); + "{} was a subtype of {} but now is not?", + self_ty, method_self_ty); } } } @@ -550,15 +550,15 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { })) } Some(_) => { - self.tcx().sess.span_bug( + span_bug!( base_expr.span, - &format!("unexpected adjustment autoref {:?}", - adr)); + "unexpected adjustment autoref {:?}", + adr); } }, None => (0, None), Some(_) => { - self.tcx().sess.span_bug( + span_bug!( base_expr.span, "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 if upcast_trait_refs.len() != 1 { - self.tcx().sess.span_bug( + span_bug!( self.span, - &format!("cannot uniquely upcast `{:?}` to `{:?}`: `{:?}`", - source_trait_ref, - target_trait_def_id, - upcast_trait_refs)); + "cannot uniquely upcast `{:?}` to `{:?}`: `{:?}`", + source_trait_ref, + target_trait_def_id, + upcast_trait_refs); } upcast_trait_refs.into_iter().next().unwrap() diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 8c8d02bd3e6d..43a18d2c1024 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -302,21 +302,19 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, } _ => { - fcx.tcx().sess.span_bug( + span_bug!( span, - &format!( - "trait method is &self but first arg is: {}", - transformed_self_ty)); + "trait method is &self but first arg is: {}", + transformed_self_ty); } } } _ => { - fcx.tcx().sess.span_bug( + span_bug!( span, - &format!( - "unexpected explicit self type in operator method: {:?}", - method_ty.explicit_self)); + "unexpected explicit self type in operator method: {:?}", + method_ty.explicit_self); } } } diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 477b46ce4cef..c4a8022071bf 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -877,8 +877,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { match tcx.trait_id_of_impl(impl_id) { Some(id) => id, None => - tcx.sess.span_bug(span, - "found inherent method when looking at traits") + span_bug!(span, + "found inherent method when looking at traits") } } } @@ -889,7 +889,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } Some(Err(MethodError::ClosureAmbiguity(..))) => { // 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![], }; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 9ed82fbab467..6c3469c9d724 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -463,8 +463,7 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, regionck::regionck_fn(&fcx, fn_id, fn_span, decl, body); writeback::resolve_type_vars_in_fn(&fcx, decl, body); } - _ => ccx.tcx.sess.impossible_case(body.span, - "check_bare_fn: function type expected") + _ => span_bug!(body.span, "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(..) => { let impl_const = match ty_impl_item { 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. @@ -969,7 +968,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, let impl_method = match ty_impl_item { 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 { @@ -990,7 +989,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, hir::ImplItemKind::Type(_) => { let impl_type = match ty_impl_item { 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 { @@ -1567,8 +1566,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match self.inh.tables.borrow().node_types.get(&ex.id) { Some(&t) => t, None => { - self.tcx().sess.bug(&format!("no type for expr in fcx {}", - self.tag())); + bug!("no type for expr in fcx {}", self.tag()); } } } @@ -1593,10 +1591,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(&t) => t, None if self.err_count_since_creation() != 0 => self.tcx().types.err, None => { - self.tcx().sess.bug( - &format!("no type for node {}: {} in fcx {}", - id, self.tcx().map.node_to_string(id), - self.tag())); + bug!("no type for node {}: {} in fcx {}", + id, self.tcx().map.node_to_string(id), + self.tag()); } } } @@ -2386,8 +2383,7 @@ fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, fty.sig.0.output } _ => { - fcx.tcx().sess.span_bug(callee_expr.span, - "method without bare fn type"); + span_bug!(callee_expr.span, "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 substs = match adt_ty.sty { 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(); @@ -3400,8 +3396,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, depth: path.segments.len() } } else { - tcx.sess.span_bug(expr.span, - &format!("unbound path {:?}", expr)) + span_bug!(expr.span, "unbound path {:?}", expr) }; 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::SelfTy(..) | 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); if fcx.mk_subty(false, TypeOrigin::Misc(span), self_ty, impl_ty).is_err() { - fcx.tcx().sess.span_bug(span, - &format!( + span_bug!(span, "instantiate_path: (UFCS) {:?} was a subtype of {:?} but now is not?", self_ty, - impl_ty)); + impl_ty); } } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 281564af6158..494135ee3ffb 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -270,8 +270,9 @@ fn name_and_trait_def_id(fcx: &FnCtxt, hir::BiShr => ("shr_assign", lang.shr_assign_trait()), hir::BiLt | hir::BiLe | hir::BiGe | hir::BiGt | hir::BiEq | hir::BiNe | hir::BiAnd | hir::BiOr => { - fcx.tcx().sess.span_bug(op.span, &format!("impossible assignment operation: {}=", - hir_util::binop_to_string(op.node))) + span_bug!(op.span, + "impossible assignment operation: {}=", + hir_util::binop_to_string(op.node)) } } } else { @@ -293,7 +294,7 @@ fn name_and_trait_def_id(fcx: &FnCtxt, hir::BiEq => ("eq", lang.eq_trait()), hir::BiNe => ("ne", lang.eq_trait()), hir::BiAnd | hir::BiOr => { - fcx.tcx().sess.span_bug(op.span, "&& and || are not overloadable") + span_bug!(op.span, "&& and || are not overloadable") } } } diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 533d24686e71..283245bd6f46 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -298,8 +298,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { match fn_sig_map.get(&id) { Some(f) => f.clone(), None => { - self.tcx().sess.bug( - &format!("No fn-sig entry for id={}", id)); + bug!("No fn-sig entry for id={}", id); } } }; @@ -446,8 +445,8 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { let subject_node_id = match self.subject { Subject(s) => s, SubjectNode::None => { - self.tcx().sess.bug("cannot resolve_regions_and_report_errors \ - without subject node"); + bug!("cannot resolve_regions_and_report_errors \ + without subject node"); } }; @@ -886,9 +885,10 @@ fn constrain_callee(rcx: &mut Rcx, // this should not happen, but it does if the program is // erroneous // - // tcx.sess.span_bug( + // bug!( // 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 { ty::TyRef(r, ref m) => (m.mutbl, r), _ => { - rcx.tcx().sess.span_bug( + span_bug!( deref_expr.span, - &format!("bad overloaded deref type {:?}", - method.ty)) + "bad overloaded deref type {:?}", + method.ty) } }; @@ -1014,7 +1014,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>, return_type, r_deref_expr); return_type } - ty::FnDiverging => unreachable!() + ty::FnDiverging => bug!() } } None => derefd_ty @@ -1057,12 +1057,10 @@ fn check_safety_of_rvalue_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 't } ty::ReStatic => {} region => { - rcx.tcx() - .sess - .span_bug(span, - &format!("unexpected rvalue region in rvalue \ - destructor safety checking: `{:?}`", - region)); + span_bug!(span, + "unexpected rvalue region in rvalue \ + destructor safety checking: `{:?}`", + region); } } } @@ -1394,10 +1392,7 @@ fn link_reborrowed_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, infer::ReborrowUpvar(span, *upvar_id) } _ => { - rcx.tcx().sess.span_bug( - span, - &format!("Illegal upvar id: {:?}", - upvar_id)); + span_bug!( span, "Illegal upvar id: {:?}", upvar_id); } } } diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 69e49e6a9864..7d51d5ec7f74 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -209,10 +209,10 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> { let closure_substs = match self.fcx.node_ty(id).sty { ty::TyClosure(_, ref substs) => substs, ref t => { - self.fcx.tcx().sess.span_bug( + span_bug!( span, - &format!("type of closure expr {:?} is not a closure {:?}", - id, t)); + "type of closure expr {:?} is not a closure {:?}", + id, t); } }; diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 047dfec1796e..68c9816b48c3 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -257,7 +257,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { let bare_fn_ty = match item_ty.sty { 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 { TypeSpace => ast_generics.ty_params[index].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 } @@ -489,7 +489,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { match space { TypeSpace => ast_generics.ty_params[index].span, SelfSpace => item.span, - FnSpace => self.tcx().sess.span_bug(item.span, "Fn space occupied?"), + FnSpace => span_bug!(item.span, "Fn space occupied?"), } } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index c3b46ef83ace..f9a4cfadc0b1 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -77,10 +77,10 @@ fn get_base_type_def_id<'a, 'tcx>(inference_context: &InferCtxt<'a, 'tcx>, TyInfer(..) | TyClosure(..) => { // `ty` comes from a user declaration so we should only expect types // that the user can type - inference_context.tcx.sess.span_bug( + span_bug!( span, - &format!("coherence encountered unexpected type searching for base type: {}", - ty)); + "coherence encountered unexpected type searching for base type: {}", + ty); } } } @@ -219,9 +219,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { }).collect() } _ => { - self.crate_context.tcx.sess.span_bug(item.span, - "can't convert a non-impl \ - to an impl"); + span_bug!(item.span, "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"); } _ => { - tcx.sess.bug("didn't find impl in ast \ - map"); + bug!("didn't find impl in ast map"); } } } else { - tcx.sess.bug("found external impl of Drop trait on \ - something other than a struct"); + bug!("found external impl of Drop trait on \ + :omething other than a struct"); } } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index a9ef0fce8809..59546f619c0a 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -274,7 +274,7 @@ impl<'a,'tcx> CrateCtxt<'a,'tcx> { if let Some(trait_id) = tcx.map.as_local_node_id(trait_id) { let item = match tcx.map.get(trait_id) { 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) @@ -1165,13 +1165,13 @@ fn ensure_super_predicates_step(ccx: &CrateCtxt, let superpredicates = superpredicates.unwrap_or_else(|| { let item = match ccx.tcx.map.get(trait_node_id) { 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 { hir::ItemTrait(_, ref generics, ref supertraits, _) => (generics, supertraits), - _ => tcx.sess.span_bug(item.span, - "ensure_super_predicates_step invoked on non-trait"), + _ => span_bug!(item.span, + "ensure_super_predicates_step invoked on non-trait"), }; // 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 { 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"); @@ -1317,12 +1317,12 @@ fn trait_defines_associated_type_named(ccx: &CrateCtxt, { let item = match ccx.tcx.map.get(trait_node_id) { 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 { 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| { @@ -1342,9 +1342,10 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item) let (generics, items) = match it.node { hir::ItemTrait(_, ref generics, _, ref items) => (generics, items), ref s => { - tcx.sess.span_bug( + span_bug!( 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) } x => { - ccx.tcx.sess.bug(&format!("unexpected sort of node \ - in get_item_type_scheme(): {:?}", - x)); + bug!("unexpected sort of node in get_item_type_scheme(): {:?}", + x); } } } else { @@ -1489,10 +1489,10 @@ fn compute_type_scheme_of_item<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, hir::ItemForeignMod(..) | hir::ItemExternCrate(..) | hir::ItemUse(..) => { - tcx.sess.span_bug( + span_bug!( it.span, - &format!("compute_type_scheme_of_item: unexpected item type: {:?}", - it.node)); + "compute_type_scheme_of_item: unexpected item type: {:?}", + it.node); } } } @@ -1528,10 +1528,10 @@ fn convert_typed_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, hir::ItemImpl(..) | hir::ItemMod(..) | hir::ItemForeignMod(..) => { - tcx.sess.span_bug( + span_bug!( it.span, - &format!("compute_type_scheme_of_item: unexpected item type: {:?}", - it.node)); + "compute_type_scheme_of_item: unexpected item type: {:?}", + it.node); } }; @@ -1836,9 +1836,9 @@ fn ty_generic_predicates<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, &hir::WherePredicate::EqPredicate(ref eq_pred) => { // FIXME(#20041) - tcx.sess.span_bug(eq_pred.span, - "Equality constraints are not yet \ - implemented (#20041)") + span_bug!(eq_pred.span, + "Equality constraints are not yet \ + implemented (#20041)") } } } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index c3ba91823434..fa23445fe630 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -88,7 +88,7 @@ This API is completely unstable and subject to change. extern crate arena; extern crate fmt_macros; -extern crate rustc; +#[macro_use] extern crate rustc; extern crate rustc_platform_intrinsics as intrinsics; extern crate rustc_front; extern crate rustc_back; @@ -258,9 +258,9 @@ fn check_main_fn_ty(ccx: &CrateCtxt, }); } _ => { - tcx.sess.span_bug(main_span, - &format!("main has a non-function type: found `{}`", - main_t)); + span_bug!(main_span, + "main has a non-function type: found `{}`", + main_t); } } } @@ -310,9 +310,9 @@ fn check_start_fn_ty(ccx: &CrateCtxt, } _ => { - tcx.sess.span_bug(start_span, - &format!("start has a non-function type: found `{}`", - start_t)); + span_bug!(start_span, + "start has a non-function type: found `{}`", + 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::EntryStart) => check_start_fn_ty(ccx, id, sp), Some(config::EntryNone) => {} - None => tcx.sess.bug("entry function without a type") + None => bug!("entry function without a type") }, None => {} } diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 1ed355c90a54..50c99e33b445 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -135,9 +135,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { match self.terms_cx.inferred_map.get(¶m_id) { Some(&index) => index, None => { - self.tcx().sess.bug(&format!( - "no inferred index entry for {}", - self.tcx().map.node_to_string(param_id))); + bug!("no inferred index entry for {}", + self.tcx().map.node_to_string(param_id)); } } } @@ -148,7 +147,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { match tcx.named_region_map.get(¶m_id) { Some(&rl::DefEarlyBoundRegion(_, _, 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 // 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)); let parent_id = tcx.map.get_parent(decl_id); 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; macro_rules! cannot_happen { () => { { - panic!("invalid parent: {} for {}", - tcx.map.node_to_string(parent_id), - tcx.map.node_to_string(param_id)); + bug!("invalid parent: {} for {}", + tcx.map.node_to_string(parent_id), + tcx.map.node_to_string(param_id)); } } } match parent { @@ -328,7 +327,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } ty::TyClosure(..) => { - self.tcx().sess.bug("Unexpected closure type in variance computation"); + bug!("Unexpected closure type in variance computation"); } ty::TyRef(region, ref mt) => { @@ -440,9 +439,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } ty::TyInfer(..) => { - self.tcx().sess.bug( - &format!("unexpected type encountered in \ - variance inference: {}", ty)); + bug!("unexpected type encountered in \ + variance inference: {}", ty); } } } @@ -525,11 +523,9 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { ty::ReSkolemized(..) | ty::ReEmpty => { // We don't expect to see anything but 'static or bound // regions when visiting member types or method types. - self.tcx() - .sess - .bug(&format!("unexpected region encountered in variance \ - inference: {:?}", - region)); + bug!("unexpected region encountered in variance \ + inference: {:?}", + region); } } }