<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Borrowing on ErrorVault — Developer Error Code Dictionary</title>
    <link>https://errorvault.dev/tags/borrowing/</link>
    <description>Recent content in Borrowing on ErrorVault — Developer Error Code Dictionary</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 30 Jul 2026 12:44:04 +0800</lastBuildDate>
    <atom:link href="https://errorvault.dev/tags/borrowing/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Fix E0386: Attempted to access value of moved or borrowed resource</title>
      <link>https://errorvault.dev/rust/rust-e0386-attempted-to-access-value-of-moved-or-borrowed-resource/</link>
      <pubDate>Thu, 30 Jul 2026 12:44:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0386-attempted-to-access-value-of-moved-or-borrowed-resource/</guid>
      <description>&lt;h1 id=&#34;fix-e0386-attempted-to-access-value-of-moved-or-borrowed-resource&#34;&gt;Fix E0386: Attempted to Access Value of Moved or Borrowed Resource&lt;/h1&gt;&#xA;&lt;p&gt;Rust&amp;rsquo;s ownership system is one of the language&amp;rsquo;s most powerful features, enabling memory safety without garbage collection. However, this strict ownership model means the compiler will reject code that attempts to use a value after it has been transferred to another owner or loaned out through a reference. Error E0386 specifically signals that you tried to access a value that no longer belongs to the current scope because ownership has moved or a borrow is active.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fix E0806: Closure Captures Variables Invalid for Current Function</title>
      <link>https://errorvault.dev/rust/rust-e0806-closure-captures-invalid-variables/</link>
      <pubDate>Tue, 28 Jul 2026 07:56:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0806-closure-captures-invalid-variables/</guid>
      <description>&lt;h2 id=&#34;1-symptoms&#34;&gt;1. Symptoms&lt;/h2&gt;&#xA;&lt;p&gt;When Rust encounters error E0806, you will see compilation failure with a message similar to the following:&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-rust&#34; data-lang=&#34;rust&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error[E0806]: &lt;span style=&#34;color:#50fa7b&#34;&gt;closure&lt;/span&gt; may outlive the current function, but it may only capture&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;variables that are valid &lt;span style=&#34;color:#ff79c6&#34;&gt;for&lt;/span&gt; the current function&#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;-&amp;gt; &lt;span style=&#34;color:#50fa7b&#34;&gt;src&lt;/span&gt;&lt;span style=&#34;color:#ff79c6&#34;&gt;/&lt;/span&gt;main.rs:&lt;span style=&#34;color:#bd93f9&#34;&gt;6&lt;/span&gt;:&lt;span style=&#34;color:#bd93f9&#34;&gt;17&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;6&lt;/span&gt;  &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;     &lt;span style=&#34;color:#8be9fd;font-style:italic&#34;&gt;let&lt;/span&gt; cl &lt;span style=&#34;color:#ff79c6&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ff79c6&#34;&gt;||&lt;/span&gt; &lt;span style=&#34;color:#50fa7b&#34;&gt;println!&lt;/span&gt;(&lt;span style=&#34;color:#f1fa8c&#34;&gt;&amp;#34;captured: &lt;/span&gt;&lt;span style=&#34;color:#f1fa8c&#34;&gt;{}&lt;/span&gt;&lt;span style=&#34;color:#f1fa8c&#34;&gt;&amp;#34;&lt;/span&gt;, captured);&#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;&#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;7&lt;/span&gt;  &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;     cl();&#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;8&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;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;note: &lt;span style=&#34;color:#50fa7b&#34;&gt;closure&lt;/span&gt; captures `captured` which is referenced by this closure&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The compiler indicates that the closure captures a variable that does not have a lifetime extending beyond the current function&amp;rsquo;s scope. In more complex scenarios with attempted return values, you might see additional notes:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fix E0503: Lifetime Mismatch Error in Rust</title>
      <link>https://errorvault.dev/rust/rust-e0503-lifetime-mismatch/</link>
      <pubDate>Mon, 27 Jul 2026 12:44:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0503-lifetime-mismatch/</guid>
      <description>&lt;h2 id=&#34;1-symptoms&#34;&gt;1. Symptoms&lt;/h2&gt;&#xA;&lt;p&gt;The Rust compiler emits error E0503 when it detects a violation of lifetime requirements. The error message typically appears as follows in the compiler output:&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-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error[E0503]: error detected&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  --&amp;gt; src/main.rs:X:Y&#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;X  |     /// description&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   |              ^^^^^^ expected lifetime&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Y  | }&#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;   = note: this is a bug in the compiler, please report it&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In practice, this error manifests when you attempt to return a reference whose lifetime cannot be guaranteed to satisfy the expected lifetime constraint. The compiler will reject the code because the borrowed data may not outlive the reference pointing to it. Common symptomatic patterns include functions that return references to locally created values, structs that hold references with improperly constrained lifetimes, and functions returning values derived from borrowed input parameters without proper lifetime annotation.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fix E0310: The Lifetime of the Destination Pointer Must Be Specified</title>
      <link>https://errorvault.dev/rust/rust-e0310-lifetime-destination-pointer/</link>
      <pubDate>Fri, 17 Jul 2026 19:56:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0310-lifetime-destination-pointer/</guid>
      <description>&lt;h1 id=&#34;fix-e0310-the-lifetime-of-the-destination-pointer-must-be-specified&#34;&gt;Fix E0310: The Lifetime of the Destination Pointer Must Be Specified&lt;/h1&gt;&#xA;&lt;p&gt;Rust&amp;rsquo;s ownership and borrowing system is one of its defining features, providing memory safety guarantees at compile time without requiring garbage collection. However, when working with raw pointers in unsafe code, the compiler sometimes cannot infer the necessary lifetime relationships on its own. Error E0310 surfaces in exactly this scenario—when you invoke pointer-manipulation functions like &lt;code&gt;std::ptr::read&lt;/code&gt; or &lt;code&gt;std::ptr::write&lt;/code&gt; and the compiler cannot determine the validity window of the resulting reference.&lt;/p&gt;</description>
    </item>
    <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>
    <item>
      <title>Fix E0713: Borrowed data escapes beyond mutable reference</title>
      <link>https://errorvault.dev/rust/rust-e0713-borrowed-data-escapes-mutable-reference/</link>
      <pubDate>Mon, 06 Jul 2026 15:08:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0713-borrowed-data-escapes-mutable-reference/</guid>
      <description>&lt;h2 id=&#34;1-symptoms&#34;&gt;1. Symptoms&lt;/h2&gt;&#xA;&lt;p&gt;When you encounter Rust compiler error E0713, the compiler produces output similar to the following:&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-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error[E0713]: borrowed data escapes beyond mutable reference&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  --&amp;gt; src/main.rs:12:9&#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 |     let value = do_something(&amp;amp;mut x);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   |                 ^^^^^^^^^^^^^^^^^ borrowed data escapes beyond mutable reference&#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;   = note: this is a special case of borrowed pointer being returned where the lifetime of the pointer is tied to the mutable reference. This typically happens when a closure captures a reference that must outlive the containing function.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;help: consider changing the return type to capture the data with a higher lifetime&#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;   = note: the lifetime from the mutable reference is only valid within the containing function. To fix this, ensure that the lifetime is tied to the output of the function, not the input.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The error message indicates that a borrowed value is escaping the scope of a mutable reference, which violates Rust&amp;rsquo;s ownership and borrowing rules. You may see this error when working with closures, higher-order functions, or custom data structures that manage references across different lifetimes.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fix E0384: Cannot Borrow as Mutable Because `self` is Also Borrowed as Immutable</title>
      <link>https://errorvault.dev/rust/rust-e0384-cannot-borrow-mutable-immutable-borrow/</link>
      <pubDate>Sun, 14 Jun 2026 19:56:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0384-cannot-borrow-mutable-immutable-borrow/</guid>
      <description>&lt;h2 id=&#34;1-symptoms&#34;&gt;1. Symptoms&lt;/h2&gt;&#xA;&lt;p&gt;When attempting to compile Rust code that returns a mutable reference to &lt;code&gt;self&lt;/code&gt; from a method that takes an immutable &lt;code&gt;&amp;amp;self&lt;/code&gt; parameter, the compiler emits error E0384.&lt;/p&gt;&#xA;&lt;p&gt;Typical error messages you&amp;rsquo;ll encounter:&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[E0384]: cannot borrow `self` as mutable because it is also borrowed as immutable&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  --&amp;gt; src/main.rs:10:9&#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;9  |     fn get_mut(&amp;amp;self) -&amp;gt; &amp;amp;mut Self {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   |                      ----- first immutable borrow occurs here&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;10 |         &amp;amp;mut *self&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   |         ^^^^^^^^^ second borrow occurs here due to use of `self` in the return type&#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;   = note: this error occurs in the generation of the v-table for trait implementation&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   = note: the old error code E0501 has been superseded&#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;```text&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error[E0384]: cannot borrow `self` as mutable because it is also borrowed as immutable&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  --&amp;gt; src/lib.rs:15:13&#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;14 |     fn push(&amp;amp;mut self, elem: T) -&amp;gt; &amp;amp;mut T {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   |             --------- first borrow occurs due to use of `self` in the return type&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;15 |         let elem_ref = &amp;amp;mut self.data[self.len];&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   |                        ^^^^^^^^^^^^^^^^^^^^^ second borrow occurs here&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The error specifically states that you cannot borrow &lt;code&gt;self&lt;/code&gt; as mutable because it is &lt;strong&gt;already borrowed as immutable&lt;/strong&gt;. This is a fundamental violation of Rust&amp;rsquo;s borrowing rules, which enforce that you cannot have both an immutable and mutable reference to the same data at the same time.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fix E0745: Rust Compiler Error - Cannot Return Reference to Local Data</title>
      <link>https://errorvault.dev/rust/rust-e0745-cannot-return-reference-to-local-data/</link>
      <pubDate>Tue, 02 Jun 2026 00:44:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0745-cannot-return-reference-to-local-data/</guid>
      <description>&lt;h2 id=&#34;1-symptoms&#34;&gt;1. Symptoms&lt;/h2&gt;&#xA;&lt;p&gt;When the Rust compiler encounters error E0745, you will see a message similar to the following:&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-rust&#34; data-lang=&#34;rust&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error[E0746]: &lt;span style=&#34;color:#50fa7b&#34;&gt;cannot&lt;/span&gt; &lt;span style=&#34;color:#ff79c6&#34;&gt;return&lt;/span&gt; reference to local data `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;-&amp;gt; &lt;span style=&#34;color:#50fa7b&#34;&gt;src&lt;/span&gt;&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;5&lt;/span&gt;  &lt;span style=&#34;color:#ff79c6&#34;&gt;|&lt;/span&gt;     &lt;span style=&#34;color:#ff79c6&#34;&gt;return&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; `x` is a local variable&#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;&#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;            returns a reference to local data&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that the error code is &lt;strong&gt;E0746&lt;/strong&gt; in the compiler output above, but &lt;strong&gt;E0745&lt;/strong&gt; appears for similar scenarios with slight variations in wording:&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-rust&#34; data-lang=&#34;rust&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error[E0745]: &lt;span style=&#34;color:#50fa7b&#34;&gt;missing&lt;/span&gt; lifetime specifier&#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;-&amp;gt; &lt;span style=&#34;color:#50fa7b&#34;&gt;src&lt;/span&gt;&lt;span style=&#34;color:#ff79c6&#34;&gt;/&lt;/span&gt;main.rs:&lt;span style=&#34;color:#bd93f9&#34;&gt;4&lt;/span&gt;:&lt;span style=&#34;color:#bd93f9&#34;&gt;20&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; &lt;span style=&#34;color:#ff79c6&#34;&gt;fn&lt;/span&gt; &lt;span style=&#34;color:#50fa7b&#34;&gt;get_data&lt;/span&gt;() -&amp;gt; &lt;span style=&#34;color:#ff79c6&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&#34;color:#8be9fd&#34;&gt;str&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; expected lifetime parameter&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The code will fail to compile, and the Rust compiler will refuse to generate any binary until the issue is resolved. Common symptoms include:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fix E0595: Closures Cannot Capture Structs with Borrow Checker Restrictions</title>
      <link>https://errorvault.dev/rust/rust-e0595-closures-cannot-capture-structs-borrow-restrictions/</link>
      <pubDate>Fri, 29 May 2026 17:32:04 +0800</pubDate>
      <guid>https://errorvault.dev/rust/rust-e0595-closures-cannot-capture-structs-borrow-restrictions/</guid>
      <description>&lt;h2 id=&#34;1-symptoms&#34;&gt;1. Symptoms&lt;/h2&gt;&#xA;&lt;p&gt;When attempting to use a closure that captures a struct containing non-&lt;code&gt;&#39;static&lt;/code&gt; references, the Rust compiler produces error E0595 with a message indicating that closures cannot capture structs with borrow checker restrictions.&lt;/p&gt;&#xA;&lt;p&gt;Common scenarios where this error manifests:&lt;/p&gt;&#xA;&lt;h3 id=&#34;scenario-1-struct-with-self-referential-lifetime-field&#34;&gt;Scenario 1: Struct with self-referential lifetime field&lt;/h3&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-rust&#34; data-lang=&#34;rust&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ff79c6&#34;&gt;struct&lt;/span&gt; &lt;span style=&#34;color:#50fa7b&#34;&gt;Config&lt;/span&gt;&lt;span style=&#34;color:#ff79c6&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#50fa7b&#34;&gt;&amp;#39;a&lt;/span&gt;&lt;span style=&#34;color:#ff79c6&#34;&gt;&amp;gt;&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    name: &lt;span style=&#34;color:#8be9fd;font-style:italic&#34;&gt;String&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    reference: &lt;span style=&#34;color:#ff79c6&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&#34;color:#50fa7b&#34;&gt;&amp;#39;a&lt;/span&gt; &lt;span style=&#34;color:#8be9fd&#34;&gt;str&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;&lt;span style=&#34;color:#ff79c6&#34;&gt;fn&lt;/span&gt; &lt;span style=&#34;color:#50fa7b&#34;&gt;main&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:#8be9fd;font-style:italic&#34;&gt;let&lt;/span&gt; config &lt;span style=&#34;color:#ff79c6&#34;&gt;=&lt;/span&gt; Config {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        name: &lt;span style=&#34;color:#8be9fd;font-style:italic&#34;&gt;String&lt;/span&gt;::from(&lt;span style=&#34;color:#f1fa8c&#34;&gt;&amp;#34;app&amp;#34;&lt;/span&gt;),&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        reference: &lt;span style=&#34;color:#f1fa8c&#34;&gt;&amp;#34;value&amp;#34;&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;    &lt;span style=&#34;color:#8be9fd;font-style:italic&#34;&gt;let&lt;/span&gt; closure &lt;span style=&#34;color:#ff79c6&#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:#50fa7b&#34;&gt;println!&lt;/span&gt;(&lt;span style=&#34;color:#f1fa8c&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f1fa8c&#34;&gt;{}&lt;/span&gt;&lt;span style=&#34;color:#f1fa8c&#34;&gt;&amp;#34;&lt;/span&gt;, config.reference);&#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;    closure();&#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;&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;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;The compiler reports:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;error[E0595]: closures cannot capture structs with borrow checker restrictions&#xA;&amp;ndash;&amp;gt; src/main.rs:10:17&#xA;|&#xA;10 |     let closure = || {&#xA;|         &amp;mdash;&amp;ndash;^^^^^&#xA;|&#xA;= note: closure may only be used as or returned from the closure&amp;rsquo;s environment,&#xA;so it cannot be stored in a struct or returned from a function&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
