Skip to content

Commit 35e1603

Browse files
committed
librustc_typeck: use bug!(), span_bug!()
1 parent 4bb7679 commit 35e1603

File tree

18 files changed

+129
-151
lines changed

18 files changed

+129
-151
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn ast_region_to_region(tcx: &TyCtxt, lifetime: &hir::Lifetime)
161161
let r = match tcx.named_region_map.get(&lifetime.id) {
162162
None => {
163163
// should have been recorded by the `resolve_lifetime` pass
164-
tcx.sess.span_bug(lifetime.span, "unresolved lifetime");
164+
span_bug!(lifetime.span, "unresolved lifetime");
165165
}
166166

167167
Some(&rl::DefStaticRegion) => {
@@ -485,7 +485,7 @@ fn create_substs_for_ast_path<'tcx>(
485485
substs.types.push(TypeSpace, default);
486486
}
487487
} else {
488-
tcx.sess.span_bug(span, "extra parameter without default");
488+
span_bug!(span, "extra parameter without default");
489489
}
490490
}
491491

@@ -839,7 +839,7 @@ fn create_substs_for_ast_trait_ref<'a,'tcx>(this: &AstConv<'tcx>,
839839
Err(ErrorReported) => {
840840
// No convenient way to recover from a cycle here. Just bail. Sorry!
841841
this.tcx().sess.abort_if_errors();
842-
this.tcx().sess.bug("ErrorReported returned, but no errors reports?")
842+
bug!("ErrorReported returned, but no errors reports?")
843843
}
844844
};
845845

@@ -1353,7 +1353,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
13531353
.expect("missing associated type");
13541354
tcx.map.local_def_id(item.id)
13551355
}
1356-
_ => unreachable!()
1356+
_ => bug!()
13571357
}
13581358
} else {
13591359
let trait_items = tcx.trait_items(trait_did);
@@ -1496,7 +1496,7 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
14961496
ty
14971497
}
14981498
} else {
1499-
tcx.sess.span_bug(span, "self type has not been fully resolved")
1499+
span_bug!(span, "self type has not been fully resolved")
15001500
}
15011501
}
15021502
Def::SelfTy(Some(_), None) => {
@@ -1654,7 +1654,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
16541654
depth: path.segments.len()
16551655
}
16561656
} else {
1657-
tcx.sess.span_bug(ast_ty.span, &format!("unbound path {:?}", ast_ty))
1657+
span_bug!(ast_ty.span, "unbound path {:?}", ast_ty)
16581658
};
16591659
let def = path_res.base_def;
16601660
let base_ty_end = path.segments.len() - path_res.depth;
@@ -1961,7 +1961,7 @@ pub fn ty_of_closure<'tcx>(
19611961
ty::FnConverging(this.ty_infer(None, None, None, decl.output.span())),
19621962
hir::Return(ref output) =>
19631963
ty::FnConverging(ast_ty_to_ty(this, &rb, &output)),
1964-
hir::DefaultReturn(..) => unreachable!(),
1964+
hir::DefaultReturn(..) => bug!(),
19651965
hir::NoReturn(..) => ty::FnDiverging
19661966
};
19671967

src/librustc_typeck/check/_match.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ fn check_assoc_item_is_const(pcx: &pat_ctxt, def: Def, span: Span) -> bool {
413413
false
414414
}
415415
_ => {
416-
pcx.fcx.ccx.tcx.sess.span_bug(span, "non-associated item in
417-
check_assoc_item_is_const");
416+
span_bug!(span, "non-associated item in check_assoc_item_is_const");
418417
}
419418
}
420419
}
@@ -588,7 +587,7 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx hir::Pat,
588587
let pat_ty = pcx.fcx.instantiate_type(def.def_id(), path);
589588
let item_substs = match pat_ty.sty {
590589
ty::TyStruct(_, substs) | ty::TyEnum(_, substs) => substs,
591-
_ => tcx.sess.span_bug(pat.span, "struct variant is not an ADT")
590+
_ => span_bug!(pat.span, "struct variant is not an ADT")
592591
};
593592
demand::eqtype(fcx, pat.span, expected, pat_ty);
594593
check_struct_pat_fields(pcx, pat.span, fields, variant, &item_substs, etc);

src/librustc_typeck/check/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
397397
write_overloaded_call_method_map(fcx, self.call_expr, method_callee);
398398
}
399399
None => {
400-
fcx.tcx().sess.span_bug(
400+
span_bug!(
401401
self.call_expr.span,
402402
"failed to find an overloaded call trait for closure call");
403403
}

src/librustc_typeck/check/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'tcx> CastCheck<'tcx> {
139139
CastError::NeedViaThinPtr => "a thin pointer",
140140
CastError::NeedViaInt => "an integer",
141141
CastError::NeedViaUsize => "a usize",
142-
_ => unreachable!()
142+
_ => bug!()
143143
}))
144144
.emit();
145145
}

src/librustc_typeck/check/coercion.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
372372
}
373373
let r_borrow = match ty.sty {
374374
ty::TyRef(r_borrow, _) => r_borrow,
375-
_ => self.tcx().sess.span_bug(span,
376-
&format!("expected a ref type, got {:?}", ty))
375+
_ => span_bug!(span, "expected a ref type, got {:?}", ty)
377376
};
378377
let autoref = Some(AutoPtr(r_borrow, mt_b.mutbl));
379378
debug!("coerce_borrowed_pointer: succeeded ty={:?} autoderefs={:?} autoref={:?}",

src/librustc_typeck/check/dropck.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ pub fn check_drop_impl(tcx: &TyCtxt, drop_impl_did: DefId) -> Result<(), ()> {
6262
// Destructors only work on nominal types. This was
6363
// already checked by coherence, so we can panic here.
6464
let span = tcx.map.def_id_span(drop_impl_did, codemap::DUMMY_SP);
65-
tcx.sess.span_bug(
66-
span, &format!("should have been rejected by coherence check: {}",
67-
dtor_self_type));
65+
span_bug!(span,
66+
"should have been rejected by coherence check: {}",
67+
dtor_self_type);
6868
}
6969
}
7070
}
@@ -276,8 +276,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>
276276
typ, scope);
277277

278278
let parent_scope = rcx.tcx().region_maps.opt_encl_scope(scope).unwrap_or_else(|| {
279-
rcx.tcx().sess.span_bug(
280-
span, &format!("no enclosing scope found for scope: {:?}", scope))
279+
span_bug!(span, "no enclosing scope found for scope: {:?}", scope)
281280
});
282281

283282
let result = iterate_over_potentially_unsafe_regions_in_type(
@@ -493,7 +492,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'b, 'tcx>(
493492
}
494493

495494
// these are always dtorck
496-
ty::TyTrait(..) | ty::TyProjection(_) => unreachable!(),
495+
ty::TyTrait(..) | ty::TyProjection(_) => bug!(),
497496
}
498497
}
499498

src/librustc_typeck/check/method/confirm.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
300300
match result {
301301
Some(r) => r,
302302
None => {
303-
self.tcx().sess.span_bug(
303+
span_bug!(
304304
self.span,
305-
&format!("self-type `{}` for ObjectPick never dereferenced to an object",
306-
self_ty))
305+
"self-type `{}` for ObjectPick never dereferenced to an object",
306+
self_ty)
307307
}
308308
}
309309
}
@@ -372,10 +372,10 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
372372
match self.fcx.mk_subty(false, TypeOrigin::Misc(self.span), self_ty, method_self_ty) {
373373
Ok(_) => {}
374374
Err(_) => {
375-
self.tcx().sess.span_bug(
375+
span_bug!(
376376
self.span,
377-
&format!("{} was a subtype of {} but now is not?",
378-
self_ty, method_self_ty));
377+
"{} was a subtype of {} but now is not?",
378+
self_ty, method_self_ty);
379379
}
380380
}
381381
}
@@ -550,15 +550,15 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
550550
}))
551551
}
552552
Some(_) => {
553-
self.tcx().sess.span_bug(
553+
span_bug!(
554554
base_expr.span,
555-
&format!("unexpected adjustment autoref {:?}",
556-
adr));
555+
"unexpected adjustment autoref {:?}",
556+
adr);
557557
}
558558
},
559559
None => (0, None),
560560
Some(_) => {
561-
self.tcx().sess.span_bug(
561+
span_bug!(
562562
base_expr.span,
563563
"unexpected adjustment type");
564564
}
@@ -646,12 +646,12 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
646646

647647
// must be exactly one trait ref or we'd get an ambig error etc
648648
if upcast_trait_refs.len() != 1 {
649-
self.tcx().sess.span_bug(
649+
span_bug!(
650650
self.span,
651-
&format!("cannot uniquely upcast `{:?}` to `{:?}`: `{:?}`",
652-
source_trait_ref,
653-
target_trait_def_id,
654-
upcast_trait_refs));
651+
"cannot uniquely upcast `{:?}` to `{:?}`: `{:?}`",
652+
source_trait_ref,
653+
target_trait_def_id,
654+
upcast_trait_refs);
655655
}
656656

657657
upcast_trait_refs.into_iter().next().unwrap()

src/librustc_typeck/check/method/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,21 +302,19 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
302302
}
303303

304304
_ => {
305-
fcx.tcx().sess.span_bug(
305+
span_bug!(
306306
span,
307-
&format!(
308-
"trait method is &self but first arg is: {}",
309-
transformed_self_ty));
307+
"trait method is &self but first arg is: {}",
308+
transformed_self_ty);
310309
}
311310
}
312311
}
313312

314313
_ => {
315-
fcx.tcx().sess.span_bug(
314+
span_bug!(
316315
span,
317-
&format!(
318-
"unexpected explicit self type in operator method: {:?}",
319-
method_ty.explicit_self));
316+
"unexpected explicit self type in operator method: {:?}",
317+
method_ty.explicit_self);
320318
}
321319
}
322320
}

src/librustc_typeck/check/method/probe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
877877
match tcx.trait_id_of_impl(impl_id) {
878878
Some(id) => id,
879879
None =>
880-
tcx.sess.span_bug(span,
881-
"found inherent method when looking at traits")
880+
span_bug!(span,
881+
"found inherent method when looking at traits")
882882
}
883883
}
884884
}
@@ -889,7 +889,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
889889
}
890890
Some(Err(MethodError::ClosureAmbiguity(..))) => {
891891
// this error only occurs when assembling candidates
892-
tcx.sess.span_bug(span, "encountered ClosureAmbiguity from pick_core");
892+
span_bug!(span, "encountered ClosureAmbiguity from pick_core");
893893
}
894894
_ => vec![],
895895
};

src/librustc_typeck/check/mod.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,7 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
463463
regionck::regionck_fn(&fcx, fn_id, fn_span, decl, body);
464464
writeback::resolve_type_vars_in_fn(&fcx, decl, body);
465465
}
466-
_ => ccx.tcx.sess.impossible_case(body.span,
467-
"check_bare_fn: function type expected")
466+
_ => span_bug!(body.span, "check_bare_fn: function type expected")
468467
}
469468
}
470469

@@ -946,7 +945,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
946945
hir::ImplItemKind::Const(..) => {
947946
let impl_const = match ty_impl_item {
948947
ty::ConstTraitItem(ref cti) => cti,
949-
_ => tcx.sess.span_bug(impl_item.span, "non-const impl-item for const")
948+
_ => span_bug!(impl_item.span, "non-const impl-item for const")
950949
};
951950

952951
// Find associated const definition.
@@ -969,7 +968,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
969968

970969
let impl_method = match ty_impl_item {
971970
ty::MethodTraitItem(ref mti) => mti,
972-
_ => tcx.sess.span_bug(impl_item.span, "non-method impl-item for method")
971+
_ => span_bug!(impl_item.span, "non-method impl-item for method")
973972
};
974973

975974
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>,
990989
hir::ImplItemKind::Type(_) => {
991990
let impl_type = match ty_impl_item {
992991
ty::TypeTraitItem(ref tti) => tti,
993-
_ => tcx.sess.span_bug(impl_item.span, "non-type impl-item for type")
992+
_ => span_bug!(impl_item.span, "non-type impl-item for type")
994993
};
995994

996995
if let &ty::TypeTraitItem(ref at) = ty_trait_item {
@@ -1567,8 +1566,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15671566
match self.inh.tables.borrow().node_types.get(&ex.id) {
15681567
Some(&t) => t,
15691568
None => {
1570-
self.tcx().sess.bug(&format!("no type for expr in fcx {}",
1571-
self.tag()));
1569+
bug!("no type for expr in fcx {}", self.tag());
15721570
}
15731571
}
15741572
}
@@ -1593,10 +1591,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15931591
Some(&t) => t,
15941592
None if self.err_count_since_creation() != 0 => self.tcx().types.err,
15951593
None => {
1596-
self.tcx().sess.bug(
1597-
&format!("no type for node {}: {} in fcx {}",
1598-
id, self.tcx().map.node_to_string(id),
1599-
self.tag()));
1594+
bug!("no type for node {}: {} in fcx {}",
1595+
id, self.tcx().map.node_to_string(id),
1596+
self.tag());
16001597
}
16011598
}
16021599
}
@@ -2386,8 +2383,7 @@ fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
23862383
fty.sig.0.output
23872384
}
23882385
_ => {
2389-
fcx.tcx().sess.span_bug(callee_expr.span,
2390-
"method without bare fn type");
2386+
span_bug!(callee_expr.span, "method without bare fn type");
23912387
}
23922388
}
23932389
}
@@ -3139,7 +3135,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
31393135
let tcx = fcx.ccx.tcx;
31403136
let substs = match adt_ty.sty {
31413137
ty::TyStruct(_, substs) | ty::TyEnum(_, substs) => substs,
3142-
_ => tcx.sess.span_bug(span, "non-ADT passed to check_expr_struct_fields")
3138+
_ => span_bug!(span, "non-ADT passed to check_expr_struct_fields")
31433139
};
31443140

31453141
let mut remaining_fields = FnvHashMap();
@@ -3400,8 +3396,7 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
34003396
depth: path.segments.len()
34013397
}
34023398
} else {
3403-
tcx.sess.span_bug(expr.span,
3404-
&format!("unbound path {:?}", expr))
3399+
span_bug!(expr.span, "unbound path {:?}", expr)
34053400
};
34063401

34073402
if let Some((opt_ty, segments, def)) =
@@ -4224,7 +4219,7 @@ fn type_scheme_and_predicates_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
42244219
Def::Label(..) |
42254220
Def::SelfTy(..) |
42264221
Def::Err => {
4227-
fcx.ccx.tcx.sess.span_bug(sp, &format!("expected value, found {:?}", defn));
4222+
span_bug!(sp, "expected value, found {:?}", defn);
42284223
}
42294224
}
42304225
}
@@ -4485,11 +4480,10 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
44854480

44864481
let impl_ty = fcx.instantiate_type_scheme(span, &substs, &impl_scheme.ty);
44874482
if fcx.mk_subty(false, TypeOrigin::Misc(span), self_ty, impl_ty).is_err() {
4488-
fcx.tcx().sess.span_bug(span,
4489-
&format!(
4483+
span_bug!(span,
44904484
"instantiate_path: (UFCS) {:?} was a subtype of {:?} but now is not?",
44914485
self_ty,
4492-
impl_ty));
4486+
impl_ty);
44934487
}
44944488
}
44954489

src/librustc_typeck/check/op.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ fn name_and_trait_def_id(fcx: &FnCtxt,
270270
hir::BiShr => ("shr_assign", lang.shr_assign_trait()),
271271
hir::BiLt | hir::BiLe | hir::BiGe | hir::BiGt | hir::BiEq | hir::BiNe | hir::BiAnd |
272272
hir::BiOr => {
273-
fcx.tcx().sess.span_bug(op.span, &format!("impossible assignment operation: {}=",
274-
hir_util::binop_to_string(op.node)))
273+
span_bug!(op.span,
274+
"impossible assignment operation: {}=",
275+
hir_util::binop_to_string(op.node))
275276
}
276277
}
277278
} else {
@@ -293,7 +294,7 @@ fn name_and_trait_def_id(fcx: &FnCtxt,
293294
hir::BiEq => ("eq", lang.eq_trait()),
294295
hir::BiNe => ("ne", lang.eq_trait()),
295296
hir::BiAnd | hir::BiOr => {
296-
fcx.tcx().sess.span_bug(op.span, "&& and || are not overloadable")
297+
span_bug!(op.span, "&& and || are not overloadable")
297298
}
298299
}
299300
}

0 commit comments

Comments
 (0)