Skip to content

internal compiler error: unexpected panic #49241

Closed
@bronvic

Description

@bronvic

I get this in the console:

error[E0434]: can't capture dynamic environment in a fn item
  --> sroriqa.rs:24:30
   |
24 |     const dimention: usize = lines.count();
   |                              ^^^^^
   |
   = help: use the `|| { ... }` closure form instead

thread 'rustc' panicked at 'LocalTableInContext: key not found', libcore/option.rs:916:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

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.26.0-nightly (75af15ee6 2018-03-20) running on x86_64-unknown-linux-gnu

Here is my code:

use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::error::Error;

fn main() {
    let path = Path::new("input");
    let display = path.display();

    let mut file = match File::open(&path) {
        Err(why) => panic!("couldn't open {}: {}", display, why.description()),
        Ok(file) => file,
    };

    let mut contents = String::new();
    match file.read_to_string(&mut contents) {
        Err(why) => panic!("couldn't read {}: {}", display, why.description()),
        Ok(_) => println!("\"{}\" contains:\n{}", display, contents),
    };

    // Files can end with empty string
    // Remove it and all empty strings that can appear by accident to calculate correct dimension of matrix
    let lines = contents.lines().filter(|x| !x.is_empty());
    const dimention: usize = lines.count();

    println!("Dimention: {:?}", dimention);

    let lines: [str; dimention] = lines.collect();

    for line in lines {
        println!("Line: {}", line);
    }
}

Meta

rustc --version --verbose
rustc 1.26.0-nightly (75af15ee6 2018-03-20)
binary: rustc
commit-hash: 75af15ee6ca0c12b699a17984b033363cd25e9c3
commit-date: 2018-03-20
host: x86_64-unknown-linux-gnu
release: 1.26.0-nightly
LLVM version: 6.0

Backtrace:

error[E0434]: can't capture dynamic environment in a fn item
  --> sroriqa.rs:24:30
   |
24 |     const dimention: usize = lines.count();
   |                              ^^^^^
   |
   = help: use the `|| { ... }` closure form instead

thread 'rustc' panicked at 'LocalTableInContext: key not found', libcore/option.rs:916:5
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:207
   3: std::panicking::default_hook
             at libstd/panicking.rs:223
   4: core::ops::function::Fn::call
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:403
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:349
   7: rust_begin_unwind
             at libstd/panicking.rs:325
   8: core::panicking::panic_fmt
             at libcore/panicking.rs:72
   9: core::option::expect_failed
             at libcore/option.rs:916
  10: <rustc::ty::context::LocalTableInContext<'a, V> as core::ops::index::Index<rustc::hir::HirId>>::index
  11: <rustc_passes::rvalue_promotion::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  12: <rustc_passes::rvalue_promotion::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_nested_body
  13: rustc_passes::rvalue_promotion::rvalue_promotable_map
  14: rustc::dep_graph::graph::DepGraph::with_task_impl
  15: rustc_errors::Handler::track_diagnostics
  16: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  17: rustc::ty::maps::<impl rustc::ty::maps::queries::rvalue_promotable_map<'tcx>>::force
  18: rustc::ty::maps::<impl rustc::ty::maps::queries::rvalue_promotable_map<'tcx>>::try_get
  19: rustc::ty::maps::TyCtxtAt::rvalue_promotable_map
  20: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::rvalue_promotable_map
  21: rustc_passes::rvalue_promotion::const_is_rvalue_promotable_to_static
  22: rustc::dep_graph::graph::DepGraph::with_task_impl
  23: rustc_errors::Handler::track_diagnostics
  24: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  25: rustc::ty::maps::<impl rustc::ty::maps::queries::const_is_rvalue_promotable_to_static<'tcx>>::force
  26: rustc::ty::maps::<impl rustc::ty::maps::queries::const_is_rvalue_promotable_to_static<'tcx>>::try_get
  27: rustc::ty::maps::TyCtxtAt::const_is_rvalue_promotable_to_static
  28: <rustc_passes::rvalue_promotion::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  29: <rustc_passes::rvalue_promotion::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_nested_body
  30: rustc_passes::rvalue_promotion::rvalue_promotable_map
  31: rustc::dep_graph::graph::DepGraph::with_task_impl
  32: rustc_errors::Handler::track_diagnostics
  33: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  34: rustc::ty::maps::<impl rustc::ty::maps::queries::rvalue_promotable_map<'tcx>>::force
  35: rustc::ty::maps::<impl rustc::ty::maps::queries::rvalue_promotable_map<'tcx>>::try_get
  36: rustc::ty::maps::TyCtxtAt::rvalue_promotable_map
  37: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::rvalue_promotable_map
  38: rustc_borrowck::borrowck::gather_loans::gather_loans_in_fn
  39: rustc_borrowck::borrowck::borrowck
  40: rustc::dep_graph::graph::DepGraph::with_task_impl
  41: rustc_errors::Handler::track_diagnostics
  42: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  43: rustc::ty::maps::<impl rustc::ty::maps::queries::borrowck<'tcx>>::force
  44: rustc::ty::maps::<impl rustc::ty::maps::queries::borrowck<'tcx>>::try_get
  45: rustc::ty::maps::TyCtxtAt::borrowck
  46: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::borrowck
  47: rustc_mir::transform::optimized_mir
  48: rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::compute_result
  49: rustc::dep_graph::graph::DepGraph::with_task_impl
  50: rustc_errors::Handler::track_diagnostics
  51: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  52: rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::force
  53: rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::try_get
  54: rustc::ty::maps::TyCtxtAt::optimized_mir
  55: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::maybe_optimized_mir
  56: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::load_mir
  57: rustc_mir::interpret::const_eval::eval_body_and_ecx
  58: rustc_mir::interpret::const_eval::const_eval_provider
  59: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::compute_result
  60: rustc::dep_graph::graph::DepGraph::with_task_impl
  61: rustc_errors::Handler::track_diagnostics
  62: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  63: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::force
  64: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  65: rustc::ty::maps::TyCtxtAt::const_eval
  66: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const
  67: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  68: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  69: rustc::traits::project::normalize
  70: rustc::infer::InferCtxt::partially_normalize_associated_types_in
  71: <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::normalize_ty
  72: <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::ast_ty_to_ty
  73: <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_local
  74: rustc::hir::intravisit::walk_expr
  75: rustc_typeck::check::check_fn
  76: rustc::ty::context::tls::enter
  77: rustc::infer::InferCtxtBuilder::enter
  78: rustc_typeck::check::typeck_tables_of
  79: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::compute_result
  80: rustc::dep_graph::graph::DepGraph::with_task_impl
  81: rustc_errors::Handler::track_diagnostics
  82: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  83: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force
  84: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  85: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  86: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  87: rustc::session::Session::track_errors
  88: rustc_typeck::check::typeck_item_bodies
  89: rustc::dep_graph::graph::DepGraph::with_task_impl
  90: rustc_errors::Handler::track_diagnostics
  91: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  92: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::force
  93: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get
  94: rustc::ty::maps::TyCtxtAt::typeck_item_bodies
  95: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies
  96: rustc_typeck::check_crate
  97: <std::thread::local::LocalKey<T>>::with
  98: <std::thread::local::LocalKey<T>>::with
  99: rustc::ty::context::TyCtxt::create_and_enter

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.26.0-nightly (75af15ee6 2018-03-20) running on x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions