<p dir="auto">While fixing some project for latest rust nightly (porting to new IO) I got an misleading error because I used a <code class="notranslate">Path</code> in an enum that was used in a vector as function argument.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="use std::path::Path;

enum SomeEnum {
    SomeBool(bool),
    SomePath(Path)
}

fn some_function(arg: &amp;mut Vec&lt;SomeEnum&gt;) {
    /* some whitespace to demonstrate that the line number is also wrong






    */
}

fn main() {
    let mut v = Vec::new();
    some_function(&amp;mut v);
}"><pre class="notranslate"><span class="pl-k">use</span> std<span class="pl-kos">::</span>path<span class="pl-kos">::</span><span class="pl-v">Path</span><span class="pl-kos">;</span>

<span class="pl-k">enum</span> <span class="pl-smi">SomeEnum</span> <span class="pl-kos">{</span>
    <span class="pl-v">SomeBool</span><span class="pl-kos">(</span><span class="pl-smi">bool</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
    <span class="pl-v">SomePath</span><span class="pl-kos">(</span><span class="pl-smi">Path</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">some_function</span><span class="pl-kos">(</span><span class="pl-s1">arg</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">Vec</span><span class="pl-kos">&lt;</span><span class="pl-smi">SomeEnum</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-c">/* some whitespace to demonstrate that the line number is also wrong</span>
<span class="pl-c"></span>
<span class="pl-c"></span>
<span class="pl-c"></span>
<span class="pl-c"></span>
<span class="pl-c"></span>
<span class="pl-c"></span>
<span class="pl-c">    */</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> v = <span class="pl-smi">Vec</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">some_function</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> v<span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;anon&gt;:8:1: 17:2 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277]
&lt;anon&gt;:8 fn some_function(arg: &amp;mut Vec&lt;SomeEnum&gt;) {
&lt;anon&gt;:9     /* some whitespace to demonstrate that the line number is also wrong
&lt;anon&gt;:10     
&lt;anon&gt;:11     
&lt;anon&gt;:12     
&lt;anon&gt;:13     
          ...
&lt;anon&gt;:8:1: 17:2 note: `[u8]` does not have a constant size known at compile-time
&lt;anon&gt;:8 fn some_function(arg: &amp;mut Vec&lt;SomeEnum&gt;) {
&lt;anon&gt;:9     /* some whitespace to demonstrate that the line number is also wrong
&lt;anon&gt;:10     
&lt;anon&gt;:11     
&lt;anon&gt;:12     
&lt;anon&gt;:13     
          ...
error: aborting due to previous error"><pre class="notranslate"><code class="notranslate">&lt;anon&gt;:8:1: 17:2 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277]
&lt;anon&gt;:8 fn some_function(arg: &amp;mut Vec&lt;SomeEnum&gt;) {
&lt;anon&gt;:9     /* some whitespace to demonstrate that the line number is also wrong
&lt;anon&gt;:10     
&lt;anon&gt;:11     
&lt;anon&gt;:12     
&lt;anon&gt;:13     
          ...
&lt;anon&gt;:8:1: 17:2 note: `[u8]` does not have a constant size known at compile-time
&lt;anon&gt;:8 fn some_function(arg: &amp;mut Vec&lt;SomeEnum&gt;) {
&lt;anon&gt;:9     /* some whitespace to demonstrate that the line number is also wrong
&lt;anon&gt;:10     
&lt;anon&gt;:11     
&lt;anon&gt;:12     
&lt;anon&gt;:13     
          ...
error: aborting due to previous error
</code></pre></div>
<p dir="auto">The error complains about a <code class="notranslate">[u8]</code> but there is no <code class="notranslate">[u8]</code> in the signature. Also the line number of the error message points to the closing bracket of the function but then goes on and prints the first lines of the function.</p>
<p dir="auto">Error was easily solved by replacing Path with PathBuf once it became clear that <code class="notranslate">Path</code> is the culprit.</p>
<p dir="auto"><a href="http://is.gd/yD8S6w" rel="nofollow">http://is.gd/yD8S6w</a></p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="use std::path::Path;

fn f(p: Path) { }"><pre class="notranslate"><span class="pl-k">use</span> std<span class="pl-kos">::</span>path<span class="pl-kos">::</span><span class="pl-v">Path</span><span class="pl-kos">;</span>

<span class="pl-k">fn</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-s1">p</span><span class="pl-kos">:</span> <span class="pl-smi">Path</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span></pre></div>
<p dir="auto">produces</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="foo.rs:3:6: 3:7 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277]
foo.rs:3 fn f(p: Path) { }
              ^
foo.rs:3:6: 3:7 note: `[u8]` does not have a constant size known at compile-time
foo.rs:3 fn f(p: Path) { }
              ^"><pre class="notranslate"><code class="notranslate">foo.rs:3:6: 3:7 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277]
foo.rs:3 fn f(p: Path) { }
              ^
foo.rs:3:6: 3:7 note: `[u8]` does not have a constant size known at compile-time
foo.rs:3 fn f(p: Path) { }
              ^
</code></pre></div>
<p dir="auto">We should give an explicit hint that <code class="notranslate">Path</code> should be passed by reference. Also the error does not mention <code class="notranslate">Path</code> and the type <code class="notranslate">u8</code> does not appear in the program.</p>
<p dir="auto"><strong>UPDATE:</strong> The message now includes a full stack trace of types, but it would be better to start out with the type the user knows about (<code class="notranslate">Path</code>, in this case) and only discuss <code class="notranslate">[u8]</code> last. -- <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/nikomatsakis/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/nikomatsakis">@nikomatsakis</a></p>