Skip to content

Bogus extra error about unsized variable (the trait bound str: std::marker::Sized is not satisfied) #44504

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

Closed
bluss opened this issue Sep 11, 2017 · 1 comment · Fixed by #64674
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bluss
Copy link
Member

bluss commented Sep 11, 2017

Given code like this (not complete):

extern crate serde_json;
let g1 = vec![0; 16];
let json1 = serde_json::to_pretty_string(&g1).unwrap();
let foo: Foo = serde_json::from_str(&json1).unwrap();

The first error is correct but the second is nonsense:

error[E0425]: cannot find function `to_pretty_string` in module `serde_json`
   --> serialization-tests/tests/serialization.rs:498:35
    |
498 |         let json1 = serde_json::to_pretty_string(&g1).unwrap();
    |                                 ^^^^^^^^^^^^^^^^ not found in `serde_json`

error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
   --> serialization-tests/tests/serialization.rs:498:13
    |
498 |         let json1 = serde_json::to_pretty_string(&g1).unwrap();
    |             ^^^^^ `str` does not have a constant size known at compile-time
    |
    = help: the trait `std::marker::Sized` is not implemented for `str`
    = note: all local variables must have a statically known size

There's an extra error here. json1 is used in a way (with the from_str function) that it should be a str or something that derefs to str. The second error message supposes it is a str, which is nonsense that the user doesn't intend at all. (If the user would only find the right name of the function, they would get a String in the json variable and the next line compiles fine.)

@bluss bluss added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 11, 2017
@bluss bluss changed the title Bogus extra error about unsized variable Bogus extra error about unsized variable (the trait bound str: std::marker::Sized is not satisfied) Sep 11, 2017
@TimNN TimNN added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 17, 2017
@jkarns275
Copy link

jkarns275 commented Mar 8, 2018

Ran into, what I believe to be the same issue, earlier today. My code boiled down to:

trait Hello {
    fn howdy(&self) -> i32;
}

struct Woah { pub field: i32 }

impl Hello for Woah {
    fn howdy(&self) -> i32 { self.field }
}

struct Container {
    pub boxed_trait: Box<Hello>
}

impl Container {
    pub fn new() -> Self {
        Container { boxed_trait: Box::new(Woah) }
    }
}

Which gave me the same bogus error when compiled.

error[E0423]: expected value, found struct `Woah`
  --> src/main.rs:21:43
   |
21 |         Container { boxed_trait: Box::new(Woah) }
   |                                           ^^^^ did you mean `Woah { /* fields */ }`?

error[E0277]: the trait bound `Hello: std::marker::Sized` is not satisfied
  --> src/main.rs:21:34
   |
21 |         Container { boxed_trait: Box::new(Woah) }
   |                                  ^^^^^^^^ `Hello` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `Hello`
   = note: required by `<std::boxed::Box<T>>::new`

Centril added a commit to Centril/rust that referenced this issue Sep 22, 2019
…tril

Propagate `types.err` in locals further to avoid spurious knock-down errors

Fix rust-lang#33575, fix rust-lang#44504.
@bors bors closed this as completed in b66e732 Sep 23, 2019
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-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants