Closed
Description
Code:
#![feature(const_fn)]
fn main() {
let _ = [0; foo() as usize];
}
const fn foo() -> *const i32 {
&0 as *const i32
}
Error with RUST_BACKTRACE=full
:
error[E0018]: raw pointers cannot be cast to integers in constants
--> foo.rs:4:17
|
4 | let _ = [0; foo() as usize];
| ^^^^^^^^^^^^^^
error: internal compiler error: librustc/ty/relate.rs:506: arrays should not have Const { ty: usize, val: Value(Scalar(Ptr(Pointer { alloc_id: AllocId(6), offset: Size { raw: 0 } }))) } as length
thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:554:9
stack backtrace:
0: 0x7fdc61e260fe - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h50a634a60cb4e5f7
at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: 0x7fdc61dfd4b6 - std::sys_common::backtrace::print::hfdd27bb0425df770
at libstd/sys_common/backtrace.rs:71
at libstd/sys_common/backtrace.rs:59
2: 0x7fdc61e2d34d - std::panicking::default_hook::{{closure}}::h027136eae47935d0
at libstd/panicking.rs:211
3: 0x7fdc61e2d0c0 - std::panicking::default_hook::hed5917d304f00a1b
at libstd/panicking.rs:227
4: 0x7fdc5e4ea3e5 - rustc::util::common::panic_hook::h9e9cb098ca9688d6
5: 0x7fdc61e2dad3 - std::panicking::rust_panic_with_hook::hc482345e1eead25b
at libstd/panicking.rs:515
6: 0x7fdc5d2b08ae - std::panicking::begin_panic::h91aef2ee5aa26450
7: 0x7fdc5d2ac261 - rustc_errors::Handler::bug::h1be2d05f14de7d85
8: 0x7fdc5e0ccbcc - rustc::session::opt_span_bug_fmt::{{closure}}::heb5c3a0ebc0b8cb9
9: 0x7fdc5e186f29 - rustc::ty::context::tls::with_opt::{{closure}}::h6294c4a9102c2647
10: 0x7fdc5e0cd95f - rustc::ty::context::tls::with_context_opt::ha499f455a0857cd3
11: 0x7fdc5e1869a6 - rustc::ty::context::tls::with_opt::h50829cbea0b4a2b5
12: 0x7fdc5e099284 - rustc::session::opt_span_bug_fmt::h909d74d76885e464
13: 0x7fdc5e0991f6 - rustc::session::bug_fmt::h56d39c05f4237f0a
14: 0x7fdc5e1f0def - rustc::ty::relate::super_relate_tys::{{closure}}::h0e5c5821e42893fb
15: 0x7fdc5e1cba81 - <rustc::infer::combine::Generalizer<'cx, 'gcx, 'tcx> as rustc::ty::relate::TypeRelation<'cx, 'gcx, 'tcx>>::tys::h79391b27f99f3d90
16: 0x7fdc5e1ca5b4 - rustc::infer::combine::CombineFields::instantiate::h1673388ad551389e
17: 0x7fdc5e1cc818 - <rustc::infer::sub::Sub<'combine, 'infcx, 'gcx, 'tcx> as rustc::ty::relate::TypeRelation<'infcx, 'gcx, 'tcx>>::tys::h9857734987984713
18: 0x7fdc60639706 - rustc::infer::InferCtxt::commit_if_ok::h2490ae759e0bddd1
19: 0x7fdc606390d2 - rustc::infer::InferCtxt::commit_if_ok::h09c65af8556fc345
20: 0x7fdc606e2fe5 - rustc_typeck::check::coercion::Coerce::coerce::h6c1101b044e206b7
21: 0x7fdc606394ec - rustc::infer::InferCtxt::commit_if_ok::h1a6a85a1fca39f19
22: 0x7fdc606410c8 - rustc::infer::InferCtxt::commit_if_ok::hafa1c534ca850ff9
23: 0x7fdc605af22c - rustc_typeck::check::coercion::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::try_coerce::h714c901dbb184ff3
24: 0x7fdc605b49c7 - rustc_typeck::check::demand::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::demand_coerce_diag::h0d3348845e18e33a
25: 0x7fdc605b47e6 - rustc_typeck::check::demand::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::demand_coerce::h605fe74462fe7c91
26: 0x7fdc605e113f - rustc_typeck::check::FnCtxt::check_decl_local::h32f94738aaeb63bb
27: 0x7fdc605e1694 - rustc_typeck::check::FnCtxt::check_block_with_expected::hee241f249d32fbd9
28: 0x7fdc605d39d6 - rustc_typeck::check::FnCtxt::check_expr_kind::h319525d17a66c8df
29: 0x7fdc605d3741 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h07919108be9f5f44
30: 0x7fdc605d2990 - rustc_typeck::check::FnCtxt::check_return_expr::h764e2e237ef673a8
31: 0x7fdc605c6132 - rustc_typeck::check::check_fn::h5c7a30d85ca0d72e
32: 0x7fdc60674dcd - rustc::ty::context::tls::with_related_context::h812eafb03d5e2a88
33: 0x7fdc60637dc8 - rustc::infer::InferCtxtBuilder::enter::hfc232c248b49f6eb
34: 0x7fdc605c4cca - rustc_typeck::check::typeck_tables_of::h7f50d10402e552d5
35: 0x7fdc5e4f2832 - rustc::ty::query::__query_compute::typeck_tables_of::hd50fa71ff0e9f45e
36: 0x7fdc5e187c1c - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute::h5ddfbde7628dd211
37: 0x7fdc5df6200d - rustc::dep_graph::graph::DepGraph::with_task_impl::h2615ca8854025f24
38: 0x7fdc5e1317f6 - rustc::ty::context::tls::with_related_context::h4513e1c17d844181
39: 0x7fdc5e2e96ce - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job::h1f4db9eb8c0a364d
40: 0x7fdc5e3beceb - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query::h9890a9d1dc40bd13
41: 0x7fdc5e3131eb - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query::hf83b36f70243fa2a
42: 0x7fdc6060a5cc - rustc::session::Session::track_errors::hba3da29fe1ce2480
43: 0x7fdc605c485a - rustc_typeck::check::typeck_item_bodies::he6482650e87a8925
44: 0x7fdc5e187bf8 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_item_bodies<'tcx>>::compute::h14d44e448ca355cc
45: 0x7fdc5df55356 - rustc::dep_graph::graph::DepGraph::with_task_impl::h0601e47024527472
46: 0x7fdc5e157c56 - rustc::ty::context::tls::with_related_context::ha696a0c6c6ade91e
47: 0x7fdc5e308f39 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job::hf8ac4b981b9250dc
48: 0x7fdc5e3e46d5 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query::hbe60cc3f7a53633b
49: 0x7fdc60609c14 - rustc::util::common::time::h62b55b79d8dc7e4e
50: 0x7fdc607359e7 - rustc_typeck::check_crate::hc769360b74ff1fdc
51: 0x7fdc6226c03a - rustc::ty::context::tls::enter_context::h91c9f96576851d36
52: 0x7fdc62219aca - <std::thread::local::LocalKey<T>>::with::hc3b25e364245c00f
53: 0x7fdc62184ec2 - rustc::ty::context::TyCtxt::create_and_enter::he17b49208d21e853
54: 0x7fdc621c50ac - rustc_driver::driver::compile_input::h95eb8b7dd032d269
55: 0x7fdc62250295 - rustc_driver::run_compiler_with_pool::h94fbd18de41dc2e2
56: 0x7fdc621b497b - <scoped_tls::ScopedKey<T>>::set::h4c03440eebe30a1f
57: 0x7fdc62189f2a - syntax::with_globals::h57af6031309babcc
58: 0x7fdc6216a722 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hb1f190602052e50b
59: 0x7fdc61e3bc59 - __rust_maybe_catch_panic
at libpanic_unwind/lib.rs:105
60: 0x7fdc6224d423 - rustc_driver::run::h7fa1696458a8f761
61: 0x7fdc6225d26a - rustc_driver::main::he4d005c782d5073a
62: 0x562dabfb7b52 - std::rt::lang_start::{{closure}}::h99d53d66d7fac3dd
63: 0x7fdc61e2d512 - std::panicking::try::do_call::h7e0ed4dd1b773c21
at libstd/rt.rs:59
at libstd/panicking.rs:310
64: 0x7fdc61e3bc59 - __rust_maybe_catch_panic
at libpanic_unwind/lib.rs:105
65: 0x7fdc61df1d55 - std::rt::lang_start_internal::h7c38f1310577c409
at libstd/panicking.rs:289
at libstd/panic.rs:392
at libstd/rt.rs:58
66: 0x562dabfb7bb3 - main
67: 0x7fdc61a202e0 - __libc_start_main
68: 0x562dabfb7a38 - <unknown>
query stack during panic:
#0 [typeck_tables_of] processing `main`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0018`.
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-unknown-linux-gnu