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

Confusing error message combining when arrays, size_of in a container #75678

Open
MikailBag opened this issue Aug 18, 2020 · 2 comments
Open
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@MikailBag
Copy link
Contributor

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ff721dd90338cf7cfa30b9fe7198db36
This code tries to use [u8; std::mem::size_of::<T>()], where T is generic parameter. This is currently not supported, so for
good function compiler gives helpful error: constant expression depends on a generic parameter.
However, for functions bad1 and bad2 (where ill-formed array declaration is wrapped into other type), compiler gives error the size for values of type T cannot be known at compilation time. Furthermore, it suggests to add Sized bound, while it is already specified. I think this message and suggestion can be confusing.

Meta

I used rust v1.45.2 on the Rust Playground.

@MikailBag MikailBag added the C-bug Category: This is a bug. label Aug 18, 2020
@MikailBag MikailBag changed the title Confusing error message combining arrays, size_of in a container Confusing error message combining when arrays, size_of in a container Aug 18, 2020
@lcnr
Copy link
Contributor

lcnr commented Aug 18, 2020

This has the same underlying reason as #62708 and should hopefully be converted to a more accurate error once we start stabilizing min_const_generics.

@estebank estebank added A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Aug 23, 2020
@ghost
Copy link

ghost commented Dec 29, 2020

A "container" is not required. This also results in confusing error message:

fn not_good<T: Sized>(x: T) {
    let _: [u8; std::mem::size_of::<T>()];
}

Edit: #80062's error message also contains this, and that code also doesn't have a "container".
Edit: This seems fixed in latest nightly. I'm late, just like in #62708. Sorry for the noise.
Edit: Unhiding since hopefully my example may be helpful for a test case.

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-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants