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

Confused by the error message #49964

Closed
juchiast opened this issue Apr 14, 2018 · 2 comments
Closed

Confused by the error message #49964

juchiast opened this issue Apr 14, 2018 · 2 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@juchiast
Copy link
Contributor

juchiast commented Apr 14, 2018

I'm trying to write this code:

fn binary_dump<T: Sized>(f: T) -> String {
    let v = [0u8; std::mem::size_of::<T>()];
    String::new()
}

rustc gives this error message:

error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
 --> src/main.rs:2:19
  |
2 |     let v = [0u8; std::mem::size_of::<T>()];
  |                   ^^^^^^^^^^^^^^^^^^^^^^ `T` does not have a constant size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `T`
  = help: consider adding a `where T: std::marker::Sized` bound
  = note: required by `std::mem::size_of`

This is confusing because T already have Sized.

@est31
Copy link
Member

est31 commented Apr 14, 2018

Known bug. #43408

@kennytm kennytm added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-fn C-bug Category: This is a bug. labels Apr 14, 2018
@ishitatsuyuki
Copy link
Contributor

I think we can close this as an exact duplicate?

@RalfJung RalfJung added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants