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

Cargo check panics when attempting to declare static arrays with the .len() of a static slice #52060

Closed
Alexendoo opened this issue Jul 4, 2018 · 3 comments
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@Alexendoo
Copy link
Member

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:

https://play.rust-lang.org/?gist=a08602110a92f1601ccb30e90032bfc8&version=nightly&mode=debug&edition=2015

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)
@oli-obk
Copy link
Contributor

oli-obk commented Jul 4, 2018

That stacktrace looks very broken.

Usually these borrowmut errors are due to calling a lock function in a match value, and thus locking for the entire match, even if we just want the result. Should be fairly easy to fix with a backtrace with line numbers.

@oli-obk oli-obk added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ E-help-wanted Call for participation: Help is requested to fix this issue. A-const-eval Area: Constant evaluation (MIR interpretation) labels Jul 4, 2018
@zilbuz
Copy link
Contributor

zilbuz commented Aug 29, 2018

The ICE seems to have moved to stable (cf. original playground link), but isn't present anymore on nightly and beta. Should this issue be closed as it will be fixed on the next rust version, or addressed in stable?

@oli-obk
Copy link
Contributor

oli-obk commented Aug 29, 2018

I don't think this is worth a point release. Let's add a regression test and call it a day

@oli-obk oli-obk added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ E-help-wanted Call for participation: Help is requested to fix this issue. labels Aug 29, 2018
zilbuz added a commit to zilbuz/rust that referenced this issue Aug 30, 2018
kennytm added a commit to kennytm/rust that referenced this issue Sep 1, 2018
bors added a commit that referenced this issue Sep 1, 2018
Rollup of 9 pull requests

Successful merges:

 - #53076 (set cfg(rustdoc) when rustdoc is running on a crate)
 - #53622 (cleanup: Add main functions to some UI tests)
 - #53769 (Also link Clippy repo in the CONTRIBUTING.md file)
 - #53774 (Add rust-gdbgui script.)
 - #53781 (bench: libcore: fix build failure of any.rs benchmark (use "dyn Any"))
 - #53782 (Make Arc cloning mechanics clearer in module docs)
 - #53790 (Add regression test for issue #52060)
 - #53801 (Prevent duplicated impl on foreign types)
 - #53850 (Nuke the `const_to_allocation` query)
Dylan-DPC-zz referenced this issue in Dylan-DPC-zz/rust Mar 21, 2021
…chenkov

Move some tests to more reasonable directories - 5

cc rust-lang#73494

Threshold is 0.95. Next time I promise I will take a look into the special/misclassified directories.

- [issues/issue-23208.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-23208.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/23208)</sup>: associated-types 0.951
- [weird-exprs.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/weird-exprs.rs) <sup>unknown</sup>: destructuring-assignment 0.958
- [issues/issue-1701.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-1701.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/1701)</sup>: structs-enums 0.974
- [issues/issue-48508-aux.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-48508-aux.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/48508)</sup>: numbers-arithmetic 0.991
- [fn_must_use.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/fn_must_use.rs) <sup>unknown</sup>: lint 1.000
- [mir_check_nonconst.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/mir_check_nonconst.rs) <sup>unknown</sup>: consts 1.002
- [issues/issue-52060.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-52060.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/52060)</sup>: consts 1.017
- [issues/issue-45729-unsafe-in-generator.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-45729-unsafe-in-generator.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/45729)</sup>: generator 1.024
- [issues/issue-10392.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-10392.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/10392)</sup>: pattern 1.039
- [no-implicit-prelude.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/no-implicit-prelude.rs) <sup>unknown</sup>: resolve 1.071
- [issues/issue-68000-unicode-ident-after-missing-comma.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-68000-unicode-ident-after-missing-comma.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/68000)</sup>: parser 1.079
- [shadow.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/shadow.rs) <sup>unknown</sup>: binding 1.099
- [issues/issue-65611.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-65611.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/65611)</sup>: consts 1.139
- [concat-rpass.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/concat-rpass.rs) <sup>unknown</sup>: macros 1.194
- [issues/issue-31597.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-31597.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/31597)</sup>: associated-types 1.195
- [issues/issue-78372.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-78372.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/78372)</sup>: resolve 1.426
- [impl-trait-in-bindings-issue-73003.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/impl-trait-in-bindings-issue-73003.rs) <sup>[issue](https://github.com/rust-lang/rust/issues/73003)</sup>: impl-trait 1.471
- [impl-trait-in-bindings.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/impl-trait-in-bindings.rs) <sup>unknown</sup>: impl-trait 2.500

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

3 participants