Merge BuildReducedGraphVisitor initialization into DefPathVisitor

This commit is contained in:
Oli Scherer
2026-02-21 20:05:23 +00:00
committed by Oli Scherer
parent 8a4f0dfb62
commit 393f3e0110
2 changed files with 17 additions and 21 deletions
@@ -31,7 +31,7 @@
use tracing::debug;
use crate::Namespace::{MacroNS, TypeNS, ValueNS};
use crate::def_collector::collect_definitions;
use crate::def_collector::{DefCollector, collect_definitions};
use crate::diagnostics::StructCtor;
use crate::imports::{ImportData, ImportKind, OnUnknownData};
use crate::macros::{MacroRulesDecl, MacroRulesScope, MacroRulesScopeRef};
@@ -242,10 +242,7 @@ pub(crate) fn build_reduced_graph(
fragment: &AstFragment,
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
collect_definitions(self, fragment, parent_scope)
}
pub(crate) fn build_reduced_graph_external(&self, module: ExternModule<'ra>) {
@@ -364,18 +361,13 @@ fn build_reduced_graph_for_external_crate_res(
}
}
struct BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
r: &'a mut Resolver<'ra, 'tcx>,
parent_scope: ParentScope<'ra>,
}
impl<'ra, 'tcx> AsMut<Resolver<'ra, 'tcx>> for BuildReducedGraphVisitor<'_, 'ra, 'tcx> {
impl<'ra, 'tcx> AsMut<Resolver<'ra, 'tcx>> for DefCollector<'_, 'ra, 'tcx> {
fn as_mut(&mut self) -> &mut Resolver<'ra, 'tcx> {
self.r
}
}
impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
impl<'a, 'ra, 'tcx> DefCollector<'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)
@@ -1387,7 +1379,7 @@ fn $visit(&mut self, node: &'a $ty) {
};
}
impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
impl<'a, 'ra, 'tcx> DefCollector<'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);
+12 -8
View File
@@ -13,24 +13,28 @@
use rustc_span::{Span, Symbol, sym};
use tracing::{debug, instrument};
use crate::{ConstArgContext, ImplTraitContext, InvocationParent, Resolver};
use crate::macros::MacroRulesScopeRef;
use crate::{ConstArgContext, ImplTraitContext, InvocationParent, ParentScope, Resolver};
pub(crate) fn collect_definitions(
resolver: &mut Resolver<'_, '_>,
pub(crate) fn collect_definitions<'ra>(
resolver: &mut Resolver<'ra, '_>,
fragment: &AstFragment,
expansion: LocalExpnId,
) {
parent_scope: ParentScope<'ra>,
) -> MacroRulesScopeRef<'ra> {
let expansion = parent_scope.expansion;
let invocation_parent = resolver.invocation_parents[&expansion];
debug!("new fragment to visit with invocation_parent: {invocation_parent:?}");
let mut visitor = DefCollector { r: resolver, expansion, invocation_parent };
let mut visitor = DefCollector { r: resolver, expansion, invocation_parent, parent_scope };
fragment.visit_with(&mut visitor);
visitor.parent_scope.macro_rules
}
/// Creates `DefId`s for nodes in the AST.
struct DefCollector<'a, 'ra, 'tcx> {
r: &'a mut Resolver<'ra, 'tcx>,
pub(crate) struct DefCollector<'a, 'ra, 'tcx> {
pub(crate) r: &'a mut Resolver<'ra, 'tcx>,
invocation_parent: InvocationParent,
expansion: LocalExpnId,
pub(crate) parent_scope: ParentScope<'ra>,
}
impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {