Merge ExpnId and SyntaxContext.
This commit is contained in:
@@ -10,29 +10,27 @@
|
||||
|
||||
use ast;
|
||||
use attr;
|
||||
use ext::hygiene::{Mark, SyntaxContext};
|
||||
use symbol::{Symbol, keywords};
|
||||
use syntax_pos::{DUMMY_SP, Span};
|
||||
use codemap::{self, ExpnInfo, NameAndSpan, MacroAttribute};
|
||||
use parse::ParseSess;
|
||||
use ptr::P;
|
||||
use tokenstream::TokenStream;
|
||||
|
||||
/// Craft a span that will be ignored by the stability lint's
|
||||
/// call to codemap's is_internal check.
|
||||
/// The expanded code uses the unstable `#[prelude_import]` attribute.
|
||||
fn ignored_span(sess: &ParseSess, sp: Span) -> Span {
|
||||
let info = ExpnInfo {
|
||||
fn ignored_span(sp: Span) -> Span {
|
||||
let mark = Mark::fresh();
|
||||
mark.set_expn_info(ExpnInfo {
|
||||
call_site: DUMMY_SP,
|
||||
callee: NameAndSpan {
|
||||
format: MacroAttribute(Symbol::intern("std_inject")),
|
||||
span: None,
|
||||
allow_internal_unstable: true,
|
||||
}
|
||||
};
|
||||
let expn_id = sess.codemap().record_expansion(info);
|
||||
let mut sp = sp;
|
||||
sp.expn_id = expn_id;
|
||||
return sp;
|
||||
});
|
||||
Span { ctxt: SyntaxContext::empty().apply_mark(mark), ..sp }
|
||||
}
|
||||
|
||||
pub fn injected_crate_name(krate: &ast::Crate) -> Option<&'static str> {
|
||||
@@ -45,10 +43,7 @@ pub fn injected_crate_name(krate: &ast::Crate) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_inject_crates_ref(sess: &ParseSess,
|
||||
mut krate: ast::Crate,
|
||||
alt_std_name: Option<String>)
|
||||
-> ast::Crate {
|
||||
pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<String>) -> ast::Crate {
|
||||
let name = match injected_crate_name(&krate) {
|
||||
Some(name) => name,
|
||||
None => return krate,
|
||||
@@ -67,7 +62,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
|
||||
span: DUMMY_SP,
|
||||
}));
|
||||
|
||||
let span = ignored_span(sess, DUMMY_SP);
|
||||
let span = ignored_span(DUMMY_SP);
|
||||
krate.module.items.insert(0, P(ast::Item {
|
||||
attrs: vec![ast::Attribute {
|
||||
style: ast::AttrStyle::Outer,
|
||||
|
||||
Reference in New Issue
Block a user