Skip to content

ICE using a type alias to a const generic struct across crates #61624

Closed
@carado

Description

@carado

In a folder a, I have a blank library crate with the following src/lib.rs:

#![feature(const_generics)]

pub struct Struct<const N: usize>([u8; N]);

pub type Alias = Struct<2>;

In a folder b, I have a blank binary crate with the follow src/main.rs:

// note: the error seems to be the same regardless of whether the following line is commented or not
//#![feature(const_generics)]

struct Container(a::Alias);

fn main() {}

b's Cargo.toml uses crate a with the following line:

[dependencies]
a = { path = "../a", version = "" }

Running cargo check or cargo build in b will produce the following ICE:

    Checking b v0.1.0 (/home/carado/tmp/rust7/b)
error: internal compiler error: src/librustc_metadata/decoder.rs:484: entry: id not found: DefIndex(18) in crate a with number 15

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:638:9
stack backtrace:
   0:     0x7f4371ffb19b - backtrace::backtrace::libunwind::trace::h034f17449c8f06d2
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1:     0x7f4371ffb19b - backtrace::backtrace::trace_unsynchronized::h88fceba984274b2d
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2:     0x7f4371ffb19b - std::sys_common::backtrace::_print::h113a7251db1bb0bb
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x7f4371ffb19b - std::sys_common::backtrace::print::he1709f3e64aa1331
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x7f4371ffb19b - std::panicking::default_hook::{{closure}}::h4c7c19a95acf509e
                               at src/libstd/panicking.rs:198
   5:     0x7f4371ffae9c - std::panicking::default_hook::haf2a960f108a3f30
                               at src/libstd/panicking.rs:212
   6:     0x7f436fd54dd1 - rustc::util::common::panic_hook::h96cf50c713bc84f6
   7:     0x7f4371ffb9f9 - std::panicking::rust_panic_with_hook::h89241749267406d1
                               at src/libstd/panicking.rs:479
   8:     0x7f436e9a652d - std::panicking::begin_panic::h23f047602abbec1f
   9:     0x7f436e9c661f - rustc_errors::Handler::bug::h1846692de954732d
  10:     0x7f436f9ceac3 - rustc::util::bug::opt_span_bug_fmt::{{closure}}::h4eeb8977ea9f490d
  11:     0x7f436f9ce09a - rustc::ty::context::tls::with_opt::{{closure}}::h4f8aad466ccd8399
  12:     0x7f436f9cdfb5 - rustc::ty::context::tls::with_context_opt::h93eb33abb81e1499
  13:     0x7f436f9ce047 - rustc::ty::context::tls::with_opt::h84f79a4206f98907
  14:     0x7f436f9ce9d8 - rustc::util::bug::opt_span_bug_fmt::hcae1e85db26d61d1
  15:     0x7f436f9ce942 - rustc::util::bug::bug_fmt::h0d9f8eae974cd447
  16:     0x7f437048e53a - rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::entry::hd6886155c7e8ad94
  17:     0x7f437048f82c - rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::get_type::he89c8116f2a9d946
  18:     0x7f4370499601 - rustc_metadata::cstore_impl::provide_extern::type_of::h81daf21c535e688b
  19:     0x7f436fce71cd - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::type_of>::compute::h6309e2152a5e3c65
  20:     0x7f436f8b5517 - rustc::dep_graph::graph::DepGraph::with_task_impl::had7a0c15c5f1905b
  21:     0x7f436fbb7456 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hb3169834330de254
  22:     0x7f436f7cea4f - rustc::ty::instance::Instance::resolve::h72798ee26e58abe1
  23:     0x7f436fd411bb - <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_const::hd5c5bcc5cc84d8c5
  24:     0x7f436f956ffa - <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter::h56ca20c895cf1fe3
  25:     0x7f436fa90fec - rustc::ty::fold::TypeFoldable::fold_with::h9620990ca94be452
  26:     0x7f436faacdcd - rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::super_fold_with::h42aca40e5d6f720c
  27:     0x7f436fd40b65 - <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_ty::h0000082e2319606a
  28:     0x7f436cd1ed64 - rustc::traits::project::normalize::hbd56f85fc248fb4d
  29:     0x7f436cb40590 - rustc_typeck::check::FnCtxt::normalize_associated_types_in::h8d3d18278d4fdeda
  30:     0x7f436cd664b0 - <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::h7a0fbf29f0ae4dd7
  31:     0x7f436ccb1f67 - rustc::ty::context::GlobalCtxt::enter_local::h05475195df7a61f1
  32:     0x7f436cd92e9b - rustc_typeck::check::wfcheck::check_item_well_formed::hdb36490216ee054e
  33:     0x7f436cb6165e - rustc::ty::query::__query_compute::check_item_well_formed::he41baf5c84b70167
  34:     0x7f436cc2b7bd - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute::h7c840c44c057109d
  35:     0x7f436cb966fb - rustc::dep_graph::graph::DepGraph::with_task_impl::h9a2f7b5bbc29bc70
  36:     0x7f436cc876f0 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::ha95df13349dc610e
  37:     0x7f436cd96967 - <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc::hir::itemlikevisit::ParItemLikeVisitor>::visit_item::ha1c79ec81b0ae69c
  38:     0x7f437200c8ea - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:85
  39:     0x7f436cba2519 - rustc_data_structures::sync::par_for_each_in::he5330af9a7aa0673
  40:     0x7f437200c8ea - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:85
  41:     0x7f436cd59313 - rustc::hir::Crate::par_visit_all_item_likes::h7e35cc6980d7d055
  42:     0x7f436cb64fcd - rustc::util::common::time::h7201fa0034b9369a
  43:     0x7f436cd78a28 - rustc_typeck::check_crate::h2869f0da763831fb
  44:     0x7f43719ceb45 - rustc_interface::passes::analysis::h3924fc0f51a4916f
  45:     0x7f437235b576 - rustc::ty::query::__query_compute::analysis::hecebb52178cb72d8
  46:     0x7f43722c5e02 - rustc::dep_graph::graph::DepGraph::with_task_impl::h13f978acfb884bfb
  47:     0x7f43722bfe0d - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h41a19a7094d84ad5
  48:     0x7f43722cfdc6 - rustc::ty::context::tls::enter_global::hde76617de84f513e
  49:     0x7f43722ee377 - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::h7e90e4645ca62211
  50:     0x7f4371a2c4d5 - rustc_interface::passes::create_global_ctxt::{{closure}}::hd1ffcd24d8253592
  51:     0x7f43722ef6ba - rustc_interface::interface::run_compiler_in_existing_thread_pool::hbb3327ac4471db7f
  52:     0x7f4372361346 - std::thread::local::LocalKey<T>::with::h889b3604823f7d6d
  53:     0x7f4372304e65 - scoped_tls::ScopedKey<T>::set::h04ec88caee9f9ad7
  54:     0x7f437232cea4 - syntax::with_globals::h380e3542e6008820
  55:     0x7f437234bd9d - std::sys_common::backtrace::__rust_begin_short_backtrace::h5f9f48a6f860c8d7
  56:     0x7f437200c8ea - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:85
  57:     0x7f43722d7f29 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hc55a01470f319106
  58:     0x7f4371fdeebf - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h3f73aebf71bfd2d8
                               at /rustc/5eeb567a27eba18420a620ca7d0c007e29d8bc0c/src/liballoc/boxed.rs:746
  59:     0x7f437200b5c0 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hf5740d907353c675
                               at /rustc/5eeb567a27eba18420a620ca7d0c007e29d8bc0c/src/liballoc/boxed.rs:746
  60:     0x7f437200b5c0 - std::sys_common::thread::start_thread::h9d627f833866d0b2
                               at src/libstd/sys_common/thread.rs:13
  61:     0x7f437200b5c0 - std::sys::unix::thread::Thread::new::thread_start::h6883c5e892c614cf
                               at src/libstd/sys/unix/thread.rs:79
  62:     0x7f4371f42fa8 - start_thread
                               at /builddir/glibc-2.29/nptl/pthread_create.c:486
  63:     0x7f4371e64a1f - __GI___clone
  64:                0x0 - <unknown>
query stack during panic:
#0 [type_of] processing `a::Alias::{{constant}}#0`
#1 [check_item_well_formed] processing `Container`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous 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.37.0-nightly (5eeb567a2 2019-06-06) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `b`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Labels

A-const-genericsArea: const generics (parameters and arguments)A-metadataArea: Crate metadataC-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions