<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>E0301 on ErrorVault — Developer Error Code Dictionary</title>
    <link>https://errorvault.dev/tags/e0301/</link>
    <description>Recent content in E0301 on ErrorVault — Developer Error Code Dictionary</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 13 Jul 2026 05:32:04 +0800</lastBuildDate>
    <atom:link href="https://errorvault.dev/tags/e0301/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Fix E0301: Mutable Immutable Borrow in Rust</title>
      <link>https://errorvault.dev/rust/rust-e0301-mutable-immutable-borrow/</link>
      <pubDate>Mon, 13 Jul 2026 05:32:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0301-mutable-immutable-borrow/</guid>
      <description>&lt;h2 id=&#34;1-symptoms&#34;&gt;1. Symptoms&lt;/h2&gt;&#xA;&lt;p&gt;The Rust compiler emits error E0301 when you attempt to mutate a value while an immutable borrow is active. This violation occurs when your code tries to reassign, modify, or take a mutable reference to a variable that is currently borrowed immutably.&lt;/p&gt;&#xA;&lt;p&gt;Typical compiler output for this error looks like:&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-mysql&#34; data-lang=&#34;mysql&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error[E0301]: cannot assign &lt;span style=&#34;color:#ff79c6&#34;&gt;to&lt;/span&gt; data &lt;span style=&#34;color:#ff79c6&#34;&gt;in&lt;/span&gt; a borrowed reference&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#ff79c6&#34;&gt;--&amp;gt;&lt;/span&gt; src&lt;span style=&#34;color:#ff79c6&#34;&gt;/&lt;/span&gt;main.rs:&lt;span style=&#34;color:#bd93f9&#34;&gt;5&lt;/span&gt;:&lt;span style=&#34;color:#bd93f9&#34;&gt;5&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bd93f9&#34;&gt;4&lt;/span&gt;  &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;     let y &lt;span style=&#34;color:#ff79c6&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ff79c6&#34;&gt;&amp;amp;&lt;/span&gt;x;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;             &lt;span style=&#34;color:#ff79c6&#34;&gt;-&lt;/span&gt; borrow of &lt;span style=&#34;color:#ff79c6&#34;&gt;`&lt;/span&gt;x&lt;span style=&#34;color:#ff79c6&#34;&gt;`&lt;/span&gt; occurs here&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bd93f9&#34;&gt;5&lt;/span&gt;  &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;     x &lt;span style=&#34;color:#ff79c6&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#bd93f9&#34;&gt;10&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;     &lt;span style=&#34;color:#ff79c6&#34;&gt;^^^^^^&lt;/span&gt; assignment &lt;span style=&#34;color:#ff79c6&#34;&gt;to&lt;/span&gt; borrowed &lt;span style=&#34;color:#ff79c6&#34;&gt;`&lt;/span&gt;x&lt;span style=&#34;color:#ff79c6&#34;&gt;`&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#ff79c6&#34;&gt;=&lt;/span&gt; note: this error occurs &lt;span style=&#34;color:#ff79c6&#34;&gt;in&lt;/span&gt; the generation of the MIR &lt;span style=&#34;color:#ff79c6&#34;&gt;for&lt;/span&gt; this function&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The error message explicitly identifies where the borrow occurs and where the invalid assignment is attempted. You may also encounter variations such as &amp;ldquo;cannot use mutably borrowed variable as mutable&amp;rdquo; or &amp;ldquo;cannot assign to &lt;code&gt;x&lt;/code&gt; because it is also borrowed&amp;rdquo;. The compiler always marks the exact line of the problematic mutation and points to the borrow site that prevents the operation.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
