]> git.lizzy.rs Git - rust.git/commitdiff
Do not rely on newtype enum dereference
authorSeo Sanghyeon <sanxiyn@gmail.com>
Tue, 2 Jul 2013 09:31:00 +0000 (18:31 +0900)
committerSeo Sanghyeon <sanxiyn@gmail.com>
Fri, 5 Jul 2013 04:03:04 +0000 (13:03 +0900)
src/librustc/front/test.rs
src/libsyntax/codemap.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/expand.rs
src/libsyntax/ext/source_util.rs

index 91000d68aad09be29aca378f16efecca3346266f..bbac4a2907c0fa8a60c57c6dd32530f8ca5f8657 100644 (file)
@@ -17,7 +17,7 @@
 use std::vec;
 use syntax::ast_util::*;
 use syntax::attr;
-use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan};
+use syntax::codemap::{dummy_sp, span, ExpnInfo, NameAndSpan};
 use syntax::codemap;
 use syntax::ext::base::ExtCtxt;
 use syntax::fold;
@@ -72,13 +72,13 @@ fn generate_test_harness(sess: session::Session,
     };
 
     let ext_cx = cx.ext_cx;
-    ext_cx.bt_push(ExpandedFrom(CallInfo {
+    ext_cx.bt_push(ExpnInfo {
         call_site: dummy_sp(),
         callee: NameAndSpan {
             name: @"test",
             span: None
         }
-    }));
+    });
 
     let precursor = @fold::AstFoldFns {
         fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ),
index bcf617c56ae1eba60aa598eaa0f8f7837a9412fc..7e89d0407816031ea3e191822df7460a798e7d00 100644 (file)
@@ -174,18 +174,13 @@ pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
 #[deriving(IterBytes)]
 pub struct NameAndSpan {name: @str, span: Option<span>}
 
+/// Extra information for tracking macro expansion of spans
 #[deriving(IterBytes)]
-pub struct CallInfo {
+pub struct ExpnInfo {
     call_site: span,
     callee: NameAndSpan
 }
 
-/// Extra information for tracking macro expansion of spans
-#[deriving(IterBytes)]
-pub enum ExpnInfo {
-    ExpandedFrom(CallInfo)
-}
-
 pub type FileName = @str;
 
 pub struct FileLines
index 78fdb99753d40bda9eb801cb24f9db8cf040485b..ad14b567b9602c6b0524239129d3277866a44d90 100644 (file)
@@ -11,8 +11,7 @@
 use ast;
 use ast::Name;
 use codemap;
-use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom};
-use codemap::CallInfo;
+use codemap::{CodeMap, span, ExpnInfo};
 use diagnostic::span_handler;
 use ext;
 use parse;
@@ -243,7 +242,7 @@ pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
     pub fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
     pub fn call_site(&self) -> span {
         match *self.backtrace {
-            Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
+            Some(@ExpnInfo {call_site: cs, _}) => cs,
             None => self.bug("missing top span")
         }
     }
@@ -254,21 +253,19 @@ pub fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
     pub fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
     pub fn bt_push(&self, ei: codemap::ExpnInfo) {
         match ei {
-            ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
+            ExpnInfo {call_site: cs, callee: ref callee} => {
                 *self.backtrace =
-                    Some(@ExpandedFrom(CallInfo {
+                    Some(@ExpnInfo {
                         call_site: span {lo: cs.lo, hi: cs.hi,
                                          expn_info: *self.backtrace},
-                        callee: copy *callee}));
+                        callee: copy *callee});
             }
         }
     }
     pub fn bt_pop(&self) {
         match *self.backtrace {
-            Some(@ExpandedFrom(
-                CallInfo {
-                    call_site: span {expn_info: prev, _}, _
-                })) => {
+            Some(@ExpnInfo {
+                call_site: span {expn_info: prev, _}, _}) => {
                 *self.backtrace = prev
             }
             _ => self.bug("tried to pop without a push")
index a78a18810a8d5317dbb2b3a791d967605d787058..2b18ede88791b01a7baaabf037b476bf48289efb 100644 (file)
@@ -16,7 +16,7 @@
 use ast_util::{new_rename, new_mark, resolve};
 use attr;
 use codemap;
-use codemap::{span, CallInfo, ExpandedFrom, NameAndSpan, spanned};
+use codemap::{span, ExpnInfo, NameAndSpan, spanned};
 use ext::base::*;
 use fold::*;
 use parse;
@@ -60,13 +60,13 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
                             expander: exp,
                             span: exp_sp
                         }))) => {
-                            cx.bt_push(ExpandedFrom(CallInfo {
+                            cx.bt_push(ExpnInfo {
                                 call_site: s,
                                 callee: NameAndSpan {
                                     name: extnamestr,
                                     span: exp_sp,
                                 },
-                            }));
+                            });
 
                             let expanded = match exp(cx, mac.span, *tts) {
                                 MRExpr(e) => e,
@@ -131,13 +131,13 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
 
             match (*extsbox).find(&intern(mname)) {
               Some(@SE(ItemDecorator(dec_fn))) => {
-                  cx.bt_push(ExpandedFrom(CallInfo {
+                  cx.bt_push(ExpnInfo {
                       call_site: attr.span,
                       callee: NameAndSpan {
                           name: mname,
                           span: None
                       }
-                  }));
+                  });
                   let r = dec_fn(cx, attr.span, attr.node.value, items);
                   cx.bt_pop();
                   r
@@ -227,13 +227,13 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
                                     given '%s'", extnamestr,
                                    ident_to_str(&it.ident)));
             }
-            cx.bt_push(ExpandedFrom(CallInfo {
+            cx.bt_push(ExpnInfo {
                 call_site: it.span,
                 callee: NameAndSpan {
                     name: extnamestr,
                     span: expand.span
                 }
-            }));
+            });
             ((*expand).expander)(cx, it.span, tts)
         }
         Some(@SE(IdentTT(ref expand))) => {
@@ -242,13 +242,13 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
                               fmt!("macro %s! expects an ident argument",
                                    extnamestr));
             }
-            cx.bt_push(ExpandedFrom(CallInfo {
+            cx.bt_push(ExpnInfo {
                 call_site: it.span,
                 callee: NameAndSpan {
                     name: extnamestr,
                     span: expand.span
                 }
-            }));
+            });
             ((*expand).expander)(cx, it.span, it.ident, tts)
         }
         _ => cx.span_fatal(
@@ -319,10 +319,10 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
 
         Some(@SE(NormalTT(
             SyntaxExpanderTT{expander: exp, span: exp_sp}))) => {
-            cx.bt_push(ExpandedFrom(CallInfo {
+            cx.bt_push(ExpnInfo {
                 call_site: sp,
                 callee: NameAndSpan { name: extnamestr, span: exp_sp }
-            }));
+            });
             let expanded = match exp(cx, mac.span, tts) {
                 MRExpr(e) =>
                     @codemap::spanned { node: stmt_expr(e, cx.next_id()),
index f6325c2eb2c123819e826be1997dde393edcded9..b43536389e2cd06829e716447f98c01143e3da23 100644 (file)
@@ -10,8 +10,8 @@
 
 use ast;
 use codemap;
-use codemap::{Pos, ExpandedFrom, span};
-use codemap::{CallInfo, NameAndSpan};
+use codemap::{Pos, span};
+use codemap::{ExpnInfo, NameAndSpan};
 use ext::base::*;
 use ext::base;
 use ext::build::AstBuilder;
@@ -117,14 +117,14 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
 // recur along an ExpnInfo chain to find the original expression
 fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo {
     match *expn_info {
-        ExpandedFrom(CallInfo { call_site: ref call_site, _ }) => {
+        ExpnInfo { call_site: ref call_site, _ } => {
             match call_site.expn_info {
                 Some(next_expn_info) => {
                     match *next_expn_info {
-                        ExpandedFrom(CallInfo {
+                        ExpnInfo {
                             callee: NameAndSpan { name: ref name, _ },
                             _
-                        }) => {
+                        } => {
                             // Don't recurse into file using "include!"
                             if "include" == *name  {
                                 expn_info