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

Unsized type allowed in array declaration #70607

Closed
DutchGhost opened this issue Mar 31, 2020 · 1 comment
Closed

Unsized type allowed in array declaration #70607

DutchGhost opened this issue Mar 31, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@DutchGhost
Copy link
Contributor

I tried this code:

type A = [dyn Send; 2];

I expected to see this happen: Fail to compile because an array doesn't allow DST's

Instead, this happened: It just compiled

Meta

rustc --version --verbose:

stable, beta and nightly

Whenever the type is used:

type A = [dyn Send; 2];

fn using(a: A) {}

rustc complains correctly:

 Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `(dyn std::marker::Send + 'static)` cannot be known at compilation time
 --> src/lib.rs:3:1
  |
3 | fn using(a: A) {}
  | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `(dyn std::marker::Send + 'static)`
  = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
  = note: slice and array elements must have `Sized` type

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 Mar 31, 2020
@jonas-schievink
Copy link
Contributor

duplicate of #44075

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants