diff options
| author | Michael Goulet <michael@errs.io> | 2025-06-18 17:57:22 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-06-25 15:42:11 +0000 |
| commit | 8cd3fa04e2e023967cf2cfe3e4170b636fd25019 (patch) | |
| tree | 42fc183b7cee5f294bde109c934bf417619062f0 /compiler/rustc_expand | |
| parent | 2801f9aaf9b7580d9b230b532b0700709857cc88 (diff) | |
| download | rust-8cd3fa04e2e023967cf2cfe3e4170b636fd25019.tar.gz rust-8cd3fa04e2e023967cf2cfe3e4170b636fd25019.zip | |
Don't give APITs names with macro expansion placeholder fragments in it
Diffstat (limited to 'compiler/rustc_expand')
| -rw-r--r-- | compiler/rustc_expand/src/base.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/expand.rs | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 7a29f8c9fbd..fe76d9e0b64 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1118,6 +1118,10 @@ pub trait ResolverExpand { trait_def_id: DefId, impl_def_id: LocalDefId, ) -> Result<Vec<(Ident, Option<Ident>)>, Indeterminate>; + + /// Record the name of an opaque `Ty::ImplTrait` pre-expansion so that it can be used + /// to generate an item name later that does not reference placeholder macros. + fn insert_impl_trait_name(&mut self, id: NodeId, name: Symbol); } pub trait LintStoreExpand { diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 0474413e762..2de09aa1a28 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1778,6 +1778,16 @@ impl InvocationCollectorNode for ast::Ty { fragment.make_ty() } fn walk(&mut self, collector: &mut InvocationCollector<'_, '_>) { + // Save the pre-expanded name of this `ImplTrait`, so that later when defining + // an APIT we use a name that doesn't have any placeholder fragments in it. + if let ast::TyKind::ImplTrait(..) = self.kind { + // HACK: pprust breaks strings with newlines when the type + // gets too long. We don't want these to show up in compiler + // output or built artifacts, so replace them here... + // Perhaps we should instead format APITs more robustly. + let name = Symbol::intern(&pprust::ty_to_string(self).replace('\n', " ")); + collector.cx.resolver.insert_impl_trait_name(self.id, name); + } walk_ty(collector, self) } fn is_mac_call(&self) -> bool { |
