Skip to content

rustdoc ICE with ConstEvalErr on array size location #47860

Closed
@ghost

Description

I have a crate that statically checks the size of a type by instantiating an invalid array if the types size is incorrect. Running cargo doc on the crate panics on the location of the array length expression.

#![feature(const_size_of)]

use std::cell::Cell;
use std::mem;

pub struct S {
    s: Cell<usize>
}

type _S = [usize; 0 - (mem::size_of::<S>() != 4) as usize];

causes this error:

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: ConstEvalErr { span: src/main.rs:10:19: 10:58, kind: Math(Overflow(Sub)) }', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: internal compiler error: unexpected panic

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.25.0-nightly (21882aad7 2018-01-28) running on x86_64-unknown-linux-gnu

rustc --version --verbose:

use std::cell::Cell;
use std::mem;

struct S {
    s: Cell<usize>,
}

type _S = [u8; 0 - (mem::size_of::<S>() != 4) as usize];

backtrace:

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: ConstEvalErr { span: src/main.rs:10:19: 10:58, kind: Math(Overflow(Sub)) }', libcore/result.rs:945:5
stack backtrace:
   0:     0x7f4f4fee5e2b - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h279fd5fd9f05345b
                               at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x7f4f4feb1530 - std::sys_common::backtrace::print::h6e90012f267bcd2d
                               at libstd/sys_common/backtrace.rs:71
                               at libstd/sys_common/backtrace.rs:59
   2:     0x7f4f4feb7550 - std::panicking::default_hook::{{closure}}::h073ace7ec685c21b
                               at libstd/panicking.rs:380
   3:     0x7f4f4feb72a7 - std::panicking::default_hook::he7b56ddcad2e358c
                               at libstd/panicking.rs:396
   4:     0x7f4f4feb7a5b - std::panicking::rust_panic_with_hook::hb4d0f8287add03b2
                               at libstd/panicking.rs:576
   5:     0x7f4f4feb791e - std::panicking::begin_panic::hc91952597c81491c
                               at libstd/panicking.rs:537
   6:     0x7f4f4feb781a - std::panicking::begin_panic_fmt::h00f630be4e5e5d35
                               at libstd/panicking.rs:521
   7:     0x7f4f4feb77b2 - rust_begin_unwind
                               at libstd/panicking.rs:497
   8:     0x7f4f4ff57850 - core::panicking::panic_fmt::h848bc35221bffff5
                               at libcore/panicking.rs:71
   9:     0x5574958285ed - core::result::unwrap_failed::hfa99739ec53d72eb
                               at /checkout/src/libcore/macros.rs:23
  10:     0x557495a5ee6f - <rustc::hir::Ty as rustdoc::clean::Clean<rustdoc::clean::Type>>::clean::hb7815fc1d916d5e9
                               at /checkout/src/libcore/result.rs:782
                               at librustdoc/clean/mod.rs:2450
  11:     0x5574958e333f - <rustdoc::doctree::Typedef as rustdoc::clean::Clean<rustdoc::clean::Item>>::clean::hfee5104da271a11c
                               at librustdoc/clean/mod.rs:86
                               at librustdoc/clean/mod.rs:3110
  12:     0x5574959b66e9 - <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::spec_extend::h9473d0f48b25c183
                               at librustdoc/clean/mod.rs:501
                               at /checkout/src/libcore/ops/function.rs:271
                               at /checkout/src/libcore/option.rs:404
                               at /checkout/src/libcore/iter/mod.rs:1251
                               at /checkout/src/liballoc/vec.rs:1844
  13:     0x5574958de5da - <rustdoc::doctree::Module as rustdoc::clean::Clean<rustdoc::clean::Item>>::clean::hfd00e08b6fc7742f
                               at /checkout/src/liballoc/vec.rs:1782
                               at librustdoc/clean/mod.rs:501
  14:     0x557495a59914 - <rustdoc::visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> as rustdoc::clean::Clean<rustdoc::clean::Crate>>::clean::h9d810f68e4f5903c
                               at librustdoc/clean/mod.rs:150
  15:     0x5574958c0c84 - rustdoc::core::run_core::{{closure}}::hc9c6b1c50e2bfa6c
                               at librustdoc/core.rs:255
  16:     0x5574958b1e22 - <std::thread::local::LocalKey<T>>::with::hc3ec3303cd604207
                               at /checkout/src/librustc_driver/driver.rs:1071
                               at /checkout/src/librustc/ty/context.rs:1573
                               at /checkout/src/libstd/thread/local.rs:377
                               at /checkout/src/libstd/thread/local.rs:288
  17:     0x5574958b1034 - <std::thread::local::LocalKey<T>>::with::hab3e16cdb2729852
                               at /checkout/src/librustc/ty/context.rs:1570
                               at /checkout/src/librustc/ty/context.rs:1557
                               at /checkout/src/libstd/thread/local.rs:377
                               at /checkout/src/libstd/thread/local.rs:288
  18:     0x55749595d493 - rustc::ty::context::TyCtxt::create_and_enter::ha6230dfc8beb1281
                               at /checkout/src/librustc/ty/context.rs:1554
                               at /checkout/src/librustc/ty/context.rs:1197
  19:     0x5574958c1624 - rustc_driver::driver::phase_3_run_analysis_passes::hccc7b178d7dc9ce3
                               at /checkout/src/librustc_driver/driver.rs:984
  20:     0x557495a6403a - rustdoc::core::run_core::h31dbfe5815dc3d35
                               at librustdoc/core.rs:213
  21:     0x5574958ea549 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1c6f4b8920eaed47
                               at librustdoc/lib.rs:537
                               at /checkout/src/librustc_driver/lib.rs:1426
                               at /checkout/src/libstd/sys_common/backtrace.rs:136
  22:     0x557495a25d6d - std::panicking::try::do_call::h14a7c45cc34b9968
                               at /checkout/src/libstd/thread/mod.rs:406
                               at /checkout/src/libstd/panic.rs:293
                               at /checkout/src/libstd/panicking.rs:479
  23:     0x7f4f4fefb11e - __rust_maybe_catch_panic
                               at libpanic_unwind/lib.rs:102
  24:     0x557495a48873 - <F as alloc::boxed::FnBox<A>>::call_box::h1785f7be69232ab0
                               at /checkout/src/libstd/panicking.rs:458
                               at /checkout/src/libstd/panic.rs:358
                               at /checkout/src/libstd/thread/mod.rs:405
                               at /checkout/src/liballoc/boxed.rs:788
  25:     0x7f4f4fee9f07 - std::sys_common::thread::start_thread::h52f16600cce7c01e
                               at /checkout/src/liballoc/boxed.rs:798
                               at libstd/sys_common/thread.rs:24
  26:     0x7f4f4feb82a8 - std::sys::unix::thread::Thread::new::thread_start::h0ab1c0a2f78d344a
                               at libstd/sys/unix/thread.rs:90
  27:     0x7f4f4fc4d08b - start_thread
  28:     0x7f4f4f76de1e - __GI___clone
  29:                0x0 - <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-rustdocRelevant to the rustdoc 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