<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Rustc on ErrorVault — Developer Error Code Dictionary</title><link>https://errorvault.dev/platforms/rustc/</link><description>Recent content in Rustc on ErrorVault — Developer Error Code Dictionary</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 05 Oct 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://errorvault.dev/platforms/rustc/feed.xml" rel="self" type="application/rss+xml"/><item><title>Fix E0005: Mismatched field count in Rust pattern matching for structs</title><link>https://errorvault.dev/rust/rust-e0005-field-count-mismatch/</link><pubDate>Sat, 05 Oct 2024 00:00:00 +0000</pubDate><guid>https://errorvault.dev/rust/rust-e0005-field-count-mismatch/</guid><description>&lt;h2 id="1-symptoms">1. Symptoms&lt;/h2>
&lt;h2 id="rust-compiler-error-e0005-occurs-during-pattern-matching-when-the-number-of-fields-in-your-pattern-does-not-match-the-definition-of-the-struct-tuple-struct-or-enum-variant-being-matched-the-error-message-typically-reads">Rust compiler error E0005 occurs during pattern matching when the number of fields in your pattern does not match the definition of the struct, tuple struct, or enum variant being matched. The error message typically reads:&lt;/h2>
&lt;p>error[E0005]: this pattern has X fields, but the corresponding tuple struct/variant &lt;code>Type&lt;/code> has Y field(s)
&amp;ndash;&amp;gt; src/main.rs:LL:CC
|
LL | Type(a) =&amp;gt; {}
| ^^^^^^ expected Y fields, found 1&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-mysql" data-lang="mysql">&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Common triggers include:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">-&lt;/span> Matching a two&lt;span style="color:#ff79c6">-&lt;/span>field struct &lt;span style="color:#ff79c6">with&lt;/span> a single&lt;span style="color:#ff79c6">-&lt;/span>field pattern.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">-&lt;/span> Destructuring tuple structs incorrectly.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">-&lt;/span> &lt;span style="color:#8be9fd">Enum&lt;/span> variants &lt;span style="color:#ff79c6">with&lt;/span> fixed field counts mismatched &lt;span style="color:#ff79c6">in&lt;/span> &lt;span style="color:#ff79c6">`&lt;/span>&lt;span style="color:#ff79c6">match&lt;/span>&lt;span style="color:#ff79c6">`&lt;/span> arms.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">**&lt;/span>Example triggering code:&lt;span style="color:#ff79c6">**&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">```&lt;/span>rust
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#6272a4">#[derive(Debug)]
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#6272a4">&lt;/span>struct Point {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> x: i32,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> y: i32,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>fn &lt;span style="color:#50fa7b">main&lt;/span>() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> let p &lt;span style="color:#ff79c6">=&lt;/span> Point { x: &lt;span style="color:#bd93f9">1&lt;/span>, y: &lt;span style="color:#bd93f9">2&lt;/span> };
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#ff79c6">match&lt;/span> p {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#50fa7b">Point&lt;/span>(x) &lt;span style="color:#ff79c6">=&amp;gt;&lt;/span> println&lt;span style="color:#ff79c6">!&lt;/span>(&lt;span style="color:#f1fa8c">&amp;#34;x: {}&amp;#34;&lt;/span>, x), &lt;span style="color:#ff79c6">//&lt;/span> Error: &lt;span style="color:#bd93f9">1&lt;/span> field vs &lt;span style="color:#bd93f9">2&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> _ &lt;span style="color:#ff79c6">=&amp;gt;&lt;/span> {}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Compilation fails with E0005, halting at pattern validation. Symptoms appear in &lt;code>match&lt;/code>, &lt;code>if let&lt;/code>, or function parameters. IDEs like rust-analyzer highlight mismatches inline. Runtime impact: none, as it&amp;rsquo;s a compile-time check. Frequency: high in beginner code refactoring structs or enums.&lt;/p></description></item><item><title>Fix E0001: Expected item, found semicolon in Rust module</title><link>https://errorvault.dev/rust/rust-e0001-expected-item-found-semicolon/</link><pubDate>Wed, 18 Sep 2024 00:00:00 +0000</pubDate><guid>https://errorvault.dev/rust/rust-e0001-expected-item-found-semicolon/</guid><description>&lt;h1 id="fix-e0001-expected-item-found-semicolon-in-rust-module">Fix E0001: Expected item, found semicolon in Rust module&lt;/h1>
&lt;h2 id="1-symptoms">1. Symptoms&lt;/h2>
&lt;p>Rust compiler error &lt;code>E0001&lt;/code> manifests during parsing when a semicolon (&lt;code>;&lt;/code>) appears in a context expecting a top-level &lt;em>item&lt;/em>. Items in Rust include functions (&lt;code>fn&lt;/code>), structs (&lt;code>struct&lt;/code>), enums (&lt;code>enum&lt;/code>), modules (&lt;code>mod&lt;/code>), traits (&lt;code>trait&lt;/code>), impl blocks (&lt;code>impl&lt;/code>), constants (&lt;code>const&lt;/code>), and statics (&lt;code>static&lt;/code>).&lt;/p>
&lt;p>The error message typically looks like this:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>error[E0001]: expected item, found `;`
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --&amp;gt; src/main.rs:3:1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> |
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>3 | ;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> | ^ expected item
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This occurs at module scope (file or &lt;code>mod&lt;/code> block level), not inside functions where statements are allowed.&lt;/p></description></item></channel></rss>