Skip to content

ICE: Associated constant and impl trait #64848

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mgjm opened this issue Sep 27, 2019 · 4 comments · Fixed by #68236
Closed

ICE: Associated constant and impl trait #64848

mgjm opened this issue Sep 27, 2019 · 4 comments · Fixed by #68236
Labels
A-associated-items Area: Associated items (types, constants & functions) A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mgjm
Copy link

mgjm commented Sep 27, 2019

When the associated constant of an impl trait is referenced it creates an ICE:

trait AssociatedConstant {
    const DATA: ();
}

impl<F, T> AssociatedConstant for F
where
    F: FnOnce() -> T,
    T: AssociatedConstant,
{
    const DATA: () = T::DATA;
}

impl AssociatedConstant for () {
    const DATA: () = ();
}

fn foo() -> impl AssociatedConstant {
    ()
}

fn get_data<T: AssociatedConstant>(_: T) -> &'static () {
    &T::DATA
}

fn main() {
    get_data(foo);
}

Meta

This panics on stable and nightly. Tested on play.rust-lang.org, macOS and in Docker:

rustc --version --verbose:
rustc 1.38.0 (625451e 2019-09-23)
binary: rustc
commit-hash: 625451e
commit-date: 2019-09-23
host: x86_64-unknown-linux-gnu
release: 1.38.0
LLVM version: 9.0

The panic originates from the same assertion as in #61432:

Backtrace:
thread 'rustc' panicked at 'assertion failed: key.value.promoted.is_none()', src/librustc_mir/const_eval.rs:607:17
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:200
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:214
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
   8: std::panicking::begin_panic
   9: rustc_mir::const_eval::const_eval_provider
  10: rustc::ty::query::__query_compute::const_eval
  11: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  12: rustc::dep_graph::graph::DepGraph::with_task_impl
  13: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  14: rustc_mir::monomorphize::collector::collect_items_rec
  15: rustc_mir::monomorphize::collector::collect_items_rec
  16: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  17: rustc::util::common::time
  18: rustc_mir::monomorphize::collector::collect_crate_mono_items
  19: rustc::util::common::time
  20: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  21: rustc::ty::query::__query_compute::collect_and_partition_mono_items
  22: rustc::dep_graph::graph::DepGraph::with_task_impl
  23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  24: rustc_codegen_ssa::base::codegen_crate
  25: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  26: rustc::util::common::time
  27: rustc_interface::passes::start_codegen
  28: rustc::ty::context::tls::enter_global
  29: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  30: rustc_interface::passes::create_global_ctxt::{{closure}}
  31: rustc_interface::passes::BoxedGlobalCtxt::enter
  32: rustc_interface::queries::Query<T>::compute
  33: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  34: rustc_interface::interface::run_compiler_in_existing_thread_pool
  35: std::thread::local::LocalKey<T>::with
  36: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [const_eval] const-evaluating + checking `get_data`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

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.38.0 (625451e37 2019-09-23) 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
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Sep 27, 2019
@Centril Centril added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Sep 27, 2019
@Centril
Copy link
Contributor

Centril commented Sep 27, 2019

cc @oli-obk

@pnkfelix
Copy link
Member

pnkfelix commented Oct 3, 2019

triage: P-medium. Removing nomination label.

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated labels Oct 3, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@JohnTitor
Copy link
Member

The ICE seems to disappear on latest nightly, could someone confirm it?

@Alexendoo
Copy link
Member

Fixed by #67631, but I believe it could do with a compile test

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 31, 2019
@bors bors closed this as completed in 2039d7e Jan 15, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants