<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Derive-Macro on ErrorVault — Developer Error Code Dictionary</title>
    <link>https://errorvault.dev/tags/derive-macro/</link>
    <description>Recent content in Derive-Macro on ErrorVault — Developer Error Code Dictionary</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 03 Jun 2026 10:20:04 +0800</lastBuildDate>
    <atom:link href="https://errorvault.dev/tags/derive-macro/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Fix E0798: Derive of #[serde]-like attribute should produce an item before calling set_proc_macro_attr</title>
      <link>https://errorvault.dev/rust/rust-e0798-derive-set-proc-macro-attr/</link>
      <pubDate>Wed, 03 Jun 2026 10:20:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0798-derive-set-proc-macro-attr/</guid>
      <description>&lt;h1 id=&#34;fix-e0798-derive-of-serde-like-attribute-should-produce-an-item-before-calling-set_proc_macro_attr&#34;&gt;Fix E0798: Derive of &lt;code&gt;#[serde]&lt;/code&gt;-like attribute should produce an item before calling &lt;code&gt;set_proc_macro_attr&lt;/code&gt;&lt;/h1&gt;&#xA;&lt;h2 id=&#34;1-symptoms&#34;&gt;1. Symptoms&lt;/h2&gt;&#xA;&lt;p&gt;When compiling a Rust project that uses derive macros (commonly with &lt;code&gt;#[serde(Serialize, Deserialize)]&lt;/code&gt; or custom derive macros), you encounter the following error:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error[E0798]: derive of `#[serde]`-like attribute should produce an item before calling `set_proc_macro_attr`&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  --&amp;gt; src/lib.rs:12:1&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   |&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;12 | #[derive(MyCustomDerive)]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   |  ^^^^^^^^^^^^^^^^^^^^^^&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;---&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;The error appears at the `#[derive(...)]` attribute site on a struct, enum, or other item. The compiler message is unambiguous: the derive macro attempted to call `set_proc_macro_attr` (a proc-macro2 function) before producing any output item.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Additional symptoms that may accompany this error:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;```text&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error: aborting due to 1 previous error&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;For more information about this error, try `rustc --explain E0798`.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;The derive macro may fail to expand, leaving the original type untransformed.&lt;/li&gt;&#xA;&lt;li&gt;If the macro is used on multiple items, every invocation triggers the same error.&lt;/li&gt;&#xA;&lt;li&gt;The error is a hard compile-time failure — no binary or library is produced.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Example code that triggers E0798:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
