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

@ -30,7 +30,7 @@ use rustc_session::lint::BuiltinLintDiagnostics;
use rustc_session::parse::feature_err;
use rustc_session::Session;
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::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
@ -62,7 +62,7 @@ pub enum MacroRulesScope<'a> {
Binding(&'a MacroRulesBinding<'a>),
/// The scope introduced by a macro invocation that can potentially
/// create a `macro_rules!` macro definition.
Invocation(ExpnId),
Invocation(LocalExpnId),
}
/// `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.
// 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] };
@ -216,9 +220,9 @@ impl<'a> ResolverExpand for Resolver<'a> {
pass: AstPass,
features: &[Symbol],
parent_module_id: Option<NodeId>,
) -> ExpnId {
) -> LocalExpnId {
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(
ExpnKind::AstPass(pass),
call_site,
@ -244,7 +248,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
fn resolve_macro_invocation(
&mut self,
invoc: &Invocation,
eager_expansion_root: ExpnId,
eager_expansion_root: LocalExpnId,
force: bool,
) -> Result<Lrc<SyntaxExtension>, Indeterminate> {
let invoc_id = invoc.expansion_data.id;
@ -328,7 +332,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
| ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => {
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
// nearest closing item - we should try to return the closest parent of the ExpnId
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])
}
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)
}
fn resolve_derives(
&mut self,
expn_id: ExpnId,
expn_id: LocalExpnId,
force: bool,
derive_paths: &dyn Fn() -> DeriveResolutions,
) -> Result<(), Indeterminate> {
@ -423,7 +427,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
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)
}
@ -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 false if the path certainly cannot be resolved in any of the three namespaces.
// 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 path = &Segment::from_path(path);
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 ok = |res, span, arenas| {
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(),
))
};