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

ICE when trying to reference an associated trait constant #63496

Closed
jyn514 opened this issue Aug 12, 2019 · 3 comments · Fixed by #65688
Closed

ICE when trying to reference an associated trait constant #63496

jyn514 opened this issue Aug 12, 2019 · 3 comments · Fixed by #65688
Labels
A-associated-items Area: Associated items such as associated types and consts. A-codegen Area: Code generation A-lazy-normalization Area: lazy normalization (tracking issue: #60471) 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. 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

@jyn514
Copy link
Member

jyn514 commented Aug 12, 2019

trait ToBytes {
    const SIZE: usize;

    fn a(self) -> [u8; ToBytes::SIZE];
    // error happens because a previous type error happened I think
    fn b(self) -> [u8; ToBytes::SIZE];
}

Error message

error: internal compiler error: src/librustc/traits/codegen/mod.rs:51: Encountered ambiguity selecting Binder(<[type error] as ToBytes>) during codegen, presuming due to overflow

This only happens if there are two erroneous functions, if I take out b it works fine.

It seems like I was trying to do this wrong in the first place since the first function gives an error error[E0283]: type annotations required: cannot resolve '_: ToBytes'. Not sure what the right way to do this is.

Traceback
error: internal compiler error: src/librustc/traits/codegen/mod.rs:51: Encountered ambiguity selecting `Binder(<[type error] as ToBytes>)` during codegen, presuming due to overflow

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:637:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc::ty::context::GlobalCtxt::enter_local
  15: rustc::traits::codegen::codegen_fulfill_obligation
  16: rustc::ty::query::__query_compute::codegen_fulfill_obligation
  17: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::codegen_fulfill_obligation>::compute
  18: rustc::dep_graph::graph::DepGraph::with_task_impl
  19: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  20: rustc::ty::instance::Instance::resolve
  21: rustc_mir::interpret::eval_context::InterpretCx<M>::resolve
  22: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpretCx<M>>::eval_const_to_op
  23: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpretCx<M>>::run
  24: rustc_mir::const_eval::eval_body_using_ecx
  25: rustc_mir::const_eval::const_eval_raw_provider
  26: rustc::ty::query::__query_compute::const_eval_raw
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  30: rustc_mir::const_eval::const_eval_provider
  31: rustc::ty::query::__query_compute::const_eval
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: <rustc::traits::project::AssociatedTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_const
  36: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::super_fold_with
  37: <rustc::traits::project::AssociatedTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_ty
  38: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  39: rustc::ty::fold::TypeFoldable::fold_with
  40: rustc::traits::project::normalize
  41: rustc_typeck::check::FnCtxt::normalize_associated_types_in
  42: rustc::ty::context::GlobalCtxt::enter_local
  43: rustc_typeck::check::wfcheck::check_associated_item
  44: rustc::ty::query::__query_compute::check_trait_item_well_formed
  45: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_trait_item_well_formed>::compute
  46: rustc::dep_graph::graph::DepGraph::with_task_impl
  47: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  48: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc::hir::itemlikevisit::ParItemLikeVisitor>::visit_trait_item
  49: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:85
  50: rustc_data_structures::sync::par_for_each_in
  51: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:85
  52: rustc::hir::Crate::par_visit_all_item_likes
  53: rustc::util::common::time
  54: rustc_typeck::check_crate
  55: rustc_interface::passes::analysis
  56: rustc::ty::query::__query_compute::analysis
  57: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  58: rustc::dep_graph::graph::DepGraph::with_task_impl
  59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  60: rustc::ty::context::tls::enter_global
  61: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  62: rustc_interface::passes::create_global_ctxt::{{closure}}
  63: rustc_interface::interface::run_compiler_in_existing_thread_pool
  64: std::thread::local::LocalKey<T>::with
  65: scoped_tls::ScopedKey<T>::set
  66: syntax::with_globals
query stack during panic:
#0 [codegen_fulfill_obligation] checking if `ToBytes` fulfills its obligations
#1 [const_eval_raw] const-evaluating `ToBytes::b::{{constant}}#0`
#2 [const_eval] const-evaluating + checking `ToBytes::b::{{constant}}#0`
#3 [check_trait_item_well_formed] processing `ToBytes::b`
#4 [analysis] running analysis passes on this crate
end of query stack

Version

$ rustc --version -v
rustc 1.36.0 (a53f9df32 2019-07-03)
binary: rustc
commit-hash: a53f9df32fbb0b5f4382caaad8f1a46f36ea887c
commit-date: 2019-07-03
host: x86_64-unknown-linux-gnu
release: 1.36.0
LLVM version: 8.0
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items such as associated types and consts. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 12, 2019
@ackxolotl
Copy link

Tried to reduce it and found a similar case with the same ICE:

trait A {
    const C: usize;
    
    fn f() -> ([u8; A::C], [u8; A::C]);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=233300ab42b3986b556a0d38e4d398a5

@jonas-schievink jonas-schievink added A-codegen Area: Code generation I-nominated and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Aug 13, 2019
@nikomatsakis nikomatsakis added the A-lazy-normalization Area: lazy normalization (tracking issue: #60471) label Aug 15, 2019
@nikomatsakis
Copy link
Contributor

Compiler triage: Seems likely to be caused by the need for lazy norm. Marking as p-medium for now.

@nikomatsakis nikomatsakis added P-medium Medium priority and removed I-nominated labels Aug 15, 2019
@JohnTitor
Copy link
Member

The ICE doesn't appear on the latest nightly, marked as E-needstest

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 15, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 22, 2019
Add some tests for fixed ICEs

Fixes rust-lang#41366 from 1.35.0
Fixes rust-lang#51431 from 1.31.0-nightly (77af314 2018-10-11) (on my local)
Fixes rust-lang#52437 from nightly
Fixes rust-lang#63496 from nightly

r? @Centril
@bors bors closed this as completed in c3e5413 Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items such as associated types and consts. A-codegen Area: Code generation A-lazy-normalization Area: lazy normalization (tracking issue: #60471) 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. 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.

5 participants