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

Wrong type name while reporting error #42509

Closed
achanda opened this issue Jun 7, 2017 · 3 comments
Closed

Wrong type name while reporting error #42509

achanda opened this issue Jun 7, 2017 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@achanda
Copy link
Contributor

achanda commented Jun 7, 2017

This piece of code gives the following error

use std::path::Path;

pub struct Foo {
    id: i32,
    path: Path
}

impl Foo {
    pub fn new() -> Foo {
        Foo{id: 42, path: Path::new()}
    }
}

fn main() {
    let b = Foo::new();
}
$ rustc test.rs
error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied in `Foo`
 --> test.rs:9:21
  |
9 |     pub fn new() -> Foo {
  |                     ^^^ `[u8]` does not have a constant size known at compile-time
  |
  = help: within `Foo`, the trait `std::marker::Sized` is not implemented for `[u8]`
  = note: required because it appears within the type `Foo`
  = note: the return type of a function must have a statically known size

error[E0061]: this function takes 1 parameter but 0 parameters were supplied
  --> test.rs:10:27
   |
10 |         Foo{id: 42, path: Path::new()}
   |                           ^^^^^^^^^^^ expected 1 parameter

error[E0308]: mismatched types
  --> test.rs:10:27
   |
10 |         Foo{id: 42, path: Path::new()}
   |                           ^^^^^^^^^^^ expected struct `std::path::Path`, found reference
   |
   = note: expected type `std::path::Path`
              found type `&std::path::Path`

error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied in `Foo`
  --> test.rs:10:9
   |
10 |         Foo{id: 42, path: Path::new()}
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `[u8]` does not have a constant size known at compile-time
   |
   = help: within `Foo`, the trait `std::marker::Sized` is not implemented for `[u8]`
   = note: required because it appears within the type `Foo`
   = note: structs must have a statically known size to be initialized

error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied in `Foo`
  --> test.rs:15:9
   |
15 |     let b = Foo::new();
   |         ^ `[u8]` does not have a constant size known at compile-time
   |
   = help: within `Foo`, the trait `std::marker::Sized` is not implemented for `[u8]`
   = note: required because it appears within the type `Foo`
   = note: all local variables must have a statically known size

error: aborting due to previous error(s)

This is a bit confusing since the span points to Foo but the message says [u8]. The ergonomics will be nicer if the message said Foo. It will be easier to debug that way.

Meta:

$ rustc --version
rustc 1.19.0-nightly (76242aebb 2017-06-06)
@Mark-Simulacrum
Copy link
Member

The message does say " = help: within Foo, the trait std::marker::Sized is not implemented for [u8]" but really, there is no [u8] within Foo, just Path, which is internally (on unix, IIRC) [u8]

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. C-bug Category: This is a bug. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 26, 2017
@estebank
Copy link
Contributor

CC #23286

@estebank
Copy link
Contributor

Current output still mentions [u8] in the main message, but clarifies things a bit:

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
 --> src/main.rs:9:21
  |
9 |     pub fn new() -> Foo {
  |                     ^^^ doesn't have a size known at compile-time
  |
  = help: within `Foo`, the trait `std::marker::Sized` is not implemented for `[u8]`
  = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
  = note: required because it appears within the type `Foo`
  = note: the return type of a function must have a statically known size

error[E0061]: this function takes 1 parameter but 0 parameters were supplied
  --> src/main.rs:10:27
   |
10 |         Foo{id: 42, path: Path::new()}
   |                           ^^^^^^^^^^^ expected 1 parameter

error[E0308]: mismatched types
  --> src/main.rs:10:27
   |
10 |         Foo{id: 42, path: Path::new()}
   |                           ^^^^^^^^^^^ expected struct `std::path::Path`, found reference
   |
   = note: expected type `std::path::Path`
              found type `&std::path::Path`

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
  --> src/main.rs:10:9
   |
10 |         Foo{id: 42, path: Path::new()}
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: within `Foo`, the trait `std::marker::Sized` is not implemented for `[u8]`
   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
   = note: required because it appears within the type `Foo`
   = note: structs must have a statically known size to be initialized

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
  --> src/main.rs:15:9
   |
15 |     let b = Foo::new();
   |         ^ doesn't have a size known at compile-time
   |
   = help: within `Foo`, the trait `std::marker::Sized` is not implemented for `[u8]`
   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
   = note: required because it appears within the type `Foo`
   = note: all local variables must have a statically known size
   = help: unsized locals are gated as an unstable feature

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
  --> src/main.rs:15:13
   |
15 |     let b = Foo::new();
   |             ^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: within `Foo`, the trait `std::marker::Sized` is not implemented for `[u8]`
   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
   = note: required because it appears within the type `Foo`
   = note: the return type of a function must have a statically known size

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 C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants