Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
pub(crate) fn get_macro(&self, res: Res) -> Option<&'ra MacroData> {
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub(crate) fn get_macro(&self, res: Res) -> Option<&'ra MacroData> {
pub(crate) fn get_macro(&self, res: Res) -> Option<&'ra Arc<SyntaxExtension>> {

Looks like the MacroData parts are never actually used.

View changes since the review

match res {
Res::Def(DefKind::Macro(..), def_id) => Some(self.get_macro_by_def_id(def_id)),
Res::NonMacroAttr(_) => Some(self.non_macro_attr),
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is incorrect in the check_reserved_macro_name case as well, not just in resolve_macro_or_delegation_path.
Something like use ignore as cfg; will now be accepted.

I'd rather not make this change in general, it seems error-prone.

View changes since the review

_ => None,
}
}
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ pub struct Resolver<'ra, 'tcx> {
extern_macro_map: CacheRefCell<FxHashMap<DefId, &'ra MacroData>>,
dummy_ext_bang: Arc<SyntaxExtension>,
dummy_ext_derive: Arc<SyntaxExtension>,
non_macro_attr: &'ra MacroData,
non_macro_attr: Arc<SyntaxExtension>,
local_macro_def_scopes: FxHashMap<LocalDefId, LocalModule<'ra>> = default::fx_hash_map(),
ast_transform_scopes: FxHashMap<LocalExpnId, LocalModule<'ra>> = default::fx_hash_map(),
unused_macros: FxIndexMap<LocalDefId, (NodeId, Ident)>,
Expand Down Expand Up @@ -1812,8 +1812,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
extern_macro_map: Default::default(),
dummy_ext_bang: Arc::new(SyntaxExtension::dummy_bang(edition)),
dummy_ext_derive: Arc::new(SyntaxExtension::dummy_derive(edition)),
non_macro_attr: arenas
.alloc_macro(MacroData::new(Arc::new(SyntaxExtension::non_macro_attr(edition)))),
non_macro_attr: Arc::new(SyntaxExtension::non_macro_attr(edition)),
unused_macros: Default::default(),
unused_macro_rules: Default::default(),
single_segment_macro_resolutions: Default::default(),
Expand Down Expand Up @@ -1984,7 +1983,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
match macro_kind {
MacroKind::Bang => Arc::clone(&self.dummy_ext_bang),
MacroKind::Derive => Arc::clone(&self.dummy_ext_derive),
MacroKind::Attr => Arc::clone(&self.non_macro_attr.ext),
MacroKind::Attr => Arc::clone(&self.non_macro_attr),
}
}

Expand Down
32 changes: 18 additions & 14 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,21 +869,25 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
};

let res = res?;
let ext = match deleg_impl {
Some((impl_def_id, star_span)) => match res {
Res::Def(DefKind::Trait, def_id) => {
let edition = self.tcx.sess.edition();
Some(Arc::new(SyntaxExtension::glob_delegation(
def_id,
impl_def_id,
star_span,
edition,
)))
}
_ => None,
},
None => self.get_macro(res).map(|macro_data| Arc::clone(&macro_data.ext)),
let ext = match res {
Res::Def(DefKind::Macro(..), def_id) => {
let md = self.get_macro_by_def_id(def_id);
Some(Arc::clone(&md.ext))
}
Res::Def(DefKind::Trait, def_id) if let Some((impl_def_id, star_span)) = deleg_impl => {
let edition = self.tcx.sess.edition();
Some(Arc::new(SyntaxExtension::glob_delegation(
def_id,
impl_def_id,
star_span,
edition,
)))
}
// Avoid ICE-ing on tool attributes in weird positions like `rustfmt::skip!()`
Res::NonMacroAttr(_) => Some(Arc::clone(&self.non_macro_attr)),
Comment thread
JohnTitor marked this conversation as resolved.
_ => None,
};

Ok((ext, res))
}

Expand Down
Loading