Introduce 'ra lifetime name.
`rustc_resolve` allocates many things in `ResolverArenas`. The lifetime used for references into the arena is mostly `'a`, and sometimes `'b`. This commit changes it to `'ra`, which is much more descriptive. The commit also changes the order of lifetimes on a couple of structs so that '`ra` is second last, before `'tcx`, and does other minor renamings such as `'r` to `'a`.
This commit is contained in:
@@ -39,10 +39,10 @@ use crate::{
|
||||
|
||||
type Res = def::Res<NodeId>;
|
||||
|
||||
impl<'a, Id: Into<DefId>> ToNameBinding<'a>
|
||||
for (Module<'a>, ty::Visibility<Id>, Span, LocalExpnId)
|
||||
impl<'ra, Id: Into<DefId>> ToNameBinding<'ra>
|
||||
for (Module<'ra>, ty::Visibility<Id>, Span, LocalExpnId)
|
||||
{
|
||||
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a> {
|
||||
fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra> {
|
||||
arenas.alloc_name_binding(NameBindingData {
|
||||
kind: NameBindingKind::Module(self.0),
|
||||
ambiguity: None,
|
||||
@@ -54,8 +54,8 @@ impl<'a, Id: Into<DefId>> ToNameBinding<'a>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Id: Into<DefId>> ToNameBinding<'a> for (Res, ty::Visibility<Id>, Span, LocalExpnId) {
|
||||
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> NameBinding<'a> {
|
||||
impl<'ra, Id: Into<DefId>> ToNameBinding<'ra> for (Res, ty::Visibility<Id>, Span, LocalExpnId) {
|
||||
fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra> {
|
||||
arenas.alloc_name_binding(NameBindingData {
|
||||
kind: NameBindingKind::Res(self.0),
|
||||
ambiguity: None,
|
||||
@@ -67,12 +67,12 @@ impl<'a, Id: Into<DefId>> ToNameBinding<'a> for (Res, ty::Visibility<Id>, Span,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
|
||||
/// otherwise, reports an error.
|
||||
pub(crate) fn define<T>(&mut self, parent: Module<'a>, ident: Ident, ns: Namespace, def: T)
|
||||
pub(crate) fn define<T>(&mut self, parent: Module<'ra>, ident: Ident, ns: Namespace, def: T)
|
||||
where
|
||||
T: ToNameBinding<'a>,
|
||||
T: ToNameBinding<'ra>,
|
||||
{
|
||||
let binding = def.to_name_binding(self.arenas);
|
||||
let key = self.new_disambiguated_key(ident, ns);
|
||||
@@ -97,7 +97,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
/// Reachable macros with block module parents exist due to `#[macro_export] macro_rules!`,
|
||||
/// but they cannot use def-site hygiene, so the assumption holds
|
||||
/// (<https://github.com/rust-lang/rust/pull/77984#issuecomment-712445508>).
|
||||
pub(crate) fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'a> {
|
||||
pub(crate) fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'ra> {
|
||||
loop {
|
||||
match self.get_module(def_id) {
|
||||
Some(module) => return module,
|
||||
@@ -106,14 +106,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn expect_module(&mut self, def_id: DefId) -> Module<'a> {
|
||||
pub(crate) fn expect_module(&mut self, def_id: DefId) -> Module<'ra> {
|
||||
self.get_module(def_id).expect("argument `DefId` is not a module")
|
||||
}
|
||||
|
||||
/// If `def_id` refers to a module (in resolver's sense, i.e. a module item, crate root, enum,
|
||||
/// or trait), then this function returns that module's resolver representation, otherwise it
|
||||
/// returns `None`.
|
||||
pub(crate) fn get_module(&mut self, def_id: DefId) -> Option<Module<'a>> {
|
||||
pub(crate) fn get_module(&mut self, def_id: DefId) -> Option<Module<'ra>> {
|
||||
if let module @ Some(..) = self.module_map.get(&def_id) {
|
||||
return module.copied();
|
||||
}
|
||||
@@ -143,7 +143,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
None
|
||||
}
|
||||
|
||||
pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'a> {
|
||||
pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'ra> {
|
||||
match expn_id.expn_data().macro_def_id {
|
||||
Some(def_id) => self.macro_def_scope(def_id),
|
||||
None => expn_id
|
||||
@@ -153,7 +153,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn macro_def_scope(&mut self, def_id: DefId) -> Module<'a> {
|
||||
pub(crate) fn macro_def_scope(&mut self, def_id: DefId) -> Module<'ra> {
|
||||
if let Some(id) = def_id.as_local() {
|
||||
self.local_macro_def_scopes[&id]
|
||||
} else {
|
||||
@@ -186,15 +186,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
pub(crate) fn build_reduced_graph(
|
||||
&mut self,
|
||||
fragment: &AstFragment,
|
||||
parent_scope: ParentScope<'a>,
|
||||
) -> MacroRulesScopeRef<'a> {
|
||||
parent_scope: ParentScope<'ra>,
|
||||
) -> MacroRulesScopeRef<'ra> {
|
||||
collect_definitions(self, fragment, parent_scope.expansion);
|
||||
let mut visitor = BuildReducedGraphVisitor { r: self, parent_scope };
|
||||
fragment.visit_with(&mut visitor);
|
||||
visitor.parent_scope.macro_rules
|
||||
}
|
||||
|
||||
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
||||
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'ra>) {
|
||||
for child in self.tcx.module_children(module.def_id()) {
|
||||
let parent_scope = ParentScope::module(module, self);
|
||||
self.build_reduced_graph_for_external_crate_res(child, parent_scope)
|
||||
@@ -205,7 +205,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
fn build_reduced_graph_for_external_crate_res(
|
||||
&mut self,
|
||||
child: &ModChild,
|
||||
parent_scope: ParentScope<'a>,
|
||||
parent_scope: ParentScope<'ra>,
|
||||
) {
|
||||
let parent = parent_scope.module;
|
||||
let ModChild { ident, res, vis, ref reexport_chain } = *child;
|
||||
@@ -273,18 +273,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
struct BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
r: &'b mut Resolver<'a, 'tcx>,
|
||||
parent_scope: ParentScope<'a>,
|
||||
struct BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
||||
r: &'a mut Resolver<'ra, 'tcx>,
|
||||
parent_scope: ParentScope<'ra>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for BuildReducedGraphVisitor<'a, '_, 'tcx> {
|
||||
fn as_mut(&mut self) -> &mut Resolver<'a, 'tcx> {
|
||||
impl<'ra, 'tcx> AsMut<Resolver<'ra, 'tcx>> for BuildReducedGraphVisitor<'_, 'ra, 'tcx> {
|
||||
fn as_mut(&mut self) -> &mut Resolver<'ra, 'tcx> {
|
||||
self.r
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
||||
fn res(&self, def_id: impl Into<DefId>) -> Res {
|
||||
let def_id = def_id.into();
|
||||
Res::Def(self.r.tcx.def_kind(def_id), def_id)
|
||||
@@ -424,7 +424,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
fn add_import(
|
||||
&mut self,
|
||||
module_path: Vec<Segment>,
|
||||
kind: ImportKind<'a>,
|
||||
kind: ImportKind<'ra>,
|
||||
span: Span,
|
||||
item: &ast::Item,
|
||||
root_span: Span,
|
||||
@@ -752,7 +752,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
/// Constructs the reduced graph for one item.
|
||||
fn build_reduced_graph_for_item(&mut self, item: &'b Item) {
|
||||
fn build_reduced_graph_for_item(&mut self, item: &'a Item) {
|
||||
let parent_scope = &self.parent_scope;
|
||||
let parent = parent_scope.module;
|
||||
let expansion = parent_scope.expansion;
|
||||
@@ -918,7 +918,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
item: &Item,
|
||||
local_def_id: LocalDefId,
|
||||
vis: ty::Visibility,
|
||||
parent: Module<'a>,
|
||||
parent: Module<'ra>,
|
||||
) {
|
||||
let ident = item.ident;
|
||||
let sp = item.span;
|
||||
@@ -1040,7 +1040,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
fn add_macro_use_binding(
|
||||
&mut self,
|
||||
name: Symbol,
|
||||
binding: NameBinding<'a>,
|
||||
binding: NameBinding<'ra>,
|
||||
span: Span,
|
||||
allow_shadowing: bool,
|
||||
) {
|
||||
@@ -1050,7 +1050,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
/// Returns `true` if we should consider the underlying `extern crate` to be used.
|
||||
fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool {
|
||||
fn process_macro_use_imports(&mut self, item: &Item, module: Module<'ra>) -> bool {
|
||||
let mut import_all = None;
|
||||
let mut single_imports = Vec::new();
|
||||
for attr in &item.attrs {
|
||||
@@ -1188,7 +1188,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
|
||||
/// Visit invocation in context in which it can emit a named item (possibly `macro_rules`)
|
||||
/// directly into its parent scope's module.
|
||||
fn visit_invoc_in_module(&mut self, id: NodeId) -> MacroRulesScopeRef<'a> {
|
||||
fn visit_invoc_in_module(&mut self, id: NodeId) -> MacroRulesScopeRef<'ra> {
|
||||
let invoc_id = self.visit_invoc(id);
|
||||
self.parent_scope.module.unexpanded_invocations.borrow_mut().insert(invoc_id);
|
||||
self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Invocation(invoc_id))
|
||||
@@ -1221,7 +1221,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> {
|
||||
fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'ra> {
|
||||
let parent_scope = self.parent_scope;
|
||||
let expansion = parent_scope.expansion;
|
||||
let feed = self.r.feed(item.id);
|
||||
@@ -1308,7 +1308,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
|
||||
macro_rules! method {
|
||||
($visit:ident: $ty:ty, $invoc:path, $walk:ident) => {
|
||||
fn $visit(&mut self, node: &'b $ty) {
|
||||
fn $visit(&mut self, node: &'a $ty) {
|
||||
if let $invoc(..) = node.kind {
|
||||
self.visit_invoc(node.id);
|
||||
} else {
|
||||
@@ -1318,12 +1318,12 @@ macro_rules! method {
|
||||
};
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
||||
method!(visit_expr: ast::Expr, ast::ExprKind::MacCall, walk_expr);
|
||||
method!(visit_pat: ast::Pat, ast::PatKind::MacCall, walk_pat);
|
||||
method!(visit_ty: ast::Ty, ast::TyKind::MacCall, walk_ty);
|
||||
|
||||
fn visit_item(&mut self, item: &'b Item) {
|
||||
fn visit_item(&mut self, item: &'a Item) {
|
||||
let orig_module_scope = self.parent_scope.module;
|
||||
self.parent_scope.macro_rules = match item.kind {
|
||||
ItemKind::MacroDef(..) => {
|
||||
@@ -1357,7 +1357,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
self.parent_scope.module = orig_module_scope;
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, stmt: &'b ast::Stmt) {
|
||||
fn visit_stmt(&mut self, stmt: &'a ast::Stmt) {
|
||||
if let ast::StmtKind::MacCall(..) = stmt.kind {
|
||||
self.parent_scope.macro_rules = self.visit_invoc_in_module(stmt.id);
|
||||
} else {
|
||||
@@ -1365,7 +1365,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, foreign_item: &'b ForeignItem) {
|
||||
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
|
||||
if let ForeignItemKind::MacCall(_) = foreign_item.kind {
|
||||
self.visit_invoc_in_module(foreign_item.id);
|
||||
return;
|
||||
@@ -1375,7 +1375,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
visit::walk_item(self, foreign_item);
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, block: &'b Block) {
|
||||
fn visit_block(&mut self, block: &'a Block) {
|
||||
let orig_current_module = self.parent_scope.module;
|
||||
let orig_current_macro_rules_scope = self.parent_scope.macro_rules;
|
||||
self.build_reduced_graph_for_block(block);
|
||||
@@ -1384,7 +1384,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
self.parent_scope.macro_rules = orig_current_macro_rules_scope;
|
||||
}
|
||||
|
||||
fn visit_assoc_item(&mut self, item: &'b AssocItem, ctxt: AssocCtxt) {
|
||||
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
|
||||
if let AssocItemKind::MacCall(_) = item.kind {
|
||||
match ctxt {
|
||||
AssocCtxt::Trait => {
|
||||
@@ -1440,7 +1440,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
visit::walk_assoc_item(self, item, ctxt);
|
||||
}
|
||||
|
||||
fn visit_attribute(&mut self, attr: &'b ast::Attribute) {
|
||||
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
|
||||
if !attr.is_doc_comment() && attr::is_builtin_attr(attr) {
|
||||
self.r
|
||||
.builtin_attrs
|
||||
@@ -1449,7 +1449,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
visit::walk_attribute(self, attr);
|
||||
}
|
||||
|
||||
fn visit_arm(&mut self, arm: &'b ast::Arm) {
|
||||
fn visit_arm(&mut self, arm: &'a ast::Arm) {
|
||||
if arm.is_placeholder {
|
||||
self.visit_invoc(arm.id);
|
||||
} else {
|
||||
@@ -1457,7 +1457,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_expr_field(&mut self, f: &'b ast::ExprField) {
|
||||
fn visit_expr_field(&mut self, f: &'a ast::ExprField) {
|
||||
if f.is_placeholder {
|
||||
self.visit_invoc(f.id);
|
||||
} else {
|
||||
@@ -1465,7 +1465,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_pat_field(&mut self, fp: &'b ast::PatField) {
|
||||
fn visit_pat_field(&mut self, fp: &'a ast::PatField) {
|
||||
if fp.is_placeholder {
|
||||
self.visit_invoc(fp.id);
|
||||
} else {
|
||||
@@ -1473,7 +1473,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_generic_param(&mut self, param: &'b ast::GenericParam) {
|
||||
fn visit_generic_param(&mut self, param: &'a ast::GenericParam) {
|
||||
if param.is_placeholder {
|
||||
self.visit_invoc(param.id);
|
||||
} else {
|
||||
@@ -1481,7 +1481,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_param(&mut self, p: &'b ast::Param) {
|
||||
fn visit_param(&mut self, p: &'a ast::Param) {
|
||||
if p.is_placeholder {
|
||||
self.visit_invoc(p.id);
|
||||
} else {
|
||||
@@ -1489,7 +1489,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_field_def(&mut self, sf: &'b ast::FieldDef) {
|
||||
fn visit_field_def(&mut self, sf: &'a ast::FieldDef) {
|
||||
if sf.is_placeholder {
|
||||
self.visit_invoc(sf.id);
|
||||
} else {
|
||||
@@ -1501,7 +1501,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
|
||||
// Constructs the reduced graph for one variant. Variants exist in the
|
||||
// type and value namespaces.
|
||||
fn visit_variant(&mut self, variant: &'b ast::Variant) {
|
||||
fn visit_variant(&mut self, variant: &'a ast::Variant) {
|
||||
if variant.is_placeholder {
|
||||
self.visit_invoc_in_module(variant.id);
|
||||
return;
|
||||
@@ -1542,7 +1542,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
visit::walk_variant(self, variant);
|
||||
}
|
||||
|
||||
fn visit_crate(&mut self, krate: &'b ast::Crate) {
|
||||
fn visit_crate(&mut self, krate: &'a ast::Crate) {
|
||||
if krate.is_placeholder {
|
||||
self.visit_invoc_in_module(krate.id);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user