Skip to content

ICE when passing slice with const eval length to method #54038

Closed
@XOSplicer

Description

@XOSplicer

I tried this code:

struct Foo<'a> {
    data: &'a [u8],
}

impl<'a> Foo<'a> {
    const LEN: usize = 4;
    fn bar(buf: &mut [u8; Self::LEN]) {
        unimplemented!()
    }
}

I expected a successful compile, however rustc panicked.
Without the lifetime annotation (only struct Foo;) the panic does not happen and it compiles successfully.

Meta

rust version: rustc 1.28.0 (9634041 2018-07-30) running on x86_64-unknown-linux-gnu

playground link: https://play.rust-lang.org/?gist=4f897c3fc9de85f853b16cc0a8c2b562&version=stable&mode=debug&edition=2015

Backtrace:

   Compiling playground v0.0.1 (file:///playground)
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some(NodeId(13))`,
 right: `None`: free_scope: DefId(0/0:4 ~ playground[a256]::{{impl}}[0]) not recognized by the region scope tree for None / Some(DefId(0/0:6 ~ playground[a256]::{{impl}}[0]::bar[0]))', librustc/middle/region.rs:734:13
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:515
   6: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:426
   7: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:413
   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::dep_graph::graph::DepGraph::with_task_impl
  19: rustc::ty::context::tls::with_related_context
  20: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  21: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  22: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  23: rustc_mir::interpret::const_eval::const_eval_provider
  24: rustc::ty::query::__query_compute::const_eval
  25: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval<'tcx>>::compute
  26: rustc::dep_graph::graph::DepGraph::with_task_impl
  27: rustc::ty::context::tls::with_related_context
  28: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  30: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const
  31: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  32: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  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_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
  36: rustc::ty::fold::TypeFoldable::fold_with
  37: rustc::traits::project::normalize
  38: rustc::infer::InferCtxt::partially_normalize_associated_types_in
  39: rustc::ty::context::tls::with_related_context
  40: rustc::infer::InferCtxtBuilder::enter
  41: rustc_typeck::check::wfcheck::check_associated_item
  42: rustc_typeck::check::wfcheck::check_impl_item
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::check_impl_item_well_formed<'tcx>>::compute
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::context::tls::with_related_context
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  47: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  48: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  49: rustc::hir::Crate::visit_all_item_likes
  50: rustc::session::Session::track_errors
  51: rustc::util::common::time
  52: rustc_typeck::check_crate
  53: rustc::ty::context::tls::enter_context
  54: <std::thread::local::LocalKey<T>>::with
  55: rustc::ty::context::TyCtxt::create_and_enter
  56: rustc_driver::driver::compile_input
  57: rustc_driver::run_compiler_with_pool
  58: <scoped_tls::ScopedKey<T>>::set
  59: syntax::with_globals
  60: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  61: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  62: rustc_driver::run
  63: rustc_driver::main
  64: std::rt::lang_start::{{closure}}
  65: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  66: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  67: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  68: main
  69: __libc_start_main
  70: <unknown>
query stack during panic:
#0 [typeck_tables_of] processing `Foo::bar::{{constant}}`
#1 [const_eval] const-evaluating `Foo::bar::{{constant}}`
#2 [check_impl_item_well_formed] processing `Foo::bar`
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.28.0 (9634041f0 2018-07-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-type-systemArea: Type systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions