use syntax::ext::hygiene::{Mark, SyntaxContext};
use syntax::print::pprust;
use syntax::ptr::P;
-use syntax::source_map::{self, respan, CompilerDesugaringKind, Spanned};
+use syntax::source_map::{self, respan, ExpnInfo, CompilerDesugaringKind, Spanned};
use syntax::source_map::CompilerDesugaringKind::IfTemporary;
use syntax::std_inject;
use syntax::symbol::{kw, sym, Symbol};
use syntax::tokenstream::{TokenStream, TokenTree};
use syntax::parse::token::{self, Token};
use syntax::visit::{self, Visitor};
-use syntax_pos::{DUMMY_SP, edition, Span};
+use syntax_pos::{DUMMY_SP, Span};
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
allow_internal_unstable: Option<Lrc<[Symbol]>>,
) -> Span {
let mark = Mark::fresh(Mark::root());
- mark.set_expn_info(source_map::ExpnInfo {
- call_site: span,
+ mark.set_expn_info(ExpnInfo {
def_site: Some(span),
- format: source_map::CompilerDesugaring(reason),
allow_internal_unstable,
- allow_internal_unsafe: false,
- local_inner_macros: false,
- edition: edition::Edition::from_session(),
+ ..ExpnInfo::default(source_map::CompilerDesugaring(reason), span, self.sess.edition())
});
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
}
mut_visit::{self, MutVisitor},
parse::ParseSess,
ptr::P,
- symbol::{kw, sym, Symbol}
+ symbol::{kw, sym}
};
use syntax_pos::Span;
fn flat_map_item(&mut self, item: P<Item>) -> SmallVec<[P<Item>; 1]> {
debug!("in submodule {}", self.in_submod);
- let name = if attr::contains_name(&item.attrs, sym::global_allocator) {
- "global_allocator"
- } else {
+ if !attr::contains_name(&item.attrs, sym::global_allocator) {
return mut_visit::noop_flat_map_item(item, self);
- };
+ }
+
match item.node {
ItemKind::Static(..) => {}
_ => {
// Create a fresh Mark for the new macro expansion we are about to do
let mark = Mark::fresh(Mark::root());
- mark.set_expn_info(ExpnInfo {
- call_site: item.span, // use the call site of the static
- def_site: None,
- format: MacroAttribute(Symbol::intern(name)),
- allow_internal_unstable: Some([sym::rustc_attrs][..].into()),
- allow_internal_unsafe: false,
- local_inner_macros: false,
- edition: self.sess.edition,
- });
+ mark.set_expn_info(ExpnInfo::with_unstable(
+ MacroAttribute(sym::global_allocator), item.span, self.sess.edition, &[sym::rustc_attrs]
+ ));
// Tie the span to the macro expansion info we just created
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
}
pretty_name.push(')');
- cx.current_expansion.mark.set_expn_info(ExpnInfo {
- call_site: span,
- def_site: None,
- format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
- allow_internal_unstable: Some([sym::rustc_attrs, sym::structural_match][..].into()),
- allow_internal_unsafe: false,
- local_inner_macros: false,
- edition: cx.parse_sess.edition,
- });
+ cx.current_expansion.mark.set_expn_info(ExpnInfo::with_unstable(
+ ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)), span, cx.parse_sess.edition,
+ &[sym::rustc_attrs, sym::structural_match],
+ ));
let span = span.with_ctxt(cx.backtrace());
item.visit_attrs(|attrs| {
/// The expanded code uses the unstable `#[prelude_import]` attribute.
fn ignored_span(sp: Span, edition: Edition) -> Span {
let mark = Mark::fresh(Mark::root());
- mark.set_expn_info(ExpnInfo {
- call_site: DUMMY_SP,
- def_site: None,
- format: MacroAttribute(Symbol::intern("std_inject")),
- allow_internal_unstable: Some([sym::prelude_import][..].into()),
- allow_internal_unsafe: false,
- local_inner_macros: false,
- edition,
- });
+ mark.set_expn_info(ExpnInfo::with_unstable(
+ MacroAttribute(Symbol::intern("std_inject")), sp, edition, &[sym::prelude_import]
+ ));
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
}
test_runner
};
- mark.set_expn_info(ExpnInfo {
- call_site: DUMMY_SP,
- def_site: None,
- format: MacroAttribute(sym::test_case),
- allow_internal_unstable: Some([sym::main, sym::test, sym::rustc_attrs][..].into()),
- allow_internal_unsafe: false,
- local_inner_macros: false,
- edition: sess.edition,
- });
+ mark.set_expn_info(ExpnInfo::with_unstable(
+ MacroAttribute(sym::test_case), DUMMY_SP, sess.edition,
+ &[sym::main, sym::test, sym::rustc_attrs],
+ ));
TestHarnessGenerator {
cx,
custom_macros: &[ProcMacroDef],
) -> P<ast::Item> {
let mark = Mark::fresh(Mark::root());
- mark.set_expn_info(ExpnInfo {
- call_site: DUMMY_SP,
- def_site: None,
- format: MacroAttribute(sym::proc_macro),
- allow_internal_unstable: Some([
- sym::rustc_attrs, Symbol::intern("proc_macro_internals")
- ][..].into()),
- allow_internal_unsafe: false,
- local_inner_macros: false,
- edition: cx.parse_sess.edition,
- });
+ mark.set_expn_info(ExpnInfo::with_unstable(
+ MacroAttribute(sym::proc_macro), DUMMY_SP, cx.parse_sess.edition,
+ &[sym::rustc_attrs, Symbol::intern("proc_macro_internals")],
+ ));
let span = DUMMY_SP.apply_mark(mark);
let hidden = cx.meta_list_item_word(span, sym::hidden);
use syntax::ast;
use syntax::print::pprust;
use syntax::symbol::{Symbol, sym};
-use syntax_pos::{DUMMY_SP, Span};
+use syntax_pos::Span;
use syntax::source_map::{ExpnInfo, MacroAttribute};
use std::iter;
let (sp, attr_sp) = {
let mark = Mark::fresh(Mark::root());
- mark.set_expn_info(ExpnInfo {
- call_site: DUMMY_SP,
- def_site: None,
- format: MacroAttribute(sym::test),
- allow_internal_unstable: Some([sym::rustc_attrs, sym::test][..].into()),
- allow_internal_unsafe: false,
- local_inner_macros: false,
- edition: cx.parse_sess.edition,
- });
+ mark.set_expn_info(ExpnInfo::with_unstable(
+ MacroAttribute(sym::test), attr_sp, cx.parse_sess.edition,
+ &[sym::rustc_attrs, sym::test],
+ ));
(item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark)),
attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(mark)))
};
use syntax::ast;
use syntax::source_map::respan;
use syntax::symbol::sym;
-use syntax_pos::{DUMMY_SP, Span};
+use syntax_pos::Span;
use syntax::source_map::{ExpnInfo, MacroAttribute};
use syntax::feature_gate;
let sp = {
let mark = Mark::fresh(Mark::root());
- mark.set_expn_info(ExpnInfo {
- call_site: DUMMY_SP,
- def_site: None,
- format: MacroAttribute(sym::test_case),
- allow_internal_unstable: Some([sym::test, sym::rustc_attrs][..].into()),
- allow_internal_unsafe: false,
- local_inner_macros: false,
- edition: ecx.parse_sess.edition,
- });
+ mark.set_expn_info(ExpnInfo::with_unstable(
+ MacroAttribute(sym::test_case), attr_sp, ecx.parse_sess.edition,
+ &[sym::test, sym::rustc_attrs],
+ ));
attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
};
pub edition: Edition,
}
+impl ExpnInfo {
+ /// Constructs an expansion info with default properties.
+ pub fn default(format: ExpnFormat, call_site: Span, edition: Edition) -> ExpnInfo {
+ ExpnInfo {
+ call_site,
+ def_site: None,
+ format,
+ allow_internal_unstable: None,
+ allow_internal_unsafe: false,
+ local_inner_macros: false,
+ edition,
+ }
+ }
+
+ pub fn with_unstable(format: ExpnFormat, call_site: Span, edition: Edition,
+ allow_internal_unstable: &[Symbol]) -> ExpnInfo {
+ ExpnInfo {
+ allow_internal_unstable: Some(allow_internal_unstable.into()),
+ ..ExpnInfo::default(format, call_site, edition)
+ }
+ }
+}
+
/// The source of expansion.
#[derive(Clone, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub enum ExpnFormat {