1
Fork 0

Use LocalExpnId where possible.

This commit is contained in:
Camille GILLOT 2021-06-25 20:43:04 +02:00
parent 6e78d6c9d6
commit 078dd37f88
19 changed files with 169 additions and 147 deletions

View file

@ -1,4 +1,4 @@
use rustc_span::{ExpnId, LocalExpnId}; use rustc_span::LocalExpnId;
use std::fmt; use std::fmt;
rustc_index::newtype_index! { rustc_index::newtype_index! {
@ -24,12 +24,12 @@ pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);
pub const DUMMY_NODE_ID: NodeId = NodeId::MAX; pub const DUMMY_NODE_ID: NodeId = NodeId::MAX;
impl NodeId { impl NodeId {
pub fn placeholder_from_expn_id(expn_id: ExpnId) -> Self { pub fn placeholder_from_expn_id(expn_id: LocalExpnId) -> Self {
NodeId::from_u32(expn_id.expect_local().as_u32()) NodeId::from_u32(expn_id.as_u32())
} }
pub fn placeholder_to_expn_id(self) -> ExpnId { pub fn placeholder_to_expn_id(self) -> LocalExpnId {
LocalExpnId::from_u32(self.as_u32()).to_expn_id() LocalExpnId::from_u32(self.as_u32())
} }
} }

View file

@ -36,8 +36,9 @@ pub fn expand_deriving_clone(
Annotatable::Item(ref annitem) => match annitem.kind { Annotatable::Item(ref annitem) => match annitem.kind {
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_data().parent; let container_id = cx.current_expansion.id.expn_data().parent.expect_local();
if cx.resolver.has_derive_copy(container_id) let has_derive_copy = cx.resolver.has_derive_copy(container_id);
if has_derive_copy
&& !params && !params
.iter() .iter()
.any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. })) .any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. }))

View file

@ -410,7 +410,7 @@ impl<'a> TraitDef<'a> {
.any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. })), .any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. })),
_ => unreachable!(), _ => unreachable!(),
}; };
let container_id = cx.current_expansion.id.expn_data().parent; let container_id = cx.current_expansion.id.expn_data().parent.expect_local();
let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id); let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id);
let use_temporaries = is_packed && always_copy; let use_temporaries = is_packed && always_copy;

View file

@ -304,7 +304,7 @@ fn mk_decls(
&[sym::rustc_attrs, sym::proc_macro_internals], &[sym::rustc_attrs, sym::proc_macro_internals],
None, None,
); );
let span = DUMMY_SP.with_def_site_ctxt(expn_id); let span = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id());
let proc_macro = Ident::new(sym::proc_macro, span); let proc_macro = Ident::new(sym::proc_macro, span);
let krate = cx.item(span, proc_macro, Vec::new(), ast::ItemKind::ExternCrate(None)); let krate = cx.item(span, proc_macro, Vec::new(), ast::ItemKind::ExternCrate(None));

View file

@ -34,8 +34,8 @@ pub fn inject(
&[sym::prelude_import], &[sym::prelude_import],
None, None,
); );
let span = DUMMY_SP.with_def_site_ctxt(expn_id); let span = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id());
let call_site = DUMMY_SP.with_call_site_ctxt(expn_id); let call_site = DUMMY_SP.with_call_site_ctxt(expn_id.to_expn_id());
let ecfg = ExpansionConfig::default("std_lib_injection".to_string()); let ecfg = ExpansionConfig::default("std_lib_injection".to_string());
let cx = ExtCtxt::new(sess, ecfg, resolver, None); let cx = ExtCtxt::new(sess, ecfg, resolver, None);

View file

@ -126,7 +126,8 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
for test in &mut tests { for test in &mut tests {
// See the comment on `mk_main` for why we're using // See the comment on `mk_main` for why we're using
// `apply_mark` directly. // `apply_mark` directly.
test.ident.span = test.ident.span.apply_mark(expn_id, Transparency::Opaque); test.ident.span =
test.ident.span.apply_mark(expn_id.to_expn_id(), Transparency::Opaque);
} }
self.cx.test_cases.extend(tests); self.cx.test_cases.extend(tests);
} }
@ -223,7 +224,7 @@ fn generate_test_harness(
&[sym::test, sym::rustc_attrs], &[sym::test, sym::rustc_attrs],
None, None,
); );
let def_site = DUMMY_SP.with_def_site_ctxt(expn_id); let def_site = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id());
// Remove the entry points // Remove the entry points
let mut cleaner = EntryPointCleaner { sess, depth: 0, def_site }; let mut cleaner = EntryPointCleaner { sess, depth: 0, def_site };

View file

@ -16,7 +16,7 @@ use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
use rustc_session::{parse::ParseSess, Limit, Session}; use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_span::def_id::{CrateNum, DefId}; use rustc_span::def_id::{CrateNum, DefId};
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnId, ExpnKind}; use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{FileName, MultiSpan, Span, DUMMY_SP}; use rustc_span::{FileName, MultiSpan, Span, DUMMY_SP};
@ -813,7 +813,7 @@ impl SyntaxExtension {
pub fn expn_data( pub fn expn_data(
&self, &self,
parent: ExpnId, parent: LocalExpnId,
call_site: Span, call_site: Span,
descr: Symbol, descr: Symbol,
macro_def_id: Option<DefId>, macro_def_id: Option<DefId>,
@ -821,7 +821,7 @@ impl SyntaxExtension {
) -> ExpnData { ) -> ExpnData {
ExpnData::new( ExpnData::new(
ExpnKind::Macro(self.macro_kind(), descr), ExpnKind::Macro(self.macro_kind(), descr),
parent, parent.to_expn_id(),
call_site, call_site,
self.span, self.span,
self.allow_internal_unstable.clone(), self.allow_internal_unstable.clone(),
@ -843,7 +843,11 @@ pub trait ResolverExpand {
fn next_node_id(&mut self) -> NodeId; fn next_node_id(&mut self) -> NodeId;
fn resolve_dollar_crates(&mut self); fn resolve_dollar_crates(&mut self);
fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment); fn visit_ast_fragment_with_placeholders(
&mut self,
expn_id: LocalExpnId,
fragment: &AstFragment,
);
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind); fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind);
fn expansion_for_ast_pass( fn expansion_for_ast_pass(
@ -852,37 +856,41 @@ pub trait ResolverExpand {
pass: AstPass, pass: AstPass,
features: &[Symbol], features: &[Symbol],
parent_module_id: Option<NodeId>, parent_module_id: Option<NodeId>,
) -> ExpnId; ) -> LocalExpnId;
fn resolve_imports(&mut self); fn resolve_imports(&mut self);
fn resolve_macro_invocation( fn resolve_macro_invocation(
&mut self, &mut self,
invoc: &Invocation, invoc: &Invocation,
eager_expansion_root: ExpnId, eager_expansion_root: LocalExpnId,
force: bool, force: bool,
) -> Result<Lrc<SyntaxExtension>, Indeterminate>; ) -> Result<Lrc<SyntaxExtension>, Indeterminate>;
fn check_unused_macros(&mut self); fn check_unused_macros(&mut self);
/// Some parent node that is close enough to the given macro call. /// Some parent node that is close enough to the given macro call.
fn lint_node_id(&self, expn_id: ExpnId) -> NodeId; fn lint_node_id(&self, expn_id: LocalExpnId) -> NodeId;
// Resolver interfaces for specific built-in macros. // Resolver interfaces for specific built-in macros.
/// Does `#[derive(...)]` attribute with the given `ExpnId` have built-in `Copy` inside it? /// Does `#[derive(...)]` attribute with the given `ExpnId` have built-in `Copy` inside it?
fn has_derive_copy(&self, expn_id: ExpnId) -> bool; fn has_derive_copy(&self, expn_id: LocalExpnId) -> bool;
/// Resolve paths inside the `#[derive(...)]` attribute with the given `ExpnId`. /// Resolve paths inside the `#[derive(...)]` attribute with the given `ExpnId`.
fn resolve_derives( fn resolve_derives(
&mut self, &mut self,
expn_id: ExpnId, expn_id: LocalExpnId,
force: bool, force: bool,
derive_paths: &dyn Fn() -> DeriveResolutions, derive_paths: &dyn Fn() -> DeriveResolutions,
) -> Result<(), Indeterminate>; ) -> Result<(), Indeterminate>;
/// Take resolutions for paths inside the `#[derive(...)]` attribute with the given `ExpnId` /// Take resolutions for paths inside the `#[derive(...)]` attribute with the given `ExpnId`
/// back from resolver. /// back from resolver.
fn take_derive_resolutions(&mut self, expn_id: ExpnId) -> Option<DeriveResolutions>; fn take_derive_resolutions(&mut self, expn_id: LocalExpnId) -> Option<DeriveResolutions>;
/// Path resolution logic for `#[cfg_accessible(path)]`. /// Path resolution logic for `#[cfg_accessible(path)]`.
fn cfg_accessible(&mut self, expn_id: ExpnId, path: &ast::Path) -> Result<bool, Indeterminate>; fn cfg_accessible(
&mut self,
expn_id: LocalExpnId,
path: &ast::Path,
) -> Result<bool, Indeterminate>;
/// Decodes the proc-macro quoted span in the specified crate, with the specified id. /// Decodes the proc-macro quoted span in the specified crate, with the specified id.
/// No caching is performed. /// No caching is performed.
@ -913,7 +921,7 @@ impl ModuleData {
#[derive(Clone)] #[derive(Clone)]
pub struct ExpansionData { pub struct ExpansionData {
pub id: ExpnId, pub id: LocalExpnId,
pub depth: usize, pub depth: usize,
pub module: Rc<ModuleData>, pub module: Rc<ModuleData>,
pub dir_ownership: DirOwnership, pub dir_ownership: DirOwnership,
@ -958,7 +966,7 @@ impl<'a> ExtCtxt<'a> {
extern_mod_loaded, extern_mod_loaded,
root_path: PathBuf::new(), root_path: PathBuf::new(),
current_expansion: ExpansionData { current_expansion: ExpansionData {
id: ExpnId::root(), id: LocalExpnId::ROOT,
depth: 0, depth: 0,
module: Default::default(), module: Default::default(),
dir_ownership: DirOwnership::Owned { relative: None }, dir_ownership: DirOwnership::Owned { relative: None },
@ -995,19 +1003,19 @@ impl<'a> ExtCtxt<'a> {
/// Equivalent of `Span::def_site` from the proc macro API, /// Equivalent of `Span::def_site` from the proc macro API,
/// except that the location is taken from the span passed as an argument. /// except that the location is taken from the span passed as an argument.
pub fn with_def_site_ctxt(&self, span: Span) -> Span { pub fn with_def_site_ctxt(&self, span: Span) -> Span {
span.with_def_site_ctxt(self.current_expansion.id) span.with_def_site_ctxt(self.current_expansion.id.to_expn_id())
} }
/// Equivalent of `Span::call_site` from the proc macro API, /// Equivalent of `Span::call_site` from the proc macro API,
/// except that the location is taken from the span passed as an argument. /// except that the location is taken from the span passed as an argument.
pub fn with_call_site_ctxt(&self, span: Span) -> Span { pub fn with_call_site_ctxt(&self, span: Span) -> Span {
span.with_call_site_ctxt(self.current_expansion.id) span.with_call_site_ctxt(self.current_expansion.id.to_expn_id())
} }
/// Equivalent of `Span::mixed_site` from the proc macro API, /// Equivalent of `Span::mixed_site` from the proc macro API,
/// except that the location is taken from the span passed as an argument. /// except that the location is taken from the span passed as an argument.
pub fn with_mixed_site_ctxt(&self, span: Span) -> Span { pub fn with_mixed_site_ctxt(&self, span: Span) -> Span {
span.with_mixed_site_ctxt(self.current_expansion.id) span.with_mixed_site_ctxt(self.current_expansion.id.to_expn_id())
} }
/// Returns span for the macro which originally caused the current expansion to happen. /// Returns span for the macro which originally caused the current expansion to happen.

View file

@ -31,7 +31,7 @@ use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_session::parse::{feature_err, ParseSess}; use rustc_session::parse::{feature_err, ParseSess};
use rustc_session::Limit; use rustc_session::Limit;
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::{ExpnId, FileName, Span}; use rustc_span::{FileName, LocalExpnId, Span};
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use std::ops::DerefMut; use std::ops::DerefMut;
@ -508,7 +508,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
.map(|(path, item, _exts)| { .map(|(path, item, _exts)| {
// FIXME: Consider using the derive resolutions (`_exts`) // FIXME: Consider using the derive resolutions (`_exts`)
// instead of enqueuing the derives to be resolved again later. // instead of enqueuing the derives to be resolved again later.
let expn_id = ExpnId::fresh_empty(); let expn_id = LocalExpnId::fresh_empty();
derive_invocations.push(( derive_invocations.push((
Invocation { Invocation {
kind: InvocationKind::Derive { path, item }, kind: InvocationKind::Derive { path, item },
@ -993,7 +993,7 @@ 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 {
let expn_id = ExpnId::fresh_empty(); let expn_id = LocalExpnId::fresh_empty();
let vis = kind.placeholder_visibility(); let vis = kind.placeholder_visibility();
self.invocations.push(( self.invocations.push((
Invocation { Invocation {

View file

@ -8,7 +8,7 @@ use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndSpacing};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_errors::{pluralize, PResult}; use rustc_errors::{pluralize, PResult};
use rustc_span::hygiene::{ExpnId, Transparency}; use rustc_span::hygiene::{LocalExpnId, Transparency};
use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::Span; use rustc_span::Span;
@ -16,7 +16,7 @@ use smallvec::{smallvec, SmallVec};
use std::mem; use std::mem;
// A Marker adds the given mark to the syntax context. // A Marker adds the given mark to the syntax context.
struct Marker(ExpnId, Transparency); struct Marker(LocalExpnId, Transparency);
impl MutVisitor for Marker { impl MutVisitor for Marker {
fn token_visiting_enabled(&self) -> bool { fn token_visiting_enabled(&self) -> bool {
@ -24,7 +24,7 @@ impl MutVisitor for Marker {
} }
fn visit_span(&mut self, span: &mut Span) { fn visit_span(&mut self, span: &mut Span) {
*span = span.apply_mark(self.0, self.1) *span = span.apply_mark(self.0.to_expn_id(), self.1)
} }
} }

View file

@ -31,7 +31,7 @@ use rustc_middle::bug;
use rustc_middle::hir::exports::Export; use rustc_middle::hir::exports::Export;
use rustc_middle::middle::cstore::CrateStore; use rustc_middle::middle::cstore::CrateStore;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_span::hygiene::{ExpnId, MacroKind}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
use rustc_span::source_map::{respan, Spanned}; use rustc_span::source_map::{respan, Spanned};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span; use rustc_span::Span;
@ -42,7 +42,7 @@ use tracing::debug;
type Res = def::Res<NodeId>; type Res = def::Res<NodeId>;
impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, ExpnId) { impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, LocalExpnId) {
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),
@ -54,7 +54,7 @@ impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, ExpnId) {
} }
} }
impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId) { impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, LocalExpnId) {
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),
@ -68,7 +68,7 @@ impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId) {
struct IsMacroExport; struct IsMacroExport;
impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, ExpnId, IsMacroExport) { impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, LocalExpnId, 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),
@ -157,7 +157,12 @@ impl<'a> Resolver<'a> {
crate fn macro_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> { crate fn macro_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> {
let def_id = match expn_id.expn_data().macro_def_id { let def_id = match expn_id.expn_data().macro_def_id {
Some(def_id) => def_id, Some(def_id) => def_id,
None => return self.ast_transform_scopes.get(&expn_id).unwrap_or(&self.graph_root), None => {
return expn_id
.as_local()
.and_then(|expn_id| self.ast_transform_scopes.get(&expn_id))
.unwrap_or(&self.graph_root);
}
}; };
self.macro_def_scope_from_def_id(def_id) self.macro_def_scope_from_def_id(def_id)
} }
@ -739,7 +744,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
if ptr::eq(parent, self.r.graph_root) { if ptr::eq(parent, self.r.graph_root) {
if let Some(entry) = self.r.extern_prelude.get(&ident.normalize_to_macros_2_0()) if let Some(entry) = self.r.extern_prelude.get(&ident.normalize_to_macros_2_0())
{ {
if expansion != ExpnId::root() if expansion != LocalExpnId::ROOT
&& orig_name.is_some() && orig_name.is_some()
&& entry.extern_crate_item.is_none() && entry.extern_crate_item.is_none()
{ {
@ -769,7 +774,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
no_implicit_prelude: parent.no_implicit_prelude || { no_implicit_prelude: parent.no_implicit_prelude || {
self.r.session.contains_name(&item.attrs, sym::no_implicit_prelude) self.r.session.contains_name(&item.attrs, sym::no_implicit_prelude)
}, },
..ModuleData::new(Some(parent), module_kind, def_id, expansion, item.span) ..ModuleData::new(
Some(parent),
module_kind,
def_id,
expansion.to_expn_id(),
item.span,
)
}); });
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion)); self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
self.r.module_map.insert(local_def_id, module); self.r.module_map.insert(local_def_id, module);
@ -808,7 +819,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
parent, parent,
module_kind, module_kind,
parent.nearest_parent_mod, parent.nearest_parent_mod,
expansion, expansion.to_expn_id(),
item.span, item.span,
); );
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion)); self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
@ -883,7 +894,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
parent, parent,
module_kind, module_kind,
parent.nearest_parent_mod, parent.nearest_parent_mod,
expansion, expansion.to_expn_id(),
item.span, item.span,
); );
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion)); self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
@ -926,7 +937,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
parent, parent,
ModuleKind::Block(block.id), ModuleKind::Block(block.id),
parent.nearest_parent_mod, parent.nearest_parent_mod,
expansion, expansion.to_expn_id(),
block.span, block.span,
); );
self.r.block_map.insert(block.id, module); self.r.block_map.insert(block.id, module);
@ -946,7 +957,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
parent, parent,
ModuleKind::Def(kind, def_id, ident.name), ModuleKind::Def(kind, def_id, ident.name),
def_id, def_id,
expansion, expansion.to_expn_id(),
span, span,
); );
self.r.define(parent, ident, TypeNS, (module, vis, span, expansion)); self.r.define(parent, ident, TypeNS, (module, vis, span, expansion));
@ -1112,7 +1123,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}) })
}; };
let allow_shadowing = self.parent_scope.expansion == ExpnId::root(); let allow_shadowing = self.parent_scope.expansion == LocalExpnId::ROOT;
if let Some(span) = import_all { if let Some(span) = import_all {
let import = macro_use_import(self, span); let import = macro_use_import(self, span);
self.r.potentially_unused_imports.push(import); self.r.potentially_unused_imports.push(import);
@ -1175,7 +1186,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
false false
} }
fn visit_invoc(&mut self, id: NodeId) -> ExpnId { fn visit_invoc(&mut self, id: NodeId) -> LocalExpnId {
let invoc_id = id.placeholder_to_expn_id(); let invoc_id = id.placeholder_to_expn_id();
let old_parent_scope = self.r.invocation_parent_scopes.insert(invoc_id, self.parent_scope); let old_parent_scope = self.r.invocation_parent_scopes.insert(invoc_id, self.parent_scope);
assert!(old_parent_scope.is_none(), "invocation data is reset for an invocation"); assert!(old_parent_scope.is_none(), "invocation data is reset for an invocation");

View file

@ -6,7 +6,7 @@ use rustc_ast_lowering::ResolverAstLowering;
use rustc_expand::expand::AstFragment; use rustc_expand::expand::AstFragment;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::definitions::*; use rustc_hir::definitions::*;
use rustc_span::hygiene::ExpnId; use rustc_span::hygiene::LocalExpnId;
use rustc_span::symbol::{kw, sym}; use rustc_span::symbol::{kw, sym};
use rustc_span::Span; use rustc_span::Span;
use tracing::debug; use tracing::debug;
@ -14,7 +14,7 @@ use tracing::debug;
crate fn collect_definitions( crate fn collect_definitions(
resolver: &mut Resolver<'_>, resolver: &mut Resolver<'_>,
fragment: &AstFragment, fragment: &AstFragment,
expansion: ExpnId, expansion: LocalExpnId,
) { ) {
let (parent_def, impl_trait_context) = resolver.invocation_parents[&expansion]; let (parent_def, impl_trait_context) = resolver.invocation_parents[&expansion];
fragment.visit_with(&mut DefCollector { resolver, parent_def, expansion, impl_trait_context }); fragment.visit_with(&mut DefCollector { resolver, parent_def, expansion, impl_trait_context });
@ -25,14 +25,14 @@ struct DefCollector<'a, 'b> {
resolver: &'a mut Resolver<'b>, resolver: &'a mut Resolver<'b>,
parent_def: LocalDefId, parent_def: LocalDefId,
impl_trait_context: ImplTraitContext, impl_trait_context: ImplTraitContext,
expansion: ExpnId, expansion: LocalExpnId,
} }
impl<'a, 'b> DefCollector<'a, 'b> { impl<'a, 'b> DefCollector<'a, 'b> {
fn create_def(&mut self, node_id: NodeId, data: DefPathData, span: Span) -> LocalDefId { fn create_def(&mut self, node_id: NodeId, data: DefPathData, span: Span) -> LocalDefId {
let parent_def = self.parent_def; let parent_def = self.parent_def;
debug!("create_def(node_id={:?}, data={:?}, parent_def={:?})", node_id, data, parent_def); debug!("create_def(node_id={:?}, data={:?}, parent_def={:?})", node_id, data, parent_def);
self.resolver.create_def(parent_def, node_id, data, self.expansion, span) self.resolver.create_def(parent_def, node_id, data, self.expansion.to_expn_id(), span)
} }
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_def: LocalDefId, f: F) { fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_def: LocalDefId, f: F) {
@ -285,7 +285,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
item_def, item_def,
node_id, node_id,
DefPathData::ImplTrait, DefPathData::ImplTrait,
self.expansion, self.expansion.to_expn_id(),
ty.span, ty.span,
), ),
ImplTraitContext::Existential => { ImplTraitContext::Existential => {

View file

@ -22,7 +22,7 @@ use rustc_middle::span_bug;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS}; use rustc_session::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS};
use rustc_session::lint::BuiltinLintDiagnostics; use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_span::hygiene::ExpnId; use rustc_span::hygiene::LocalExpnId;
use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_span::{MultiSpan, Span}; use rustc_span::{MultiSpan, Span};
@ -237,8 +237,9 @@ impl<'a> Resolver<'a> {
if ns == TypeNS { if ns == TypeNS {
if ident.name == kw::Crate || ident.name == kw::DollarCrate { if ident.name == kw::Crate || ident.name == kw::DollarCrate {
let module = self.resolve_crate_root(ident); let module = self.resolve_crate_root(ident);
let binding = (module, ty::Visibility::Public, module.span, ExpnId::root()) let binding =
.to_name_binding(self.arenas); (module, ty::Visibility::Public, module.span, LocalExpnId::ROOT)
.to_name_binding(self.arenas);
return Ok(binding); return Ok(binding);
} else if ident.name == kw::Super || ident.name == kw::SelfLower { } else if ident.name == kw::Super || ident.name == kw::SelfLower {
// FIXME: Implement these with renaming requirements so that e.g. // FIXME: Implement these with renaming requirements so that e.g.
@ -265,7 +266,7 @@ impl<'a> Resolver<'a> {
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports. self.resolution(module, key).try_borrow_mut().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 != ExpnId::root() { if !restricted_shadowing && binding.expansion != LocalExpnId::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));
} }
@ -307,7 +308,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 != ExpnId::root() && binding.expansion != LocalExpnId::ROOT
&& binding.res() != shadowed_glob.res() && binding.res() != shadowed_glob.res()
{ {
self.ambiguity_errors.push(AmbiguityError { self.ambiguity_errors.push(AmbiguityError {
@ -521,7 +522,7 @@ impl<'a> Resolver<'a> {
if old_glob { (old_binding, binding) } else { (binding, old_binding) }; if old_glob { (old_binding, binding) } else { (binding, old_binding) };
if glob_binding.res() != nonglob_binding.res() if glob_binding.res() != nonglob_binding.res()
&& key.ns == MacroNS && key.ns == MacroNS
&& nonglob_binding.expansion != ExpnId::root() && nonglob_binding.expansion != LocalExpnId::ROOT
{ {
resolution.binding = Some(this.ambiguity( resolution.binding = Some(this.ambiguity(
AmbiguityKind::GlobVsExpanded, AmbiguityKind::GlobVsExpanded,
@ -1271,7 +1272,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 import.parent_scope.expansion != ExpnId::root() { if import.parent_scope.expansion != LocalExpnId::ROOT {
return; return;
} }

View file

@ -53,7 +53,7 @@ use rustc_session::lint;
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer}; use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::hygiene::{ExpnId, ExpnKind, MacroKind, SyntaxContext, Transparency}; use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext, Transparency};
use rustc_span::source_map::{CachingSourceMapView, Spanned}; use rustc_span::source_map::{CachingSourceMapView, Spanned};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -103,7 +103,7 @@ impl Determinacy {
/// but not for late resolution yet. /// but not for late resolution yet.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
enum Scope<'a> { enum Scope<'a> {
DeriveHelpers(ExpnId), DeriveHelpers(LocalExpnId),
DeriveHelpersCompat, DeriveHelpersCompat,
MacroRules(MacroRulesScopeRef<'a>), MacroRules(MacroRulesScopeRef<'a>),
CrateRoot, CrateRoot,
@ -143,7 +143,7 @@ enum ScopeSet<'a> {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct ParentScope<'a> { pub struct ParentScope<'a> {
module: Module<'a>, module: Module<'a>,
expansion: ExpnId, expansion: LocalExpnId,
macro_rules: MacroRulesScopeRef<'a>, macro_rules: MacroRulesScopeRef<'a>,
derives: &'a [ast::Path], derives: &'a [ast::Path],
} }
@ -154,7 +154,7 @@ impl<'a> ParentScope<'a> {
pub fn module(module: Module<'a>, resolver: &Resolver<'a>) -> ParentScope<'a> { pub fn module(module: Module<'a>, resolver: &Resolver<'a>) -> ParentScope<'a> {
ParentScope { ParentScope {
module, module,
expansion: ExpnId::root(), expansion: LocalExpnId::ROOT,
macro_rules: resolver.arenas.alloc_macro_rules_scope(MacroRulesScope::Empty), macro_rules: resolver.arenas.alloc_macro_rules_scope(MacroRulesScope::Empty),
derives: &[], derives: &[],
} }
@ -515,7 +515,7 @@ pub struct ModuleData<'a> {
populate_on_access: Cell<bool>, populate_on_access: Cell<bool>,
/// Macro invocations that can expand into items in this module. /// Macro invocations that can expand into items in this module.
unexpanded_invocations: RefCell<FxHashSet<ExpnId>>, unexpanded_invocations: RefCell<FxHashSet<LocalExpnId>>,
/// Whether `#[no_implicit_prelude]` is active. /// Whether `#[no_implicit_prelude]` is active.
no_implicit_prelude: bool, no_implicit_prelude: bool,
@ -645,7 +645,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: ExpnId, expansion: LocalExpnId,
span: Span, span: Span,
vis: ty::Visibility, vis: ty::Visibility,
} }
@ -829,7 +829,11 @@ 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: ExpnId, binding: &NameBinding<'_>) -> bool { fn may_appear_after(
&self,
invoc_parent_expansion: LocalExpnId,
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.
@ -966,7 +970,7 @@ pub struct Resolver<'a> {
dummy_ext_derive: Lrc<SyntaxExtension>, dummy_ext_derive: Lrc<SyntaxExtension>,
non_macro_attrs: [Lrc<SyntaxExtension>; 2], non_macro_attrs: [Lrc<SyntaxExtension>; 2],
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'a>>, local_macro_def_scopes: FxHashMap<LocalDefId, Module<'a>>,
ast_transform_scopes: FxHashMap<ExpnId, Module<'a>>, ast_transform_scopes: FxHashMap<LocalExpnId, Module<'a>>,
unused_macros: FxHashMap<LocalDefId, (NodeId, Span)>, unused_macros: FxHashMap<LocalDefId, (NodeId, Span)>,
proc_macro_stubs: FxHashSet<LocalDefId>, proc_macro_stubs: FxHashSet<LocalDefId>,
/// Traces collected during macro resolution and validated when it's complete. /// Traces collected during macro resolution and validated when it's complete.
@ -978,18 +982,18 @@ pub struct Resolver<'a> {
/// `derive(Copy)` marks items they are applied to so they are treated specially later. /// `derive(Copy)` marks items they are applied to so they are treated specially later.
/// Derive macros cannot modify the item themselves and have to store the markers in the global /// Derive macros cannot modify the item themselves and have to store the markers in the global
/// context, so they attach the markers to derive container IDs using this resolver table. /// context, so they attach the markers to derive container IDs using this resolver table.
containers_deriving_copy: FxHashSet<ExpnId>, containers_deriving_copy: FxHashSet<LocalExpnId>,
/// Parent scopes in which the macros were invoked. /// Parent scopes in which the macros were invoked.
/// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere. /// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere.
invocation_parent_scopes: FxHashMap<ExpnId, ParentScope<'a>>, invocation_parent_scopes: FxHashMap<LocalExpnId, ParentScope<'a>>,
/// `macro_rules` scopes *produced* by expanding the macro invocations, /// `macro_rules` scopes *produced* by expanding the macro invocations,
/// include all the `macro_rules` items and other invocations generated by them. /// include all the `macro_rules` items and other invocations generated by them.
output_macro_rules_scopes: FxHashMap<ExpnId, MacroRulesScopeRef<'a>>, output_macro_rules_scopes: FxHashMap<LocalExpnId, MacroRulesScopeRef<'a>>,
/// Helper attributes that are in scope for the given expansion. /// Helper attributes that are in scope for the given expansion.
helper_attrs: FxHashMap<ExpnId, Vec<Ident>>, helper_attrs: FxHashMap<LocalExpnId, Vec<Ident>>,
/// Ready or in-progress results of resolving paths inside the `#[derive(...)]` attribute /// Ready or in-progress results of resolving paths inside the `#[derive(...)]` attribute
/// with the given `ExpnId`. /// with the given `ExpnId`.
derive_data: FxHashMap<ExpnId, DeriveData>, derive_data: FxHashMap<LocalExpnId, DeriveData>,
/// Avoid duplicated errors for "name already defined". /// Avoid duplicated errors for "name already defined".
name_already_seen: FxHashMap<Symbol, Span>, name_already_seen: FxHashMap<Symbol, Span>,
@ -1018,7 +1022,7 @@ pub struct Resolver<'a> {
/// When collecting definitions from an AST fragment produced by a macro invocation `ExpnId` /// 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,
/// and how the `impl Trait` fragments were introduced. /// and how the `impl Trait` fragments were introduced.
invocation_parents: FxHashMap<ExpnId, (LocalDefId, ImplTraitContext)>, invocation_parents: FxHashMap<LocalExpnId, (LocalDefId, ImplTraitContext)>,
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>, next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
/// Some way to know that we are in a *trait* impl in `visit_assoc_item`. /// Some way to know that we are in a *trait* impl in `visit_assoc_item`.
@ -1268,7 +1272,7 @@ impl<'a> Resolver<'a> {
node_id_to_def_id.insert(CRATE_NODE_ID, root); node_id_to_def_id.insert(CRATE_NODE_ID, root);
let mut invocation_parents = FxHashMap::default(); let mut invocation_parents = FxHashMap::default();
invocation_parents.insert(ExpnId::root(), (root, ImplTraitContext::Existential)); invocation_parents.insert(LocalExpnId::ROOT, (root, ImplTraitContext::Existential));
let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = session let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = session
.opts .opts
@ -1342,7 +1346,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: ExpnId::root(), expansion: LocalExpnId::ROOT,
span: DUMMY_SP, span: DUMMY_SP,
vis: ty::Visibility::Public, vis: ty::Visibility::Public,
}), }),
@ -1392,7 +1396,7 @@ impl<'a> Resolver<'a> {
}; };
let root_parent_scope = ParentScope::module(graph_root, &resolver); let root_parent_scope = ParentScope::module(graph_root, &resolver);
resolver.invocation_parent_scopes.insert(ExpnId::root(), root_parent_scope); resolver.invocation_parent_scopes.insert(LocalExpnId::ROOT, root_parent_scope);
resolver resolver
} }
@ -1810,7 +1814,8 @@ impl<'a> Resolver<'a> {
} }
scope = match scope { scope = match scope {
Scope::DeriveHelpers(expn_id) if expn_id != ExpnId::root() => { Scope::DeriveHelpers(LocalExpnId::ROOT) => Scope::DeriveHelpersCompat,
Scope::DeriveHelpers(expn_id) => {
// Derive helpers are not visible to code generated by bang or derive macros. // Derive helpers are not visible to code generated by bang or derive macros.
let expn_data = expn_id.expn_data(); let expn_data = expn_id.expn_data();
match expn_data.kind { match expn_data.kind {
@ -1818,10 +1823,9 @@ impl<'a> Resolver<'a> {
| ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => { | ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => {
Scope::DeriveHelpersCompat Scope::DeriveHelpersCompat
} }
_ => Scope::DeriveHelpers(expn_data.parent), _ => Scope::DeriveHelpers(expn_data.parent.expect_local()),
} }
} }
Scope::DeriveHelpers(..) => Scope::DeriveHelpersCompat,
Scope::DeriveHelpersCompat => Scope::MacroRules(parent_scope.macro_rules), Scope::DeriveHelpersCompat => Scope::MacroRules(parent_scope.macro_rules),
Scope::MacroRules(macro_rules_scope) => match macro_rules_scope.get() { Scope::MacroRules(macro_rules_scope) => match macro_rules_scope.get() {
MacroRulesScope::Binding(binding) => { MacroRulesScope::Binding(binding) => {
@ -3248,7 +3252,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 });
Some( Some(
(crate_root, ty::Visibility::Public, DUMMY_SP, ExpnId::root()) (crate_root, ty::Visibility::Public, DUMMY_SP, LocalExpnId::ROOT)
.to_name_binding(self.arenas), .to_name_binding(self.arenas),
) )
} }

View file

@ -30,7 +30,7 @@ use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_session::parse::feature_err; use rustc_session::parse::feature_err;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::hygiene::{self, ExpnData, ExpnId, ExpnKind}; use rustc_span::hygiene::{self, ExpnData, ExpnKind, LocalExpnId};
use rustc_span::hygiene::{AstPass, MacroKind}; use rustc_span::hygiene::{AstPass, MacroKind};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -62,7 +62,7 @@ pub enum MacroRulesScope<'a> {
Binding(&'a MacroRulesBinding<'a>), Binding(&'a MacroRulesBinding<'a>),
/// The scope introduced by a macro invocation that can potentially /// The scope introduced by a macro invocation that can potentially
/// create a `macro_rules!` macro definition. /// create a `macro_rules!` macro definition.
Invocation(ExpnId), Invocation(LocalExpnId),
} }
/// `macro_rules!` scopes are always kept by reference and inside a cell. /// `macro_rules!` scopes are always kept by reference and inside a cell.
@ -190,7 +190,11 @@ impl<'a> ResolverExpand for Resolver<'a> {
}); });
} }
fn visit_ast_fragment_with_placeholders(&mut self, expansion: ExpnId, fragment: &AstFragment) { fn visit_ast_fragment_with_placeholders(
&mut self,
expansion: LocalExpnId,
fragment: &AstFragment,
) {
// Integrate the new AST fragment into all the definition and module structures. // Integrate the new AST fragment into all the definition and module structures.
// We are inside the `expansion` now, but other parent scope components are still the same. // We are inside the `expansion` now, but other parent scope components are still the same.
let parent_scope = ParentScope { expansion, ..self.invocation_parent_scopes[&expansion] }; let parent_scope = ParentScope { expansion, ..self.invocation_parent_scopes[&expansion] };
@ -216,9 +220,9 @@ impl<'a> ResolverExpand for Resolver<'a> {
pass: AstPass, pass: AstPass,
features: &[Symbol], features: &[Symbol],
parent_module_id: Option<NodeId>, parent_module_id: Option<NodeId>,
) -> ExpnId { ) -> LocalExpnId {
let parent_module = parent_module_id.map(|module_id| self.local_def_id(module_id)); let parent_module = parent_module_id.map(|module_id| self.local_def_id(module_id));
let expn_id = ExpnId::fresh( let expn_id = LocalExpnId::fresh(
ExpnData::allow_unstable( ExpnData::allow_unstable(
ExpnKind::AstPass(pass), ExpnKind::AstPass(pass),
call_site, call_site,
@ -244,7 +248,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
fn resolve_macro_invocation( fn resolve_macro_invocation(
&mut self, &mut self,
invoc: &Invocation, invoc: &Invocation,
eager_expansion_root: ExpnId, eager_expansion_root: LocalExpnId,
force: bool, force: bool,
) -> Result<Lrc<SyntaxExtension>, Indeterminate> { ) -> Result<Lrc<SyntaxExtension>, Indeterminate> {
let invoc_id = invoc.expansion_data.id; let invoc_id = invoc.expansion_data.id;
@ -328,7 +332,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
| ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => { | ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => {
break; break;
} }
_ => expn_id = expn_data.parent, _ => expn_id = expn_data.parent.expect_local(),
} }
} }
} }
@ -344,7 +348,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
} }
} }
fn lint_node_id(&self, expn_id: ExpnId) -> NodeId { fn lint_node_id(&self, expn_id: LocalExpnId) -> NodeId {
// FIXME - make this more precise. This currently returns the NodeId of the // FIXME - make this more precise. This currently returns the NodeId of the
// nearest closing item - we should try to return the closest parent of the ExpnId // nearest closing item - we should try to return the closest parent of the ExpnId
self.invocation_parents self.invocation_parents
@ -352,13 +356,13 @@ impl<'a> ResolverExpand for Resolver<'a> {
.map_or(ast::CRATE_NODE_ID, |id| self.def_id_to_node_id[id.0]) .map_or(ast::CRATE_NODE_ID, |id| self.def_id_to_node_id[id.0])
} }
fn has_derive_copy(&self, expn_id: ExpnId) -> bool { fn has_derive_copy(&self, expn_id: LocalExpnId) -> bool {
self.containers_deriving_copy.contains(&expn_id) self.containers_deriving_copy.contains(&expn_id)
} }
fn resolve_derives( fn resolve_derives(
&mut self, &mut self,
expn_id: ExpnId, expn_id: LocalExpnId,
force: bool, force: bool,
derive_paths: &dyn Fn() -> DeriveResolutions, derive_paths: &dyn Fn() -> DeriveResolutions,
) -> Result<(), Indeterminate> { ) -> Result<(), Indeterminate> {
@ -423,7 +427,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
Ok(()) Ok(())
} }
fn take_derive_resolutions(&mut self, expn_id: ExpnId) -> Option<DeriveResolutions> { fn take_derive_resolutions(&mut self, expn_id: LocalExpnId) -> Option<DeriveResolutions> {
self.derive_data.remove(&expn_id).map(|data| data.resolutions) self.derive_data.remove(&expn_id).map(|data| data.resolutions)
} }
@ -431,7 +435,11 @@ impl<'a> ResolverExpand for Resolver<'a> {
// Returns true if the path can certainly be resolved in one of three namespaces, // Returns true if the path can certainly be resolved in one of three namespaces,
// returns false if the path certainly cannot be resolved in any of the three namespaces. // returns false if the path certainly cannot be resolved in any of the three namespaces.
// Returns `Indeterminate` if we cannot give a certain answer yet. // Returns `Indeterminate` if we cannot give a certain answer yet.
fn cfg_accessible(&mut self, expn_id: ExpnId, path: &ast::Path) -> Result<bool, Indeterminate> { fn cfg_accessible(
&mut self,
expn_id: LocalExpnId,
path: &ast::Path,
) -> Result<bool, Indeterminate> {
let span = path.span; let span = path.span;
let path = &Segment::from_path(path); let path = &Segment::from_path(path);
let parent_scope = self.invocation_parent_scopes[&expn_id]; let parent_scope = self.invocation_parent_scopes[&expn_id];
@ -714,7 +722,8 @@ impl<'a> Resolver<'a> {
let ident = Ident::new(orig_ident.name, orig_ident.span.with_ctxt(ctxt)); let ident = Ident::new(orig_ident.name, orig_ident.span.with_ctxt(ctxt));
let ok = |res, span, arenas| { let ok = |res, span, arenas| {
Ok(( Ok((
(res, ty::Visibility::Public, span, ExpnId::root()).to_name_binding(arenas), (res, ty::Visibility::Public, span, LocalExpnId::ROOT)
.to_name_binding(arenas),
Flags::empty(), Flags::empty(),
)) ))
}; };

View file

@ -198,19 +198,6 @@ impl ExpnId {
ExpnId { krate: LOCAL_CRATE, local_id: ExpnIndex::from_u32(0) } ExpnId { krate: LOCAL_CRATE, local_id: ExpnIndex::from_u32(0) }
} }
pub fn fresh_empty() -> ExpnId {
LocalExpnId::fresh_empty().to_expn_id()
}
pub fn fresh(expn_data: ExpnData, ctx: impl HashStableContext) -> ExpnId {
LocalExpnId::fresh(expn_data, ctx).to_expn_id()
}
#[inline]
pub fn set_expn_data(self, expn_data: ExpnData, ctx: impl HashStableContext) {
self.expect_local().set_expn_data(expn_data, ctx)
}
#[inline] #[inline]
pub fn expn_hash(self) -> ExpnHash { pub fn expn_hash(self) -> ExpnHash {
HygieneData::with(|data| data.expn_hash(self)) HygieneData::with(|data| data.expn_hash(self))
@ -819,7 +806,7 @@ impl Span {
transparency: Transparency, transparency: Transparency,
ctx: impl HashStableContext, ctx: impl HashStableContext,
) -> Span { ) -> Span {
let expn_id = ExpnId::fresh(expn_data, ctx); let expn_id = LocalExpnId::fresh(expn_data, ctx).to_expn_id();
HygieneData::with(|data| { HygieneData::with(|data| {
self.with_ctxt(data.apply_mark(SyntaxContext::root(), expn_id, transparency)) self.with_ctxt(data.apply_mark(SyntaxContext::root(), expn_id, transparency))
}) })

View file

@ -19,10 +19,10 @@ fn y /* 0#0 */() { }
/* /*
Expansions: Expansions:
0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root crate0::{{expn0}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Root
1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "foo") crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "foo")
SyntaxContexts: SyntaxContexts:
#0: parent: #0, outer_mark: (ExpnId(0), Opaque) #0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (ExpnId(1), SemiTransparent) #1: parent: #0, outer_mark: (crate0::{{expn1}}, SemiTransparent)
*/ */

View file

@ -43,23 +43,23 @@ fn main /* 0#0 */() { ; }
/* /*
Expansions: Expansions:
0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root crate0::{{expn0}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Root
1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports) crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "produce_it") crate0::{{expn2}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "produce_it")
3: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports) crate0::{{expn3}}: parent: crate0::{{expn2}}, call_site_ctxt: #4, def_site_ctxt: #0, kind: Macro(Bang, "meta_macro::print_def_site")
4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #0, kind: Macro(Bang, "meta_macro::print_def_site") crate0::{{expn4}}: parent: crate0::{{expn3}}, call_site_ctxt: #5, def_site_ctxt: #0, kind: Macro(Bang, "$crate::dummy")
5: parent: ExpnId(4), call_site_ctxt: #5, def_site_ctxt: #0, kind: Macro(Bang, "$crate::dummy") crate2::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
SyntaxContexts: SyntaxContexts:
#0: parent: #0, outer_mark: (ExpnId(0), Opaque) #0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (ExpnId(1), Opaque) #1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque)
#2: parent: #0, outer_mark: (ExpnId(1), Transparent) #2: parent: #0, outer_mark: (crate0::{{expn1}}, Transparent)
#3: parent: #0, outer_mark: (ExpnId(3), Opaque) #3: parent: #0, outer_mark: (crate2::{{expn1}}, Opaque)
#4: parent: #0, outer_mark: (ExpnId(2), SemiTransparent) #4: parent: #0, outer_mark: (crate0::{{expn2}}, SemiTransparent)
#5: parent: #0, outer_mark: (ExpnId(4), Opaque) #5: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque)
#6: parent: #4, outer_mark: (ExpnId(4), Transparent) #6: parent: #4, outer_mark: (crate0::{{expn3}}, Transparent)
#7: parent: #0, outer_mark: (ExpnId(4), SemiTransparent) #7: parent: #0, outer_mark: (crate0::{{expn3}}, SemiTransparent)
#8: parent: #0, outer_mark: (ExpnId(5), Opaque) #8: parent: #0, outer_mark: (crate0::{{expn4}}, Opaque)
#9: parent: #5, outer_mark: (ExpnId(5), Transparent) #9: parent: #5, outer_mark: (crate0::{{expn4}}, Transparent)
#10: parent: #5, outer_mark: (ExpnId(5), SemiTransparent) #10: parent: #5, outer_mark: (crate0::{{expn4}}, SemiTransparent)
*/ */

View file

@ -67,22 +67,22 @@ fn main /* 0#0 */() { }
/* /*
Expansions: Expansions:
0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root crate0::{{expn0}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Root
1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports) crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "outer") crate0::{{expn2}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "outer")
3: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports) crate0::{{expn3}}: parent: crate0::{{expn2}}, call_site_ctxt: #4, def_site_ctxt: #4, kind: Macro(Bang, "inner")
4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #4, kind: Macro(Bang, "inner") crate0::{{expn4}}: parent: crate0::{{expn3}}, call_site_ctxt: #6, def_site_ctxt: #0, kind: Macro(Bang, "print_bang")
5: parent: ExpnId(4), call_site_ctxt: #6, def_site_ctxt: #0, kind: Macro(Bang, "print_bang") crate2::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
SyntaxContexts: SyntaxContexts:
#0: parent: #0, outer_mark: (ExpnId(0), Opaque) #0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (ExpnId(1), Opaque) #1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque)
#2: parent: #0, outer_mark: (ExpnId(1), Transparent) #2: parent: #0, outer_mark: (crate0::{{expn1}}, Transparent)
#3: parent: #0, outer_mark: (ExpnId(3), Opaque) #3: parent: #0, outer_mark: (crate2::{{expn1}}, Opaque)
#4: parent: #0, outer_mark: (ExpnId(2), SemiTransparent) #4: parent: #0, outer_mark: (crate0::{{expn2}}, SemiTransparent)
#5: parent: #0, outer_mark: (ExpnId(4), Opaque) #5: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque)
#6: parent: #4, outer_mark: (ExpnId(4), Opaque) #6: parent: #4, outer_mark: (crate0::{{expn3}}, Opaque)
#7: parent: #0, outer_mark: (ExpnId(5), Opaque) #7: parent: #0, outer_mark: (crate0::{{expn4}}, Opaque)
#8: parent: #6, outer_mark: (ExpnId(5), Transparent) #8: parent: #6, outer_mark: (crate0::{{expn4}}, Transparent)
#9: parent: #5, outer_mark: (ExpnId(5), SemiTransparent) #9: parent: #5, outer_mark: (crate0::{{expn4}}, SemiTransparent)
*/ */

View file

@ -6,7 +6,7 @@ use rustc_ast::ast::{
}; };
use rustc_ast::ptr; use rustc_ast::ptr;
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_span::{sym, symbol, BytePos, ExpnId, Span, Symbol, SyntaxContext}; use rustc_span::{sym, symbol, BytePos, LocalExpnId, Span, Symbol, SyntaxContext};
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses}; use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses};
@ -675,7 +675,7 @@ pub(crate) trait NodeIdExt {
impl NodeIdExt for NodeId { impl NodeIdExt for NodeId {
fn root() -> NodeId { fn root() -> NodeId {
NodeId::placeholder_from_expn_id(ExpnId::root()) NodeId::placeholder_from_expn_id(LocalExpnId::ROOT)
} }
} }