Rollup merge of #148808 - nnethercote:resolve-cleanups, r=chenyukang,petrochenkov

Some resolve cleanups

Minor improvements I found while looking over this code.

r? ```````@petrochenkov```````
This commit is contained in:
Stuart Cook
2025-11-14 13:14:00 +11:00
committed by GitHub
3 changed files with 23 additions and 36 deletions
+3
View File
@@ -1099,6 +1099,9 @@ pub fn expn_data(
pub struct DeriveResolution {
pub path: ast::Path,
pub item: Annotatable,
// FIXME: currently this field is only used in `is_none`/`is_some` conditions. However, the
// `Arc<SyntaxExtension>` will be used if the FIXME in `MacroExpander::fully_expand_fragment`
// is completed.
pub exts: Option<Arc<SyntaxExtension>>,
pub is_const: bool,
}
+1 -4
View File
@@ -458,14 +458,11 @@ struct Flags: u8 {
let mut result = Err(Determinacy::Determined);
for derive in parent_scope.derives {
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
match this.reborrow().resolve_macro_path(
match this.reborrow().resolve_derive_macro_path(
derive,
MacroKind::Derive,
parent_scope,
true,
force,
ignore_import,
None,
) {
Ok((Some(ext), _)) => {
if ext.helper_attrs.contains(&ident.name) {
+19 -32
View File
@@ -396,14 +396,11 @@ fn resolve_derives(
for (i, resolution) in entry.resolutions.iter_mut().enumerate() {
if resolution.exts.is_none() {
resolution.exts = Some(
match self.cm().resolve_macro_path(
match self.cm().resolve_derive_macro_path(
&resolution.path,
MacroKind::Derive,
&parent_scope,
true,
force,
None,
None,
) {
Ok((Some(ext), _)) => {
if !ext.helper_attrs.is_empty() {
@@ -571,7 +568,6 @@ fn smart_resolve_macro_path(
path,
kind,
parent_scope,
true,
force,
deleg_impl,
invoc_in_mod_inert_attr.map(|def_id| (def_id, node_id)),
@@ -713,26 +709,22 @@ fn smart_resolve_macro_path(
Ok((ext, res))
}
pub(crate) fn resolve_macro_path<'r>(
pub(crate) fn resolve_derive_macro_path<'r>(
self: CmResolver<'r, 'ra, 'tcx>,
path: &ast::Path,
kind: MacroKind,
parent_scope: &ParentScope<'ra>,
trace: bool,
force: bool,
ignore_import: Option<Import<'ra>>,
suggestion_span: Option<Span>,
) -> Result<(Option<Arc<SyntaxExtension>>, Res), Determinacy> {
self.resolve_macro_or_delegation_path(
path,
kind,
MacroKind::Derive,
parent_scope,
trace,
force,
None,
None,
ignore_import,
suggestion_span,
None,
)
}
@@ -741,7 +733,6 @@ fn resolve_macro_or_delegation_path<'r>(
ast_path: &ast::Path,
kind: MacroKind,
parent_scope: &ParentScope<'ra>,
trace: bool,
force: bool,
deleg_impl: Option<LocalDefId>,
invoc_in_mod_inert_attr: Option<(LocalDefId, NodeId)>,
@@ -780,16 +771,14 @@ fn resolve_macro_or_delegation_path<'r>(
PathResult::Module(..) => unreachable!(),
};
if trace {
self.multi_segment_macro_resolutions.borrow_mut(&self).push((
path,
path_span,
kind,
*parent_scope,
res.ok(),
ns,
));
}
self.multi_segment_macro_resolutions.borrow_mut(&self).push((
path,
path_span,
kind,
*parent_scope,
res.ok(),
ns,
));
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
res
@@ -807,15 +796,13 @@ fn resolve_macro_or_delegation_path<'r>(
return Err(Determinacy::Undetermined);
}
if trace {
self.single_segment_macro_resolutions.borrow_mut(&self).push((
path[0].ident,
kind,
*parent_scope,
binding.ok(),
suggestion_span,
));
}
self.single_segment_macro_resolutions.borrow_mut(&self).push((
path[0].ident,
kind,
*parent_scope,
binding.ok(),
suggestion_span,
));
let res = binding.map(|binding| binding.res());
self.prohibit_imported_non_macro_attrs(binding.ok(), res.ok(), path_span);