Skip to content

Commit

Permalink
librustc_typeck: 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 4bb7679 commit 35e1603
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 151 deletions.
14 changes: 7 additions & 7 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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?")
}
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
};

Expand Down
5 changes: 2 additions & 3 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -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");
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/callee.rs
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/cast.rs
Expand Up @@ -139,7 +139,7 @@ impl<'tcx> CastCheck<'tcx> {
CastError::NeedViaThinPtr => "a thin pointer",
CastError::NeedViaInt => "an integer",
CastError::NeedViaUsize => "a usize",
_ => unreachable!()
_ => bug!()
}))
.emit();
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_typeck/check/coercion.rs
Expand Up @@ -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={:?}",
Expand Down
11 changes: 5 additions & 6 deletions src/librustc_typeck/check/dropck.rs
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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!(),
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/librustc_typeck/check/method/confirm.rs
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 6 additions & 8 deletions src/librustc_typeck/check/method/mod.rs
Expand Up @@ -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);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/method/probe.rs
Expand Up @@ -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")
}
}
}
Expand All @@ -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![],
};
Expand Down
34 changes: 14 additions & 20 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
}
}
}
Expand All @@ -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());
}
}
}
Expand Down Expand Up @@ -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");
}
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)) =
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/librustc_typeck/check/op.rs
Expand Up @@ -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 {
Expand All @@ -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")
}
}
}
Expand Down

0 comments on commit 35e1603

Please sign in to comment.