Skip to content

Commit

Permalink
librustc: replace panic!() with bug!()
Browse files Browse the repository at this point in the history
  • Loading branch information
ben0x539 committed Mar 31, 2016
1 parent 2fa867a commit e3a7a66
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/edges.rs
Expand Up @@ -122,7 +122,7 @@ impl DepGraphEdges {
{
match self.current_node() {
Some(open_node) => self.add_edge_from_open_node(open_node, op),
None => panic!("no current node, cannot add edge into dependency graph")
None => bug!("no current node, cannot add edge into dependency graph")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/thread.rs
Expand Up @@ -148,7 +148,7 @@ impl DepGraphThreadData {

// Outline this too.
fn invalid_message(&self, string: &str) {
panic!("{}; see src/librustc/dep_graph/README.md for more information", string)
bug!("{}; see src/librustc/dep_graph/README.md for more information", string)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/front/map/blocks.rs
Expand Up @@ -231,21 +231,21 @@ impl<'a> FnLikeNode<'a> {
span: i.span,
attrs: &i.attrs,
}),
_ => panic!("item FnLikeNode that is not fn-like"),
_ => bug!("item FnLikeNode that is not fn-like"),
},
map::NodeTraitItem(ti) => match ti.node {
ast::MethodTraitItem(ref sig, Some(ref body)) => {
method(ti.id, ti.name, sig, None, body, ti.span, &ti.attrs)
}
_ => panic!("trait method FnLikeNode that is not fn-like"),
_ => bug!("trait method FnLikeNode that is not fn-like"),
},
map::NodeImplItem(ii) => {
match ii.node {
ast::ImplItemKind::Method(ref sig, ref body) => {
method(ii.id, ii.name, sig, Some(ii.vis), body, ii.span, &ii.attrs)
}
_ => {
panic!("impl method FnLikeNode that is not fn-like")
bug!("impl method FnLikeNode that is not fn-like")
}
}
}
Expand All @@ -256,9 +256,9 @@ impl<'a> FnLikeNode<'a> {
e.id,
e.span,
e.attrs.as_attr_slice())),
_ => panic!("expr FnLikeNode that is not fn-like"),
_ => bug!("expr FnLikeNode that is not fn-like"),
},
_ => panic!("other FnLikeNode that is not fn-like"),
_ => bug!("other FnLikeNode that is not fn-like"),
}
}
}
40 changes: 20 additions & 20 deletions src/librustc/front/map/mod.rs
Expand Up @@ -335,9 +335,9 @@ impl<'ast> Map<'ast> {
return self.opt_local_def_id(id)
.map(|def_id| DepNode::Hir(def_id))
.unwrap_or_else(|| {
panic!("Walking parents from `{}` \
led to `NotPresent` at `{}`",
id0, id)
bug!("Walking parents from `{}` \
led to `NotPresent` at `{}`",
id0, id)
}),
}
}
Expand All @@ -363,8 +363,8 @@ impl<'ast> Map<'ast> {

pub fn local_def_id(&self, node: NodeId) -> DefId {
self.opt_local_def_id(node).unwrap_or_else(|| {
panic!("local_def_id: no entry for `{}`, which has a map of `{:?}`",
node, self.find_entry(node))
bug!("local_def_id: no entry for `{}`, which has a map of `{:?}`",
node, self.find_entry(node))
})
}

Expand Down Expand Up @@ -402,7 +402,7 @@ impl<'ast> Map<'ast> {
pub fn get(&self, id: NodeId) -> Node<'ast> {
match self.find(id) {
Some(node) => node, // read recorded by `find`
None => panic!("couldn't find node id {} in the AST map", id)
None => bug!("couldn't find node id {} in the AST map", id)
}
}

Expand Down Expand Up @@ -576,22 +576,22 @@ impl<'ast> Map<'ast> {
self.read(id); // reveals some of the content of a node
abi
}
None => panic!("expected foreign mod or inlined parent, found {}",
None => bug!("expected foreign mod or inlined parent, found {}",
self.node_to_string(parent))
}
}

pub fn expect_item(&self, id: NodeId) -> &'ast Item {
match self.find(id) { // read recorded by `find`
Some(NodeItem(item)) => item,
_ => panic!("expected item, found {}", self.node_to_string(id))
_ => bug!("expected item, found {}", self.node_to_string(id))
}
}

pub fn expect_trait_item(&self, id: NodeId) -> &'ast TraitItem {
match self.find(id) {
Some(NodeTraitItem(item)) => item,
_ => panic!("expected trait item, found {}", self.node_to_string(id))
_ => bug!("expected trait item, found {}", self.node_to_string(id))
}
}

Expand All @@ -600,38 +600,38 @@ impl<'ast> Map<'ast> {
Some(NodeItem(i)) => {
match i.node {
ItemStruct(ref struct_def, _) => struct_def,
_ => panic!("struct ID bound to non-struct")
_ => bug!("struct ID bound to non-struct")
}
}
Some(NodeVariant(variant)) => {
if variant.node.data.is_struct() {
&variant.node.data
} else {
panic!("struct ID bound to enum variant that isn't struct-like")
bug!("struct ID bound to enum variant that isn't struct-like")
}
}
_ => panic!(format!("expected struct, found {}", self.node_to_string(id))),
_ => bug!("expected struct, found {}", self.node_to_string(id)),
}
}

pub fn expect_variant(&self, id: NodeId) -> &'ast Variant {
match self.find(id) {
Some(NodeVariant(variant)) => variant,
_ => panic!(format!("expected variant, found {}", self.node_to_string(id))),
_ => bug!("expected variant, found {}", self.node_to_string(id)),
}
}

pub fn expect_foreign_item(&self, id: NodeId) -> &'ast ForeignItem {
match self.find(id) {
Some(NodeForeignItem(item)) => item,
_ => panic!("expected foreign item, found {}", self.node_to_string(id))
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
}
}

pub fn expect_expr(&self, id: NodeId) -> &'ast Expr {
match self.find(id) { // read recorded by find
Some(NodeExpr(expr)) => expr,
_ => panic!("expected expr, found {}", self.node_to_string(id))
_ => bug!("expected expr, found {}", self.node_to_string(id))
}
}

Expand All @@ -656,7 +656,7 @@ impl<'ast> Map<'ast> {
NodeLocal(&Pat { node: PatKind::Ident(_,l,_), .. }) => {
PathName(l.node.name)
},
_ => panic!("no path elem for {:?}", node)
_ => bug!("no path elem for {:?}", node)
}
}

Expand Down Expand Up @@ -773,7 +773,7 @@ impl<'ast> Map<'ast> {
pub fn span(&self, id: NodeId) -> Span {
self.read(id); // reveals span from node
self.opt_span(id)
.unwrap_or_else(|| panic!("AstMap.span: could not find span for id {:?}", id))
.unwrap_or_else(|| bug!("AstMap.span: could not find span for id {:?}", id))
}

pub fn span_if_local(&self, id: DefId) -> Option<Span> {
Expand Down Expand Up @@ -1019,12 +1019,12 @@ impl<'a> NodePrinter for pprust::State<'a> {
NodePat(a) => self.print_pat(&a),
NodeBlock(a) => self.print_block(&a),
NodeLifetime(a) => self.print_lifetime(&a),
NodeTyParam(_) => panic!("cannot print TyParam"),
NodeTyParam(_) => bug!("cannot print TyParam"),
// these cases do not carry enough information in the
// ast_map to reconstruct their full structure for pretty
// printing.
NodeLocal(_) => panic!("cannot print isolated Local"),
NodeStructCtor(_) => panic!("cannot print isolated StructCtor"),
NodeLocal(_) => bug!("cannot print isolated Local"),
NodeStructCtor(_) => bug!("cannot print isolated StructCtor"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting.rs
Expand Up @@ -404,7 +404,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
bound_failures.push((origin.clone(), kind.clone(), region));
}
ProcessedErrors(..) => {
panic!("should not encounter a `ProcessedErrors` yet: {:?}", error)
bug!("should not encounter a `ProcessedErrors` yet: {:?}", error)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/region_inference/graphviz.rs
Expand Up @@ -182,13 +182,13 @@ impl<'a, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'tcx> {
fn node_id(&self, n: &Node) -> dot::Id {
let node_id = match self.node_ids.get(n) {
Some(node_id) => node_id,
None => panic!("no node_id found for node: {:?}", n),
None => bug!("no node_id found for node: {:?}", n),
};
let name = || format!("node_{}", node_id);
match dot::Id::new(name()) {
Ok(id) => id,
Err(_) => {
panic!("failed to create graphviz node identified by {}", name());
bug!("failed to create graphviz node identified by {}", name());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/region_inference/mod.rs
Expand Up @@ -309,7 +309,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
while undo_log.len() > snapshot.length + 1 {
match undo_log.pop().unwrap() {
OpenSnapshot => {
panic!("Failure to observe stack discipline");
bug!("Failure to observe stack discipline");
}
CommitedSnapshot => {}
AddVar(vid) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/type_variable.rs
Expand Up @@ -159,8 +159,8 @@ impl<'tcx> TypeVariableTable<'tcx> {

let (relations, default) = match old_value {
Bounded { relations, default } => (relations, default),
Known(_) => panic!("Asked to instantiate variable that is \
already instantiated")
Known(_) => bug!("Asked to instantiate variable that is \
already instantiated")
};

for &(dir, vid) in &relations {
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {

fn relations<'a>(v: &'a mut TypeVariableData) -> &'a mut Vec<Relation> {
match v.value {
Known(_) => panic!("var_sub_var: variable is known"),
Known(_) => bug!("var_sub_var: variable is known"),
Bounded { ref mut relations, .. } => relations
}
}
4 changes: 2 additions & 2 deletions src/librustc/lint/context.rs
Expand Up @@ -232,7 +232,7 @@ impl LintStore {
pub fn register_renamed(&mut self, old_name: &str, new_name: &str) {
let target = match self.by_name.get(new_name) {
Some(&Id(lint_id)) => lint_id.clone(),
_ => panic!("invalid lint renaming of {} to {}", old_name, new_name)
_ => bug!("invalid lint renaming of {} to {}", old_name, new_name)
};
self.by_name.insert(old_name.to_string(), Renamed(new_name.to_string(), target));
}
Expand Down Expand Up @@ -430,7 +430,7 @@ pub fn raw_struct_lint<'a>(sess: &'a Session,
format!("{} [-{} {}]", msg,
match level {
Warn => 'W', Deny => 'D', Forbid => 'F',
Allow => panic!()
Allow => bug!()
}, name.replace("_", "-"))
},
Node(src) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/cstore.rs
Expand Up @@ -309,7 +309,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
{
let mut say = |s: &str| {
match (sp, sess) {
(_, None) => panic!("{}", s),
(_, None) => bug!("{}", s),
(Some(sp), Some(sess)) => sess.span_err(sp, s),
(None, Some(sess)) => sess.err(s),
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/def.rs
Expand Up @@ -71,7 +71,7 @@ impl PathResolution {
/// Get the definition, if fully resolved, otherwise panic.
pub fn full_def(&self) -> Def {
if self.depth != 0 {
panic!("path not fully resolved: {:?}", self);
bug!("path not fully resolved: {:?}", self);
}
self.base_def
}
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Def {
Def::TyParam(..) | Def::Struct(..) | Def::Trait(..) |
Def::Method(..) | Def::Const(..) | Def::AssociatedConst(..) |
Def::PrimTy(..) | Def::Label(..) | Def::SelfTy(..) | Def::Err => {
panic!("attempted .var_id() on invalid {:?}", self)
bug!("attempted .var_id() on invalid {:?}", self)
}
}
}
Expand All @@ -135,7 +135,7 @@ impl Def {
Def::PrimTy(..) |
Def::SelfTy(..) |
Def::Err => {
panic!("attempted .def_id() on invalid def: {:?}", self)
bug!("attempted .def_id() on invalid def: {:?}", self)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -611,7 +611,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
}))
}

Def::Err => panic!("Def::Err in memory categorization")
Def::Err => bug!("Def::Err in memory categorization")
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/region.rs
Expand Up @@ -343,7 +343,7 @@ impl RegionMaps {
pub fn lookup_code_extent(&self, e: CodeExtentData) -> CodeExtent {
match self.code_extent_interner.borrow().get(&e) {
Some(&d) => d,
None => panic!("unknown code extent {:?}", e)
None => bug!("unknown code extent {:?}", e)
}
}
pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
Expand Down Expand Up @@ -470,7 +470,7 @@ impl RegionMaps {
pub fn var_scope(&self, var_id: ast::NodeId) -> CodeExtent {
match self.var_map.borrow().get(&var_id) {
Some(&r) => r,
None => { panic!("no enclosing scope for id {:?}", var_id); }
None => { bug!("no enclosing scope for id {:?}", var_id); }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/filesearch.rs
Expand Up @@ -155,14 +155,14 @@ pub fn get_or_default_sysroot() -> PathBuf {
// gcc chokes on verbatim paths which fs::canonicalize generates
// so we try to avoid those kinds of paths.
Ok(canon) => Some(rustcfs::fix_windows_verbatim_for_gcc(&canon)),
Err(e) => panic!("failed to get realpath: {}", e),
Err(e) => bug!("failed to get realpath: {}", e),
}
})
}

match canonicalize(env::current_exe().ok()) {
Some(mut p) => { p.pop(); p.pop(); p }
None => panic!("can't determine value for sysroot")
None => bug!("can't determine value for sysroot")
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/specialize/specialization_graph.rs
Expand Up @@ -145,8 +145,8 @@ impl Graph {
/// Insert cached metadata mapping from a child impl back to its parent.
pub fn record_impl_from_cstore(&mut self, parent: DefId, child: DefId) {
if self.parent.insert(child, parent).is_some() {
panic!("When recording an impl from the crate store, information about its parent \
was already present.");
bug!("When recording an impl from the crate store, information about its parent \
was already present.");
}

self.children.entry(parent).or_insert(vec![]).push(child);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Expand Up @@ -1647,7 +1647,7 @@ impl<'tcx, 'container> AdtDefData<'tcx, 'container> {
match def {
Def::Variant(_, vid) => self.variant_with_id(vid),
Def::Struct(..) | Def::TyAlias(..) => self.struct_variant(),
_ => panic!("unexpected def {:?} in variant_of_def", def)
_ => bug!("unexpected def {:?} in variant_of_def", def)
}
}

Expand Down Expand Up @@ -1857,7 +1857,7 @@ fn lookup_locally_or_in_crate_store<M, F>(descr: &str,
{
map.memoize(def_id, || {
if def_id.is_local() {
panic!("No def'n found for {:?} in tcx.{}", def_id, descr);
bug!("No def'n found for {:?} in tcx.{}", def_id, descr);
}
load_external()
})
Expand Down

0 comments on commit e3a7a66

Please sign in to comment.