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 error about the size of a parameter not being known at compiletime #78834

Closed
DutchGhost opened this issue Nov 7, 2020 · 4 comments · Fixed by #133785
Closed

Wrong error about the size of a parameter not being known at compiletime #78834

DutchGhost opened this issue Nov 7, 2020 · 4 comments · Fixed by #133785
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Nov 7, 2020

I tried this code:

struct B<A: Sized = [(); {
    let x = [0u8; !0usize];
    1
}]> {
    a: A
}

fn main() {

}

I expected to see this happen: This code should compile, as A is a generic type with the default type being [(); 1]. When I remove the let x = [0u8; !0usize] line, everything compiles fine.

Instead, this happened: I got an error message, error[E0277]

Meta

rustc --version --verbose:

Stable version: 1.47.0
Beta version: 1.48.0-beta.5
1.49.0-nightly (2020-11-05 9d78d1d02761b906038b)
Backtrace

   Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `A` cannot be known at compilation time
  --> src/main.rs:32:19
   |
31 | struct B<A: Sized = [(); {
   |          -
   |          |
   |          this type parameter needs to be `Sized`
   |          required by this bound in `B`
32 |     let x = [0u8; !0usize];
   |                   ^^^^^^^ doesn't have a size known at compile-time

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.

@DutchGhost DutchGhost added the C-bug Category: This is a bug. label Nov 7, 2020
@Dylan-DPC
Copy link
Member

Current output:

error[[E0277]](https://doc.rust-lang.org/stable/error_codes/E0277.html): the size for values of type `A` cannot be known at compilation time
 --> src/main.rs:2:19
  |
1 |   struct B<A: Sized = [(); {
  |  __________-
2 | |     let x = [0u8; !0usize];
  | |                   ^^^^^^^ doesn't have a size known at compile-time
3 | |     1
4 | | }]> {
  | |__- this type parameter needs to be `std::marker::Sized`
  |
note: required by a bound in `B`
 --> src/main.rs:1:10
  |
1 |   struct B<A: Sized = [(); {
  |  __________^
2 | |     let x = [0u8; !0usize];
3 | |     1
4 | | }]> {
  | |__^ required by this bound in `B`

For more information about this error, try `rustc --explain E0277`.

@fmease
Copy link
Member

fmease commented Sep 7, 2023

If you opt out of Sized for the type parameter A, then rustc emits the correct error (I assume it's the correct one):

struct B<
    A: ?Sized = [(); {
                    let x = [0u8; !0usize];
                    1
                }],
> {
    a: A,
}

fn main() {}
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the current architecture
 --> src/main.rs:3:29
  |
3 |                     let x = [0u8; !0usize];
  |                             ^^^^^^^^^^^^^^

@fmease fmease 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. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. and removed C-bug Category: This is a bug. needs-triage-legacy labels Sep 7, 2023
@estebank
Copy link
Contributor

Current output:

error[E0080]: evaluation of constant value failed
 --> src/main.rs:2:13
  |
2 |     let x = [0u8; !0usize];
  |             ^^^^^^^^^^^^^^ values of the type `[u8; usize::MAX]` are too big for the target architecture

and

error[E0080]: evaluation of constant value failed
 --> src/main.rs:3:29
  |
3 |                     let x = [0u8; !0usize];
  |                             ^^^^^^^^^^^^^^ values of the type `[u8; usize::MAX]` are too big for the target architecture

@estebank estebank added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Nov 21, 2024
@HypheX
Copy link
Contributor

HypheX commented Nov 25, 2024

@rustbot claim
Thanks, I'll work on this shortly.

jhpratt added a commit to jhpratt/rust that referenced this issue Dec 3, 2024
@bors bors closed this as completed in 8ae1114 Dec 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 3, 2024
Rollup merge of rust-lang#133785 - HypheX:add-ui-test, r=compiler-errors

Add const evaluation error UI test.

This closes rust-lang#78834
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 E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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.

6 participants