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

This commit is contained in:
Benjamin Herr 2016-03-28 23:00:01 +02:00
parent 8aaf6eee2f
commit 0305537652
8 changed files with 62 additions and 74 deletions

View file

@ -991,7 +991,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
region: this.read_enum_variant_arg(1,
|this| Ok(this.read_region(dcx))).unwrap()
}),
_ => panic!("bad enum variant for ty::UpvarCapture")
_ => bug!("bad enum variant for ty::UpvarCapture")
})
})
}).unwrap()
@ -1013,7 +1013,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
adjustment::AdjustDerefRef(auto_deref_ref)
}
_ => panic!("bad enum variant for adjustment::AutoAdjustment")
_ => bug!("bad enum variant for adjustment::AutoAdjustment")
})
})
}).unwrap()
@ -1072,7 +1072,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
adjustment::AutoUnsafe(m)
}
_ => panic!("bad enum variant for adjustment::AutoRef")
_ => bug!("bad enum variant for adjustment::AutoRef")
})
})
}).unwrap()
@ -1140,9 +1140,7 @@ fn decode_side_tables(dcx: &DecodeContext,
let decoded_tag: Option<c::astencode_tag> = c::astencode_tag::from_u32(tag);
match decoded_tag {
None => {
dcx.tcx.sess.bug(
&format!("unknown tag found in side tables: {:x}",
tag));
bug!("unknown tag found in side tables: {:x}", tag);
}
Some(value) => {
let val_dsr = &mut entry_dsr;
@ -1206,9 +1204,7 @@ fn decode_side_tables(dcx: &DecodeContext,
dcx.tcx.const_qualif_map.borrow_mut().insert(id, qualif);
}
_ => {
dcx.tcx.sess.bug(
&format!("unknown tag found in side tables: {:x}",
tag));
bug!("unknown tag found in side tables: {:x}", tag);
}
}
}
@ -1404,6 +1400,6 @@ fn test_simplification() {
assert!(pprust::item_to_string(&item_out) ==
pprust::item_to_string(&item_exp));
}
_ => panic!()
_ => bug!()
}
}

View file

@ -36,7 +36,6 @@ use syntax::codemap::{self, Span, mk_sp, Pos};
use syntax::parse;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::errors::FatalError;
use syntax::parse::token::InternedString;
use rustc_front::intravisit::Visitor;
use rustc_front::hir;
@ -527,7 +526,7 @@ impl<'a> CrateReader<'a> {
load_ctxt.filesearch = self.sess.target_filesearch(PathKind::Crate);
load_ctxt.load_library_crate()
}
None => { load_ctxt.report_load_errs(); unreachable!() },
None => { load_ctxt.report_load_errs(); },
};
let dylib = library.dylib.clone();
@ -573,7 +572,8 @@ impl<'a> CrateReader<'a> {
Ok(body) => body,
Err(mut err) => {
err.emit();
panic!(FatalError);
self.sess.abort_if_errors();
unreachable!();
}
};
let local_span = mk_sp(lo, p.last_span.hi);

View file

@ -70,7 +70,7 @@ impl crate_metadata {
fn lookup_item(&self, item_id: DefIndex) -> rbml::Doc {
match self.get_item(item_id) {
None => panic!("lookup_item: id not found: {:?}", item_id),
None => bug!("lookup_item: id not found: {:?}", item_id),
Some(d) => d
}
}
@ -136,7 +136,7 @@ fn item_family(item: rbml::Doc) -> Family {
'u' => Struct(VariantKind::Unit),
'g' => PublicField,
'N' => InheritedField,
c => panic!("unexpected family char: {}", c)
c => bug!("unexpected family char: {}", c)
}
}
@ -147,7 +147,7 @@ fn item_visibility(item: rbml::Doc) -> hir::Visibility {
match reader::doc_as_u8(visibility_doc) as char {
'y' => hir::Public,
'i' => hir::Inherited,
_ => panic!("unknown visibility character")
_ => bug!("unknown visibility character")
}
}
}
@ -160,7 +160,7 @@ fn fn_constness(item: rbml::Doc) -> hir::Constness {
match reader::doc_as_u8(constness_doc) as char {
'c' => hir::Constness::Const,
'n' => hir::Constness::NotConst,
_ => panic!("unknown constness character")
_ => bug!("unknown constness character")
}
}
}
@ -173,7 +173,7 @@ fn item_defaultness(item: rbml::Doc) -> hir::Defaultness {
match reader::doc_as_u8(defaultness_doc) as char {
'd' => hir::Defaultness::Default,
'f' => hir::Defaultness::Final,
_ => panic!("unknown defaultness character")
_ => bug!("unknown defaultness character")
}
}
}
@ -387,16 +387,15 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
item_id: DefIndex,
tcx: &TyCtxt<'tcx>) -> ty::AdtDefMaster<'tcx>
{
fn expect_variant_kind<'tcx>(family: Family, tcx: &TyCtxt<'tcx>) -> ty::VariantKind {
fn expect_variant_kind(family: Family) -> ty::VariantKind {
match family_to_variant_kind(family) {
Some(kind) => kind,
_ => tcx.sess.bug(&format!("unexpected family: {:?}", family)),
_ => bug!("unexpected family: {:?}", family),
}
}
fn get_enum_variants<'tcx>(intr: &IdentInterner,
cdata: Cmd,
doc: rbml::Doc,
tcx: &TyCtxt<'tcx>) -> Vec<ty::VariantDefData<'tcx, 'tcx>> {
doc: rbml::Doc) -> Vec<ty::VariantDefData<'tcx, 'tcx>> {
let mut disr_val = 0;
reader::tagged_docs(doc, tag_items_data_item_variant).map(|p| {
let did = translated_def_id(cdata, p);
@ -411,22 +410,21 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
ty::VariantDefData {
did: did,
name: item_name(intr, item),
fields: get_variant_fields(intr, cdata, item, tcx),
fields: get_variant_fields(intr, cdata, item),
disr_val: ConstInt::Infer(disr),
kind: expect_variant_kind(item_family(item), tcx),
kind: expect_variant_kind(item_family(item)),
}
}).collect()
}
fn get_variant_fields<'tcx>(intr: &IdentInterner,
cdata: Cmd,
doc: rbml::Doc,
tcx: &TyCtxt<'tcx>) -> Vec<ty::FieldDefData<'tcx, 'tcx>> {
doc: rbml::Doc) -> Vec<ty::FieldDefData<'tcx, 'tcx>> {
let mut index = 0;
reader::tagged_docs(doc, tag_item_field).map(|f| {
let ff = item_family(f);
match ff {
PublicField | InheritedField => {},
_ => tcx.sess.bug(&format!("expected field, found {:?}", ff))
_ => bug!("expected field, found {:?}", ff)
};
ty::FieldDefData::new(item_def_id(f, cdata),
item_name(intr, f),
@ -442,14 +440,13 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
fn get_struct_variant<'tcx>(intr: &IdentInterner,
cdata: Cmd,
doc: rbml::Doc,
did: DefId,
tcx: &TyCtxt<'tcx>) -> ty::VariantDefData<'tcx, 'tcx> {
did: DefId) -> ty::VariantDefData<'tcx, 'tcx> {
ty::VariantDefData {
did: did,
name: item_name(intr, doc),
fields: get_variant_fields(intr, cdata, doc, tcx),
fields: get_variant_fields(intr, cdata, doc),
disr_val: ConstInt::Infer(0),
kind: expect_variant_kind(item_family(doc), tcx),
kind: expect_variant_kind(item_family(doc)),
}
}
@ -458,18 +455,17 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
let (kind, variants) = match item_family(doc) {
Enum => {
(ty::AdtKind::Enum,
get_enum_variants(intr, cdata, doc, tcx))
get_enum_variants(intr, cdata, doc))
}
Struct(..) => {
let ctor_did =
reader::maybe_get_doc(doc, tag_items_data_item_struct_ctor).
map_or(did, |ctor_doc| translated_def_id(cdata, ctor_doc));
(ty::AdtKind::Struct,
vec![get_struct_variant(intr, cdata, doc, ctor_did, tcx)])
vec![get_struct_variant(intr, cdata, doc, ctor_did)])
}
_ => tcx.sess.bug(
&format!("get_adt_def called on a non-ADT {:?} - {:?}",
item_family(doc), did))
_ => bug!("get_adt_def called on a non-ADT {:?} - {:?}",
item_family(doc), did)
};
let adt = tcx.intern_adt_def(did, kind, variants);
@ -495,7 +491,7 @@ pub fn get_adt_def<'tcx>(intr: &IdentInterner,
assert!(!inputs.has_escaping_regions());
inputs
},
_ => tcx.sess.bug("tuple-variant ctor is not an ADT")
_ => bug!("tuple-variant ctor is not an ADT")
};
for (field, &ty) in variant.fields.iter().zip(field_tys.iter()) {
field.fulfill_ty(ty);
@ -915,7 +911,7 @@ fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
match ch as char {
'i' => hir::MutImmutable,
'm' => hir::MutMutable,
_ => panic!("unknown mutability character: `{}`", ch as char),
_ => bug!("unknown mutability character: `{}`", ch as char),
}
}
@ -933,7 +929,7 @@ fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
ty::ReEmpty,
get_mutability(string.as_bytes()[1]))
}
_ => panic!("unknown self type code: `{}`", explicit_self_kind as char)
_ => bug!("unknown self type code: `{}`", explicit_self_kind as char)
}
}
@ -946,7 +942,7 @@ pub fn get_impl_items(cdata: Cmd, impl_id: DefIndex)
Some('C') | Some('c') => ty::ConstTraitItemId(def_id),
Some('r') | Some('p') => ty::MethodTraitItemId(def_id),
Some('t') => ty::TypeTraitItemId(def_id),
_ => panic!("unknown impl item sort"),
_ => bug!("unknown impl item sort"),
}
}).collect()
}
@ -1012,9 +1008,9 @@ pub fn get_impl_or_trait_item<'tcx>(intr: Rc<IdentInterner>,
let ity = tcx.lookup_item_type(def_id).ty;
let fty = match ity.sty {
ty::TyFnDef(_, _, fty) => fty.clone(),
_ => tcx.sess.bug(&format!(
_ => bug!(
"the type {:?} of the method {:?} is not a function?",
ity, name))
ity, name)
};
let explicit_self = get_explicit_self(item_doc);
@ -1052,7 +1048,7 @@ pub fn get_trait_item_def_ids(cdata: Cmd, id: DefIndex)
Some('C') | Some('c') => ty::ConstTraitItemId(def_id),
Some('r') | Some('p') => ty::MethodTraitItemId(def_id),
Some('t') => ty::TypeTraitItemId(def_id),
_ => panic!("unknown trait item sort"),
_ => bug!("unknown trait item sort"),
}
}).collect()
}
@ -1172,7 +1168,7 @@ fn struct_field_family_to_visibility(family: Family) -> hir::Visibility {
match family {
PublicField => hir::Public,
InheritedField => hir::Inherited,
_ => panic!()
_ => bug!()
}
}
@ -1354,7 +1350,7 @@ pub fn translate_def_id(cdata: Cmd, did: DefId) -> DefId {
index: did.index,
}
}
None => panic!("didn't find a crate in the cnum_map")
None => bug!("didn't find a crate in the cnum_map")
}
}
@ -1544,7 +1540,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd)
let cnum: ast::CrateNum = cnum.parse().unwrap();
let cnum = match cdata.cnum_map.borrow().get(&cnum) {
Some(&n) => n,
None => panic!("didn't find a crate in the cnum_map")
None => bug!("didn't find a crate in the cnum_map")
};
result.push((cnum, if link == "d" {
LinkagePreference::RequireDynamic
@ -1772,7 +1768,7 @@ pub fn def_key(cdata: Cmd, id: DefIndex) -> hir_map::DefKey {
hir_map::DefKey::decode(&mut decoder).unwrap()
}
None => {
panic!("failed to find block with tag {:?} for item with family {:?}",
bug!("failed to find block with tag {:?} for item with family {:?}",
tag_def_key,
item_family(item_doc))
}

View file

@ -217,7 +217,7 @@ fn encode_symbol(ecx: &EncodeContext,
rbml_w.wr_tagged_str(tag_items_data_item_symbol, x);
}
None => {
ecx.diag.bug(&format!("encode_symbol: id not found {}", id));
bug!("encode_symbol: id not found {}", id);
}
}
}

View file

@ -33,6 +33,7 @@ extern crate flate;
extern crate rbml;
extern crate serialize;
#[macro_use]
extern crate rustc;
extern crate rustc_back;
extern crate rustc_front;

View file

@ -300,16 +300,10 @@ impl<'a> Context<'a> {
}
pub fn load_library_crate(&mut self) -> Library {
match self.find_library_crate() {
Some(t) => t,
None => {
self.report_load_errs();
unreachable!()
}
}
self.find_library_crate().unwrap_or_else(|| self.report_load_errs())
}
pub fn report_load_errs(&mut self) {
pub fn report_load_errs(&mut self) -> ! {
let add = match self.root {
&None => String::new(),
&Some(ref r) => format!(" which `{}` depends on",
@ -374,6 +368,7 @@ impl<'a> Context<'a> {
err.emit();
self.sess.abort_if_errors();
unreachable!();
}
fn find_library_crate(&mut self) -> Option<Library> {

View file

@ -167,7 +167,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
ty::BrFresh(id)
}
'e' => ty::BrEnv,
_ => panic!("parse_bound_region: bad input")
_ => bug!("parse_bound_region: bad input")
}
}
@ -214,7 +214,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
'e' => {
ty::ReStatic
}
_ => panic!("parse_region: bad input")
_ => bug!("parse_region: bad input")
}
}
@ -266,7 +266,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
};
region::CodeExtentData::Remainder(block_remainder)
}
_ => panic!("parse_scope: bad input")
_ => bug!("parse_scope: bad input")
})
}
@ -276,7 +276,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
match self.next() {
'n' => None,
's' => Some(f(self)),
_ => panic!("parse_opt: bad input")
_ => bug!("parse_opt: bad input")
}
}
@ -315,7 +315,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
'D' => return tcx.types.i64,
'f' => return tcx.types.f32,
'F' => return tcx.types.f64,
_ => panic!("parse_ty: bad numeric type")
_ => bug!("parse_ty: bad numeric type")
}
}
'c' => return tcx.types.char,
@ -441,7 +441,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
'e' => {
return tcx.types.err;
}
c => { panic!("unexpected char in type string: {}", c);}
c => { bug!("unexpected char in type string: {}", c);}
}
}
@ -523,7 +523,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
let variadic = match self.next() {
'V' => true,
'N' => false,
r => panic!(format!("bad variadic: {}", r)),
r => bug!("bad variadic: {}", r),
};
let output = match self.peek() {
'z' => {
@ -553,7 +553,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
assert_eq!(self.next(), '|');
ty::Predicate::ObjectSafe(def_id)
}
c => panic!("Encountered invalid character in metadata: {}", c)
c => bug!("Encountered invalid character in metadata: {}", c)
}
}
@ -602,7 +602,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
'R' => bounds.push(self.parse_region()),
'.' => { break; }
c => {
panic!("parse_region_param_def: bad bounds ('{}')", c)
bug!("parse_region_param_def: bad bounds ('{}')", c)
}
}
}
@ -624,7 +624,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
let region = self.parse_region();
ty::ObjectLifetimeDefault::Specific(region)
}
_ => panic!("parse_object_lifetime_default: bad input")
_ => bug!("parse_object_lifetime_default: bad input")
}
}
@ -640,7 +640,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
}
'.' => { break; }
c => {
panic!("parse_bounds: bad bounds ('{}')", c)
bug!("parse_bounds: bad bounds ('{}')", c)
}
}
}
@ -669,7 +669,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
return builtin_bounds;
}
c => {
panic!("parse_bounds: bad builtin bounds ('{}')", c)
bug!("parse_bounds: bad builtin bounds ('{}')", c)
}
}
}
@ -683,7 +683,7 @@ fn parse_defid(buf: &[u8]) -> DefId {
while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1; }
if colon_idx == len {
error!("didn't find ':' when parsing def id");
panic!();
bug!();
}
let crate_part = &buf[0..colon_idx];
@ -693,14 +693,14 @@ fn parse_defid(buf: &[u8]) -> DefId {
s.parse::<usize>().ok()
}) {
Some(cn) => cn as ast::CrateNum,
None => panic!("internal error: parse_defid: crate number expected, found {:?}",
None => bug!("internal error: parse_defid: crate number expected, found {:?}",
crate_part)
};
let def_num = match str::from_utf8(def_part).ok().and_then(|s| {
s.parse::<usize>().ok()
}) {
Some(dn) => dn,
None => panic!("internal error: parse_defid: id expected, found {:?}",
None => bug!("internal error: parse_defid: id expected, found {:?}",
def_part)
};
let index = DefIndex::new(def_num);
@ -711,6 +711,6 @@ fn parse_unsafety(c: char) -> hir::Unsafety {
match c {
'u' => hir::Unsafety::Unsafe,
'n' => hir::Unsafety::Normal,
_ => panic!("parse_unsafety: bad unsafety {}", c)
_ => bug!("parse_unsafety: bad unsafety {}", c)
}
}

View file

@ -146,7 +146,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Cursor<Vec<u8>>, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx
enc_bare_fn_ty(w, cx, f);
}
ty::TyInfer(_) => {
cx.diag.bug("cannot encode inference variable types");
bug!("cannot encode inference variable types");
}
ty::TyParam(ParamTy {space, idx, name}) => {
write!(w, "p[{}|{}|{}]", idx, space.to_uint(), name);
@ -285,7 +285,7 @@ pub fn enc_region(w: &mut Cursor<Vec<u8>>, cx: &ctxt, r: ty::Region) {
}
ty::ReVar(_) | ty::ReSkolemized(..) => {
// these should not crop up after typeck
cx.diag.bug("cannot encode region variables");
bug!("cannot encode region variables");
}
}
}