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

struct containing array of size given in Self and slice causes compiler panic #63838

Closed
dbartussek opened this issue Aug 23, 2019 · 2 comments
Closed
Labels
A-associated-items Area: Associated items (types, constants & functions) A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. 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.

Comments

@dbartussek
Copy link

dbartussek commented Aug 23, 2019

A struct containing an array and a reference to a slice causes the compiler to panic if the array size is defined in the impl block.
The issue also occurs for smaller array sizes.

pub struct Memory<'rom> {
    rom: &'rom [u8],
    ram: [u8; Self::SIZE],
}

impl<'rom> Memory<'rom> {
    pub const SIZE: usize = 0x8000;
}

Backtrace for Playground:

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc_mir/borrow_check/nll/universal_regions.rs:741: cannot convert `ReEarlyBound(0, 'rom)` to a region vid

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:650:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.29/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_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::bug_fmt
  16: rustc_mir::borrow_check::nll::universal_regions::UniversalRegionIndices::to_region_vid::{{closure}}
  17: rustc_mir::borrow_check::nll::type_check::constraint_conversion::ConstraintConversion::to_region_vid
  18: rustc_mir::borrow_check::nll::type_check::constraint_conversion::ConstraintConversion::convert_all
  19: rustc_mir::borrow_check::nll::type_check::TypeChecker::fully_perform_op
  20: rustc_mir::borrow_check::nll::type_check::type_check
  21: rustc_mir::borrow_check::nll::compute_regions
  22: rustc_mir::borrow_check::do_mir_borrowck
  23: rustc::ty::context::GlobalCtxt::enter_local
  24: rustc_mir::borrow_check::mir_borrowck
  25: rustc::ty::query::__query_compute::mir_borrowck
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  27: rustc::dep_graph::graph::DepGraph::with_task_impl
  28: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  30: rustc_mir::transform::optimized_mir
  31: rustc::ty::query::__query_compute::optimized_mir
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_mir::interpret::eval_context::InterpretCx<M>::load_mir
  36: rustc_mir::const_eval::const_eval_raw_provider
  37: rustc::ty::query::__query_compute::const_eval_raw
  38: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  39: rustc::dep_graph::graph::DepGraph::with_task_impl
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  41: rustc_mir::const_eval::const_eval_provider
  42: rustc::ty::query::__query_compute::const_eval
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  46: <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_const
  47: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::super_fold_with
  48: <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_ty
  49: rustc::traits::project::normalize
  50: rustc_typeck::check::FnCtxt::normalize_associated_types_in
  51: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  52: rustc::ty::context::GlobalCtxt::enter_local
  53: rustc_typeck::check::wfcheck::check_item_well_formed
  54: rustc::ty::query::__query_compute::check_item_well_formed
  55: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute
  56: rustc::dep_graph::graph::DepGraph::with_task_impl
  57: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  58: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc::hir::itemlikevisit::ParItemLikeVisitor>::visit_item
  59: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:82
  60: rustc_data_structures::sync::par_for_each_in
  61: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:82
  62: rustc::hir::Crate::par_visit_all_item_likes
  63: rustc::util::common::time
  64: rustc_typeck::check_crate
  65: rustc_interface::passes::analysis
  66: rustc::ty::query::__query_compute::analysis
  67: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  68: rustc::dep_graph::graph::DepGraph::with_task_impl
  69: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  70: rustc::ty::context::tls::enter_global
  71: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  72: rustc_interface::passes::create_global_ctxt::{{closure}}
  73: rustc_interface::interface::run_compiler_in_existing_thread_pool
  74: std::thread::local::LocalKey<T>::with
  75: scoped_tls::ScopedKey<T>::set
  76: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [mir_borrowck] processing `Memory::ram::{{constant}}#0`
#1 [optimized_mir] processing `Memory::ram::{{constant}}#0`
 --> src/lib.rs:3:15
  |
3 |     ram: [u8; Self::SIZE],
  |               ^^^^^^^^^^
#2 [const_eval_raw] const-evaluating `Memory::ram::{{constant}}#0`
#3 [const_eval] const-evaluating + checking `Memory::ram::{{constant}}#0`
#4 [check_item_well_formed] processing `Memory`
#5 [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 (eae3437df 2019-08-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C codegen-units=1 --crate-type lib

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

error: Could not compile `playground`.

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

Warnings

No main function was detected, so your code was compiled
but not run. If you’d like to execute your code, please
add a main function.
@jonas-schievink jonas-schievink added A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-associated-items Area: Associated items (types, constants & functions) labels Aug 23, 2019
@dbartussek
Copy link
Author

I found this issue #56445. I think mine may be a duplicate.

@jonas-schievink
Copy link
Contributor

Yup, closing as a duplicate, but thanks for the report!

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 (types, constants & functions) A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. 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.
Projects
None yet
Development

No branches or pull requests

2 participants