Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librustc: Add bug!(), bug_span!() macros as unified entry points for internal compiler errors #32562

Merged
merged 19 commits into from
Apr 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
return *l;
}
}
self.tcx.sess.span_bug(expr.span,
&format!("no loop scope for id {}", loop_id));
span_bug!(expr.span, "no loop scope for id {}", loop_id);
}

r => {
self.tcx.sess.span_bug(expr.span,
&format!("bad entry `{:?}` in def_map for label", r));
span_bug!(expr.span, "bad entry `{:?}` in def_map for label", r);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/edges.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions src/librustc/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ impl<'cx, 'tcx> ty::fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
// Early-bound regions should really have been substituted away before
// we get to this point.
ty::ReEarlyBound(..) => {
self.tcx().sess.span_bug(
span_bug!(
self.span,
&format!("Encountered early bound region when generalizing: {:?}",
r));
"Encountered early bound region when generalizing: {:?}",
r);
}

// Always make a fresh region variable for skolemized regions;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting.rs
Original file line number Diff line number Diff line change
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
9 changes: 4 additions & 5 deletions src/librustc/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
ty::TyInfer(ty::FreshIntTy(c)) |
ty::TyInfer(ty::FreshFloatTy(c)) => {
if c >= self.freshen_count {
tcx.sess.bug(
&format!("Encountered a freshend type with id {} \
but our counter is only at {}",
c,
self.freshen_count));
bug!("Encountered a freshend type with id {} \
but our counter is only at {}",
c,
self.freshen_count);
}
t
}
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,10 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
}
}

infcx.tcx.sess.span_bug(
span_bug!(
span,
&format!("region {:?} is not associated with \
any bound region from A!",
r0))
"region {:?} is not associated with any bound region from A!",
r0)
}
}

Expand Down Expand Up @@ -297,7 +296,7 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {

if a_r.is_some() && b_r.is_some() && only_new_vars {
// Related to exactly one bound variable from each fn:
return rev_lookup(infcx, span, a_map, a_r.unwrap());
return rev_lookup(span, a_map, a_r.unwrap());
} else if a_r.is_none() && b_r.is_none() {
// Not related to bound variables from either fn:
assert!(!r0.is_bound());
Expand All @@ -308,8 +307,7 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
}
}

fn rev_lookup(infcx: &InferCtxt,
span: Span,
fn rev_lookup(span: Span,
a_map: &FnvHashMap<ty::BoundRegion, ty::Region>,
r: ty::Region) -> ty::Region
{
Expand All @@ -318,9 +316,10 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
return ty::ReLateBound(ty::DebruijnIndex::new(1), *a_br);
}
}
infcx.tcx.sess.span_bug(
span_bug!(
span,
&format!("could not find original bound region for {:?}", r));
"could not find original bound region for {:?}",
r);
}

fn fresh_bound_variable(infcx: &InferCtxt, debruijn: ty::DebruijnIndex) -> ty::Region {
Expand All @@ -336,9 +335,10 @@ fn var_ids<'a, 'tcx>(fields: &CombineFields<'a, 'tcx>,
.map(|(_, r)| match *r {
ty::ReVar(r) => { r }
r => {
fields.tcx().sess.span_bug(
span_bug!(
fields.trace.origin.span(),
&format!("found non-region-vid: {:?}", r));
"found non-region-vid: {:?}",
r);
}
})
.collect()
Expand Down
15 changes: 7 additions & 8 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ pub fn mk_eq_impl_headers<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
match (a.trait_ref, b.trait_ref) {
(Some(a_ref), Some(b_ref)) => mk_eq_trait_refs(cx, a_is_expected, origin, a_ref, b_ref),
(None, None) => mk_eqty(cx, a_is_expected, origin, a.self_ty, b.self_ty),
_ => cx.tcx.sess.bug("mk_eq_impl_headers given mismatched impl kinds"),
_ => bug!("mk_eq_impl_headers given mismatched impl kinds"),
}
}

Expand Down Expand Up @@ -536,10 +536,10 @@ pub fn drain_fulfillment_cx_or_panic<'a,'tcx,T>(span: Span,
match drain_fulfillment_cx(infcx, fulfill_cx, result) {
Ok(v) => v,
Err(errors) => {
infcx.tcx.sess.span_bug(
span_bug!(
span,
&format!("Encountered errors `{:?}` fulfilling during trans",
errors));
"Encountered errors `{:?}` fulfilling during trans",
errors);
}
}
}
Expand Down Expand Up @@ -1114,9 +1114,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
None if self.errors_since_creation() =>
self.tcx.types.err,
None => {
self.tcx.sess.bug(
&format!("no type for node {}: {} in fcx",
id, self.tcx.map.node_to_string(id)));
bug!("no type for node {}: {} in fcx",
id, self.tcx.map.node_to_string(id));
}
}
}
Expand All @@ -1125,7 +1124,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
match self.tables.borrow().node_types.get(&ex.id) {
Some(&t) => t,
None => {
self.tcx.sess.bug("no type for expr in fcx");
bug!("no type for expr in fcx");
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/region_inference/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
};

if output_template.is_empty() {
tcx.sess.bug("empty string provided as RUST_REGION_GRAPH");
bug!("empty string provided as RUST_REGION_GRAPH");
}

if output_template.contains('%') {
Expand Down 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
Loading