resolve: Do not call resolve_macro_path from late resolution

`maybe_resolve_path` is less precise in corner cases, but it's only used for diagnostics and error recovery, so it's good enough.
This commit is contained in:
Vadim Petrochenkov 2025-08-08 19:54:27 +03:00
parent 8e7795415a
commit 51eb5ed8f0
4 changed files with 13 additions and 28 deletions

View file

@ -1047,7 +1047,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
let Ok((Some(ext), _)) = this.reborrow().resolve_macro_path(
derive,
Some(MacroKind::Derive),
MacroKind::Derive,
parent_scope,
false,
false,

View file

@ -469,7 +469,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
match this.reborrow().resolve_macro_path(
derive,
Some(MacroKind::Derive),
MacroKind::Derive,
parent_scope,
true,
force,

View file

@ -4315,7 +4315,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
qself,
path,
ns,
path_span,
source.defer_to_typeck(),
finalize,
source,
@ -4438,7 +4437,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
qself: &Option<Box<QSelf>>,
path: &[Segment],
primary_ns: Namespace,
span: Span,
defer_to_typeck: bool,
finalize: Finalize,
source: PathSource<'_, 'ast, 'ra>,
@ -4463,21 +4461,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
assert!(primary_ns != MacroNS);
if qself.is_none() {
let path_seg = |seg: &Segment| PathSegment::from_ident(seg.ident);
let path = Path { segments: path.iter().map(path_seg).collect(), span, tokens: None };
if let Ok((_, res)) = self.r.cm().resolve_macro_path(
&path,
None,
&self.parent_scope,
false,
false,
None,
None,
) {
return Ok(Some(PartialRes::new(res)));
}
if qself.is_none()
&& let PathResult::NonModule(res) =
self.r.cm().maybe_resolve_path(path, Some(MacroNS), &self.parent_scope, None)
{
return Ok(Some(res));
}
Ok(fin_res)

View file

@ -398,7 +398,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
resolution.exts = Some(
match self.cm().resolve_macro_path(
&resolution.path,
Some(MacroKind::Derive),
MacroKind::Derive,
&parent_scope,
true,
force,
@ -563,7 +563,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
) -> Result<(Arc<SyntaxExtension>, Res), Indeterminate> {
let (ext, res) = match self.cm().resolve_macro_or_delegation_path(
path,
Some(kind),
kind,
parent_scope,
true,
force,
@ -710,7 +710,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
pub(crate) fn resolve_macro_path<'r>(
self: CmResolver<'r, 'ra, 'tcx>,
path: &ast::Path,
kind: Option<MacroKind>,
kind: MacroKind,
parent_scope: &ParentScope<'ra>,
trace: bool,
force: bool,
@ -733,7 +733,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
fn resolve_macro_or_delegation_path<'r>(
mut self: CmResolver<'r, 'ra, 'tcx>,
ast_path: &ast::Path,
kind: Option<MacroKind>,
kind: MacroKind,
parent_scope: &ParentScope<'ra>,
trace: bool,
force: bool,
@ -747,7 +747,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// Possibly apply the macro helper hack
if deleg_impl.is_none()
&& kind == Some(MacroKind::Bang)
&& kind == MacroKind::Bang
&& let [segment] = path.as_slice()
&& segment.ident.span.ctxt().outer_expn_data().local_inner_macros
{
@ -775,7 +775,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
};
if trace {
let kind = kind.expect("macro kind must be specified if tracing is enabled");
// FIXME: Should be an output of Speculative Resolution.
self.multi_segment_macro_resolutions.borrow_mut().push((
path,
@ -790,10 +789,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
res
} else {
let scope_set = kind.map_or(ScopeSet::All(MacroNS), ScopeSet::Macro);
let binding = self.reborrow().early_resolve_ident_in_lexical_scope(
path[0].ident,
scope_set,
ScopeSet::Macro(kind),
parent_scope,
None,
force,
@ -805,7 +803,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
if trace {
let kind = kind.expect("macro kind must be specified if tracing is enabled");
// FIXME: Should be an output of Speculative Resolution.
self.single_segment_macro_resolutions.borrow_mut().push((
path[0].ident,