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

Compiler panic when using associated constants for array length #52808

Closed
nikolads opened this issue Jul 28, 2018 · 2 comments
Closed

Compiler panic when using associated constants for array length #52808

nikolads opened this issue Jul 28, 2018 · 2 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@nikolads
Copy link

The following code causes a compiler panic:

struct Foo<'a>([&'a (); 2]);

impl<'a> Foo<'a> {
    const LEN: usize = 2;

    fn new() -> Self {
        Foo({
            let arr: [_; Self::LEN] = [&(), &()];
            arr
        })
    }
}

Error:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some(NodeId(15))`,
 right: `None`: free_scope: DefId(0/0:4 ~ rustc_ice[3d2b]::{{impl}}[0]) not recognized by the region scope tree for None / Some(DefId(0/0:6 ~ rustc_ice[3d2b]::{{impl}}[0]::new[0]))', librustc/middle/region.rs:734:13

Using the constant on the right hand side as in let arr = [&(); Self::LEN]; causes the same error.

The lifetimes are required. If I replace the struct with struct Foo([&'static (); 2]) the code compiles fine.

Rustc version: rustc 1.29.0-nightly (6a1c0637c 2018-07-23).
Also panics on 1.27.2-stable.

Backtrace:

stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:479
   6: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:390
   7: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:345
   8: rustc::middle::region::ScopeTree::early_free_scope
   9: rustc::middle::free_region::RegionRelations::is_subregion_of
  10: rustc::infer::lexical_region_resolve::resolve
  11: rustc::infer::InferCtxt::resolve_regions_and_report_errors_inner
  12: rustc_typeck::check::regionck::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::regionck_expr
  13: rustc::ty::context::tls::with_related_context
  14: rustc::infer::InferCtxtBuilder::enter
  15: rustc_typeck::check::typeck_tables_of
  16: rustc::ty::query::__query_compute::typeck_tables_of
  17: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute
  18: rustc::ty::context::tls::with_context
  19: rustc::dep_graph::graph::DepGraph::with_task_impl
  20: rustc::ty::context::tls::with_related_context
  21: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  23: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  24: rustc_mir::interpret::const_eval::const_eval_provider
  25: rustc::ty::query::__query_compute::const_eval
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval<'tcx>>::compute
  27: rustc::ty::context::tls::with_context
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::context::tls::with_related_context
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  32: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const
  33: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  34: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  35: rustc::infer::InferCtxt::partially_normalize_associated_types_in
  36: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::normalize_ty
  37: <(dyn rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o)>::ast_ty_to_ty
  38: <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_local
  39: rustc::hir::intravisit::walk_expr
  40: rustc::hir::intravisit::walk_expr
  41: rustc_typeck::check::check_fn
  42: rustc::ty::context::tls::with_related_context
  43: rustc::infer::InferCtxtBuilder::enter
  44: rustc_typeck::check::typeck_tables_of
  45: rustc::ty::query::__query_compute::typeck_tables_of
  46: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute
  47: rustc::ty::context::tls::with_context
  48: rustc::dep_graph::graph::DepGraph::with_task_impl
  49: rustc::ty::context::tls::with_related_context
  50: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  51: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  52: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  53: rustc_typeck::check::typeck_item_bodies
  54: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_item_bodies<'tcx>>::compute
  55: rustc::ty::context::tls::with_context
  56: rustc::dep_graph::graph::DepGraph::with_task_impl
  57: rustc::ty::context::tls::with_related_context
  58: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  60: rustc::util::common::time
  61: rustc_typeck::check_crate
  62: rustc::ty::context::tls::enter_context
  63: <std::thread::local::LocalKey<T>>::with
  64: rustc::ty::context::TyCtxt::create_and_enter
  65: rustc_driver::driver::compile_input
  66: rustc_driver::run_compiler_with_pool
  67: <scoped_tls::ScopedKey<T>>::set
  68: <scoped_tls::ScopedKey<T>>::set
  69: syntax::with_globals
  70: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  71: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:106
  72: rustc_driver::run
  73: rustc_driver::main
  74: std::rt::lang_start::{{closure}}
  75: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  76: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:106
  77: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  78: main
  79: __libc_start_main
  80: <unknown>
query stack during panic:
#0 [typeck_tables_of] processing `Foo::new::{{constant}}`
#1 [const_eval] const-evaluating `Foo::new::{{constant}}`
#2 [typeck_tables_of] processing `Foo::new`
#3 [typeck_item_bodies] type-checking all item bodies
end of query stack
@huonw
Copy link
Member

huonw commented Sep 5, 2018

Reduced slightly:

struct Foo<'a> { x: &'a () }

impl<'a> Foo<'a> {
    const X: usize = 0;

    fn foo(_: [u8; Self::X]) {}
}


fn main() {}

@memoryruins memoryruins added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 11, 2018
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-NLL Area: Non-lexical lifetimes (NLL) labels Aug 6, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@pnkfelix pnkfelix added A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) and removed A-NLL Area: Non-lexical lifetimes (NLL) labels Nov 14, 2019
@pnkfelix
Copy link
Member

closing as duplicate of #56445 (since I think the latter has more useful info in its comment thread.)

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-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

6 participants