Skip to content

Do not rely on newtype enum dereference #7560

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

Closed
wants to merge 1 commit into from
Closed
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: 3 additions & 3 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use front::config;
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;
Expand Down Expand Up @@ -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) ),
Expand Down
9 changes: 2 additions & 7 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -243,7 +242,7 @@ impl ExtCtxt {
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")
}
}
Expand All @@ -254,21 +253,19 @@ impl ExtCtxt {
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")
Expand Down
22 changes: 11 additions & 11 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ast;
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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))) => {
Expand All @@ -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(
Expand Down Expand Up @@ -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()),
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/ext/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down