Skip to content

ICE in Layout::compute with const cycle #44415

Closed
@plietar

Description

@plietar

This is a slightly modified version of the compile-fail/const-size_of-cycle test, adding a field at the end of the struct.

#![feature(const_fn)]

struct Foo {
    bytes: [u8; std::mem::size_of::<Foo>()],
    x: usize,
}

fn main() {}

It ends up in the following ICE. The "unsupported cyclic reference between types/traits detected" error is expected.

error[E0391]: unsupported cyclic reference between types/traits detected
  --> src/test/compile-fail/const-size_of-cycle.rs:14:5
   |
14 |     bytes: [u8; std::mem::size_of::<Foo>()],
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic reference
   |
note: the cycle begins when processing `Foo::bytes`...
  --> src/test/compile-fail/const-size_of-cycle.rs:14:5
   |
14 |     bytes: [u8; std::mem::size_of::<Foo>()],
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which then requires const-evaluating `Foo::{{initializer}}`...
  --> src/test/compile-fail/const-size_of-cycle.rs:14:17
   |
14 |     bytes: [u8; std::mem::size_of::<Foo>()],
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which then requires computing layout of `Foo`...
   = note: ...which then again requires processing `Foo::bytes`, completing the cycle.

error: internal compiler error: src/librustc/ty/layout.rs:1541: Layout::compute: unexpected type `[type error]`

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.21.0-nightly (97b01abf3 2017-08-31) running on x86_64-apple-darwin

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:492:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
   1: std::panicking::default_hook::{{closure}}
   2: std::panicking::default_hook
   3: std::panicking::rust_panic_with_hook
   4: std::panicking::begin_panic
   5: rustc_errors::Handler::bug
   6: rustc::session::opt_span_bug_fmt::{{closure}}
   7: rustc::session::opt_span_bug_fmt
   8: rustc::session::bug_fmt
   9: rustc::ty::layout::Layout::compute_uncached
  10: rustc::ty::util::layout_raw
  11: rustc::ty::maps::<impl rustc::ty::maps::queries::layout_raw<'tcx>>::try_get
  12: rustc::ty::maps::TyCtxtAt::layout_raw
  13: rustc::ty::util::<impl rustc::ty::TyS<'tcx>>::layout
  14: <&'a mut I as core::iter::iterator::Iterator>::next
  15: rustc::ty::layout::Layout::compute_uncached
  16: rustc::ty::util::layout_raw
  17: rustc::ty::maps::<impl rustc::ty::maps::queries::layout_raw<'tcx>>::try_get
  18: rustc::ty::maps::TyCtxtAt::layout_raw
  19: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::layout_raw
  20: rustc_const_eval::eval::eval_const_expr_partial::{{closure}}
  21: rustc_const_eval::eval::eval_const_expr_partial
  22: rustc_const_eval::eval::eval_const_expr_partial
  23: rustc_const_eval::eval::eval_const_expr_partial
  24: rustc_const_eval::eval::eval_const_expr_partial
  25: rustc_const_eval::eval::const_eval
  26: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  27: rustc::ty::maps::TyCtxtAt::const_eval
  28: rustc::middle::const_val::eval_length
  29: <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::ast_ty_to_ty
  30: rustc_typeck::collect::type_of
  31: rustc::dep_graph::graph::DepGraph::with_task
  32: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  33: rustc::ty::maps::<impl rustc::ty::maps::queries::type_of<'tcx>>::try_get
  34: rustc::ty::maps::TyCtxtAt::type_of
  35: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::type_of
  36: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  37: rustc_typeck::check_crate::{{closure}}::{{closure}}
  38: rustc_typeck::check_crate
  39: rustc::ty::context::TyCtxt::create_and_enter
  40: rustc_driver::driver::compile_input
  41: rustc_driver::run_compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions