libsyntax: Remove Mark
into ExpnId
This commit is contained in:
parent
f9477a77c5
commit
31e10aec83
23 changed files with 183 additions and 182 deletions
|
@ -60,7 +60,7 @@ use syntax::attr;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
use syntax::errors;
|
use syntax::errors;
|
||||||
use syntax::ext::hygiene::Mark;
|
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, ExpnInfo, ExpnKind, DesugaringKind, Spanned};
|
||||||
use syntax::std_inject;
|
use syntax::std_inject;
|
||||||
|
@ -437,7 +437,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
owner,
|
owner,
|
||||||
id,
|
id,
|
||||||
DefPathData::Misc,
|
DefPathData::Misc,
|
||||||
Mark::root(),
|
ExpnId::root(),
|
||||||
tree.prefix.span,
|
tree.prefix.span,
|
||||||
);
|
);
|
||||||
self.lctx.allocate_hir_id_counter(id);
|
self.lctx.allocate_hir_id_counter(id);
|
||||||
|
@ -875,7 +875,7 @@ 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(Mark::root(), ExpnInfo {
|
span.fresh_expansion(ExpnId::root(), ExpnInfo {
|
||||||
def_site: span,
|
def_site: span,
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition())
|
..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition())
|
||||||
|
@ -968,7 +968,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
parent_index,
|
parent_index,
|
||||||
node_id,
|
node_id,
|
||||||
DefPathData::LifetimeNs(str_name),
|
DefPathData::LifetimeNs(str_name),
|
||||||
Mark::root(),
|
ExpnId::root(),
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1462,7 +1462,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
parent_def_index,
|
parent_def_index,
|
||||||
impl_trait_node_id,
|
impl_trait_node_id,
|
||||||
DefPathData::ImplTrait,
|
DefPathData::ImplTrait,
|
||||||
Mark::root(),
|
ExpnId::root(),
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1921,7 +1921,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
self.parent,
|
self.parent,
|
||||||
def_node_id,
|
def_node_id,
|
||||||
DefPathData::LifetimeNs(name.ident().as_interned_str()),
|
DefPathData::LifetimeNs(name.ident().as_interned_str()),
|
||||||
Mark::root(),
|
ExpnId::root(),
|
||||||
lifetime.span);
|
lifetime.span);
|
||||||
|
|
||||||
let (name, kind) = match name {
|
let (name, kind) = match name {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::hir::map::definitions::*;
|
||||||
use crate::hir::def_id::DefIndex;
|
use crate::hir::def_id::DefIndex;
|
||||||
|
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax::visit;
|
use syntax::visit;
|
||||||
use syntax::symbol::{kw, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax::parse::token::{self, Token};
|
use syntax::parse::token::{self, Token};
|
||||||
|
@ -12,11 +12,11 @@ use syntax_pos::Span;
|
||||||
pub struct DefCollector<'a> {
|
pub struct DefCollector<'a> {
|
||||||
definitions: &'a mut Definitions,
|
definitions: &'a mut Definitions,
|
||||||
parent_def: DefIndex,
|
parent_def: DefIndex,
|
||||||
expansion: Mark,
|
expansion: ExpnId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DefCollector<'a> {
|
impl<'a> DefCollector<'a> {
|
||||||
pub fn new(definitions: &'a mut Definitions, expansion: Mark) -> Self {
|
pub fn new(definitions: &'a mut Definitions, expansion: ExpnId) -> Self {
|
||||||
let parent_def = definitions.invocation_parent(expansion);
|
let parent_def = definitions.invocation_parent(expansion);
|
||||||
DefCollector { definitions, parent_def, expansion }
|
DefCollector { definitions, parent_def, expansion }
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use std::borrow::Borrow;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax::symbol::{Symbol, sym, InternedString};
|
use syntax::symbol::{Symbol, sym, InternedString};
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
use crate::util::nodemap::NodeMap;
|
use crate::util::nodemap::NodeMap;
|
||||||
|
@ -93,16 +93,16 @@ pub struct Definitions {
|
||||||
node_to_def_index: NodeMap<DefIndex>,
|
node_to_def_index: NodeMap<DefIndex>,
|
||||||
def_index_to_node: Vec<ast::NodeId>,
|
def_index_to_node: Vec<ast::NodeId>,
|
||||||
pub(super) node_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
|
pub(super) node_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
|
||||||
/// If `Mark` is an ID of some macro expansion,
|
/// If `ExpnId` is an ID of some macro expansion,
|
||||||
/// then `DefId` is the normal module (`mod`) in which the expanded macro was defined.
|
/// then `DefId` is the normal module (`mod`) in which the expanded macro was defined.
|
||||||
parent_modules_of_macro_defs: FxHashMap<Mark, DefId>,
|
parent_modules_of_macro_defs: FxHashMap<ExpnId, DefId>,
|
||||||
/// Item with a given `DefIndex` was defined during macro expansion with ID `Mark`.
|
/// Item with a given `DefIndex` was defined during macro expansion with ID `ExpnId`.
|
||||||
expansions_that_defined: FxHashMap<DefIndex, Mark>,
|
expansions_that_defined: FxHashMap<DefIndex, ExpnId>,
|
||||||
next_disambiguator: FxHashMap<(DefIndex, DefPathData), u32>,
|
next_disambiguator: FxHashMap<(DefIndex, DefPathData), u32>,
|
||||||
def_index_to_span: FxHashMap<DefIndex, Span>,
|
def_index_to_span: FxHashMap<DefIndex, Span>,
|
||||||
/// When collecting definitions from an AST fragment produced by a macro invocation `Mark`
|
/// When collecting definitions from an AST fragment produced by a macro invocation `ExpnId`
|
||||||
/// we know what parent node that fragment should be attached to thanks to this table.
|
/// we know what parent node that fragment should be attached to thanks to this table.
|
||||||
invocation_parents: FxHashMap<Mark, DefIndex>,
|
invocation_parents: FxHashMap<ExpnId, DefIndex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A unique identifier that we can use to lookup a definition
|
/// A unique identifier that we can use to lookup a definition
|
||||||
|
@ -437,7 +437,7 @@ impl Definitions {
|
||||||
assert!(self.def_index_to_node.is_empty());
|
assert!(self.def_index_to_node.is_empty());
|
||||||
self.def_index_to_node.push(ast::CRATE_NODE_ID);
|
self.def_index_to_node.push(ast::CRATE_NODE_ID);
|
||||||
self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index);
|
self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index);
|
||||||
self.set_invocation_parent(Mark::root(), root_index);
|
self.set_invocation_parent(ExpnId::root(), root_index);
|
||||||
|
|
||||||
// Allocate some other DefIndices that always must exist.
|
// Allocate some other DefIndices that always must exist.
|
||||||
GlobalMetaDataKind::allocate_def_indices(self);
|
GlobalMetaDataKind::allocate_def_indices(self);
|
||||||
|
@ -450,7 +450,7 @@ impl Definitions {
|
||||||
parent: DefIndex,
|
parent: DefIndex,
|
||||||
node_id: ast::NodeId,
|
node_id: ast::NodeId,
|
||||||
data: DefPathData,
|
data: DefPathData,
|
||||||
expansion: Mark,
|
expansion: ExpnId,
|
||||||
span: Span)
|
span: Span)
|
||||||
-> DefIndex {
|
-> DefIndex {
|
||||||
debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})",
|
debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})",
|
||||||
|
@ -498,7 +498,7 @@ impl Definitions {
|
||||||
self.node_to_def_index.insert(node_id, index);
|
self.node_to_def_index.insert(node_id, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if expansion != Mark::root() {
|
if expansion != ExpnId::root() {
|
||||||
self.expansions_that_defined.insert(index, expansion);
|
self.expansions_that_defined.insert(index, expansion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,23 +519,23 @@ impl Definitions {
|
||||||
self.node_to_hir_id = mapping;
|
self.node_to_hir_id = mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expansion_that_defined(&self, index: DefIndex) -> Mark {
|
pub fn expansion_that_defined(&self, index: DefIndex) -> ExpnId {
|
||||||
self.expansions_that_defined.get(&index).cloned().unwrap_or(Mark::root())
|
self.expansions_that_defined.get(&index).cloned().unwrap_or(ExpnId::root())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parent_module_of_macro_def(&self, mark: Mark) -> DefId {
|
pub fn parent_module_of_macro_def(&self, mark: ExpnId) -> DefId {
|
||||||
self.parent_modules_of_macro_defs[&mark]
|
self.parent_modules_of_macro_defs[&mark]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_parent_module_of_macro_def(&mut self, mark: Mark, module: DefId) {
|
pub fn add_parent_module_of_macro_def(&mut self, mark: ExpnId, module: DefId) {
|
||||||
self.parent_modules_of_macro_defs.insert(mark, module);
|
self.parent_modules_of_macro_defs.insert(mark, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invocation_parent(&self, invoc_id: Mark) -> DefIndex {
|
pub fn invocation_parent(&self, invoc_id: ExpnId) -> DefIndex {
|
||||||
self.invocation_parents[&invoc_id]
|
self.invocation_parents[&invoc_id]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_invocation_parent(&mut self, invoc_id: Mark, parent: DefIndex) {
|
pub fn set_invocation_parent(&mut self, invoc_id: ExpnId, parent: DefIndex) {
|
||||||
let old_parent = self.invocation_parents.insert(invoc_id, parent);
|
let old_parent = self.invocation_parents.insert(invoc_id, parent);
|
||||||
assert!(old_parent.is_none(), "parent def-index is reset for an invocation");
|
assert!(old_parent.is_none(), "parent def-index is reset for an invocation");
|
||||||
}
|
}
|
||||||
|
@ -624,7 +624,7 @@ macro_rules! define_global_metadata_kind {
|
||||||
CRATE_DEF_INDEX,
|
CRATE_DEF_INDEX,
|
||||||
ast::DUMMY_NODE_ID,
|
ast::DUMMY_NODE_ID,
|
||||||
DefPathData::GlobalMetaData(instance.name().as_interned_str()),
|
DefPathData::GlobalMetaData(instance.name().as_interned_str()),
|
||||||
Mark::root(),
|
ExpnId::root(),
|
||||||
DUMMY_SP
|
DUMMY_SP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -359,7 +359,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
|
||||||
// times, we cache a stable hash of it and hash that instead of
|
// times, we cache a stable hash of it and hash that instead of
|
||||||
// recursing every time.
|
// recursing every time.
|
||||||
thread_local! {
|
thread_local! {
|
||||||
static CACHE: RefCell<FxHashMap<hygiene::Mark, u64>> = Default::default();
|
static CACHE: RefCell<FxHashMap<hygiene::ExpnId, u64>> = Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
let sub_hash: u64 = CACHE.with(|cache| {
|
let sub_hash: u64 = CACHE.with(|cache| {
|
||||||
|
|
|
@ -44,7 +44,7 @@ use std::{mem, ptr};
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use syntax::ast::{self, Name, Ident, NodeId};
|
use syntax::ast::{self, Name, Ident, NodeId};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax::symbol::{kw, sym, Symbol, LocalInternedString, InternedString};
|
use syntax::symbol::{kw, sym, Symbol, LocalInternedString, InternedString};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
|
@ -3071,10 +3071,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.expansion_that_defined(def_parent_def_id))
|
self.expansion_that_defined(def_parent_def_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expansion_that_defined(self, scope: DefId) -> Mark {
|
fn expansion_that_defined(self, scope: DefId) -> ExpnId {
|
||||||
match scope.krate {
|
match scope.krate {
|
||||||
LOCAL_CRATE => self.hir().definitions().expansion_that_defined(scope.index),
|
LOCAL_CRATE => self.hir().definitions().expansion_that_defined(scope.index),
|
||||||
_ => Mark::root(),
|
_ => ExpnId::root(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ 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::{Mark, SyntaxContext, ExpnInfo};
|
use syntax_pos::hygiene::{ExpnId, SyntaxContext, ExpnInfo};
|
||||||
|
|
||||||
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
|
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
|
||||||
|
|
||||||
|
@ -594,7 +594,7 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
|
||||||
// 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::new(lo, hi, SyntaxContext::empty());
|
let location = || Span::new(lo, hi, SyntaxContext::empty());
|
||||||
let recover_from_expn_info = |this: &Self, expn_info, pos| {
|
let recover_from_expn_info = |this: &Self, expn_info, pos| {
|
||||||
let span = location().fresh_expansion(Mark::root(), expn_info);
|
let span = location().fresh_expansion(ExpnId::root(), expn_info);
|
||||||
this.synthetic_expansion_infos.borrow_mut().insert(pos, span.ctxt());
|
this.synthetic_expansion_infos.borrow_mut().insert(pos, span.ctxt());
|
||||||
span
|
span
|
||||||
};
|
};
|
||||||
|
@ -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<Mark, AbsoluteBytePos>,
|
expn_info_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>,
|
||||||
|
|
|
@ -14,7 +14,7 @@ use syntax::{
|
||||||
base::{ExtCtxt, MacroKind, Resolver},
|
base::{ExtCtxt, MacroKind, Resolver},
|
||||||
build::AstBuilder,
|
build::AstBuilder,
|
||||||
expand::ExpansionConfig,
|
expand::ExpansionConfig,
|
||||||
hygiene::Mark,
|
hygiene::ExpnId,
|
||||||
},
|
},
|
||||||
mut_visit::{self, MutVisitor},
|
mut_visit::{self, MutVisitor},
|
||||||
parse::ParseSess,
|
parse::ParseSess,
|
||||||
|
@ -85,7 +85,7 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
|
||||||
self.found = true;
|
self.found = true;
|
||||||
|
|
||||||
// Create a new expansion for the generated allocator code.
|
// Create a new expansion for the generated allocator code.
|
||||||
let span = item.span.fresh_expansion(Mark::root(), ExpnInfo::allow_unstable(
|
let span = item.span.fresh_expansion(ExpnId::root(), ExpnInfo::allow_unstable(
|
||||||
ExpnKind::Macro(MacroKind::Attr, sym::global_allocator), item.span, self.sess.edition,
|
ExpnKind::Macro(MacroKind::Attr, sym::global_allocator), item.span, self.sess.edition,
|
||||||
[sym::rustc_attrs][..].into(),
|
[sym::rustc_attrs][..].into(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -26,7 +26,7 @@ use rustc_errors::{Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId};
|
||||||
use rustc_errors::emitter::{Emitter};
|
use rustc_errors::emitter::{Emitter};
|
||||||
use rustc_target::spec::MergeFunctions;
|
use rustc_target::spec::MergeFunctions;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax_pos::MultiSpan;
|
use syntax_pos::MultiSpan;
|
||||||
use syntax_pos::symbol::{Symbol, sym};
|
use syntax_pos::symbol::{Symbol, sym};
|
||||||
use jobserver::{Client, Acquired};
|
use jobserver::{Client, Acquired};
|
||||||
|
@ -1775,7 +1775,7 @@ impl SharedEmitterMain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => {
|
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg)) => {
|
||||||
match Mark::from_u32(cookie).expn_info() {
|
match ExpnId::from_u32(cookie).expn_info() {
|
||||||
Some(ei) => sess.span_err(ei.call_site, &msg),
|
Some(ei) => sess.span_err(ei.call_site, &msg),
|
||||||
None => sess.err(&msg),
|
None => sess.err(&msg),
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ use syntax::ast::{self, Ident};
|
||||||
use syntax::source_map;
|
use syntax::source_map;
|
||||||
use syntax::symbol::{Symbol, sym};
|
use syntax::symbol::{Symbol, sym};
|
||||||
use syntax::ext::base::{MacroKind, SyntaxExtension};
|
use syntax::ext::base::{MacroKind, SyntaxExtension};
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
|
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ crate fn proc_macro_def_path_table(crate_root: &CrateRoot<'_>,
|
||||||
crate_root,
|
crate_root,
|
||||||
ast::DUMMY_NODE_ID,
|
ast::DUMMY_NODE_ID,
|
||||||
DefPathData::MacroNs(name.as_interned_str()),
|
DefPathData::MacroNs(name.as_interned_str()),
|
||||||
Mark::root(),
|
ExpnId::root(),
|
||||||
DUMMY_SP);
|
DUMMY_SP);
|
||||||
debug!("definition for {:?} is {:?}", name, def_index);
|
debug!("definition for {:?} is {:?}", name, def_index);
|
||||||
assert_eq!(def_index, DefIndex::from_proc_macro_index(index));
|
assert_eq!(def_index, DefIndex::from_proc_macro_index(index));
|
||||||
|
|
|
@ -30,7 +30,7 @@ use syntax::attr;
|
||||||
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId};
|
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId};
|
||||||
use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind, Variant};
|
use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind, Variant};
|
||||||
use syntax::ext::base::SyntaxExtension;
|
use syntax::ext::base::SyntaxExtension;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax::ext::tt::macro_rules;
|
use syntax::ext::tt::macro_rules;
|
||||||
use syntax::feature_gate::is_builtin_attr;
|
use syntax::feature_gate::is_builtin_attr;
|
||||||
use syntax::parse::token::{self, Token};
|
use syntax::parse::token::{self, Token};
|
||||||
|
@ -45,7 +45,7 @@ use log::debug;
|
||||||
|
|
||||||
type Res = def::Res<NodeId>;
|
type Res = def::Res<NodeId>;
|
||||||
|
|
||||||
impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, Mark) {
|
impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, ExpnId) {
|
||||||
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
|
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
|
||||||
arenas.alloc_name_binding(NameBinding {
|
arenas.alloc_name_binding(NameBinding {
|
||||||
kind: NameBindingKind::Module(self.0),
|
kind: NameBindingKind::Module(self.0),
|
||||||
|
@ -57,7 +57,7 @@ impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, Mark) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, Mark) {
|
impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId) {
|
||||||
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
|
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
|
||||||
arenas.alloc_name_binding(NameBinding {
|
arenas.alloc_name_binding(NameBinding {
|
||||||
kind: NameBindingKind::Res(self.0, false),
|
kind: NameBindingKind::Res(self.0, false),
|
||||||
|
@ -71,7 +71,7 @@ impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, Mark) {
|
||||||
|
|
||||||
pub(crate) struct IsMacroExport;
|
pub(crate) struct IsMacroExport;
|
||||||
|
|
||||||
impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, Mark, IsMacroExport) {
|
impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId, IsMacroExport) {
|
||||||
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
|
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
|
||||||
arenas.alloc_name_binding(NameBinding {
|
arenas.alloc_name_binding(NameBinding {
|
||||||
kind: NameBindingKind::Res(self.0, true),
|
kind: NameBindingKind::Res(self.0, true),
|
||||||
|
@ -397,7 +397,7 @@ impl<'a> Resolver<'a> {
|
||||||
let imported_binding = self.import(binding, directive);
|
let imported_binding = self.import(binding, directive);
|
||||||
if ptr::eq(self.current_module, self.graph_root) {
|
if ptr::eq(self.current_module, self.graph_root) {
|
||||||
if let Some(entry) = self.extern_prelude.get(&ident.modern()) {
|
if let Some(entry) = self.extern_prelude.get(&ident.modern()) {
|
||||||
if expansion != Mark::root() && orig_name.is_some() &&
|
if expansion != ExpnId::root() && orig_name.is_some() &&
|
||||||
entry.extern_crate_item.is_none() {
|
entry.extern_crate_item.is_none() {
|
||||||
self.session.span_err(item.span, "macro-expanded `extern crate` items \
|
self.session.span_err(item.span, "macro-expanded `extern crate` items \
|
||||||
cannot shadow names passed with \
|
cannot shadow names passed with \
|
||||||
|
@ -571,7 +571,7 @@ impl<'a> Resolver<'a> {
|
||||||
variant: &Variant,
|
variant: &Variant,
|
||||||
parent: Module<'a>,
|
parent: Module<'a>,
|
||||||
vis: ty::Visibility,
|
vis: ty::Visibility,
|
||||||
expansion: Mark) {
|
expansion: ExpnId) {
|
||||||
let ident = variant.node.ident;
|
let ident = variant.node.ident;
|
||||||
|
|
||||||
// Define a name in the type namespace.
|
// Define a name in the type namespace.
|
||||||
|
@ -600,7 +600,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs the reduced graph for one foreign item.
|
/// Constructs the reduced graph for one foreign item.
|
||||||
fn build_reduced_graph_for_foreign_item(&mut self, item: &ForeignItem, expansion: Mark) {
|
fn build_reduced_graph_for_foreign_item(&mut self, item: &ForeignItem, expansion: ExpnId) {
|
||||||
let (res, ns) = match item.node {
|
let (res, ns) = match item.node {
|
||||||
ForeignItemKind::Fn(..) => {
|
ForeignItemKind::Fn(..) => {
|
||||||
(Res::Def(DefKind::Fn, self.definitions.local_def_id(item.id)), ValueNS)
|
(Res::Def(DefKind::Fn, self.definitions.local_def_id(item.id)), ValueNS)
|
||||||
|
@ -618,7 +618,7 @@ impl<'a> Resolver<'a> {
|
||||||
self.define(parent, item.ident, ns, (res, vis, item.span, expansion));
|
self.define(parent, item.ident, ns, (res, vis, item.span, expansion));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_reduced_graph_for_block(&mut self, block: &Block, expansion: Mark) {
|
fn build_reduced_graph_for_block(&mut self, block: &Block, expansion: ExpnId) {
|
||||||
let parent = self.current_module;
|
let parent = self.current_module;
|
||||||
if self.block_needs_anonymous_module(block) {
|
if self.block_needs_anonymous_module(block) {
|
||||||
let module = self.new_module(parent,
|
let module = self.new_module(parent,
|
||||||
|
@ -642,7 +642,7 @@ impl<'a> Resolver<'a> {
|
||||||
// but metadata cannot encode gensyms currently, so we create it here.
|
// but metadata cannot encode gensyms currently, so we create it here.
|
||||||
// This is only a guess, two equivalent idents may incorrectly get different gensyms here.
|
// This is only a guess, two equivalent idents may incorrectly get different gensyms here.
|
||||||
let ident = ident.gensym_if_underscore();
|
let ident = ident.gensym_if_underscore();
|
||||||
let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene
|
let expansion = ExpnId::root(); // FIXME(jseyfried) intercrate hygiene
|
||||||
match res {
|
match res {
|
||||||
Res::Def(kind @ DefKind::Mod, def_id)
|
Res::Def(kind @ DefKind::Mod, def_id)
|
||||||
| Res::Def(kind @ DefKind::Enum, def_id) => {
|
| Res::Def(kind @ DefKind::Enum, def_id) => {
|
||||||
|
@ -734,13 +734,14 @@ impl<'a> Resolver<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let kind = ModuleKind::Def(DefKind::Mod, def_id, name.as_symbol());
|
let kind = ModuleKind::Def(DefKind::Mod, def_id, name.as_symbol());
|
||||||
let module =
|
let module = self.arenas.alloc_module(ModuleData::new(
|
||||||
self.arenas.alloc_module(ModuleData::new(parent, kind, def_id, Mark::root(), DUMMY_SP));
|
parent, kind, def_id, ExpnId::root(), DUMMY_SP
|
||||||
|
));
|
||||||
self.extern_module_map.insert((def_id, macros_only), module);
|
self.extern_module_map.insert((def_id, macros_only), module);
|
||||||
module
|
module
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn macro_def_scope(&mut self, expansion: Mark) -> Module<'a> {
|
pub fn macro_def_scope(&mut self, expansion: ExpnId) -> Module<'a> {
|
||||||
let def_id = match self.macro_defs.get(&expansion) {
|
let def_id = match self.macro_defs.get(&expansion) {
|
||||||
Some(def_id) => *def_id,
|
Some(def_id) => *def_id,
|
||||||
None => return self.graph_root,
|
None => return self.graph_root,
|
||||||
|
@ -858,7 +859,7 @@ impl<'a> Resolver<'a> {
|
||||||
used: Cell::new(false),
|
used: Cell::new(false),
|
||||||
});
|
});
|
||||||
|
|
||||||
let allow_shadowing = parent_scope.expansion == Mark::root();
|
let allow_shadowing = parent_scope.expansion == ExpnId::root();
|
||||||
if let Some(span) = import_all {
|
if let Some(span) = import_all {
|
||||||
let directive = macro_use_directive(span);
|
let directive = macro_use_directive(span);
|
||||||
self.potentially_unused_imports.push(directive);
|
self.potentially_unused_imports.push(directive);
|
||||||
|
@ -918,7 +919,7 @@ impl<'a> Resolver<'a> {
|
||||||
pub struct BuildReducedGraphVisitor<'a, 'b> {
|
pub struct BuildReducedGraphVisitor<'a, 'b> {
|
||||||
pub resolver: &'a mut Resolver<'b>,
|
pub resolver: &'a mut Resolver<'b>,
|
||||||
pub current_legacy_scope: LegacyScope<'b>,
|
pub current_legacy_scope: LegacyScope<'b>,
|
||||||
pub expansion: Mark,
|
pub expansion: ExpnId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
|
|
|
@ -39,7 +39,7 @@ use rustc_metadata::creader::CrateLoader;
|
||||||
use rustc_metadata::cstore::CStore;
|
use rustc_metadata::cstore::CStore;
|
||||||
|
|
||||||
use syntax::source_map::SourceMap;
|
use syntax::source_map::SourceMap;
|
||||||
use syntax::ext::hygiene::{Mark, Transparency, SyntaxContext};
|
use syntax::ext::hygiene::{ExpnId, Transparency, SyntaxContext};
|
||||||
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
|
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
|
||||||
use syntax::ext::base::SyntaxExtension;
|
use syntax::ext::base::SyntaxExtension;
|
||||||
use syntax::ext::base::MacroKind;
|
use syntax::ext::base::MacroKind;
|
||||||
|
@ -141,7 +141,7 @@ enum ScopeSet {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ParentScope<'a> {
|
pub struct ParentScope<'a> {
|
||||||
module: Module<'a>,
|
module: Module<'a>,
|
||||||
expansion: Mark,
|
expansion: ExpnId,
|
||||||
legacy: LegacyScope<'a>,
|
legacy: LegacyScope<'a>,
|
||||||
derives: Vec<ast::Path>,
|
derives: Vec<ast::Path>,
|
||||||
}
|
}
|
||||||
|
@ -1178,7 +1178,7 @@ pub struct ModuleData<'a> {
|
||||||
builtin_attrs: RefCell<Vec<(Ident, ParentScope<'a>)>>,
|
builtin_attrs: RefCell<Vec<(Ident, ParentScope<'a>)>>,
|
||||||
|
|
||||||
// Macro invocations that can expand into items in this module.
|
// Macro invocations that can expand into items in this module.
|
||||||
unresolved_invocations: RefCell<FxHashSet<Mark>>,
|
unresolved_invocations: RefCell<FxHashSet<ExpnId>>,
|
||||||
|
|
||||||
no_implicit_prelude: bool,
|
no_implicit_prelude: bool,
|
||||||
|
|
||||||
|
@ -1196,7 +1196,7 @@ pub struct ModuleData<'a> {
|
||||||
/// Span of the module itself. Used for error reporting.
|
/// Span of the module itself. Used for error reporting.
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
||||||
expansion: Mark,
|
expansion: ExpnId,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Module<'a> = &'a ModuleData<'a>;
|
type Module<'a> = &'a ModuleData<'a>;
|
||||||
|
@ -1205,7 +1205,7 @@ impl<'a> ModuleData<'a> {
|
||||||
fn new(parent: Option<Module<'a>>,
|
fn new(parent: Option<Module<'a>>,
|
||||||
kind: ModuleKind,
|
kind: ModuleKind,
|
||||||
normal_ancestor_id: DefId,
|
normal_ancestor_id: DefId,
|
||||||
expansion: Mark,
|
expansion: ExpnId,
|
||||||
span: Span) -> Self {
|
span: Span) -> Self {
|
||||||
ModuleData {
|
ModuleData {
|
||||||
parent,
|
parent,
|
||||||
|
@ -1304,7 +1304,7 @@ impl<'a> fmt::Debug for ModuleData<'a> {
|
||||||
pub struct NameBinding<'a> {
|
pub struct NameBinding<'a> {
|
||||||
kind: NameBindingKind<'a>,
|
kind: NameBindingKind<'a>,
|
||||||
ambiguity: Option<(&'a NameBinding<'a>, AmbiguityKind)>,
|
ambiguity: Option<(&'a NameBinding<'a>, AmbiguityKind)>,
|
||||||
expansion: Mark,
|
expansion: ExpnId,
|
||||||
span: Span,
|
span: Span,
|
||||||
vis: ty::Visibility,
|
vis: ty::Visibility,
|
||||||
}
|
}
|
||||||
|
@ -1513,7 +1513,7 @@ impl<'a> NameBinding<'a> {
|
||||||
// in some later round and screw up our previously found resolution.
|
// in some later round and screw up our previously found resolution.
|
||||||
// See more detailed explanation in
|
// See more detailed explanation in
|
||||||
// https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049
|
// https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049
|
||||||
fn may_appear_after(&self, invoc_parent_expansion: Mark, binding: &NameBinding<'_>) -> bool {
|
fn may_appear_after(&self, invoc_parent_expansion: ExpnId, binding: &NameBinding<'_>) -> bool {
|
||||||
// self > max(invoc, binding) => !(self <= invoc || self <= binding)
|
// self > max(invoc, binding) => !(self <= invoc || self <= binding)
|
||||||
// Expansions are partially ordered, so "may appear after" is an inversion of
|
// Expansions are partially ordered, so "may appear after" is an inversion of
|
||||||
// "certainly appears before or simultaneously" and includes unordered cases.
|
// "certainly appears before or simultaneously" and includes unordered cases.
|
||||||
|
@ -1686,13 +1686,13 @@ pub struct Resolver<'a> {
|
||||||
dummy_ext_bang: Lrc<SyntaxExtension>,
|
dummy_ext_bang: Lrc<SyntaxExtension>,
|
||||||
dummy_ext_derive: Lrc<SyntaxExtension>,
|
dummy_ext_derive: Lrc<SyntaxExtension>,
|
||||||
non_macro_attrs: [Lrc<SyntaxExtension>; 2],
|
non_macro_attrs: [Lrc<SyntaxExtension>; 2],
|
||||||
macro_defs: FxHashMap<Mark, DefId>,
|
macro_defs: FxHashMap<ExpnId, DefId>,
|
||||||
local_macro_def_scopes: FxHashMap<NodeId, Module<'a>>,
|
local_macro_def_scopes: FxHashMap<NodeId, Module<'a>>,
|
||||||
unused_macros: NodeMap<Span>,
|
unused_macros: NodeMap<Span>,
|
||||||
proc_macro_stubs: NodeSet,
|
proc_macro_stubs: NodeSet,
|
||||||
|
|
||||||
/// Maps the `Mark` of an expansion to its containing module or block.
|
/// Maps the `ExpnId` of an expansion to its containing module or block.
|
||||||
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
|
invocations: FxHashMap<ExpnId, &'a InvocationData<'a>>,
|
||||||
|
|
||||||
/// Avoid duplicated errors for "name already defined".
|
/// Avoid duplicated errors for "name already defined".
|
||||||
name_already_seen: FxHashMap<Name, Span>,
|
name_already_seen: FxHashMap<Name, Span>,
|
||||||
|
@ -1918,7 +1918,7 @@ impl<'a> Resolver<'a> {
|
||||||
);
|
);
|
||||||
let graph_root = arenas.alloc_module(ModuleData {
|
let graph_root = arenas.alloc_module(ModuleData {
|
||||||
no_implicit_prelude: attr::contains_name(&krate.attrs, sym::no_implicit_prelude),
|
no_implicit_prelude: attr::contains_name(&krate.attrs, sym::no_implicit_prelude),
|
||||||
..ModuleData::new(None, root_module_kind, root_def_id, Mark::root(), krate.span)
|
..ModuleData::new(None, root_module_kind, root_def_id, ExpnId::root(), krate.span)
|
||||||
});
|
});
|
||||||
let mut module_map = FxHashMap::default();
|
let mut module_map = FxHashMap::default();
|
||||||
module_map.insert(DefId::local(CRATE_DEF_INDEX), graph_root);
|
module_map.insert(DefId::local(CRATE_DEF_INDEX), graph_root);
|
||||||
|
@ -1941,11 +1941,11 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut invocations = FxHashMap::default();
|
let mut invocations = FxHashMap::default();
|
||||||
invocations.insert(Mark::root(),
|
invocations.insert(ExpnId::root(),
|
||||||
arenas.alloc_invocation_data(InvocationData::root(graph_root)));
|
arenas.alloc_invocation_data(InvocationData::root(graph_root)));
|
||||||
|
|
||||||
let mut macro_defs = FxHashMap::default();
|
let mut macro_defs = FxHashMap::default();
|
||||||
macro_defs.insert(Mark::root(), root_def_id);
|
macro_defs.insert(ExpnId::root(), root_def_id);
|
||||||
|
|
||||||
let features = session.features_untracked();
|
let features = session.features_untracked();
|
||||||
let non_macro_attr =
|
let non_macro_attr =
|
||||||
|
@ -2014,7 +2014,7 @@ impl<'a> Resolver<'a> {
|
||||||
dummy_binding: arenas.alloc_name_binding(NameBinding {
|
dummy_binding: arenas.alloc_name_binding(NameBinding {
|
||||||
kind: NameBindingKind::Res(Res::Err, false),
|
kind: NameBindingKind::Res(Res::Err, false),
|
||||||
ambiguity: None,
|
ambiguity: None,
|
||||||
expansion: Mark::root(),
|
expansion: ExpnId::root(),
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
vis: ty::Visibility::Public,
|
vis: ty::Visibility::Public,
|
||||||
}),
|
}),
|
||||||
|
@ -2095,7 +2095,7 @@ impl<'a> Resolver<'a> {
|
||||||
parent: Module<'a>,
|
parent: Module<'a>,
|
||||||
kind: ModuleKind,
|
kind: ModuleKind,
|
||||||
normal_ancestor_id: DefId,
|
normal_ancestor_id: DefId,
|
||||||
expansion: Mark,
|
expansion: ExpnId,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Module<'a> {
|
) -> Module<'a> {
|
||||||
let module = ModuleData::new(Some(parent), kind, normal_ancestor_id, expansion, span);
|
let module = ModuleData::new(Some(parent), kind, normal_ancestor_id, expansion, span);
|
||||||
|
@ -2243,7 +2243,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
Scope::CrateRoot => match ns {
|
Scope::CrateRoot => match ns {
|
||||||
TypeNS => {
|
TypeNS => {
|
||||||
ident.span.adjust(Mark::root());
|
ident.span.adjust(ExpnId::root());
|
||||||
Scope::ExternPrelude
|
Scope::ExternPrelude
|
||||||
}
|
}
|
||||||
ValueNS | MacroNS => break,
|
ValueNS | MacroNS => break,
|
||||||
|
@ -2253,7 +2253,7 @@ impl<'a> Resolver<'a> {
|
||||||
match self.hygienic_lexical_parent(module, &mut ident.span) {
|
match self.hygienic_lexical_parent(module, &mut ident.span) {
|
||||||
Some(parent_module) => Scope::Module(parent_module),
|
Some(parent_module) => Scope::Module(parent_module),
|
||||||
None => {
|
None => {
|
||||||
ident.span.adjust(Mark::root());
|
ident.span.adjust(ExpnId::root());
|
||||||
match ns {
|
match ns {
|
||||||
TypeNS => Scope::ExternPrelude,
|
TypeNS => Scope::ExternPrelude,
|
||||||
ValueNS => Scope::StdLibPrelude,
|
ValueNS => Scope::StdLibPrelude,
|
||||||
|
@ -2399,7 +2399,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !module.no_implicit_prelude {
|
if !module.no_implicit_prelude {
|
||||||
ident.span.adjust(Mark::root());
|
ident.span.adjust(ExpnId::root());
|
||||||
if ns == TypeNS {
|
if ns == TypeNS {
|
||||||
if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
|
if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
|
||||||
return Some(LexicalScopeBinding::Item(binding));
|
return Some(LexicalScopeBinding::Item(binding));
|
||||||
|
@ -2407,7 +2407,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
if ns == TypeNS && KNOWN_TOOLS.contains(&ident.name) {
|
if ns == TypeNS && KNOWN_TOOLS.contains(&ident.name) {
|
||||||
let binding = (Res::ToolMod, ty::Visibility::Public,
|
let binding = (Res::ToolMod, ty::Visibility::Public,
|
||||||
DUMMY_SP, Mark::root()).to_name_binding(self.arenas);
|
DUMMY_SP, ExpnId::root()).to_name_binding(self.arenas);
|
||||||
return Some(LexicalScopeBinding::Item(binding));
|
return Some(LexicalScopeBinding::Item(binding));
|
||||||
}
|
}
|
||||||
if let Some(prelude) = self.prelude {
|
if let Some(prelude) = self.prelude {
|
||||||
|
@ -2506,7 +2506,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ModuleOrUniformRoot::ExternPrelude => {
|
ModuleOrUniformRoot::ExternPrelude => {
|
||||||
ident.span.modernize_and_adjust(Mark::root());
|
ident.span.modernize_and_adjust(ExpnId::root());
|
||||||
}
|
}
|
||||||
ModuleOrUniformRoot::CrateRootAndExternPrelude |
|
ModuleOrUniformRoot::CrateRootAndExternPrelude |
|
||||||
ModuleOrUniformRoot::CurrentScope => {
|
ModuleOrUniformRoot::CurrentScope => {
|
||||||
|
@ -2552,7 +2552,7 @@ impl<'a> Resolver<'a> {
|
||||||
result
|
result
|
||||||
} else {
|
} else {
|
||||||
ctxt = ctxt.modern();
|
ctxt = ctxt.modern();
|
||||||
ctxt.adjust(Mark::root())
|
ctxt.adjust(ExpnId::root())
|
||||||
};
|
};
|
||||||
let module = match mark {
|
let module = match mark {
|
||||||
Some(def) => self.macro_def_scope(def),
|
Some(def) => self.macro_def_scope(def),
|
||||||
|
@ -5063,7 +5063,7 @@ impl<'a> Resolver<'a> {
|
||||||
};
|
};
|
||||||
let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
|
let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
|
||||||
self.populate_module_if_necessary(&crate_root);
|
self.populate_module_if_necessary(&crate_root);
|
||||||
Some((crate_root, ty::Visibility::Public, DUMMY_SP, Mark::root())
|
Some((crate_root, ty::Visibility::Public, DUMMY_SP, ExpnId::root())
|
||||||
.to_name_binding(self.arenas))
|
.to_name_binding(self.arenas))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,7 +16,7 @@ use syntax::attr::{self, StabilityLevel};
|
||||||
use syntax::ext::base::{self, Indeterminate};
|
use syntax::ext::base::{self, Indeterminate};
|
||||||
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, Mark, ExpnInfo, ExpnKind};
|
use syntax::ext::hygiene::{self, ExpnId, ExpnInfo, 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;
|
||||||
|
@ -135,8 +135,8 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
self.session.next_node_id()
|
self.session.next_node_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark {
|
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId {
|
||||||
let span = DUMMY_SP.fresh_expansion(Mark::root(), ExpnInfo::default(
|
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::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 mark = span.ctxt().outer();
|
let mark = span.ctxt().outer();
|
||||||
|
@ -160,8 +160,8 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFragment,
|
fn visit_ast_fragment_with_placeholders(&mut self, mark: ExpnId, fragment: &AstFragment,
|
||||||
derives: &[Mark]) {
|
derives: &[ExpnId]) {
|
||||||
fragment.visit_with(&mut DefCollector::new(&mut self.definitions, mark));
|
fragment.visit_with(&mut DefCollector::new(&mut self.definitions, mark));
|
||||||
|
|
||||||
let invocation = self.invocations[&mark];
|
let invocation = self.invocations[&mark];
|
||||||
|
@ -194,7 +194,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
ambiguity: None,
|
ambiguity: None,
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
vis: ty::Visibility::Public,
|
vis: ty::Visibility::Public,
|
||||||
expansion: Mark::root(),
|
expansion: ExpnId::root(),
|
||||||
});
|
});
|
||||||
if self.builtin_macros.insert(ident.name, binding).is_some() {
|
if self.builtin_macros.insert(ident.name, binding).is_some() {
|
||||||
self.session.span_err(ident.span,
|
self.session.span_err(ident.span,
|
||||||
|
@ -206,7 +206,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
ImportResolver { resolver: self }.resolve_imports()
|
ImportResolver { resolver: self }.resolve_imports()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force: bool)
|
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, force: bool)
|
||||||
-> Result<Option<Lrc<SyntaxExtension>>, Indeterminate> {
|
-> Result<Option<Lrc<SyntaxExtension>>, Indeterminate> {
|
||||||
let (path, kind, derives_in_scope, after_derive) = match invoc.kind {
|
let (path, kind, derives_in_scope, after_derive) = match invoc.kind {
|
||||||
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
|
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
|
||||||
|
@ -250,10 +250,10 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
|
|
||||||
impl<'a> Resolver<'a> {
|
impl<'a> Resolver<'a> {
|
||||||
pub fn dummy_parent_scope(&self) -> ParentScope<'a> {
|
pub fn dummy_parent_scope(&self) -> ParentScope<'a> {
|
||||||
self.invoc_parent_scope(Mark::root(), Vec::new())
|
self.invoc_parent_scope(ExpnId::root(), Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invoc_parent_scope(&self, invoc_id: Mark, derives: Vec<ast::Path>) -> ParentScope<'a> {
|
fn invoc_parent_scope(&self, invoc_id: ExpnId, derives: Vec<ast::Path>) -> ParentScope<'a> {
|
||||||
let invoc = self.invocations[&invoc_id];
|
let invoc = self.invocations[&invoc_id];
|
||||||
ParentScope {
|
ParentScope {
|
||||||
module: invoc.module.nearest_item_scope(),
|
module: invoc.module.nearest_item_scope(),
|
||||||
|
@ -460,7 +460,7 @@ impl<'a> Resolver<'a> {
|
||||||
&parent_scope, true, force) {
|
&parent_scope, true, force) {
|
||||||
Ok((Some(ext), _)) => if ext.helper_attrs.contains(&ident.name) {
|
Ok((Some(ext), _)) => if ext.helper_attrs.contains(&ident.name) {
|
||||||
let binding = (Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper),
|
let binding = (Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper),
|
||||||
ty::Visibility::Public, derive.span, Mark::root())
|
ty::Visibility::Public, derive.span, ExpnId::root())
|
||||||
.to_name_binding(this.arenas);
|
.to_name_binding(this.arenas);
|
||||||
result = Ok((binding, Flags::empty()));
|
result = Ok((binding, Flags::empty()));
|
||||||
break;
|
break;
|
||||||
|
@ -541,7 +541,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
Scope::BuiltinAttrs => if is_builtin_attr_name(ident.name) {
|
Scope::BuiltinAttrs => if is_builtin_attr_name(ident.name) {
|
||||||
let binding = (Res::NonMacroAttr(NonMacroAttrKind::Builtin),
|
let binding = (Res::NonMacroAttr(NonMacroAttrKind::Builtin),
|
||||||
ty::Visibility::Public, DUMMY_SP, Mark::root())
|
ty::Visibility::Public, DUMMY_SP, ExpnId::root())
|
||||||
.to_name_binding(this.arenas);
|
.to_name_binding(this.arenas);
|
||||||
Ok((binding, Flags::PRELUDE))
|
Ok((binding, Flags::PRELUDE))
|
||||||
} else {
|
} else {
|
||||||
|
@ -550,7 +550,7 @@ impl<'a> Resolver<'a> {
|
||||||
Scope::LegacyPluginHelpers => if this.session.plugin_attributes.borrow().iter()
|
Scope::LegacyPluginHelpers => if this.session.plugin_attributes.borrow().iter()
|
||||||
.any(|(name, _)| ident.name == *name) {
|
.any(|(name, _)| ident.name == *name) {
|
||||||
let binding = (Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper),
|
let binding = (Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper),
|
||||||
ty::Visibility::Public, DUMMY_SP, Mark::root())
|
ty::Visibility::Public, DUMMY_SP, ExpnId::root())
|
||||||
.to_name_binding(this.arenas);
|
.to_name_binding(this.arenas);
|
||||||
Ok((binding, Flags::PRELUDE))
|
Ok((binding, Flags::PRELUDE))
|
||||||
} else {
|
} else {
|
||||||
|
@ -563,7 +563,7 @@ impl<'a> Resolver<'a> {
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
Scope::ToolPrelude => if KNOWN_TOOLS.contains(&ident.name) {
|
Scope::ToolPrelude => if KNOWN_TOOLS.contains(&ident.name) {
|
||||||
let binding = (Res::ToolMod, ty::Visibility::Public, DUMMY_SP, Mark::root())
|
let binding = (Res::ToolMod, ty::Visibility::Public, DUMMY_SP, ExpnId::root())
|
||||||
.to_name_binding(this.arenas);
|
.to_name_binding(this.arenas);
|
||||||
Ok((binding, Flags::PRELUDE))
|
Ok((binding, Flags::PRELUDE))
|
||||||
} else {
|
} else {
|
||||||
|
@ -588,7 +588,7 @@ impl<'a> Resolver<'a> {
|
||||||
.get(&ident.name).cloned() {
|
.get(&ident.name).cloned() {
|
||||||
Some(prim_ty) => {
|
Some(prim_ty) => {
|
||||||
let binding = (Res::PrimTy(prim_ty), ty::Visibility::Public,
|
let binding = (Res::PrimTy(prim_ty), ty::Visibility::Public,
|
||||||
DUMMY_SP, Mark::root()).to_name_binding(this.arenas);
|
DUMMY_SP, ExpnId::root()).to_name_binding(this.arenas);
|
||||||
Ok((binding, Flags::PRELUDE))
|
Ok((binding, Flags::PRELUDE))
|
||||||
}
|
}
|
||||||
None => Err(Determinacy::Determined)
|
None => Err(Determinacy::Determined)
|
||||||
|
@ -688,7 +688,7 @@ impl<'a> Resolver<'a> {
|
||||||
// the last segment, so we are certainly working with a single-segment attribute here.)
|
// the last segment, so we are certainly working with a single-segment attribute here.)
|
||||||
assert!(ns == MacroNS);
|
assert!(ns == MacroNS);
|
||||||
let binding = (Res::NonMacroAttr(NonMacroAttrKind::Custom),
|
let binding = (Res::NonMacroAttr(NonMacroAttrKind::Custom),
|
||||||
ty::Visibility::Public, orig_ident.span, Mark::root())
|
ty::Visibility::Public, orig_ident.span, ExpnId::root())
|
||||||
.to_name_binding(self.arenas);
|
.to_name_binding(self.arenas);
|
||||||
Ok(binding)
|
Ok(binding)
|
||||||
} else {
|
} else {
|
||||||
|
@ -846,7 +846,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
pub fn define_macro(&mut self,
|
pub fn define_macro(&mut self,
|
||||||
item: &ast::Item,
|
item: &ast::Item,
|
||||||
expansion: Mark,
|
expansion: ExpnId,
|
||||||
current_legacy_scope: &mut LegacyScope<'a>) {
|
current_legacy_scope: &mut LegacyScope<'a>) {
|
||||||
let (ext, ident, span, is_legacy) = match &item.node {
|
let (ext, ident, span, is_legacy) = match &item.node {
|
||||||
ItemKind::MacroDef(def) => {
|
ItemKind::MacroDef(def) => {
|
||||||
|
|
|
@ -28,7 +28,7 @@ use rustc::util::nodemap::FxHashSet;
|
||||||
use rustc::{bug, span_bug};
|
use rustc::{bug, span_bug};
|
||||||
|
|
||||||
use syntax::ast::{self, Ident, Name, NodeId, CRATE_NODE_ID};
|
use syntax::ast::{self, Ident, Name, NodeId, CRATE_NODE_ID};
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax::symbol::kw;
|
use syntax::symbol::kw;
|
||||||
use syntax::util::lev_distance::find_best_match_for_name;
|
use syntax::util::lev_distance::find_best_match_for_name;
|
||||||
use syntax::{struct_span_err, unwrap_or};
|
use syntax::{struct_span_err, unwrap_or};
|
||||||
|
@ -221,7 +221,7 @@ impl<'a> Resolver<'a> {
|
||||||
ident.name == kw::DollarCrate {
|
ident.name == kw::DollarCrate {
|
||||||
let module = self.resolve_crate_root(ident);
|
let module = self.resolve_crate_root(ident);
|
||||||
let binding = (module, ty::Visibility::Public,
|
let binding = (module, ty::Visibility::Public,
|
||||||
module.span, Mark::root())
|
module.span, ExpnId::root())
|
||||||
.to_name_binding(self.arenas);
|
.to_name_binding(self.arenas);
|
||||||
return Ok(binding);
|
return Ok(binding);
|
||||||
} else if ident.name == kw::Super ||
|
} else if ident.name == kw::Super ||
|
||||||
|
@ -246,7 +246,7 @@ impl<'a> Resolver<'a> {
|
||||||
.map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
|
.map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
|
||||||
|
|
||||||
if let Some(binding) = resolution.binding {
|
if let Some(binding) = resolution.binding {
|
||||||
if !restricted_shadowing && binding.expansion != Mark::root() {
|
if !restricted_shadowing && binding.expansion != ExpnId::root() {
|
||||||
if let NameBindingKind::Res(_, true) = binding.kind {
|
if let NameBindingKind::Res(_, true) = binding.kind {
|
||||||
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
|
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@ impl<'a> Resolver<'a> {
|
||||||
if let Some(shadowed_glob) = resolution.shadowed_glob {
|
if let Some(shadowed_glob) = resolution.shadowed_glob {
|
||||||
// Forbid expanded shadowing to avoid time travel.
|
// Forbid expanded shadowing to avoid time travel.
|
||||||
if restricted_shadowing &&
|
if restricted_shadowing &&
|
||||||
binding.expansion != Mark::root() &&
|
binding.expansion != ExpnId::root() &&
|
||||||
binding.res() != shadowed_glob.res() {
|
binding.res() != shadowed_glob.res() {
|
||||||
self.ambiguity_errors.push(AmbiguityError {
|
self.ambiguity_errors.push(AmbiguityError {
|
||||||
kind: AmbiguityKind::GlobVsExpanded,
|
kind: AmbiguityKind::GlobVsExpanded,
|
||||||
|
@ -525,7 +525,7 @@ impl<'a> Resolver<'a> {
|
||||||
(binding, old_binding)
|
(binding, old_binding)
|
||||||
};
|
};
|
||||||
if glob_binding.res() != nonglob_binding.res() &&
|
if glob_binding.res() != nonglob_binding.res() &&
|
||||||
ns == MacroNS && nonglob_binding.expansion != Mark::root() {
|
ns == MacroNS && nonglob_binding.expansion != ExpnId::root() {
|
||||||
resolution.binding = Some(this.ambiguity(AmbiguityKind::GlobVsExpanded,
|
resolution.binding = Some(this.ambiguity(AmbiguityKind::GlobVsExpanded,
|
||||||
nonglob_binding, glob_binding));
|
nonglob_binding, glob_binding));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1248,7 +1248,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||||
target: Ident,
|
target: Ident,
|
||||||
) {
|
) {
|
||||||
// Skip if the import was produced by a macro.
|
// Skip if the import was produced by a macro.
|
||||||
if directive.parent_scope.expansion != Mark::root() {
|
if directive.parent_scope.expansion != ExpnId::root() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub use UnsafeSource::*;
|
||||||
pub use crate::symbol::{Ident, Symbol as Name};
|
pub use crate::symbol::{Ident, Symbol as Name};
|
||||||
pub use crate::util::parser::ExprPrecedence;
|
pub use crate::util::parser::ExprPrecedence;
|
||||||
|
|
||||||
use crate::ext::hygiene::{Mark, SyntaxContext};
|
use crate::ext::hygiene::{ExpnId, SyntaxContext};
|
||||||
use crate::parse::token::{self, DelimToken};
|
use crate::parse::token::{self, DelimToken};
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
|
@ -251,12 +251,12 @@ mod node_id_inner {
|
||||||
pub use node_id_inner::NodeId;
|
pub use node_id_inner::NodeId;
|
||||||
|
|
||||||
impl NodeId {
|
impl NodeId {
|
||||||
pub fn placeholder_from_mark(mark: Mark) -> Self {
|
pub fn placeholder_from_mark(mark: ExpnId) -> Self {
|
||||||
NodeId::from_u32(mark.as_u32())
|
NodeId::from_u32(mark.as_u32())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn placeholder_to_mark(self) -> Mark {
|
pub fn placeholder_to_mark(self) -> ExpnId {
|
||||||
Mark::from_u32(self.as_u32())
|
ExpnId::from_u32(self.as_u32())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::attr::{HasAttrs, Stability, Deprecation};
|
||||||
use crate::source_map::{SourceMap, Spanned, respan};
|
use crate::source_map::{SourceMap, Spanned, respan};
|
||||||
use crate::edition::Edition;
|
use crate::edition::Edition;
|
||||||
use crate::ext::expand::{self, AstFragment, Invocation};
|
use crate::ext::expand::{self, AstFragment, Invocation};
|
||||||
use crate::ext::hygiene::{Mark, SyntaxContext, Transparency};
|
use crate::ext::hygiene::{ExpnId, SyntaxContext, Transparency};
|
||||||
use crate::mut_visit::{self, MutVisitor};
|
use crate::mut_visit::{self, MutVisitor};
|
||||||
use crate::parse::{self, parser, DirectoryOwnership};
|
use crate::parse::{self, parser, DirectoryOwnership};
|
||||||
use crate::parse::token;
|
use crate::parse::token;
|
||||||
|
@ -682,16 +682,16 @@ pub struct Indeterminate;
|
||||||
pub trait Resolver {
|
pub trait Resolver {
|
||||||
fn next_node_id(&mut self) -> ast::NodeId;
|
fn next_node_id(&mut self) -> ast::NodeId;
|
||||||
|
|
||||||
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
|
fn get_module_scope(&mut self, id: ast::NodeId) -> ExpnId;
|
||||||
|
|
||||||
fn resolve_dollar_crates(&mut self);
|
fn resolve_dollar_crates(&mut self);
|
||||||
fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFragment,
|
fn visit_ast_fragment_with_placeholders(&mut self, mark: ExpnId, fragment: &AstFragment,
|
||||||
derives: &[Mark]);
|
derives: &[ExpnId]);
|
||||||
fn add_builtin(&mut self, ident: ast::Ident, ext: Lrc<SyntaxExtension>);
|
fn add_builtin(&mut self, ident: ast::Ident, ext: Lrc<SyntaxExtension>);
|
||||||
|
|
||||||
fn resolve_imports(&mut self);
|
fn resolve_imports(&mut self);
|
||||||
|
|
||||||
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force: bool)
|
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, force: bool)
|
||||||
-> Result<Option<Lrc<SyntaxExtension>>, Indeterminate>;
|
-> Result<Option<Lrc<SyntaxExtension>>, Indeterminate>;
|
||||||
|
|
||||||
fn check_unused_macros(&self);
|
fn check_unused_macros(&self);
|
||||||
|
@ -705,7 +705,7 @@ pub struct ModuleData {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ExpansionData {
|
pub struct ExpansionData {
|
||||||
pub mark: Mark,
|
pub mark: ExpnId,
|
||||||
pub depth: usize,
|
pub depth: usize,
|
||||||
pub module: Rc<ModuleData>,
|
pub module: Rc<ModuleData>,
|
||||||
pub directory_ownership: DirectoryOwnership,
|
pub directory_ownership: DirectoryOwnership,
|
||||||
|
@ -735,7 +735,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
root_path: PathBuf::new(),
|
root_path: PathBuf::new(),
|
||||||
resolver,
|
resolver,
|
||||||
current_expansion: ExpansionData {
|
current_expansion: ExpansionData {
|
||||||
mark: Mark::root(),
|
mark: ExpnId::root(),
|
||||||
depth: 0,
|
depth: 0,
|
||||||
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
|
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
|
||||||
directory_ownership: DirectoryOwnership::Owned { relative: None },
|
directory_ownership: DirectoryOwnership::Owned { relative: None },
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::source_map::{dummy_spanned, respan};
|
||||||
use crate::config::StripUnconfigured;
|
use crate::config::StripUnconfigured;
|
||||||
use crate::ext::base::*;
|
use crate::ext::base::*;
|
||||||
use crate::ext::derive::{add_derived_markers, collect_derives};
|
use crate::ext::derive::{add_derived_markers, collect_derives};
|
||||||
use crate::ext::hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnKind};
|
use crate::ext::hygiene::{ExpnId, SyntaxContext, ExpnInfo, ExpnKind};
|
||||||
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};
|
||||||
use crate::mut_visit::*;
|
use crate::mut_visit::*;
|
||||||
|
@ -304,7 +304,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
// Unresolved macros produce dummy outputs as a recovery measure.
|
// Unresolved macros produce dummy outputs as a recovery measure.
|
||||||
invocations.reverse();
|
invocations.reverse();
|
||||||
let mut expanded_fragments = Vec::new();
|
let mut expanded_fragments = Vec::new();
|
||||||
let mut derives: FxHashMap<Mark, Vec<_>> = FxHashMap::default();
|
let mut derives: FxHashMap<ExpnId, Vec<_>> = FxHashMap::default();
|
||||||
let mut undetermined_invocations = Vec::new();
|
let mut undetermined_invocations = Vec::new();
|
||||||
let (mut progress, mut force) = (false, !self.monotonic);
|
let (mut progress, mut force) = (false, !self.monotonic);
|
||||||
loop {
|
loop {
|
||||||
|
@ -367,7 +367,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
derives.reserve(traits.len());
|
derives.reserve(traits.len());
|
||||||
invocations.reserve(traits.len());
|
invocations.reserve(traits.len());
|
||||||
for path in traits {
|
for path in traits {
|
||||||
let mark = Mark::fresh(self.cx.current_expansion.mark, None);
|
let mark = ExpnId::fresh(self.cx.current_expansion.mark, None);
|
||||||
derives.push(mark);
|
derives.push(mark);
|
||||||
invocations.push(Invocation {
|
invocations.push(Invocation {
|
||||||
kind: InvocationKind::Derive {
|
kind: InvocationKind::Derive {
|
||||||
|
@ -423,7 +423,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
/// them with "placeholders" - dummy macro invocations with specially crafted `NodeId`s.
|
/// them with "placeholders" - dummy macro invocations with specially crafted `NodeId`s.
|
||||||
/// Then call into resolver that builds a skeleton ("reduced graph") of the fragment and
|
/// Then call into resolver that builds a skeleton ("reduced graph") of the fragment and
|
||||||
/// prepares data for resolving paths of macro invocations.
|
/// prepares data for resolving paths of macro invocations.
|
||||||
fn collect_invocations(&mut self, mut fragment: AstFragment, derives: &[Mark])
|
fn collect_invocations(&mut self, mut fragment: AstFragment, derives: &[ExpnId])
|
||||||
-> (AstFragment, Vec<Invocation>) {
|
-> (AstFragment, Vec<Invocation>) {
|
||||||
// Resolve `$crate`s in the fragment for pretty-printing.
|
// Resolve `$crate`s in the fragment for pretty-printing.
|
||||||
self.cx.resolver.resolve_dollar_crates();
|
self.cx.resolver.resolve_dollar_crates();
|
||||||
|
@ -822,7 +822,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
||||||
)),
|
)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let mark = Mark::fresh(self.cx.current_expansion.mark, expn_info);
|
let mark = ExpnId::fresh(self.cx.current_expansion.mark, expn_info);
|
||||||
self.invocations.push(Invocation {
|
self.invocations.push(Invocation {
|
||||||
kind,
|
kind,
|
||||||
fragment_kind,
|
fragment_kind,
|
||||||
|
@ -1402,7 +1402,7 @@ impl<'feat> ExpansionConfig<'feat> {
|
||||||
|
|
||||||
// A Marker adds the given mark to the syntax context.
|
// A Marker adds the given mark to the syntax context.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Marker(pub Mark);
|
pub struct Marker(pub ExpnId);
|
||||||
|
|
||||||
impl MutVisitor for Marker {
|
impl MutVisitor for Marker {
|
||||||
fn visit_span(&mut self, span: &mut Span) {
|
fn visit_span(&mut self, span: &mut Span) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::ast::{self, NodeId};
|
||||||
use crate::source_map::{DUMMY_SP, dummy_spanned};
|
use crate::source_map::{DUMMY_SP, dummy_spanned};
|
||||||
use crate::ext::base::ExtCtxt;
|
use crate::ext::base::ExtCtxt;
|
||||||
use crate::ext::expand::{AstFragment, AstFragmentKind};
|
use crate::ext::expand::{AstFragment, AstFragmentKind};
|
||||||
use crate::ext::hygiene::Mark;
|
use crate::ext::hygiene::ExpnId;
|
||||||
use crate::tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
use crate::mut_visit::*;
|
use crate::mut_visit::*;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
|
@ -84,7 +84,7 @@ impl<'a, 'b> PlaceholderExpander<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment, derives: Vec<Mark>) {
|
pub fn add(&mut self, id: ast::NodeId, mut fragment: AstFragment, derives: Vec<ExpnId>) {
|
||||||
fragment.mut_visit_with(self);
|
fragment.mut_visit_with(self);
|
||||||
if let AstFragment::Items(mut items) = fragment {
|
if let AstFragment::Items(mut items) = fragment {
|
||||||
for derive in derives {
|
for derive in derives {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::ast;
|
use crate::ast;
|
||||||
use crate::attr;
|
use crate::attr;
|
||||||
use crate::edition::Edition;
|
use crate::edition::Edition;
|
||||||
use crate::ext::hygiene::{Mark, MacroKind};
|
use crate::ext::hygiene::{ExpnId, MacroKind};
|
||||||
use crate::symbol::{Ident, Symbol, kw, sym};
|
use crate::symbol::{Ident, Symbol, kw, sym};
|
||||||
use crate::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan};
|
use crate::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan};
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
|
@ -75,7 +75,7 @@ pub fn maybe_inject_crates_ref(
|
||||||
|
|
||||||
INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name)));
|
INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name)));
|
||||||
|
|
||||||
let span = DUMMY_SP.fresh_expansion(Mark::root(), ExpnInfo::allow_unstable(
|
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::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(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crate::entry::{self, EntryPointType};
|
||||||
use crate::ext::base::{ExtCtxt, Resolver};
|
use crate::ext::base::{ExtCtxt, Resolver};
|
||||||
use crate::ext::build::AstBuilder;
|
use crate::ext::build::AstBuilder;
|
||||||
use crate::ext::expand::ExpansionConfig;
|
use crate::ext::expand::ExpansionConfig;
|
||||||
use crate::ext::hygiene::{self, Mark, SyntaxContext, MacroKind};
|
use crate::ext::hygiene::{self, ExpnId, SyntaxContext, MacroKind};
|
||||||
use crate::mut_visit::{*, ExpectOne};
|
use crate::mut_visit::{*, ExpectOne};
|
||||||
use crate::feature_gate::Features;
|
use crate::feature_gate::Features;
|
||||||
use crate::util::map_in_place::MapInPlace;
|
use crate::util::map_in_place::MapInPlace;
|
||||||
|
@ -303,7 +303,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(Mark::root(), ExpnInfo::allow_unstable(
|
let sp = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::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(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::parse::Directory;
|
||||||
use crate::parse::token::{self, DelimToken, Token, TokenKind};
|
use crate::parse::token::{self, DelimToken, Token, TokenKind};
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
|
|
||||||
use syntax_pos::{BytePos, Mark, Span, DUMMY_SP};
|
use syntax_pos::{BytePos, ExpnId, Span, DUMMY_SP};
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use rustc_data_structures::static_assert_size;
|
use rustc_data_structures::static_assert_size;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
|
@ -545,7 +545,7 @@ impl DelimSpan {
|
||||||
self.open.with_hi(self.close.hi())
|
self.open.with_hi(self.close.hi())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_mark(self, mark: Mark) -> Self {
|
pub fn apply_mark(self, mark: ExpnId) -> Self {
|
||||||
DelimSpan {
|
DelimSpan {
|
||||||
open: self.open.apply_mark(mark),
|
open: self.open.apply_mark(mark),
|
||||||
close: self.close.apply_mark(mark),
|
close: self.close.apply_mark(mark),
|
||||||
|
|
|
@ -8,7 +8,7 @@ use syntax::source_map::{ExpnInfo, ExpnKind, respan};
|
||||||
use syntax::ext::base::{ExtCtxt, MacroKind};
|
use syntax::ext::base::{ExtCtxt, MacroKind};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::ext::expand::ExpansionConfig;
|
use syntax::ext::expand::ExpansionConfig;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::ExpnId;
|
||||||
use syntax::mut_visit::MutVisitor;
|
use syntax::mut_visit::MutVisitor;
|
||||||
use syntax::parse::ParseSess;
|
use syntax::parse::ParseSess;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
@ -346,7 +346,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(Mark::root(), ExpnInfo::allow_unstable(
|
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::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(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -11,14 +11,14 @@
|
||||||
// ensuring that multiple HygieneData accesses are combined into a single
|
// ensuring that multiple HygieneData accesses are combined into a single
|
||||||
// `HygieneData::with`.
|
// `HygieneData::with`.
|
||||||
//
|
//
|
||||||
// This explains why `HygieneData`, `SyntaxContext` and `Mark` 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_info` combines `SyntaxContext::outer` and
|
||||||
// `Mark::expn_info` so that two `HygieneData` accesses can be performed within
|
// `ExpnId::expn_info` 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
|
||||||
// `SyntaxContext` or `Mark`. For example, `HygieneData::outer` and
|
// `SyntaxContext` or `ExpnId`. For example, `HygieneData::outer` and
|
||||||
// `SyntaxContext::outer` do the same thing, but the former is for use within a
|
// `SyntaxContext::outer` do the same thing, but the former is for use within a
|
||||||
// `HygieneData::with` call while the latter is for use outside such a call.
|
// `HygieneData::with` call while the latter is for use outside such a call.
|
||||||
// When modifying this file it is important to understand this distinction,
|
// When modifying this file it is important to understand this distinction,
|
||||||
|
@ -41,7 +41,7 @@ pub struct SyntaxContext(u32);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct SyntaxContextData {
|
struct SyntaxContextData {
|
||||||
outer_mark: Mark,
|
outer_mark: ExpnId,
|
||||||
transparency: Transparency,
|
transparency: Transparency,
|
||||||
prev_ctxt: SyntaxContext,
|
prev_ctxt: SyntaxContext,
|
||||||
/// This context, but with all transparent and semi-transparent marks filtered away.
|
/// This context, but with all transparent and semi-transparent marks filtered away.
|
||||||
|
@ -54,11 +54,11 @@ struct SyntaxContextData {
|
||||||
|
|
||||||
/// A mark is a unique ID associated with a macro expansion.
|
/// A mark is a unique ID associated with a macro expansion.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||||
pub struct Mark(u32);
|
pub struct ExpnId(u32);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct MarkData {
|
struct MarkData {
|
||||||
parent: Mark,
|
parent: ExpnId,
|
||||||
/// Each mark should have an associated expansion info, but sometimes there's a delay between
|
/// Each mark should have an associated expansion info, but sometimes there's a delay between
|
||||||
/// creation of a mark and obtaining its info (e.g. macros are collected first and then
|
/// creation of a mark and obtaining its info (e.g. macros are collected first and then
|
||||||
/// resolved later), so we use an `Option` here.
|
/// resolved later), so we use an `Option` here.
|
||||||
|
@ -84,15 +84,15 @@ pub enum Transparency {
|
||||||
Opaque,
|
Opaque,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mark {
|
impl ExpnId {
|
||||||
pub fn fresh(parent: Mark, expn_info: Option<ExpnInfo>) -> Self {
|
pub fn fresh(parent: ExpnId, expn_info: Option<ExpnInfo>) -> Self {
|
||||||
HygieneData::with(|data| data.fresh_mark(parent, expn_info))
|
HygieneData::with(|data| data.fresh_mark(parent, expn_info))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The mark of the theoretical expansion that generates freshly parsed, unexpanded AST.
|
/// The mark of the theoretical expansion that generates freshly parsed, unexpanded AST.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn root() -> Self {
|
pub fn root() -> Self {
|
||||||
Mark(0)
|
ExpnId(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -101,12 +101,12 @@ impl Mark {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_u32(raw: u32) -> Mark {
|
pub fn from_u32(raw: u32) -> ExpnId {
|
||||||
Mark(raw)
|
ExpnId(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parent(self) -> Mark {
|
pub fn parent(self) -> ExpnId {
|
||||||
HygieneData::with(|data| data.marks[self.0 as usize].parent)
|
HygieneData::with(|data| data.marks[self.0 as usize].parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ impl Mark {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_descendant_of(self, ancestor: Mark) -> bool {
|
pub fn is_descendant_of(self, ancestor: ExpnId) -> bool {
|
||||||
HygieneData::with(|data| data.is_descendant_of(self, ancestor))
|
HygieneData::with(|data| data.is_descendant_of(self, ancestor))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,18 +154,18 @@ impl Mark {
|
||||||
crate struct HygieneData {
|
crate struct HygieneData {
|
||||||
marks: Vec<MarkData>,
|
marks: Vec<MarkData>,
|
||||||
syntax_contexts: Vec<SyntaxContextData>,
|
syntax_contexts: Vec<SyntaxContextData>,
|
||||||
markings: FxHashMap<(SyntaxContext, Mark, Transparency), SyntaxContext>,
|
markings: FxHashMap<(SyntaxContext, ExpnId, Transparency), SyntaxContext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HygieneData {
|
impl HygieneData {
|
||||||
crate fn new(edition: Edition) -> Self {
|
crate fn new(edition: Edition) -> Self {
|
||||||
HygieneData {
|
HygieneData {
|
||||||
marks: vec![MarkData {
|
marks: vec![MarkData {
|
||||||
parent: Mark::root(),
|
parent: ExpnId::root(),
|
||||||
expn_info: Some(ExpnInfo::default(ExpnKind::Root, DUMMY_SP, edition)),
|
expn_info: Some(ExpnInfo::default(ExpnKind::Root, DUMMY_SP, edition)),
|
||||||
}],
|
}],
|
||||||
syntax_contexts: vec![SyntaxContextData {
|
syntax_contexts: vec![SyntaxContextData {
|
||||||
outer_mark: Mark::root(),
|
outer_mark: ExpnId::root(),
|
||||||
transparency: Transparency::Opaque,
|
transparency: Transparency::Opaque,
|
||||||
prev_ctxt: SyntaxContext(0),
|
prev_ctxt: SyntaxContext(0),
|
||||||
opaque: SyntaxContext(0),
|
opaque: SyntaxContext(0),
|
||||||
|
@ -180,13 +180,13 @@ impl HygieneData {
|
||||||
GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut()))
|
GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fresh_mark(&mut self, parent: Mark, expn_info: Option<ExpnInfo>) -> Mark {
|
fn fresh_mark(&mut self, parent: ExpnId, expn_info: Option<ExpnInfo>) -> ExpnId {
|
||||||
self.marks.push(MarkData { parent, expn_info });
|
self.marks.push(MarkData { parent, expn_info });
|
||||||
Mark(self.marks.len() as u32 - 1)
|
ExpnId(self.marks.len() as u32 - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expn_info(&self, mark: Mark) -> Option<&ExpnInfo> {
|
fn expn_info(&self, mark: ExpnId) -> Option<&ExpnInfo> {
|
||||||
if mark != Mark::root() {
|
if mark != ExpnId::root() {
|
||||||
Some(self.marks[mark.0 as usize].expn_info.as_ref()
|
Some(self.marks[mark.0 as usize].expn_info.as_ref()
|
||||||
.expect("no expansion info for a mark"))
|
.expect("no expansion info for a mark"))
|
||||||
} else {
|
} else {
|
||||||
|
@ -197,9 +197,9 @@ impl HygieneData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_descendant_of(&self, mut mark: Mark, ancestor: Mark) -> bool {
|
fn is_descendant_of(&self, mut mark: ExpnId, ancestor: ExpnId) -> bool {
|
||||||
while mark != ancestor {
|
while mark != ancestor {
|
||||||
if mark == Mark::root() {
|
if mark == ExpnId::root() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mark = self.marks[mark.0 as usize].parent;
|
mark = self.marks[mark.0 as usize].parent;
|
||||||
|
@ -207,7 +207,7 @@ impl HygieneData {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_transparency(&self, mark: Mark) -> Transparency {
|
fn default_transparency(&self, mark: ExpnId) -> Transparency {
|
||||||
self.expn_info(mark).map_or(
|
self.expn_info(mark).map_or(
|
||||||
Transparency::SemiTransparent, |einfo| einfo.default_transparency
|
Transparency::SemiTransparent, |einfo| einfo.default_transparency
|
||||||
)
|
)
|
||||||
|
@ -221,7 +221,7 @@ impl HygieneData {
|
||||||
self.syntax_contexts[ctxt.0 as usize].opaque_and_semitransparent
|
self.syntax_contexts[ctxt.0 as usize].opaque_and_semitransparent
|
||||||
}
|
}
|
||||||
|
|
||||||
fn outer(&self, ctxt: SyntaxContext) -> Mark {
|
fn outer(&self, ctxt: SyntaxContext) -> ExpnId {
|
||||||
self.syntax_contexts[ctxt.0 as usize].outer_mark
|
self.syntax_contexts[ctxt.0 as usize].outer_mark
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,13 +233,13 @@ impl HygieneData {
|
||||||
self.syntax_contexts[ctxt.0 as usize].prev_ctxt
|
self.syntax_contexts[ctxt.0 as usize].prev_ctxt
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_mark(&self, ctxt: &mut SyntaxContext) -> Mark {
|
fn remove_mark(&self, ctxt: &mut SyntaxContext) -> ExpnId {
|
||||||
let outer_mark = self.syntax_contexts[ctxt.0 as usize].outer_mark;
|
let outer_mark = self.syntax_contexts[ctxt.0 as usize].outer_mark;
|
||||||
*ctxt = self.prev_ctxt(*ctxt);
|
*ctxt = self.prev_ctxt(*ctxt);
|
||||||
outer_mark
|
outer_mark
|
||||||
}
|
}
|
||||||
|
|
||||||
fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(Mark, Transparency)> {
|
fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(ExpnId, Transparency)> {
|
||||||
let mut marks = Vec::new();
|
let mut marks = Vec::new();
|
||||||
while ctxt != SyntaxContext::empty() {
|
while ctxt != SyntaxContext::empty() {
|
||||||
let outer_mark = self.outer(ctxt);
|
let outer_mark = self.outer(ctxt);
|
||||||
|
@ -263,7 +263,7 @@ impl HygieneData {
|
||||||
span
|
span
|
||||||
}
|
}
|
||||||
|
|
||||||
fn adjust(&self, ctxt: &mut SyntaxContext, expansion: Mark) -> Option<Mark> {
|
fn adjust(&self, ctxt: &mut SyntaxContext, expansion: ExpnId) -> Option<ExpnId> {
|
||||||
let mut scope = None;
|
let mut scope = None;
|
||||||
while !self.is_descendant_of(expansion, self.outer(*ctxt)) {
|
while !self.is_descendant_of(expansion, self.outer(*ctxt)) {
|
||||||
scope = Some(self.remove_mark(ctxt));
|
scope = Some(self.remove_mark(ctxt));
|
||||||
|
@ -271,14 +271,14 @@ impl HygieneData {
|
||||||
scope
|
scope
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_mark(&mut self, ctxt: SyntaxContext, mark: Mark) -> SyntaxContext {
|
fn apply_mark(&mut self, ctxt: SyntaxContext, mark: ExpnId) -> SyntaxContext {
|
||||||
assert_ne!(mark, Mark::root());
|
assert_ne!(mark, ExpnId::root());
|
||||||
self.apply_mark_with_transparency(ctxt, mark, self.default_transparency(mark))
|
self.apply_mark_with_transparency(ctxt, mark, self.default_transparency(mark))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_mark_with_transparency(&mut self, ctxt: SyntaxContext, mark: Mark,
|
fn apply_mark_with_transparency(&mut self, ctxt: SyntaxContext, mark: ExpnId,
|
||||||
transparency: Transparency) -> SyntaxContext {
|
transparency: Transparency) -> SyntaxContext {
|
||||||
assert_ne!(mark, Mark::root());
|
assert_ne!(mark, ExpnId::root());
|
||||||
if transparency == Transparency::Opaque {
|
if transparency == Transparency::Opaque {
|
||||||
return self.apply_mark_internal(ctxt, mark, transparency);
|
return self.apply_mark_internal(ctxt, mark, transparency);
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ impl HygieneData {
|
||||||
self.apply_mark_internal(call_site_ctxt, mark, transparency)
|
self.apply_mark_internal(call_site_ctxt, mark, transparency)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_mark_internal(&mut self, ctxt: SyntaxContext, mark: Mark, transparency: Transparency)
|
fn apply_mark_internal(&mut self, ctxt: SyntaxContext, mark: ExpnId, transparency: Transparency)
|
||||||
-> SyntaxContext {
|
-> SyntaxContext {
|
||||||
let syntax_contexts = &mut self.syntax_contexts;
|
let syntax_contexts = &mut self.syntax_contexts;
|
||||||
let mut opaque = syntax_contexts[ctxt.0 as usize].opaque;
|
let mut opaque = syntax_contexts[ctxt.0 as usize].opaque;
|
||||||
|
@ -410,12 +410,12 @@ impl SyntaxContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extend a syntax context with a given mark and default transparency for that mark.
|
/// Extend a syntax context with a given mark and default transparency for that mark.
|
||||||
pub fn apply_mark(self, mark: Mark) -> SyntaxContext {
|
pub fn apply_mark(self, mark: ExpnId) -> SyntaxContext {
|
||||||
HygieneData::with(|data| data.apply_mark(self, mark))
|
HygieneData::with(|data| data.apply_mark(self, mark))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extend a syntax context with a given mark and transparency
|
/// Extend a syntax context with a given mark and transparency
|
||||||
pub fn apply_mark_with_transparency(self, mark: Mark, transparency: Transparency)
|
pub fn apply_mark_with_transparency(self, mark: ExpnId, transparency: Transparency)
|
||||||
-> SyntaxContext {
|
-> SyntaxContext {
|
||||||
HygieneData::with(|data| data.apply_mark_with_transparency(self, mark, transparency))
|
HygieneData::with(|data| data.apply_mark_with_transparency(self, mark, transparency))
|
||||||
}
|
}
|
||||||
|
@ -436,11 +436,11 @@ impl SyntaxContext {
|
||||||
/// of g (call it g1), calling remove_mark will result in the SyntaxContext for the
|
/// of g (call it g1), calling remove_mark will result in the SyntaxContext for the
|
||||||
/// invocation of f that created g1.
|
/// invocation of f that created g1.
|
||||||
/// Returns the mark that was removed.
|
/// Returns the mark that was removed.
|
||||||
pub fn remove_mark(&mut self) -> Mark {
|
pub fn remove_mark(&mut self) -> ExpnId {
|
||||||
HygieneData::with(|data| data.remove_mark(self))
|
HygieneData::with(|data| data.remove_mark(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn marks(self) -> Vec<(Mark, Transparency)> {
|
pub fn marks(self) -> Vec<(ExpnId, Transparency)> {
|
||||||
HygieneData::with(|data| data.marks(self))
|
HygieneData::with(|data| data.marks(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,13 +452,13 @@ impl SyntaxContext {
|
||||||
/// m!(f);
|
/// m!(f);
|
||||||
/// macro m($f:ident) {
|
/// macro m($f:ident) {
|
||||||
/// mod bar {
|
/// mod bar {
|
||||||
/// pub fn f() {} // `f`'s `SyntaxContext` has a single `Mark` from `m`.
|
/// pub fn f() {} // `f`'s `SyntaxContext` has a single `ExpnId` from `m`.
|
||||||
/// pub fn $f() {} // `$f`'s `SyntaxContext` is empty.
|
/// pub fn $f() {} // `$f`'s `SyntaxContext` is empty.
|
||||||
/// }
|
/// }
|
||||||
/// foo::f(); // `f`'s `SyntaxContext` has a single `Mark` from `m`
|
/// foo::f(); // `f`'s `SyntaxContext` has a single `ExpnId` from `m`
|
||||||
/// //^ Since `mod foo` is outside this expansion, `adjust` removes the mark from `f`,
|
/// //^ Since `mod foo` is outside this expansion, `adjust` removes the mark from `f`,
|
||||||
/// //| and it resolves to `::foo::f`.
|
/// //| and it resolves to `::foo::f`.
|
||||||
/// bar::f(); // `f`'s `SyntaxContext` has a single `Mark` from `m`
|
/// bar::f(); // `f`'s `SyntaxContext` has a single `ExpnId` from `m`
|
||||||
/// //^ Since `mod bar` not outside this expansion, `adjust` does not change `f`,
|
/// //^ Since `mod bar` not outside this expansion, `adjust` does not change `f`,
|
||||||
/// //| and it resolves to `::bar::f`.
|
/// //| and it resolves to `::bar::f`.
|
||||||
/// bar::$f(); // `f`'s `SyntaxContext` is empty.
|
/// bar::$f(); // `f`'s `SyntaxContext` is empty.
|
||||||
|
@ -468,12 +468,12 @@ impl SyntaxContext {
|
||||||
/// ```
|
/// ```
|
||||||
/// This returns the expansion whose definition scope we use to privacy check the resolution,
|
/// This returns the expansion whose definition scope we use to privacy check the resolution,
|
||||||
/// or `None` if we privacy check as usual (i.e., not w.r.t. a macro definition scope).
|
/// or `None` if we privacy check as usual (i.e., not w.r.t. a macro definition scope).
|
||||||
pub fn adjust(&mut self, expansion: Mark) -> Option<Mark> {
|
pub fn adjust(&mut self, expansion: ExpnId) -> Option<ExpnId> {
|
||||||
HygieneData::with(|data| data.adjust(self, expansion))
|
HygieneData::with(|data| data.adjust(self, expansion))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like `SyntaxContext::adjust`, but also modernizes `self`.
|
/// Like `SyntaxContext::adjust`, but also modernizes `self`.
|
||||||
pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
|
pub fn modernize_and_adjust(&mut self, expansion: ExpnId) -> Option<ExpnId> {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
*self = data.modern(*self);
|
*self = data.modern(*self);
|
||||||
data.adjust(self, expansion)
|
data.adjust(self, expansion)
|
||||||
|
@ -488,7 +488,7 @@ impl SyntaxContext {
|
||||||
/// m!(f);
|
/// m!(f);
|
||||||
/// macro m($i:ident) {
|
/// macro m($i:ident) {
|
||||||
/// mod foo {
|
/// mod foo {
|
||||||
/// pub fn f() {} // `f`'s `SyntaxContext` has a single `Mark` from `m`.
|
/// pub fn f() {} // `f`'s `SyntaxContext` has a single `ExpnId` from `m`.
|
||||||
/// pub fn $i() {} // `$i`'s `SyntaxContext` is empty.
|
/// pub fn $i() {} // `$i`'s `SyntaxContext` is empty.
|
||||||
/// }
|
/// }
|
||||||
/// n(f);
|
/// n(f);
|
||||||
|
@ -505,7 +505,7 @@ impl SyntaxContext {
|
||||||
/// ```
|
/// ```
|
||||||
/// This returns `None` if the context cannot be glob-adjusted.
|
/// This returns `None` if the context cannot be glob-adjusted.
|
||||||
/// Otherwise, it returns the scope to use when privacy checking (see `adjust` for details).
|
/// Otherwise, it returns the scope to use when privacy checking (see `adjust` for details).
|
||||||
pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option<Option<Mark>> {
|
pub fn glob_adjust(&mut self, expansion: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
let mut scope = None;
|
let mut scope = None;
|
||||||
let mut glob_ctxt = data.modern(glob_span.ctxt());
|
let mut glob_ctxt = data.modern(glob_span.ctxt());
|
||||||
|
@ -529,8 +529,8 @@ impl SyntaxContext {
|
||||||
/// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope));
|
/// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope));
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn reverse_glob_adjust(&mut self, expansion: Mark, glob_span: Span)
|
pub fn reverse_glob_adjust(&mut self, expansion: ExpnId, glob_span: Span)
|
||||||
-> Option<Option<Mark>> {
|
-> Option<Option<ExpnId>> {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
if data.adjust(self, expansion).is_some() {
|
if data.adjust(self, expansion).is_some() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -550,7 +550,7 @@ impl SyntaxContext {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hygienic_eq(self, other: SyntaxContext, mark: Mark) -> bool {
|
pub fn hygienic_eq(self, other: SyntaxContext, mark: ExpnId) -> bool {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
let mut self_modern = data.modern(self);
|
let mut self_modern = data.modern(self);
|
||||||
data.adjust(&mut self_modern, mark);
|
data.adjust(&mut self_modern, mark);
|
||||||
|
@ -569,7 +569,7 @@ impl SyntaxContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn outer(self) -> Mark {
|
pub fn outer(self) -> ExpnId {
|
||||||
HygieneData::with(|data| data.outer(self))
|
HygieneData::with(|data| data.outer(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,7 +583,7 @@ impl SyntaxContext {
|
||||||
/// `ctxt.outer_and_expn_info()` is equivalent to but faster than
|
/// `ctxt.outer_and_expn_info()` is equivalent to but faster than
|
||||||
/// `{ let outer = ctxt.outer(); (outer, outer.expn_info()) }`.
|
/// `{ let outer = ctxt.outer(); (outer, outer.expn_info()) }`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn outer_and_expn_info(self) -> (Mark, Option<ExpnInfo>) {
|
pub fn outer_and_expn_info(self) -> (ExpnId, Option<ExpnInfo>) {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
let outer = data.outer(self);
|
let outer = data.outer(self);
|
||||||
(outer, data.expn_info(outer).cloned())
|
(outer, data.expn_info(outer).cloned())
|
||||||
|
@ -607,7 +607,7 @@ 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, parent: Mark, expn_info: ExpnInfo) -> Span {
|
pub fn fresh_expansion(self, parent: ExpnId, expn_info: ExpnInfo) -> Span {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
let mark = data.fresh_mark(parent, Some(expn_info));
|
let mark = data.fresh_mark(parent, Some(expn_info));
|
||||||
self.with_ctxt(data.apply_mark(SyntaxContext::empty(), mark))
|
self.with_ctxt(data.apply_mark(SyntaxContext::empty(), mark))
|
||||||
|
@ -681,7 +681,7 @@ impl ExpnInfo {
|
||||||
/// Expansion kind.
|
/// Expansion kind.
|
||||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
|
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
|
||||||
pub enum ExpnKind {
|
pub enum ExpnKind {
|
||||||
/// No expansion, aka root expansion. Only `Mark::root()` has this kind.
|
/// No expansion, aka root expansion. Only `ExpnId::root()` has this kind.
|
||||||
Root,
|
Root,
|
||||||
/// Expansion produced by a macro.
|
/// Expansion produced by a macro.
|
||||||
/// FIXME: Some code injected by the compiler before HIR lowering also gets this kind.
|
/// FIXME: Some code injected by the compiler before HIR lowering also gets this kind.
|
||||||
|
|
|
@ -27,7 +27,7 @@ extern crate serialize as rustc_serialize; // used by deriving
|
||||||
pub mod edition;
|
pub mod edition;
|
||||||
use edition::Edition;
|
use edition::Edition;
|
||||||
pub mod hygiene;
|
pub mod hygiene;
|
||||||
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnKind, MacroKind, DesugaringKind};
|
pub use hygiene::{ExpnId, SyntaxContext, ExpnInfo, ExpnKind, MacroKind, DesugaringKind};
|
||||||
|
|
||||||
mod span_encoding;
|
mod span_encoding;
|
||||||
pub use span_encoding::{Span, DUMMY_SP};
|
pub use span_encoding::{Span, DUMMY_SP};
|
||||||
|
@ -516,13 +516,13 @@ impl Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn apply_mark(self, mark: Mark) -> Span {
|
pub fn apply_mark(self, mark: ExpnId) -> Span {
|
||||||
let span = self.data();
|
let span = self.data();
|
||||||
span.with_ctxt(span.ctxt.apply_mark(mark))
|
span.with_ctxt(span.ctxt.apply_mark(mark))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn remove_mark(&mut self) -> Mark {
|
pub fn remove_mark(&mut self) -> ExpnId {
|
||||||
let mut span = self.data();
|
let mut span = self.data();
|
||||||
let mark = span.ctxt.remove_mark();
|
let mark = span.ctxt.remove_mark();
|
||||||
*self = Span::new(span.lo, span.hi, span.ctxt);
|
*self = Span::new(span.lo, span.hi, span.ctxt);
|
||||||
|
@ -530,7 +530,7 @@ impl Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn adjust(&mut self, expansion: Mark) -> Option<Mark> {
|
pub fn adjust(&mut self, expansion: ExpnId) -> Option<ExpnId> {
|
||||||
let mut span = self.data();
|
let mut span = self.data();
|
||||||
let mark = span.ctxt.adjust(expansion);
|
let mark = span.ctxt.adjust(expansion);
|
||||||
*self = Span::new(span.lo, span.hi, span.ctxt);
|
*self = Span::new(span.lo, span.hi, span.ctxt);
|
||||||
|
@ -538,7 +538,7 @@ impl Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
|
pub fn modernize_and_adjust(&mut self, expansion: ExpnId) -> Option<ExpnId> {
|
||||||
let mut span = self.data();
|
let mut span = self.data();
|
||||||
let mark = span.ctxt.modernize_and_adjust(expansion);
|
let mark = span.ctxt.modernize_and_adjust(expansion);
|
||||||
*self = Span::new(span.lo, span.hi, span.ctxt);
|
*self = Span::new(span.lo, span.hi, span.ctxt);
|
||||||
|
@ -546,7 +546,7 @@ impl Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option<Option<Mark>> {
|
pub fn glob_adjust(&mut self, expansion: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> {
|
||||||
let mut span = self.data();
|
let mut span = self.data();
|
||||||
let mark = span.ctxt.glob_adjust(expansion, glob_span);
|
let mark = span.ctxt.glob_adjust(expansion, glob_span);
|
||||||
*self = Span::new(span.lo, span.hi, span.ctxt);
|
*self = Span::new(span.lo, span.hi, span.ctxt);
|
||||||
|
@ -554,8 +554,8 @@ impl Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn reverse_glob_adjust(&mut self, expansion: Mark, glob_span: Span)
|
pub fn reverse_glob_adjust(&mut self, expansion: ExpnId, glob_span: Span)
|
||||||
-> Option<Option<Mark>> {
|
-> Option<Option<ExpnId>> {
|
||||||
let mut span = self.data();
|
let mut span = self.data();
|
||||||
let mark = span.ctxt.reverse_glob_adjust(expansion, glob_span);
|
let mark = span.ctxt.reverse_glob_adjust(expansion, glob_span);
|
||||||
*self = Span::new(span.lo, span.hi, span.ctxt);
|
*self = Span::new(span.lo, span.hi, span.ctxt);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue