hygiene: ExpnInfo
-> ExpnData
For naming consistency with everything else in this area
This commit is contained in:
parent
650f19aeae
commit
136db2235a
25 changed files with 168 additions and 168 deletions
|
@ -67,7 +67,7 @@ use syntax::errors;
|
||||||
use syntax::ext::base::SpecialDerives;
|
use syntax::ext::base::SpecialDerives;
|
||||||
use syntax::ext::hygiene::ExpnId;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
use syntax::source_map::{respan, ExpnInfo, ExpnKind, DesugaringKind, Spanned};
|
use syntax::source_map::{respan, ExpnData, ExpnKind, DesugaringKind, Spanned};
|
||||||
use syntax::symbol::{kw, sym, Symbol};
|
use syntax::symbol::{kw, sym, Symbol};
|
||||||
use syntax::tokenstream::{TokenStream, TokenTree};
|
use syntax::tokenstream::{TokenStream, TokenTree};
|
||||||
use syntax::parse::token::{self, Token};
|
use syntax::parse::token::{self, Token};
|
||||||
|
@ -704,9 +704,9 @@ impl<'a> LoweringContext<'a> {
|
||||||
span: Span,
|
span: Span,
|
||||||
allow_internal_unstable: Option<Lrc<[Symbol]>>,
|
allow_internal_unstable: Option<Lrc<[Symbol]>>,
|
||||||
) -> Span {
|
) -> Span {
|
||||||
span.fresh_expansion(ExpnInfo {
|
span.fresh_expansion(ExpnData {
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition())
|
..ExpnData::default(ExpnKind::Desugaring(reason), span, self.sess.edition())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,7 +370,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut hasher = StableHasher::new();
|
let mut hasher = StableHasher::new();
|
||||||
expn_id.expn_info().hash_stable(hcx, &mut hasher);
|
expn_id.expn_data().hash_stable(hcx, &mut hasher);
|
||||||
let sub_hash: Fingerprint = hasher.finish();
|
let sub_hash: Fingerprint = hasher.finish();
|
||||||
let sub_hash = sub_hash.to_smaller_hash();
|
let sub_hash = sub_hash.to_smaller_hash();
|
||||||
cache.borrow_mut().insert(expn_id, sub_hash);
|
cache.borrow_mut().insert(expn_id, sub_hash);
|
||||||
|
|
|
@ -397,7 +397,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
|
||||||
Opaque,
|
Opaque,
|
||||||
});
|
});
|
||||||
|
|
||||||
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
|
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData {
|
||||||
kind,
|
kind,
|
||||||
parent -> _,
|
parent -> _,
|
||||||
call_site,
|
call_site,
|
||||||
|
|
|
@ -227,10 +227,10 @@ impl EarlyLintPass for LintPassImpl {
|
||||||
if let ItemKind::Impl(_, _, _, _, Some(lint_pass), _, _) = &item.node {
|
if let ItemKind::Impl(_, _, _, _, Some(lint_pass), _, _) = &item.node {
|
||||||
if let Some(last) = lint_pass.path.segments.last() {
|
if let Some(last) = lint_pass.path.segments.last() {
|
||||||
if last.ident.name == sym::LintPass {
|
if last.ident.name == sym::LintPass {
|
||||||
let expn_info = lint_pass.path.span.ctxt().outer_expn_info();
|
let expn_data = lint_pass.path.span.ctxt().outer_expn_data();
|
||||||
let call_site = expn_info.call_site;
|
let call_site = expn_data.call_site;
|
||||||
if expn_info.kind.descr() != sym::impl_lint_pass &&
|
if expn_data.kind.descr() != sym::impl_lint_pass &&
|
||||||
call_site.ctxt().outer_expn_info().kind.descr() != sym::declare_lint_pass {
|
call_site.ctxt().outer_expn_data().kind.descr() != sym::declare_lint_pass {
|
||||||
cx.struct_span_lint(
|
cx.struct_span_lint(
|
||||||
LINT_PASS_IMPL_WITHOUT_MACRO,
|
LINT_PASS_IMPL_WITHOUT_MACRO,
|
||||||
lint_pass.path.span,
|
lint_pass.path.span,
|
||||||
|
|
|
@ -885,16 +885,16 @@ pub fn provide(providers: &mut Providers<'_>) {
|
||||||
/// This is used to test whether a lint should not even begin to figure out whether it should
|
/// This is used to test whether a lint should not even begin to figure out whether it should
|
||||||
/// be reported on the current node.
|
/// be reported on the current node.
|
||||||
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
||||||
let expn_info = span.ctxt().outer_expn_info();
|
let expn_data = span.ctxt().outer_expn_data();
|
||||||
match expn_info.kind {
|
match expn_data.kind {
|
||||||
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
|
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
|
||||||
ExpnKind::Desugaring(_) => true, // well, it's "external"
|
ExpnKind::Desugaring(_) => true, // well, it's "external"
|
||||||
ExpnKind::Macro(MacroKind::Bang, _) => {
|
ExpnKind::Macro(MacroKind::Bang, _) => {
|
||||||
if expn_info.def_site.is_dummy() {
|
if expn_data.def_site.is_dummy() {
|
||||||
// dummy span for the def_site means it's an external macro
|
// dummy span for the def_site means it's an external macro
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
match sess.source_map().span_to_snippet(expn_info.def_site) {
|
match sess.source_map().span_to_snippet(expn_data.def_site) {
|
||||||
Ok(code) => !code.starts_with("macro_rules"),
|
Ok(code) => !code.starts_with("macro_rules"),
|
||||||
// no snippet = external macro or compiler-builtin expansion
|
// no snippet = external macro or compiler-builtin expansion
|
||||||
Err(_) => true,
|
Err(_) => true,
|
||||||
|
@ -906,7 +906,7 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
||||||
|
|
||||||
/// Returns whether `span` originates in a derive macro's expansion
|
/// Returns whether `span` originates in a derive macro's expansion
|
||||||
pub fn in_derive_expansion(span: Span) -> bool {
|
pub fn in_derive_expansion(span: Span) -> bool {
|
||||||
if let ExpnKind::Macro(MacroKind::Derive, _) = span.ctxt().outer_expn_info().kind {
|
if let ExpnKind::Macro(MacroKind::Derive, _) = span.ctxt().outer_expn_data().kind {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
@ -61,9 +61,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
// We want to ignore desugarings here: spans are equivalent even
|
// We want to ignore desugarings here: spans are equivalent even
|
||||||
// if one is the result of a desugaring and the other is not.
|
// if one is the result of a desugaring and the other is not.
|
||||||
let mut span = error.obligation.cause.span;
|
let mut span = error.obligation.cause.span;
|
||||||
let expn_info = span.ctxt().outer_expn_info();
|
let expn_data = span.ctxt().outer_expn_data();
|
||||||
if let ExpnKind::Desugaring(_) = expn_info.kind {
|
if let ExpnKind::Desugaring(_) = expn_data.kind {
|
||||||
span = expn_info.call_site;
|
span = expn_data.call_site;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_map.entry(span).or_default().push(
|
error_map.entry(span).or_default().push(
|
||||||
|
|
|
@ -23,16 +23,16 @@ use std::mem;
|
||||||
use syntax::ast::NodeId;
|
use syntax::ast::NodeId;
|
||||||
use syntax::source_map::{SourceMap, StableSourceFileId};
|
use syntax::source_map::{SourceMap, StableSourceFileId};
|
||||||
use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile};
|
use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile};
|
||||||
use syntax_pos::hygiene::{ExpnId, SyntaxContext, ExpnInfo};
|
use syntax_pos::hygiene::{ExpnId, SyntaxContext, ExpnData};
|
||||||
|
|
||||||
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
|
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
|
||||||
|
|
||||||
const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0;
|
const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0;
|
||||||
const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1;
|
const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1;
|
||||||
|
|
||||||
const TAG_NO_EXPANSION_INFO: u8 = 0;
|
const TAG_NO_EXPN_DATA: u8 = 0;
|
||||||
const TAG_EXPANSION_INFO_SHORTHAND: u8 = 1;
|
const TAG_EXPN_DATA_SHORTHAND: u8 = 1;
|
||||||
const TAG_EXPANSION_INFO_INLINE: u8 = 2;
|
const TAG_EXPN_DATA_INLINE: u8 = 2;
|
||||||
|
|
||||||
const TAG_VALID_SPAN: u8 = 0;
|
const TAG_VALID_SPAN: u8 = 0;
|
||||||
const TAG_INVALID_SPAN: u8 = 1;
|
const TAG_INVALID_SPAN: u8 = 1;
|
||||||
|
@ -58,7 +58,7 @@ pub struct OnDiskCache<'sess> {
|
||||||
|
|
||||||
// These two fields caches that are populated lazily during decoding.
|
// These two fields caches that are populated lazily during decoding.
|
||||||
file_index_to_file: Lock<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
|
file_index_to_file: Lock<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
|
||||||
synthetic_expansion_infos: Lock<FxHashMap<AbsoluteBytePos, SyntaxContext>>,
|
synthetic_syntax_contexts: Lock<FxHashMap<AbsoluteBytePos, SyntaxContext>>,
|
||||||
|
|
||||||
// A map from dep-node to the position of the cached query result in
|
// A map from dep-node to the position of the cached query result in
|
||||||
// `serialized_data`.
|
// `serialized_data`.
|
||||||
|
@ -135,7 +135,7 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
current_diagnostics: Default::default(),
|
current_diagnostics: Default::default(),
|
||||||
query_result_index: footer.query_result_index.into_iter().collect(),
|
query_result_index: footer.query_result_index.into_iter().collect(),
|
||||||
prev_diagnostics_index: footer.diagnostics_index.into_iter().collect(),
|
prev_diagnostics_index: footer.diagnostics_index.into_iter().collect(),
|
||||||
synthetic_expansion_infos: Default::default(),
|
synthetic_syntax_contexts: Default::default(),
|
||||||
alloc_decoding_state: AllocDecodingState::new(footer.interpret_alloc_index),
|
alloc_decoding_state: AllocDecodingState::new(footer.interpret_alloc_index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
current_diagnostics: Default::default(),
|
current_diagnostics: Default::default(),
|
||||||
query_result_index: Default::default(),
|
query_result_index: Default::default(),
|
||||||
prev_diagnostics_index: Default::default(),
|
prev_diagnostics_index: Default::default(),
|
||||||
synthetic_expansion_infos: Default::default(),
|
synthetic_syntax_contexts: Default::default(),
|
||||||
alloc_decoding_state: AllocDecodingState::new(Vec::new()),
|
alloc_decoding_state: AllocDecodingState::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
encoder,
|
encoder,
|
||||||
type_shorthands: Default::default(),
|
type_shorthands: Default::default(),
|
||||||
predicate_shorthands: Default::default(),
|
predicate_shorthands: Default::default(),
|
||||||
expn_info_shorthands: Default::default(),
|
expn_data_shorthands: Default::default(),
|
||||||
interpret_allocs: Default::default(),
|
interpret_allocs: Default::default(),
|
||||||
interpret_allocs_inverse: Vec::new(),
|
interpret_allocs_inverse: Vec::new(),
|
||||||
source_map: CachingSourceMapView::new(tcx.sess.source_map()),
|
source_map: CachingSourceMapView::new(tcx.sess.source_map()),
|
||||||
|
@ -383,7 +383,7 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
cnum_map: self.cnum_map.get(),
|
cnum_map: self.cnum_map.get(),
|
||||||
file_index_to_file: &self.file_index_to_file,
|
file_index_to_file: &self.file_index_to_file,
|
||||||
file_index_to_stable_id: &self.file_index_to_stable_id,
|
file_index_to_stable_id: &self.file_index_to_stable_id,
|
||||||
synthetic_expansion_infos: &self.synthetic_expansion_infos,
|
synthetic_syntax_contexts: &self.synthetic_syntax_contexts,
|
||||||
alloc_decoding_session: self.alloc_decoding_state.new_decoding_session(),
|
alloc_decoding_session: self.alloc_decoding_state.new_decoding_session(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ struct CacheDecoder<'a, 'tcx> {
|
||||||
opaque: opaque::Decoder<'a>,
|
opaque: opaque::Decoder<'a>,
|
||||||
source_map: &'a SourceMap,
|
source_map: &'a SourceMap,
|
||||||
cnum_map: &'a IndexVec<CrateNum, Option<CrateNum>>,
|
cnum_map: &'a IndexVec<CrateNum, Option<CrateNum>>,
|
||||||
synthetic_expansion_infos: &'a Lock<FxHashMap<AbsoluteBytePos, SyntaxContext>>,
|
synthetic_syntax_contexts: &'a Lock<FxHashMap<AbsoluteBytePos, SyntaxContext>>,
|
||||||
file_index_to_file: &'a Lock<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
|
file_index_to_file: &'a Lock<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
|
||||||
file_index_to_stable_id: &'a FxHashMap<SourceFileIndex, StableSourceFileId>,
|
file_index_to_stable_id: &'a FxHashMap<SourceFileIndex, StableSourceFileId>,
|
||||||
alloc_decoding_session: AllocDecodingSession<'a>,
|
alloc_decoding_session: AllocDecodingSession<'a>,
|
||||||
|
@ -586,37 +586,37 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
|
||||||
let lo = file_lo.lines[line_lo - 1] + col_lo;
|
let lo = file_lo.lines[line_lo - 1] + col_lo;
|
||||||
let hi = lo + len;
|
let hi = lo + len;
|
||||||
|
|
||||||
let expn_info_tag = u8::decode(self)?;
|
let expn_data_tag = u8::decode(self)?;
|
||||||
|
|
||||||
// FIXME(mw): This method does not restore `ExpnInfo::parent` or
|
// FIXME(mw): This method does not restore `ExpnData::parent` or
|
||||||
// `SyntaxContextData::prev_ctxt` or `SyntaxContextData::opaque`. These things
|
// `SyntaxContextData::prev_ctxt` or `SyntaxContextData::opaque`. These things
|
||||||
// don't seem to be used after HIR lowering, so everything should be fine
|
// don't seem to be used after HIR lowering, so everything should be fine
|
||||||
// as long as incremental compilation does not kick in before that.
|
// as long as incremental compilation does not kick in before that.
|
||||||
let location = || Span::with_root_ctxt(lo, hi);
|
let location = || Span::with_root_ctxt(lo, hi);
|
||||||
let recover_from_expn_info = |this: &Self, expn_info, pos| {
|
let recover_from_expn_data = |this: &Self, expn_data, pos| {
|
||||||
let span = location().fresh_expansion(expn_info);
|
let span = location().fresh_expansion(expn_data);
|
||||||
this.synthetic_expansion_infos.borrow_mut().insert(pos, span.ctxt());
|
this.synthetic_syntax_contexts.borrow_mut().insert(pos, span.ctxt());
|
||||||
span
|
span
|
||||||
};
|
};
|
||||||
Ok(match expn_info_tag {
|
Ok(match expn_data_tag {
|
||||||
TAG_NO_EXPANSION_INFO => {
|
TAG_NO_EXPN_DATA => {
|
||||||
location()
|
location()
|
||||||
}
|
}
|
||||||
TAG_EXPANSION_INFO_INLINE => {
|
TAG_EXPN_DATA_INLINE => {
|
||||||
let expn_info = Decodable::decode(self)?;
|
let expn_data = Decodable::decode(self)?;
|
||||||
recover_from_expn_info(
|
recover_from_expn_data(
|
||||||
self, expn_info, AbsoluteBytePos::new(self.opaque.position())
|
self, expn_data, AbsoluteBytePos::new(self.opaque.position())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TAG_EXPANSION_INFO_SHORTHAND => {
|
TAG_EXPN_DATA_SHORTHAND => {
|
||||||
let pos = AbsoluteBytePos::decode(self)?;
|
let pos = AbsoluteBytePos::decode(self)?;
|
||||||
let cached_ctxt = self.synthetic_expansion_infos.borrow().get(&pos).cloned();
|
let cached_ctxt = self.synthetic_syntax_contexts.borrow().get(&pos).cloned();
|
||||||
if let Some(ctxt) = cached_ctxt {
|
if let Some(ctxt) = cached_ctxt {
|
||||||
Span::new(lo, hi, ctxt)
|
Span::new(lo, hi, ctxt)
|
||||||
} else {
|
} else {
|
||||||
let expn_info =
|
let expn_data =
|
||||||
self.with_position(pos.to_usize(), |this| ExpnInfo::decode(this))?;
|
self.with_position(pos.to_usize(), |this| ExpnData::decode(this))?;
|
||||||
recover_from_expn_info(self, expn_info, pos)
|
recover_from_expn_data(self, expn_data, pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -725,7 +725,7 @@ struct CacheEncoder<'a, 'tcx, E: ty_codec::TyEncoder> {
|
||||||
encoder: &'a mut E,
|
encoder: &'a mut E,
|
||||||
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
|
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
|
||||||
predicate_shorthands: FxHashMap<ty::Predicate<'tcx>, usize>,
|
predicate_shorthands: FxHashMap<ty::Predicate<'tcx>, usize>,
|
||||||
expn_info_shorthands: FxHashMap<ExpnId, AbsoluteBytePos>,
|
expn_data_shorthands: FxHashMap<ExpnId, AbsoluteBytePos>,
|
||||||
interpret_allocs: FxHashMap<interpret::AllocId, usize>,
|
interpret_allocs: FxHashMap<interpret::AllocId, usize>,
|
||||||
interpret_allocs_inverse: Vec<interpret::AllocId>,
|
interpret_allocs_inverse: Vec<interpret::AllocId>,
|
||||||
source_map: CachingSourceMapView<'tcx>,
|
source_map: CachingSourceMapView<'tcx>,
|
||||||
|
@ -817,17 +817,17 @@ where
|
||||||
len.encode(self)?;
|
len.encode(self)?;
|
||||||
|
|
||||||
if span_data.ctxt == SyntaxContext::root() {
|
if span_data.ctxt == SyntaxContext::root() {
|
||||||
TAG_NO_EXPANSION_INFO.encode(self)
|
TAG_NO_EXPN_DATA.encode(self)
|
||||||
} else {
|
} else {
|
||||||
let (expn_id, expn_info) = span_data.ctxt.outer_expn_with_info();
|
let (expn_id, expn_data) = span_data.ctxt.outer_expn_with_data();
|
||||||
if let Some(pos) = self.expn_info_shorthands.get(&expn_id).cloned() {
|
if let Some(pos) = self.expn_data_shorthands.get(&expn_id).cloned() {
|
||||||
TAG_EXPANSION_INFO_SHORTHAND.encode(self)?;
|
TAG_EXPN_DATA_SHORTHAND.encode(self)?;
|
||||||
pos.encode(self)
|
pos.encode(self)
|
||||||
} else {
|
} else {
|
||||||
TAG_EXPANSION_INFO_INLINE.encode(self)?;
|
TAG_EXPN_DATA_INLINE.encode(self)?;
|
||||||
let pos = AbsoluteBytePos::new(self.position());
|
let pos = AbsoluteBytePos::new(self.position());
|
||||||
self.expn_info_shorthands.insert(expn_id, pos);
|
self.expn_data_shorthands.insert(expn_id, pos);
|
||||||
expn_info.encode(self)
|
expn_data.encode(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1775,7 +1775,7 @@ impl SharedEmitterMain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => {
|
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => {
|
||||||
sess.span_err(ExpnId::from_u32(cookie).expn_info().call_site, &msg)
|
sess.span_err(ExpnId::from_u32(cookie).expn_data().call_site, &msg)
|
||||||
}
|
}
|
||||||
Ok(SharedEmitterMessage::AbortIfErrors) => {
|
Ok(SharedEmitterMessage::AbortIfErrors) => {
|
||||||
sess.abort_if_errors();
|
sess.abort_if_errors();
|
||||||
|
|
|
@ -517,7 +517,7 @@ impl EarlyLintPass for UnusedParens {
|
||||||
// trigger in situations that macro authors shouldn't have to care about, e.g.,
|
// trigger in situations that macro authors shouldn't have to care about, e.g.,
|
||||||
// when a parenthesized token tree matched in one macro expansion is matched as
|
// when a parenthesized token tree matched in one macro expansion is matched as
|
||||||
// an expression in another and used as a fn/method argument (Issue #47775)
|
// an expression in another and used as a fn/method argument (Issue #47775)
|
||||||
if e.span.ctxt().outer_expn_info().call_site.from_expansion() {
|
if e.span.ctxt().outer_expn_data().call_site.from_expansion() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let msg = format!("{} argument", call_kind);
|
let msg = format!("{} argument", call_kind);
|
||||||
|
|
|
@ -17,7 +17,7 @@ use syntax::edition::Edition;
|
||||||
use syntax::ext::base::{self, Indeterminate, SpecialDerives};
|
use syntax::ext::base::{self, Indeterminate, SpecialDerives};
|
||||||
use syntax::ext::base::{MacroKind, SyntaxExtension};
|
use syntax::ext::base::{MacroKind, SyntaxExtension};
|
||||||
use syntax::ext::expand::{AstFragment, Invocation, InvocationKind};
|
use syntax::ext::expand::{AstFragment, Invocation, InvocationKind};
|
||||||
use syntax::ext::hygiene::{self, ExpnId, ExpnInfo, ExpnKind};
|
use syntax::ext::hygiene::{self, ExpnId, ExpnData, ExpnKind};
|
||||||
use syntax::ext::tt::macro_rules;
|
use syntax::ext::tt::macro_rules;
|
||||||
use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name};
|
use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name};
|
||||||
use syntax::feature_gate::GateIssue;
|
use syntax::feature_gate::GateIssue;
|
||||||
|
@ -97,7 +97,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId {
|
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId {
|
||||||
let expn_id = ExpnId::fresh(Some(ExpnInfo::default(
|
let expn_id = ExpnId::fresh(Some(ExpnData::default(
|
||||||
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, self.session.edition()
|
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, self.session.edition()
|
||||||
)));
|
)));
|
||||||
let module = self.module_map[&self.definitions.local_def_id(id)];
|
let module = self.module_map[&self.definitions.local_def_id(id)];
|
||||||
|
@ -185,8 +185,8 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
let (ext, res) = self.smart_resolve_macro_path(path, kind, parent_scope, force)?;
|
let (ext, res) = self.smart_resolve_macro_path(path, kind, parent_scope, force)?;
|
||||||
|
|
||||||
let span = invoc.span();
|
let span = invoc.span();
|
||||||
invoc.expansion_data.id.set_expn_info(
|
invoc.expansion_data.id.set_expn_data(
|
||||||
ext.expn_info(parent_scope.expansion, span, fast_print_path(path))
|
ext.expn_data(parent_scope.expansion, span, fast_print_path(path))
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Res::Def(_, def_id) = res {
|
if let Res::Def(_, def_id) = res {
|
||||||
|
@ -302,7 +302,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
// Possibly apply the macro helper hack
|
// Possibly apply the macro helper hack
|
||||||
if kind == Some(MacroKind::Bang) && path.len() == 1 &&
|
if kind == Some(MacroKind::Bang) && path.len() == 1 &&
|
||||||
path[0].ident.span.ctxt().outer_expn_info().local_inner_macros {
|
path[0].ident.span.ctxt().outer_expn_data().local_inner_macros {
|
||||||
let root = Ident::new(kw::DollarCrate, path[0].ident.span);
|
let root = Ident::new(kw::DollarCrate, path[0].ident.span);
|
||||||
path.insert(0, Segment::from_ident(root));
|
path.insert(0, Segment::from_ident(root));
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::tokenstream::{self, TokenStream, TokenTree};
|
||||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
use errors::{DiagnosticBuilder, DiagnosticId};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
use syntax_pos::{FileName, Span, MultiSpan, DUMMY_SP};
|
use syntax_pos::{FileName, Span, MultiSpan, DUMMY_SP};
|
||||||
use syntax_pos::hygiene::{ExpnInfo, ExpnKind};
|
use syntax_pos::hygiene::{ExpnData, ExpnKind};
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::{self, Lrc};
|
use rustc_data_structures::sync::{self, Lrc};
|
||||||
|
@ -640,8 +640,8 @@ impl SyntaxExtension {
|
||||||
SyntaxExtension::default(SyntaxExtensionKind::NonMacroAttr { mark_used }, edition)
|
SyntaxExtension::default(SyntaxExtensionKind::NonMacroAttr { mark_used }, edition)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expn_info(&self, parent: ExpnId, call_site: Span, descr: Symbol) -> ExpnInfo {
|
pub fn expn_data(&self, parent: ExpnId, call_site: Span, descr: Symbol) -> ExpnData {
|
||||||
ExpnInfo {
|
ExpnData {
|
||||||
kind: ExpnKind::Macro(self.macro_kind(), descr),
|
kind: ExpnKind::Macro(self.macro_kind(), descr),
|
||||||
parent,
|
parent,
|
||||||
call_site,
|
call_site,
|
||||||
|
@ -708,7 +708,7 @@ pub struct ExpansionData {
|
||||||
|
|
||||||
/// One of these is made during expansion and incrementally updated as we go;
|
/// One of these is made during expansion and incrementally updated as we go;
|
||||||
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
|
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
|
||||||
/// -> expn_info` of their expansion context stored into their span.
|
/// -> expn_data` of their expansion context stored into their span.
|
||||||
pub struct ExtCtxt<'a> {
|
pub struct ExtCtxt<'a> {
|
||||||
pub parse_sess: &'a parse::ParseSess,
|
pub parse_sess: &'a parse::ParseSess,
|
||||||
pub ecfg: expand::ExpansionConfig<'a>,
|
pub ecfg: expand::ExpansionConfig<'a>,
|
||||||
|
@ -757,7 +757,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess }
|
pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess }
|
||||||
pub fn cfg(&self) -> &ast::CrateConfig { &self.parse_sess.config }
|
pub fn cfg(&self) -> &ast::CrateConfig { &self.parse_sess.config }
|
||||||
pub fn call_site(&self) -> Span {
|
pub fn call_site(&self) -> Span {
|
||||||
self.current_expansion.id.expn_info().call_site
|
self.current_expansion.id.expn_data().call_site
|
||||||
}
|
}
|
||||||
pub fn backtrace(&self) -> SyntaxContext {
|
pub fn backtrace(&self) -> SyntaxContext {
|
||||||
SyntaxContext::root().apply_mark(self.current_expansion.id)
|
SyntaxContext::root().apply_mark(self.current_expansion.id)
|
||||||
|
@ -770,13 +770,13 @@ impl<'a> ExtCtxt<'a> {
|
||||||
let mut ctxt = self.backtrace();
|
let mut ctxt = self.backtrace();
|
||||||
let mut last_macro = None;
|
let mut last_macro = None;
|
||||||
loop {
|
loop {
|
||||||
let expn_info = ctxt.outer_expn_info();
|
let expn_data = ctxt.outer_expn_data();
|
||||||
// Stop going up the backtrace once include! is encountered
|
// Stop going up the backtrace once include! is encountered
|
||||||
if expn_info.is_root() || expn_info.kind.descr() == sym::include {
|
if expn_data.is_root() || expn_data.kind.descr() == sym::include {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ctxt = expn_info.call_site.ctxt();
|
ctxt = expn_data.call_site.ctxt();
|
||||||
last_macro = Some(expn_info.call_site);
|
last_macro = Some(expn_data.call_site);
|
||||||
}
|
}
|
||||||
last_macro
|
last_macro
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::source_map::respan;
|
||||||
use crate::config::StripUnconfigured;
|
use crate::config::StripUnconfigured;
|
||||||
use crate::ext::base::*;
|
use crate::ext::base::*;
|
||||||
use crate::ext::proc_macro::collect_derives;
|
use crate::ext::proc_macro::collect_derives;
|
||||||
use crate::ext::hygiene::{ExpnId, SyntaxContext, ExpnInfo, ExpnKind};
|
use crate::ext::hygiene::{ExpnId, SyntaxContext, ExpnData, ExpnKind};
|
||||||
use crate::ext::tt::macro_rules::annotate_err_with_kind;
|
use crate::ext::tt::macro_rules::annotate_err_with_kind;
|
||||||
use crate::ext::placeholders::{placeholder, PlaceholderExpander};
|
use crate::ext::placeholders::{placeholder, PlaceholderExpander};
|
||||||
use crate::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
|
use crate::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
|
||||||
|
@ -475,11 +475,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
|
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
|
||||||
let info = self.cx.current_expansion.id.expn_info();
|
let expn_data = self.cx.current_expansion.id.expn_data();
|
||||||
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
|
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
|
||||||
let mut err = self.cx.struct_span_err(info.call_site,
|
let mut err = self.cx.struct_span_err(expn_data.call_site,
|
||||||
&format!("recursion limit reached while expanding the macro `{}`",
|
&format!("recursion limit reached while expanding the macro `{}`",
|
||||||
info.kind.descr()));
|
expn_data.kind.descr()));
|
||||||
err.help(&format!(
|
err.help(&format!(
|
||||||
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
|
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
|
||||||
suggested_limit));
|
suggested_limit));
|
||||||
|
@ -796,20 +796,20 @@ struct InvocationCollector<'a, 'b> {
|
||||||
|
|
||||||
impl<'a, 'b> InvocationCollector<'a, 'b> {
|
impl<'a, 'b> InvocationCollector<'a, 'b> {
|
||||||
fn collect(&mut self, fragment_kind: AstFragmentKind, kind: InvocationKind) -> AstFragment {
|
fn collect(&mut self, fragment_kind: AstFragmentKind, kind: InvocationKind) -> AstFragment {
|
||||||
// Expansion info for all the collected invocations is set upon their resolution,
|
// Expansion data for all the collected invocations is set upon their resolution,
|
||||||
// with exception of the derive container case which is not resolved and can get
|
// with exception of the derive container case which is not resolved and can get
|
||||||
// its expansion info immediately.
|
// its expansion data immediately.
|
||||||
let expn_info = match &kind {
|
let expn_data = match &kind {
|
||||||
InvocationKind::DeriveContainer { item, .. } => Some(ExpnInfo {
|
InvocationKind::DeriveContainer { item, .. } => Some(ExpnData {
|
||||||
parent: self.cx.current_expansion.id,
|
parent: self.cx.current_expansion.id,
|
||||||
..ExpnInfo::default(
|
..ExpnData::default(
|
||||||
ExpnKind::Macro(MacroKind::Attr, sym::derive),
|
ExpnKind::Macro(MacroKind::Attr, sym::derive),
|
||||||
item.span(), self.cx.parse_sess.edition,
|
item.span(), self.cx.parse_sess.edition,
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let expn_id = ExpnId::fresh(expn_info);
|
let expn_id = ExpnId::fresh(expn_data);
|
||||||
self.invocations.push(Invocation {
|
self.invocations.push(Invocation {
|
||||||
kind,
|
kind,
|
||||||
fragment_kind,
|
fragment_kind,
|
||||||
|
|
|
@ -362,7 +362,7 @@ pub(crate) struct Rustc<'a> {
|
||||||
impl<'a> Rustc<'a> {
|
impl<'a> Rustc<'a> {
|
||||||
pub fn new(cx: &'a ExtCtxt<'_>) -> Self {
|
pub fn new(cx: &'a ExtCtxt<'_>) -> Self {
|
||||||
// No way to determine def location for a proc macro right now, so use call location.
|
// No way to determine def location for a proc macro right now, so use call location.
|
||||||
let location = cx.current_expansion.id.expn_info().call_site;
|
let location = cx.current_expansion.id.expn_data().call_site;
|
||||||
let to_span = |transparency| {
|
let to_span = |transparency| {
|
||||||
location.with_ctxt(
|
location.with_ctxt(
|
||||||
SyntaxContext::root()
|
SyntaxContext::root()
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl ParseSess {
|
||||||
included_mod_stack: Lock::new(vec![]),
|
included_mod_stack: Lock::new(vec![]),
|
||||||
source_map,
|
source_map,
|
||||||
buffered_lints: Lock::new(vec![]),
|
buffered_lints: Lock::new(vec![]),
|
||||||
edition: ExpnId::root().expn_info().edition,
|
edition: ExpnId::root().expn_data().edition,
|
||||||
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
|
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
|
||||||
param_attr_spans: Lock::new(Vec::new()),
|
param_attr_spans: Lock::new(Vec::new()),
|
||||||
let_chains_spans: Lock::new(Vec::new()),
|
let_chains_spans: Lock::new(Vec::new()),
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//! information, source code snippets, etc.
|
//! information, source code snippets, etc.
|
||||||
|
|
||||||
pub use syntax_pos::*;
|
pub use syntax_pos::*;
|
||||||
pub use syntax_pos::hygiene::{ExpnKind, ExpnInfo};
|
pub use syntax_pos::hygiene::{ExpnKind, ExpnData};
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::StableHasher;
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
|
@ -29,15 +29,15 @@ mod tests;
|
||||||
|
|
||||||
/// Returns the span itself if it doesn't come from a macro expansion,
|
/// Returns the span itself if it doesn't come from a macro expansion,
|
||||||
/// otherwise return the call site span up to the `enclosing_sp` by
|
/// otherwise return the call site span up to the `enclosing_sp` by
|
||||||
/// following the `expn_info` chain.
|
/// following the `expn_data` chain.
|
||||||
pub fn original_sp(sp: Span, enclosing_sp: Span) -> Span {
|
pub fn original_sp(sp: Span, enclosing_sp: Span) -> Span {
|
||||||
let expn_info1 = sp.ctxt().outer_expn_info();
|
let expn_data1 = sp.ctxt().outer_expn_data();
|
||||||
let expn_info2 = enclosing_sp.ctxt().outer_expn_info();
|
let expn_data2 = enclosing_sp.ctxt().outer_expn_data();
|
||||||
if expn_info1.is_root() ||
|
if expn_data1.is_root() ||
|
||||||
!expn_info2.is_root() && expn_info1.call_site == expn_info2.call_site {
|
!expn_data2.is_root() && expn_data1.call_site == expn_data2.call_site {
|
||||||
sp
|
sp
|
||||||
} else {
|
} else {
|
||||||
original_sp(expn_info1.call_site, enclosing_sp)
|
original_sp(expn_data1.call_site, enclosing_sp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
|
||||||
match annitem.node {
|
match annitem.node {
|
||||||
ItemKind::Struct(_, Generics { ref params, .. }) |
|
ItemKind::Struct(_, Generics { ref params, .. }) |
|
||||||
ItemKind::Enum(_, Generics { ref params, .. }) => {
|
ItemKind::Enum(_, Generics { ref params, .. }) => {
|
||||||
let container_id = cx.current_expansion.id.expn_info().parent;
|
let container_id = cx.current_expansion.id.expn_data().parent;
|
||||||
if cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
|
if cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
|
||||||
!params.iter().any(|param| match param.kind {
|
!params.iter().any(|param| match param.kind {
|
||||||
ast::GenericParamKind::Type { .. } => true,
|
ast::GenericParamKind::Type { .. } => true,
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
|
||||||
mitem: &MetaItem,
|
mitem: &MetaItem,
|
||||||
item: &Annotatable,
|
item: &Annotatable,
|
||||||
push: &mut dyn FnMut(Annotatable)) {
|
push: &mut dyn FnMut(Annotatable)) {
|
||||||
cx.resolver.add_derives(cx.current_expansion.id.expn_info().parent, SpecialDerives::EQ);
|
cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::EQ);
|
||||||
|
|
||||||
let inline = cx.meta_word(span, sym::inline);
|
let inline = cx.meta_word(span, sym::inline);
|
||||||
let hidden = cx.meta_list_item_word(span, sym::hidden);
|
let hidden = cx.meta_list_item_word(span, sym::hidden);
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
|
||||||
mitem: &MetaItem,
|
mitem: &MetaItem,
|
||||||
item: &Annotatable,
|
item: &Annotatable,
|
||||||
push: &mut dyn FnMut(Annotatable)) {
|
push: &mut dyn FnMut(Annotatable)) {
|
||||||
cx.resolver.add_derives(cx.current_expansion.id.expn_info().parent, SpecialDerives::PARTIAL_EQ);
|
cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::PARTIAL_EQ);
|
||||||
|
|
||||||
// structures are equal if all fields are equal, and non equal, if
|
// structures are equal if all fields are equal, and non equal, if
|
||||||
// any fields are not equal or if the enum variants are different
|
// any fields are not equal or if the enum variants are different
|
||||||
|
|
|
@ -425,7 +425,7 @@ impl<'a> TraitDef<'a> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let container_id = cx.current_expansion.id.expn_info().parent;
|
let container_id = cx.current_expansion.id.expn_data().parent;
|
||||||
let is_always_copy =
|
let is_always_copy =
|
||||||
cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
|
cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
|
||||||
has_no_type_params;
|
has_no_type_params;
|
||||||
|
|
|
@ -11,7 +11,7 @@ use syntax::source_map::respan;
|
||||||
use syntax::symbol::sym;
|
use syntax::symbol::sym;
|
||||||
use syntax::tokenstream::*;
|
use syntax::tokenstream::*;
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
use syntax_pos::hygiene::{ExpnInfo, ExpnKind, MacroKind};
|
use syntax_pos::hygiene::{ExpnData, ExpnKind, MacroKind};
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ pub fn inject(
|
||||||
) {
|
) {
|
||||||
if !named_exts.is_empty() {
|
if !named_exts.is_empty() {
|
||||||
let mut extra_items = Vec::new();
|
let mut extra_items = Vec::new();
|
||||||
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
|
let span = DUMMY_SP.fresh_expansion(ExpnData::allow_unstable(
|
||||||
ExpnKind::Macro(MacroKind::Attr, sym::plugin), DUMMY_SP, edition,
|
ExpnKind::Macro(MacroKind::Attr, sym::plugin), DUMMY_SP, edition,
|
||||||
[sym::rustc_attrs][..].into(),
|
[sym::rustc_attrs][..].into(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::mem;
|
||||||
use smallvec::smallvec;
|
use smallvec::smallvec;
|
||||||
use syntax::ast::{self, Ident};
|
use syntax::ast::{self, Ident};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::source_map::{ExpnInfo, ExpnKind, respan};
|
use syntax::source_map::{ExpnData, ExpnKind, respan};
|
||||||
use syntax::ext::base::{ExtCtxt, MacroKind};
|
use syntax::ext::base::{ExtCtxt, MacroKind};
|
||||||
use syntax::ext::expand::{AstFragment, ExpansionConfig};
|
use syntax::ext::expand::{AstFragment, ExpansionConfig};
|
||||||
use syntax::ext::proc_macro::is_proc_macro_attr;
|
use syntax::ext::proc_macro::is_proc_macro_attr;
|
||||||
|
@ -327,7 +327,7 @@ fn mk_decls(
|
||||||
custom_attrs: &[ProcMacroDef],
|
custom_attrs: &[ProcMacroDef],
|
||||||
custom_macros: &[ProcMacroDef],
|
custom_macros: &[ProcMacroDef],
|
||||||
) -> P<ast::Item> {
|
) -> P<ast::Item> {
|
||||||
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
|
let span = DUMMY_SP.fresh_expansion(ExpnData::allow_unstable(
|
||||||
ExpnKind::Macro(MacroKind::Attr, sym::proc_macro), DUMMY_SP, cx.parse_sess.edition,
|
ExpnKind::Macro(MacroKind::Attr, sym::proc_macro), DUMMY_SP, cx.parse_sess.edition,
|
||||||
[sym::rustc_attrs, sym::proc_macro_internals][..].into(),
|
[sym::rustc_attrs, sym::proc_macro_internals][..].into(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -2,7 +2,7 @@ use syntax::{ast, attr};
|
||||||
use syntax::edition::Edition;
|
use syntax::edition::Edition;
|
||||||
use syntax::ext::hygiene::MacroKind;
|
use syntax::ext::hygiene::MacroKind;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan};
|
use syntax::source_map::{ExpnData, ExpnKind, dummy_spanned, respan};
|
||||||
use syntax::symbol::{Ident, Symbol, kw, sym};
|
use syntax::symbol::{Ident, Symbol, kw, sym};
|
||||||
use syntax_pos::DUMMY_SP;
|
use syntax_pos::DUMMY_SP;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ pub fn inject(
|
||||||
// the prelude.
|
// the prelude.
|
||||||
let name = names[0];
|
let name = names[0];
|
||||||
|
|
||||||
let span = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
|
let span = DUMMY_SP.fresh_expansion(ExpnData::allow_unstable(
|
||||||
ExpnKind::Macro(MacroKind::Attr, sym::std_inject), DUMMY_SP, edition,
|
ExpnKind::Macro(MacroKind::Attr, sym::std_inject), DUMMY_SP, edition,
|
||||||
[sym::prelude_import][..].into(),
|
[sym::prelude_import][..].into(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -11,7 +11,7 @@ use syntax::feature_gate::Features;
|
||||||
use syntax::mut_visit::{*, ExpectOne};
|
use syntax::mut_visit::{*, ExpectOne};
|
||||||
use syntax::parse::ParseSess;
|
use syntax::parse::ParseSess;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::source_map::{ExpnInfo, ExpnKind, dummy_spanned};
|
use syntax::source_map::{ExpnData, ExpnKind, dummy_spanned};
|
||||||
use syntax::symbol::{kw, sym, Symbol};
|
use syntax::symbol::{kw, sym, Symbol};
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
||||||
// #![main]
|
// #![main]
|
||||||
// test::test_main_static(&[..tests]);
|
// test::test_main_static(&[..tests]);
|
||||||
// }
|
// }
|
||||||
let sp = DUMMY_SP.fresh_expansion(ExpnInfo::allow_unstable(
|
let sp = DUMMY_SP.fresh_expansion(ExpnData::allow_unstable(
|
||||||
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, cx.ext_cx.parse_sess.edition,
|
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, cx.ext_cx.parse_sess.edition,
|
||||||
[sym::main, sym::test, sym::rustc_attrs][..].into(),
|
[sym::main, sym::test, sym::rustc_attrs][..].into(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
//
|
//
|
||||||
// This explains why `HygieneData`, `SyntaxContext` and `ExpnId` have interfaces
|
// This explains why `HygieneData`, `SyntaxContext` and `ExpnId` have interfaces
|
||||||
// with a certain amount of redundancy in them. For example,
|
// with a certain amount of redundancy in them. For example,
|
||||||
// `SyntaxContext::outer_expn_info` combines `SyntaxContext::outer` and
|
// `SyntaxContext::outer_expn_data` combines `SyntaxContext::outer` and
|
||||||
// `ExpnId::expn_info` so that two `HygieneData` accesses can be performed within
|
// `ExpnId::expn_data` so that two `HygieneData` accesses can be performed within
|
||||||
// a single `HygieneData::with` call.
|
// a single `HygieneData::with` call.
|
||||||
//
|
//
|
||||||
// It also explains why many functions appear in `HygieneData` and again in
|
// It also explains why many functions appear in `HygieneData` and again in
|
||||||
|
@ -76,8 +76,8 @@ pub enum Transparency {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExpnId {
|
impl ExpnId {
|
||||||
pub fn fresh(expn_info: Option<ExpnInfo>) -> Self {
|
pub fn fresh(expn_data: Option<ExpnData>) -> Self {
|
||||||
HygieneData::with(|data| data.fresh_expn(expn_info))
|
HygieneData::with(|data| data.fresh_expn(expn_data))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The ID of the theoretical expansion that generates freshly parsed, unexpanded AST.
|
/// The ID of the theoretical expansion that generates freshly parsed, unexpanded AST.
|
||||||
|
@ -97,16 +97,16 @@ impl ExpnId {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn expn_info(self) -> ExpnInfo {
|
pub fn expn_data(self) -> ExpnData {
|
||||||
HygieneData::with(|data| data.expn_info(self).clone())
|
HygieneData::with(|data| data.expn_data(self).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_expn_info(self, info: ExpnInfo) {
|
pub fn set_expn_data(self, expn_data: ExpnData) {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
let old_info = &mut data.expn_data[self.0 as usize];
|
let old_expn_data = &mut data.expn_data[self.0 as usize];
|
||||||
assert!(old_info.is_none(), "expansion info is reset for an expansion ID");
|
assert!(old_expn_data.is_none(), "expansion data is reset for an expansion ID");
|
||||||
*old_info = Some(info);
|
*old_expn_data = Some(expn_data);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,9 +124,9 @@ impl ExpnId {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn looks_like_proc_macro_derive(self) -> bool {
|
pub fn looks_like_proc_macro_derive(self) -> bool {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
let expn_info = data.expn_info(self);
|
let expn_data = data.expn_data(self);
|
||||||
if let ExpnKind::Macro(MacroKind::Derive, _) = expn_info.kind {
|
if let ExpnKind::Macro(MacroKind::Derive, _) = expn_data.kind {
|
||||||
return expn_info.default_transparency == Transparency::Opaque;
|
return expn_data.default_transparency == Transparency::Opaque;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
})
|
})
|
||||||
|
@ -135,10 +135,10 @@ impl ExpnId {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
crate struct HygieneData {
|
crate struct HygieneData {
|
||||||
/// Each expansion should have an associated expansion info, but sometimes there's a delay
|
/// Each expansion should have an associated expansion data, but sometimes there's a delay
|
||||||
/// between creation of an expansion ID and obtaining its info (e.g. macros are collected
|
/// between creation of an expansion ID and obtaining its data (e.g. macros are collected
|
||||||
/// first and then resolved later), so we use an `Option` here.
|
/// first and then resolved later), so we use an `Option` here.
|
||||||
expn_data: Vec<Option<ExpnInfo>>,
|
expn_data: Vec<Option<ExpnData>>,
|
||||||
syntax_context_data: Vec<SyntaxContextData>,
|
syntax_context_data: Vec<SyntaxContextData>,
|
||||||
syntax_context_map: FxHashMap<(SyntaxContext, ExpnId, Transparency), SyntaxContext>,
|
syntax_context_map: FxHashMap<(SyntaxContext, ExpnId, Transparency), SyntaxContext>,
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ crate struct HygieneData {
|
||||||
impl HygieneData {
|
impl HygieneData {
|
||||||
crate fn new(edition: Edition) -> Self {
|
crate fn new(edition: Edition) -> Self {
|
||||||
HygieneData {
|
HygieneData {
|
||||||
expn_data: vec![Some(ExpnInfo::default(ExpnKind::Root, DUMMY_SP, edition))],
|
expn_data: vec![Some(ExpnData::default(ExpnKind::Root, DUMMY_SP, edition))],
|
||||||
syntax_context_data: vec![SyntaxContextData {
|
syntax_context_data: vec![SyntaxContextData {
|
||||||
outer_expn: ExpnId::root(),
|
outer_expn: ExpnId::root(),
|
||||||
outer_transparency: Transparency::Opaque,
|
outer_transparency: Transparency::Opaque,
|
||||||
|
@ -163,14 +163,14 @@ impl HygieneData {
|
||||||
GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut()))
|
GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fresh_expn(&mut self, expn_info: Option<ExpnInfo>) -> ExpnId {
|
fn fresh_expn(&mut self, expn_data: Option<ExpnData>) -> ExpnId {
|
||||||
self.expn_data.push(expn_info);
|
self.expn_data.push(expn_data);
|
||||||
ExpnId(self.expn_data.len() as u32 - 1)
|
ExpnId(self.expn_data.len() as u32 - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expn_info(&self, expn_id: ExpnId) -> &ExpnInfo {
|
fn expn_data(&self, expn_id: ExpnId) -> &ExpnData {
|
||||||
self.expn_data[expn_id.0 as usize].as_ref()
|
self.expn_data[expn_id.0 as usize].as_ref()
|
||||||
.expect("no expansion info for an expansion ID")
|
.expect("no expansion data for an expansion ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_descendant_of(&self, mut expn_id: ExpnId, ancestor: ExpnId) -> bool {
|
fn is_descendant_of(&self, mut expn_id: ExpnId, ancestor: ExpnId) -> bool {
|
||||||
|
@ -178,7 +178,7 @@ impl HygieneData {
|
||||||
if expn_id == ExpnId::root() {
|
if expn_id == ExpnId::root() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
expn_id = self.expn_info(expn_id).parent;
|
expn_id = self.expn_data(expn_id).parent;
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ impl HygieneData {
|
||||||
|
|
||||||
fn walk_chain(&self, mut span: Span, to: SyntaxContext) -> Span {
|
fn walk_chain(&self, mut span: Span, to: SyntaxContext) -> Span {
|
||||||
while span.from_expansion() && span.ctxt() != to {
|
while span.from_expansion() && span.ctxt() != to {
|
||||||
span = self.expn_info(self.outer_expn(span.ctxt())).call_site;
|
span = self.expn_data(self.outer_expn(span.ctxt())).call_site;
|
||||||
}
|
}
|
||||||
span
|
span
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ impl HygieneData {
|
||||||
fn apply_mark(&mut self, ctxt: SyntaxContext, expn_id: ExpnId) -> SyntaxContext {
|
fn apply_mark(&mut self, ctxt: SyntaxContext, expn_id: ExpnId) -> SyntaxContext {
|
||||||
assert_ne!(expn_id, ExpnId::root());
|
assert_ne!(expn_id, ExpnId::root());
|
||||||
self.apply_mark_with_transparency(
|
self.apply_mark_with_transparency(
|
||||||
ctxt, expn_id, self.expn_info(expn_id).default_transparency
|
ctxt, expn_id, self.expn_data(expn_id).default_transparency
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ impl HygieneData {
|
||||||
return self.apply_mark_internal(ctxt, expn_id, transparency);
|
return self.apply_mark_internal(ctxt, expn_id, transparency);
|
||||||
}
|
}
|
||||||
|
|
||||||
let call_site_ctxt = self.expn_info(expn_id).call_site.ctxt();
|
let call_site_ctxt = self.expn_data(expn_id).call_site.ctxt();
|
||||||
let mut call_site_ctxt = if transparency == Transparency::SemiTransparent {
|
let mut call_site_ctxt = if transparency == Transparency::SemiTransparent {
|
||||||
self.modern(call_site_ctxt)
|
self.modern(call_site_ctxt)
|
||||||
} else {
|
} else {
|
||||||
|
@ -540,20 +540,20 @@ impl SyntaxContext {
|
||||||
HygieneData::with(|data| data.outer_expn(self))
|
HygieneData::with(|data| data.outer_expn(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `ctxt.outer_expn_info()` is equivalent to but faster than
|
/// `ctxt.outer_expn_data()` is equivalent to but faster than
|
||||||
/// `ctxt.outer_expn().expn_info()`.
|
/// `ctxt.outer_expn().expn_data()`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn outer_expn_info(self) -> ExpnInfo {
|
pub fn outer_expn_data(self) -> ExpnData {
|
||||||
HygieneData::with(|data| data.expn_info(data.outer_expn(self)).clone())
|
HygieneData::with(|data| data.expn_data(data.outer_expn(self)).clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `ctxt.outer_expn_with_info()` is equivalent to but faster than
|
/// `ctxt.outer_expn_with_data()` is equivalent to but faster than
|
||||||
/// `{ let outer = ctxt.outer_expn(); (outer, outer.expn_info()) }`.
|
/// `{ let outer = ctxt.outer_expn(); (outer, outer.expn_data()) }`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn outer_expn_with_info(self) -> (ExpnId, ExpnInfo) {
|
pub fn outer_expn_with_data(self) -> (ExpnId, ExpnData) {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
let outer = data.outer_expn(self);
|
let outer = data.outer_expn(self);
|
||||||
(outer, data.expn_info(outer).clone())
|
(outer, data.expn_data(outer).clone())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,9 +574,9 @@ impl Span {
|
||||||
/// other compiler-generated code to set per-span properties like allowed unstable features.
|
/// other compiler-generated code to set per-span properties like allowed unstable features.
|
||||||
/// The returned span belongs to the created expansion and has the new properties,
|
/// The returned span belongs to the created expansion and has the new properties,
|
||||||
/// but its location is inherited from the current span.
|
/// but its location is inherited from the current span.
|
||||||
pub fn fresh_expansion(self, expn_info: ExpnInfo) -> Span {
|
pub fn fresh_expansion(self, expn_data: ExpnData) -> Span {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
let expn_id = data.fresh_expn(Some(expn_info));
|
let expn_id = data.fresh_expn(Some(expn_data));
|
||||||
self.with_ctxt(data.apply_mark(SyntaxContext::root(), expn_id))
|
self.with_ctxt(data.apply_mark(SyntaxContext::root(), expn_id))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -585,7 +585,7 @@ impl Span {
|
||||||
/// A subset of properties from both macro definition and macro call available through global data.
|
/// A subset of properties from both macro definition and macro call available through global data.
|
||||||
/// Avoid using this if you have access to the original definition or call structures.
|
/// Avoid using this if you have access to the original definition or call structures.
|
||||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
|
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
|
||||||
pub struct ExpnInfo {
|
pub struct ExpnData {
|
||||||
// --- The part unique to each expansion.
|
// --- The part unique to each expansion.
|
||||||
/// The kind of this expansion - macro or compiler desugaring.
|
/// The kind of this expansion - macro or compiler desugaring.
|
||||||
pub kind: ExpnKind,
|
pub kind: ExpnKind,
|
||||||
|
@ -598,7 +598,7 @@ pub struct ExpnInfo {
|
||||||
/// `foo!()` invoked `bar!()` internally, and there was an
|
/// `foo!()` invoked `bar!()` internally, and there was an
|
||||||
/// expression inside `bar!`; the call_site of the expression in
|
/// expression inside `bar!`; the call_site of the expression in
|
||||||
/// the expansion would point to the `bar!` invocation; that
|
/// the expansion would point to the `bar!` invocation; that
|
||||||
/// call_site span would have its own ExpnInfo, with the call_site
|
/// call_site span would have its own ExpnData, with the call_site
|
||||||
/// pointing to the `foo!` invocation.
|
/// pointing to the `foo!` invocation.
|
||||||
pub call_site: Span,
|
pub call_site: Span,
|
||||||
|
|
||||||
|
@ -609,7 +609,7 @@ pub struct ExpnInfo {
|
||||||
/// The span of the macro definition (possibly dummy).
|
/// The span of the macro definition (possibly dummy).
|
||||||
/// This span serves only informational purpose and is not used for resolution.
|
/// This span serves only informational purpose and is not used for resolution.
|
||||||
pub def_site: Span,
|
pub def_site: Span,
|
||||||
/// Transparency used by `apply_mark` for the expansion with this expansion info by default.
|
/// Transparency used by `apply_mark` for the expansion with this expansion data by default.
|
||||||
pub default_transparency: Transparency,
|
pub default_transparency: Transparency,
|
||||||
/// List of #[unstable]/feature-gated features that the macro is allowed to use
|
/// List of #[unstable]/feature-gated features that the macro is allowed to use
|
||||||
/// internally without forcing the whole crate to opt-in
|
/// internally without forcing the whole crate to opt-in
|
||||||
|
@ -625,10 +625,10 @@ pub struct ExpnInfo {
|
||||||
pub edition: Edition,
|
pub edition: Edition,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExpnInfo {
|
impl ExpnData {
|
||||||
/// Constructs an expansion info with default properties.
|
/// Constructs expansion data with default properties.
|
||||||
pub fn default(kind: ExpnKind, call_site: Span, edition: Edition) -> ExpnInfo {
|
pub fn default(kind: ExpnKind, call_site: Span, edition: Edition) -> ExpnData {
|
||||||
ExpnInfo {
|
ExpnData {
|
||||||
kind,
|
kind,
|
||||||
parent: ExpnId::root(),
|
parent: ExpnId::root(),
|
||||||
call_site,
|
call_site,
|
||||||
|
@ -642,10 +642,10 @@ impl ExpnInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allow_unstable(kind: ExpnKind, call_site: Span, edition: Edition,
|
pub fn allow_unstable(kind: ExpnKind, call_site: Span, edition: Edition,
|
||||||
allow_internal_unstable: Lrc<[Symbol]>) -> ExpnInfo {
|
allow_internal_unstable: Lrc<[Symbol]>) -> ExpnData {
|
||||||
ExpnInfo {
|
ExpnData {
|
||||||
allow_internal_unstable: Some(allow_internal_unstable),
|
allow_internal_unstable: Some(allow_internal_unstable),
|
||||||
..ExpnInfo::default(kind, call_site, edition)
|
..ExpnData::default(kind, call_site, edition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ use rustc_serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||||
pub mod edition;
|
pub mod edition;
|
||||||
use edition::Edition;
|
use edition::Edition;
|
||||||
pub mod hygiene;
|
pub mod hygiene;
|
||||||
pub use hygiene::{ExpnId, SyntaxContext, ExpnInfo, ExpnKind, MacroKind, DesugaringKind};
|
pub use hygiene::{ExpnId, SyntaxContext, ExpnData, ExpnKind, MacroKind, DesugaringKind};
|
||||||
|
|
||||||
mod span_encoding;
|
mod span_encoding;
|
||||||
pub use span_encoding::{Span, DUMMY_SP};
|
pub use span_encoding::{Span, DUMMY_SP};
|
||||||
|
@ -353,20 +353,20 @@ impl Span {
|
||||||
/// Returns the source span -- this is either the supplied span, or the span for
|
/// Returns the source span -- this is either the supplied span, or the span for
|
||||||
/// the macro callsite that expanded to it.
|
/// the macro callsite that expanded to it.
|
||||||
pub fn source_callsite(self) -> Span {
|
pub fn source_callsite(self) -> Span {
|
||||||
let expn_info = self.ctxt().outer_expn_info();
|
let expn_data = self.ctxt().outer_expn_data();
|
||||||
if !expn_info.is_root() { expn_info.call_site.source_callsite() } else { self }
|
if !expn_data.is_root() { expn_data.call_site.source_callsite() } else { self }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The `Span` for the tokens in the previous macro expansion from which `self` was generated,
|
/// The `Span` for the tokens in the previous macro expansion from which `self` was generated,
|
||||||
/// if any.
|
/// if any.
|
||||||
pub fn parent(self) -> Option<Span> {
|
pub fn parent(self) -> Option<Span> {
|
||||||
let expn_info = self.ctxt().outer_expn_info();
|
let expn_data = self.ctxt().outer_expn_data();
|
||||||
if !expn_info.is_root() { Some(expn_info.call_site) } else { None }
|
if !expn_data.is_root() { Some(expn_data.call_site) } else { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Edition of the crate from which this span came.
|
/// Edition of the crate from which this span came.
|
||||||
pub fn edition(self) -> edition::Edition {
|
pub fn edition(self) -> edition::Edition {
|
||||||
self.ctxt().outer_expn_info().edition
|
self.ctxt().outer_expn_data().edition
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -382,22 +382,22 @@ impl Span {
|
||||||
/// Returns the source callee.
|
/// Returns the source callee.
|
||||||
///
|
///
|
||||||
/// Returns `None` if the supplied span has no expansion trace,
|
/// Returns `None` if the supplied span has no expansion trace,
|
||||||
/// else returns the `ExpnInfo` for the macro definition
|
/// else returns the `ExpnData` for the macro definition
|
||||||
/// corresponding to the source callsite.
|
/// corresponding to the source callsite.
|
||||||
pub fn source_callee(self) -> Option<ExpnInfo> {
|
pub fn source_callee(self) -> Option<ExpnData> {
|
||||||
fn source_callee(expn_info: ExpnInfo) -> ExpnInfo {
|
fn source_callee(expn_data: ExpnData) -> ExpnData {
|
||||||
let next_expn_info = expn_info.call_site.ctxt().outer_expn_info();
|
let next_expn_data = expn_data.call_site.ctxt().outer_expn_data();
|
||||||
if !next_expn_info.is_root() { source_callee(next_expn_info) } else { expn_info }
|
if !next_expn_data.is_root() { source_callee(next_expn_data) } else { expn_data }
|
||||||
}
|
}
|
||||||
let expn_info = self.ctxt().outer_expn_info();
|
let expn_data = self.ctxt().outer_expn_data();
|
||||||
if !expn_info.is_root() { Some(source_callee(expn_info)) } else { None }
|
if !expn_data.is_root() { Some(source_callee(expn_data)) } else { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if a span is "internal" to a macro in which `#[unstable]`
|
/// Checks if a span is "internal" to a macro in which `#[unstable]`
|
||||||
/// items can be used (that is, a macro marked with
|
/// items can be used (that is, a macro marked with
|
||||||
/// `#[allow_internal_unstable]`).
|
/// `#[allow_internal_unstable]`).
|
||||||
pub fn allows_unstable(&self, feature: Symbol) -> bool {
|
pub fn allows_unstable(&self, feature: Symbol) -> bool {
|
||||||
self.ctxt().outer_expn_info().allow_internal_unstable.map_or(false, |features| {
|
self.ctxt().outer_expn_data().allow_internal_unstable.map_or(false, |features| {
|
||||||
features.iter().any(|&f| {
|
features.iter().any(|&f| {
|
||||||
f == feature || f == sym::allow_internal_unstable_backcompat_hack
|
f == feature || f == sym::allow_internal_unstable_backcompat_hack
|
||||||
})
|
})
|
||||||
|
@ -406,7 +406,7 @@ impl Span {
|
||||||
|
|
||||||
/// Checks if this span arises from a compiler desugaring of kind `kind`.
|
/// Checks if this span arises from a compiler desugaring of kind `kind`.
|
||||||
pub fn is_desugaring(&self, kind: DesugaringKind) -> bool {
|
pub fn is_desugaring(&self, kind: DesugaringKind) -> bool {
|
||||||
match self.ctxt().outer_expn_info().kind {
|
match self.ctxt().outer_expn_data().kind {
|
||||||
ExpnKind::Desugaring(k) => k == kind,
|
ExpnKind::Desugaring(k) => k == kind,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@ impl Span {
|
||||||
/// Returns the compiler desugaring that created this span, or `None`
|
/// Returns the compiler desugaring that created this span, or `None`
|
||||||
/// if this span is not from a desugaring.
|
/// if this span is not from a desugaring.
|
||||||
pub fn desugaring_kind(&self) -> Option<DesugaringKind> {
|
pub fn desugaring_kind(&self) -> Option<DesugaringKind> {
|
||||||
match self.ctxt().outer_expn_info().kind {
|
match self.ctxt().outer_expn_data().kind {
|
||||||
ExpnKind::Desugaring(k) => Some(k),
|
ExpnKind::Desugaring(k) => Some(k),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
|
@ -425,20 +425,20 @@ impl Span {
|
||||||
/// can be used without triggering the `unsafe_code` lint
|
/// can be used without triggering the `unsafe_code` lint
|
||||||
// (that is, a macro marked with `#[allow_internal_unsafe]`).
|
// (that is, a macro marked with `#[allow_internal_unsafe]`).
|
||||||
pub fn allows_unsafe(&self) -> bool {
|
pub fn allows_unsafe(&self) -> bool {
|
||||||
self.ctxt().outer_expn_info().allow_internal_unsafe
|
self.ctxt().outer_expn_data().allow_internal_unsafe
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn macro_backtrace(mut self) -> Vec<MacroBacktrace> {
|
pub fn macro_backtrace(mut self) -> Vec<MacroBacktrace> {
|
||||||
let mut prev_span = DUMMY_SP;
|
let mut prev_span = DUMMY_SP;
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
loop {
|
loop {
|
||||||
let info = self.ctxt().outer_expn_info();
|
let expn_data = self.ctxt().outer_expn_data();
|
||||||
if info.is_root() {
|
if expn_data.is_root() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Don't print recursive invocations.
|
// Don't print recursive invocations.
|
||||||
if !info.call_site.source_equal(&prev_span) {
|
if !expn_data.call_site.source_equal(&prev_span) {
|
||||||
let (pre, post) = match info.kind {
|
let (pre, post) = match expn_data.kind {
|
||||||
ExpnKind::Root => break,
|
ExpnKind::Root => break,
|
||||||
ExpnKind::Desugaring(..) => ("desugaring of ", ""),
|
ExpnKind::Desugaring(..) => ("desugaring of ", ""),
|
||||||
ExpnKind::Macro(macro_kind, _) => match macro_kind {
|
ExpnKind::Macro(macro_kind, _) => match macro_kind {
|
||||||
|
@ -448,14 +448,14 @@ impl Span {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
result.push(MacroBacktrace {
|
result.push(MacroBacktrace {
|
||||||
call_site: info.call_site,
|
call_site: expn_data.call_site,
|
||||||
macro_decl_name: format!("{}{}{}", pre, info.kind.descr(), post),
|
macro_decl_name: format!("{}{}{}", pre, expn_data.kind.descr(), post),
|
||||||
def_site_span: info.def_site,
|
def_site_span: expn_data.def_site,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_span = self;
|
prev_span = self;
|
||||||
self = info.call_site;
|
self = expn_data.call_site;
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue