Skip to content

Misleading error message when trying to use a Vec of an unsized enum as function argument #23371

Closed
@bitvoid

Description

@bitvoid

While fixing some project for latest rust nightly (porting to new IO) I got an misleading error because I used a Path in an enum that was used in a vector as function argument.

use std::path::Path;

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

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






    */
}

fn main() {
    let mut v = Vec::new();
    some_function(&mut v);
}
<anon>:8:1: 17:2 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277]
<anon>:8 fn some_function(arg: &mut Vec<SomeEnum>) {
<anon>:9     /* some whitespace to demonstrate that the line number is also wrong
<anon>:10     
<anon>:11     
<anon>:12     
<anon>:13     
          ...
<anon>:8:1: 17:2 note: `[u8]` does not have a constant size known at compile-time
<anon>:8 fn some_function(arg: &mut Vec<SomeEnum>) {
<anon>:9     /* some whitespace to demonstrate that the line number is also wrong
<anon>:10     
<anon>:11     
<anon>:12     
<anon>:13     
          ...
error: aborting due to previous error

The error complains about a [u8] but there is no [u8] 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.

Error was easily solved by replacing Path with PathBuf once it became clear that Path is the culprit.

http://is.gd/yD8S6w

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions