diff --git a/src/librustc/dep_graph/edges.rs b/src/librustc/dep_graph/edges.rs index 4b25285c476..d3ced8aa518 100644 --- a/src/librustc/dep_graph/edges.rs +++ b/src/librustc/dep_graph/edges.rs @@ -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") } } diff --git a/src/librustc/dep_graph/thread.rs b/src/librustc/dep_graph/thread.rs index c43b4b15b76..1b1d3469bc5 100644 --- a/src/librustc/dep_graph/thread.rs +++ b/src/librustc/dep_graph/thread.rs @@ -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) } } diff --git a/src/librustc/front/map/blocks.rs b/src/librustc/front/map/blocks.rs index 976a8c6dda0..2eb3d56bb5e 100644 --- a/src/librustc/front/map/blocks.rs +++ b/src/librustc/front/map/blocks.rs @@ -231,13 +231,13 @@ 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 { @@ -245,7 +245,7 @@ impl<'a> FnLikeNode<'a> { 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") } } } @@ -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"), } } } diff --git a/src/librustc/front/map/mod.rs b/src/librustc/front/map/mod.rs index 3605de44495..817bec58407 100644 --- a/src/librustc/front/map/mod.rs +++ b/src/librustc/front/map/mod.rs @@ -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) }), } } @@ -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)) }) } @@ -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) } } @@ -576,7 +576,7 @@ 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)) } } @@ -584,14 +584,14 @@ impl<'ast> Map<'ast> { 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)) } } @@ -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)) } } @@ -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) } } @@ -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 { @@ -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"), } } } diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 20c01344144..8079a6d1bbc 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -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) } } } diff --git a/src/librustc/infer/region_inference/graphviz.rs b/src/librustc/infer/region_inference/graphviz.rs index 8200e7825a0..e611c005691 100644 --- a/src/librustc/infer/region_inference/graphviz.rs +++ b/src/librustc/infer/region_inference/graphviz.rs @@ -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()); } } } diff --git a/src/librustc/infer/region_inference/mod.rs b/src/librustc/infer/region_inference/mod.rs index 32eeb9c4ea3..2f610bf2380 100644 --- a/src/librustc/infer/region_inference/mod.rs +++ b/src/librustc/infer/region_inference/mod.rs @@ -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) => { diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index 141556c102d..3cc076f1f00 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -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 { @@ -318,7 +318,7 @@ impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> { fn relations<'a>(v: &'a mut TypeVariableData) -> &'a mut Vec { match v.value { - Known(_) => panic!("var_sub_var: variable is known"), + Known(_) => bug!("var_sub_var: variable is known"), Bounded { ref mut relations, .. } => relations } } diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 7e6eb0146fc..e78ff513ac4 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -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)); } @@ -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) => { diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 305b64f3320..4efb40abdb0 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -309,7 +309,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option) { { 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), } diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs index 6cbcd41d84a..e6ea000936c 100644 --- a/src/librustc/middle/def.rs +++ b/src/librustc/middle/def.rs @@ -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 } @@ -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) } } } @@ -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) } } } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 1eb0a9956d0..ef031ad13f1 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -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") } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 7a607e2419d..2cde6ce9320 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -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 { @@ -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); } } } diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs index 09c6b54d99c..e54acf3fdc3 100644 --- a/src/librustc/session/filesearch.rs +++ b/src/librustc/session/filesearch.rs @@ -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") } } diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index eaafeb1a969..d3146697ee6 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -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); diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index b52460f6c57..edfad09ae1f 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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) } } @@ -1857,7 +1857,7 @@ fn lookup_locally_or_in_crate_store(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() }) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 191c261b7e3..fee0aaff445 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -987,14 +987,14 @@ impl<'tcx> TyS<'tcx> { TyStruct(def, substs) => { def.struct_variant().fields[0].ty(cx, substs) } - _ => panic!("simd_type called on invalid type") + _ => bug!("simd_type called on invalid type") } } pub fn simd_size(&self, _cx: &TyCtxt) -> usize { match self.sty { TyStruct(def, _) => def.struct_variant().fields.len(), - _ => panic!("simd_size called on invalid type") + _ => bug!("simd_size called on invalid type") } } @@ -1147,7 +1147,7 @@ impl<'tcx> TyS<'tcx> { pub fn fn_sig(&self) -> &'tcx PolyFnSig<'tcx> { match self.sty { TyFnDef(_, _, ref f) | TyFnPtr(ref f) => &f.sig, - _ => panic!("Ty::fn_sig() called on non-fn type: {:?}", self) + _ => bug!("Ty::fn_sig() called on non-fn type: {:?}", self) } } @@ -1155,7 +1155,7 @@ impl<'tcx> TyS<'tcx> { pub fn fn_abi(&self) -> abi::Abi { match self.sty { TyFnDef(_, _, ref f) | TyFnPtr(ref f) => f.abi, - _ => panic!("Ty::fn_abi() called on non-fn type"), + _ => bug!("Ty::fn_abi() called on non-fn type"), } } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 81f50e2e0a1..5b05c632a97 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -193,7 +193,7 @@ impl ParamSpace { 0 => TypeSpace, 1 => SelfSpace, 2 => FnSpace, - _ => panic!("Invalid ParamSpace: {}", u) + _ => bug!("Invalid ParamSpace: {}", u) } } } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index e5f2e5fc70a..6e8363f629b 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -88,7 +88,7 @@ impl IntTypeExt for attr::IntType { (UnsignedInt(ast::UintTy::U32), ConstInt::U32(_)) => {}, (UnsignedInt(ast::UintTy::U64), ConstInt::U64(_)) => {}, (UnsignedInt(ast::UintTy::Us), ConstInt::Usize(_)) => {}, - _ => panic!("disr type mismatch: {:?} vs {:?}", self, val), + _ => bug!("disr type mismatch: {:?} vs {:?}", self, val), } }