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

Incorrect error message: type parameter needs to be Sized, despite explicit bound #74149

Closed
e2-71828 opened this issue Jul 8, 2020 · 4 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users.

Comments

@e2-71828
Copy link

e2-71828 commented Jul 8, 2020

For the code below, the compiler complains that Item needs to be Sized, despite that being an explicitly-stated bound.

const PAGE_SIZE:usize=4096;

#[repr(align(4096))]
struct Page<Item: std::marker::Sized> {
    arr: [Item; PAGE_SIZE/std::mem::size_of::<Item>()],
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `Item` cannot be known at compilation time
   --> src/lib.rs:5:47
    |
4   | struct Page<Item: std::marker::Sized> {
    |             ---- this type parameter needs to be `std::marker::Sized`
5   |     arr: [Item; PAGE_SIZE/std::mem::size_of::<Item>()],
    |                                               ^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `std::marker::Sized` is not implemented for `Item`
    = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

@lcnr
Copy link
Contributor

lcnr commented Jul 8, 2020

This is blocked on lazy normalization of constants, see #72219 for more details,
you can use #![feature(lazy_normalization_consts)] on nightly to try experiment
with the still incomplete implementation.

@lcnr lcnr added A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Jul 8, 2020
@lcnr
Copy link
Contributor

lcnr commented Jul 8, 2020

Closing this in favor of #43408

@lcnr lcnr closed this as completed Jul 8, 2020
@e2-71828
Copy link
Author

e2-71828 commented Jul 8, 2020

Note that this bug isn’t about the ability to define this per se, but that the compiler is emitting an error that is nonsensical on its face— if this isn’t possible, the compiler should say so, insted of complaining about a falsehood.

@lcnr
Copy link
Contributor

lcnr commented Jul 8, 2020

That's true, #43408 currently seems to track both the error message and the more general problem.
While this isn't optimal, considering how many people already subscribed to that issue I personally think it's better to keep it this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users.
Projects
None yet
Development

No branches or pull requests

2 participants