- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Description
This isn't valid code but it causes a panic none the less. It doesn't cause a panic on stable.
rustc 1.28.0-nightly (e3bf634e0 2018-06-28) and rustc 1.28.0-beta.6 (915ac6602 2018-06-30) are affected
Example:
static A: &'static [u32] = &[1];
static B: [u32; 1] = [0; A.len()];It affects slices but not arrays on their own, the following does not panic:
static A: [u32; 1] = [1];
static B: [u32; 1] = [0; A.len()];And here's a backtrace
       Fresh ucd-raw v0.2.0
    Checking general-suffix v0.1.0 (file:///W:/Rust/general-suffix)
     Running `rustc --crate-name general_suffix src\lib.rs --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=167d6e50645cc7bb -C extra-filename=-167d6e50645cc7bb --out-dir W:\Rust\general-suffix\target\debug\deps -C incremental=W:\Rust\general-suffix\target\debug\incremental -L dependency=W:\Rust\general-suffix\target\debug\deps --extern ucd_raw=W:\Rust\general-suffix\target\debug\deps\libucd_raw-42a16cbe8e690df3.rmeta`
error[E0013]: constants cannot refer to statics, use a constant instead
 --> src\lib.rs:2:26
  |
2 | static B: [u32; 1] = [0; A.len()];
  |                          ^
error[E0394]: cannot refer to statics by value, use a constant instead
 --> src\lib.rs:2:26
  |
2 | static B: [u32; 1] = [0; A.len()];
  |                          ^ referring to another static by value
  |
  = note: use the address-of operator or a constant instead
error: `core::slice::<impl [T]>::len` is not yet stable as a const fn
 --> src\lib.rs:2:26
  |
2 | static B: [u32; 1] = [0; A.len()];
  |                          ^^^^^^^
  |
  = help: in Nightly builds, add `#![feature(const_slice_len)]` to the crate attributes to enable
thread 'main' panicked at 'already borrowed: BorrowMutError', libcore\result.rs:945:5
stack backtrace:
   0: <std::collections::hash::map::DefaultHasher as core::fmt::Debug>::fmt
   1: <std::sys::windows::dynamic_lib::DynamicLibrary as core::ops::drop::Drop>::drop
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: <rustc::ty::SymbolName as core::fmt::Debug>::fmt
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: <rustc_mir::transform::uniform_array_move_out::LocalUse as core::fmt::Debug>::fmt
  10: rustc_mir::interpret::eval_context::Frame::storage_dead
  11: rustc_mir::interpret::eval_context::Frame::storage_dead
  12: rustc_mir::interpret::const_eval::value_to_const_value
  13: rustc_mir::interpret::const_eval::const_eval_provider
  14: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  15: rustc::ty::context::tls::track_diagnostic
  16: rustc::ty::context::tls::track_diagnostic
  17: rustc::dep_graph::graph::DepGraph::assert_ignored
  18: rustc::ty::context::tls::track_diagnostic
  19: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  20: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  21: rustc::ty::query::TyCtxtAt::const_eval
  22: rustc_mir::interpret::eval_context::Frame::storage_dead
  23: rustc_mir::interpret::eval_context::Frame::storage_dead
  24: rustc_mir::dataflow::dataflow_path
  25: rustc_mir::dataflow::dataflow_path
  26: rustc_mir::dataflow::dataflow_path
  27: rustc_mir::interpret::eval_context::Frame::storage_dead
  28: rustc_mir::interpret::const_eval::value_to_const_value
  29: rustc_mir::interpret::const_eval::const_eval_provider
  30: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  31: rustc::ty::context::tls::track_diagnostic
  32: rustc::ty::context::tls::track_diagnostic
  33: rustc::dep_graph::graph::DepGraph::assert_ignored
  34: rustc::ty::context::tls::track_diagnostic
  35: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  36: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  37: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::const_eval
  38: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  39: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty
  40: <rustc_typeck::collect::has_late_bound_regions::LateBoundRegionsDetector<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_lifetime
  41: <rustc_typeck::check_unused::CollectExternCrateVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  42: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  43: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  44: rustc::ty::context::tls::track_diagnostic
  45: rustc::ty::context::tls::track_diagnostic
  46: rustc::dep_graph::graph::DepGraph::assert_ignored
  47: rustc::ty::context::tls::track_diagnostic
  48: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  49: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  50: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  51: <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_pat
  52: <rustc_typeck::variance::test::VarianceTest<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  53: <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_fn
  54: rustc_typeck::check_crate
  55: <humantime::date::Error as std::error::Error>::cause
  56: <rustc_driver::pretty::IdentifiedAnnotation<'hir> as rustc_driver::pretty::PrinterSupport>::sess
  57: <unknown>
  58: rustc_driver::driver::compile_input
  59: rustc_driver::run_compiler
  60: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  61: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  62: _rust_maybe_catch_panic
  63: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  64: rustc_driver::main
  65: <unknown>
  66: std::panicking::update_panic_count
  67: _rust_maybe_catch_panic
  68: std::rt::lang_start_internal
  69: <unknown>
  70: <unknown>
  71: BaseThreadInitThunk
  72: RtlUserThreadStart
query stack during panic:
#0 [const_eval] const-evaluating `A`
 --> src\lib.rs:2:26
  |
2 | static B: [u32; 1] = [0; A.len()];
  |                          ^
#1 [const_eval] const-evaluating `B::{{constant}}`
#2 [typeck_tables_of] processing `B`
end of query stack
error: aborting due to 3 previous errors
Some errors occurred: E0013, E0394.
For more information about an error, try `rustc --explain E0013`.
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.28.0-nightly (e3bf634e0 2018-06-28) running on x86_64-pc-windows-msvc
note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `general-suffix`.
Caused by:
  process didn't exit successfully: `rustc --crate-name general_suffix src\lib.rs --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=167d6e50645cc7bb -C extra-filename=-167d6e50645cc7bb --out-dir W:\Rust\general-suffix\target\debug\deps -C incremental=W:\Rust\general-suffix\target\debug\incremental -L dependency=W:\Rust\general-suffix\target\debug\deps --extern ucd_raw=W:\Rust\general-suffix\target\debug\deps\libucd_raw-42a16cbe8e690df3.rmeta` (exit code: 101)
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.