syntax: swap from .span_fatal to .span_err in #[deriving(FromPrimitive)]

This commit is contained in:
Erick Tryzelaar 2013-09-17 07:45:49 -07:00
parent 0feaccf526
commit 8f8cc061d9
2 changed files with 21 additions and 9 deletions

View File

@ -136,6 +136,7 @@ fn expr_method_call(&self, span: Span,
fn expr_some(&self, sp: Span, expr: @ast::Expr) -> @ast::Expr;
fn expr_none(&self, sp: Span) -> @ast::Expr;
fn expr_fail(&self, span: Span, msg: @str) -> @ast::Expr;
fn expr_unreachable(&self, span: Span) -> @ast::Expr;
fn pat(&self, span: Span, pat: ast::Pat_) -> @ast::Pat;
@ -591,7 +592,7 @@ fn expr_none(&self, sp: Span) -> @ast::Expr {
self.expr_path(none)
}
fn expr_unreachable(&self, span: Span) -> @ast::Expr {
fn expr_fail(&self, span: Span, msg: @str) -> @ast::Expr {
let loc = self.codemap().lookup_char_pos(span.lo);
self.expr_call_global(
span,
@ -602,12 +603,16 @@ fn expr_unreachable(&self, span: Span) -> @ast::Expr {
self.ident_of("fail_with"),
],
~[
self.expr_str(span, @"internal error: entered unreachable code"),
self.expr_str(span, msg),
self.expr_str(span, loc.file.name),
self.expr_uint(span, loc.line),
])
}
fn expr_unreachable(&self, span: Span) -> @ast::Expr {
self.expr_fail(span, @"internal error: entered unreachable code")
}
fn pat(&self, span: Span, pat: ast::Pat_) -> @ast::Pat {
@ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span }

View File

@ -64,10 +64,15 @@ fn cs_from(name: &str, cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr
_ => cx.span_bug(span, "Incorrect number of arguments in `deriving(FromPrimitive)`")
};
return match *substr.fields {
match *substr.fields {
StaticStruct(*) => {
cx.span_err(span, "`FromPrimitive` cannot be derived for structs");
return cx.expr_fail(span, @"");
}
StaticEnum(enum_def, _) => {
if enum_def.variants.is_empty() {
cx.span_fatal(span, "`FromPrimitive` cannot be derived for enums with no variants");
cx.span_err(span, "`FromPrimitive` cannot be derived for enums with no variants");
return cx.expr_fail(span, @"");
}
let mut arms = ~[];
@ -76,8 +81,9 @@ fn cs_from(name: &str, cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr
match variant.node.kind {
ast::tuple_variant_kind(ref args) => {
if !args.is_empty() {
cx.span_fatal(span, "`FromPrimitive` cannot be derived for \
enum variants with arguments");
cx.span_err(span, "`FromPrimitive` cannot be derived for \
enum variants with arguments");
return cx.expr_fail(span, @"");
}
// expr for `$n == $variant as $name`
@ -99,8 +105,9 @@ fn cs_from(name: &str, cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr
arms.push(arm);
}
ast::struct_variant_kind(_) => {
cx.span_fatal(span, "`FromPrimitive` cannot be derived for enums \
with struct variants");
cx.span_err(span, "`FromPrimitive` cannot be derived for enums \
with struct variants");
return cx.expr_fail(span, @"");
}
}
}
@ -116,5 +123,5 @@ fn cs_from(name: &str, cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr
cx.expr_match(span, n, arms)
}
_ => cx.bug("expected StaticEnum in deriving(FromPrimitive)")
};
}
}