From 8f8cc061d9a82f7cfd9b9c9d7312c9551c4b286f Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 17 Sep 2013 07:45:49 -0700 Subject: [PATCH] syntax: swap from .span_fatal to .span_err in #[deriving(FromPrimitive)] --- src/libsyntax/ext/build.rs | 9 +++++++-- src/libsyntax/ext/deriving/primitive.rs | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 8e4f553cb83..65a6572fa5e 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -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 } diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index 6e012eedfa3..ddf8fc404d4 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -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)") - }; + } }