Skip to content

lazy_type_alias: error doesn't have a size known at compile-time #114214

@matthiaskrgr

Description

@matthiaskrgr

I tried this code:
src/tools/miri/tests/pass/issues/issue-36278-prefix-nesting.rs

// Issue 36278: On an unsized struct with >1 level of nontrivial
// nesting, ensure we are computing dynamic size of prefix correctly.

use std::mem;

const SZ: usize = 100;
struct P<T: ?Sized>([u8; SZ], T);

type Ack<T> = P<P<T>>;

fn main() {
    let size_of_sized;
    let size_of_unsized;
    let x: Box<Ack<[u8; 0]>> = Box::new(P([0; SZ], P([0; SZ], [0; 0])));
    size_of_sized = mem::size_of_val::<Ack<_>>(&x);
    let align_of_sized = mem::align_of_val::<Ack<_>>(&x);
    let y: Box<Ack<[u8]>> = x;
    size_of_unsized = mem::size_of_val::<Ack<_>>(&y);
    assert_eq!(size_of_sized, size_of_unsized);
    assert_eq!(align_of_sized, 1);
    assert_eq!(mem::align_of_val::<Ack<_>>(&y), 1);
}

without `-Zcrate-attr=feature(lazy_type_alias)´: dead code warnings

with -Zcrate-attr=feature(lazy_type_alias):

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
  --> src/tools/miri/tests/pass/issues/issue-36278-prefix-nesting.rs:17:16
   |
17 |     let y: Box<Ack<[u8]>> = x;
   |                ^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `[u8]`
note: required by a bound on the type alias `Ack`
  --> src/tools/miri/tests/pass/issues/issue-36278-prefix-nesting.rs:9:10
   |
9  | type Ack<T> = P<P<T>>;
   |          ^ required by this bound

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
  --> src/tools/miri/tests/pass/issues/issue-36278-prefix-nesting.rs:18:42
   |
18 |     size_of_unsized = mem::size_of_val::<Ack<_>>(&y);
   |                                          ^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `[u8]`
note: required by a bound on the type alias `Ack`
  --> src/tools/miri/tests/pass/issues/issue-36278-prefix-nesting.rs:9:10
   |
9  | type Ack<T> = P<P<T>>;
   |          ^ required by this bound

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
  --> src/tools/miri/tests/pass/issues/issue-36278-prefix-nesting.rs:21:36
   |
21 |     assert_eq!(mem::align_of_val::<Ack<_>>(&y), 1);
   |                                    ^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `[u8]`
note: required by a bound on the type alias `Ack`
  --> src/tools/miri/tests/pass/issues/issue-36278-prefix-nesting.rs:9:10
   |
9  | type Ack<T> = P<P<T>>;
   |          ^ required by this bound

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
rustc 1.73.0-nightly (04abc370b 2023-07-28)
binary: rustc
commit-hash: 04abc370b9f3855b28172b65a7f7d5a433f41412
commit-date: 2023-07-28
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleF-lazy_type_alias`#![feature(lazy_type_alias)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions