Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bitvoid opened this issue Mar 14, 2015 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@bitvoid
Copy link

bitvoid commented Mar 14, 2015

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

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 18, 2015
@apasel422
Copy link
Contributor

This is a duplicate of #23286.

@Gankra Gankra closed this as completed Jul 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

4 participants